View Javadoc

1   // %1126721046026:hoplugins.commons.ui.sorter%
2   /*
3    * Created on 7-apr-2005
4    *
5    * To change the template for this generated file go to
6    * Window>Preferences>Java>Code Generation>Code and Comments
7    */
8   package hoplugins.commons.ui.sorter;
9   
10  import javax.swing.Icon;
11  
12  import java.awt.Color;
13  import java.awt.Component;
14  import java.awt.Graphics;
15  
16  /***
17   * DOCUMENT ME!
18   *
19   * @author
20   */
21  class Arrow implements Icon {
22      private boolean descending;
23      private int priority;
24      private int size;
25  
26      /***
27       * Creates a new Arrow object.
28       *
29       * @param descending
30       * @param size
31       * @param priority
32       */
33      public Arrow(boolean descending, int size, int priority) {
34          this.descending = descending;
35          this.size = size;
36          this.priority = priority;
37      }
38  
39      /***
40       * DOCUMENT ME!
41       *
42       * @return
43       */
44      public int getIconHeight() {
45          return size;
46      }
47  
48      /***
49       * DOCUMENT ME!
50       *
51       * @return
52       */
53      public int getIconWidth() {
54          return size;
55      }
56  
57      /***
58       * DOCUMENT ME!
59       *
60       * @param c
61       * @param g
62       * @param x
63       * @param y
64       */
65      public void paintIcon(Component c, Graphics g, int x, int y) {
66          Color color = (c == null) ? Color.GRAY : c.getBackground();
67  
68          // In a compound sort, make each succesive triangle 20% 
69          // smaller than the previous one. 
70          int dx = (int) (size / 2 * Math.pow(0.8, priority));
71          int dy = descending ? dx : (-dx);
72  
73          // Align icon (roughly) with font baseline. 
74          y = y + ((5 * size) / 6) + (descending ? (-dy) : 0);
75  
76          int shift = descending ? 1 : (-1);
77  
78          g.translate(x, y);
79  
80          // Right diagonal. 
81          g.setColor(color.darker());
82          g.drawLine(dx / 2, dy, 0, 0);
83          g.drawLine(dx / 2, dy + shift, 0, shift);
84  
85          // Left diagonal. 
86          g.setColor(color.brighter());
87          g.drawLine(dx / 2, dy, dx, 0);
88          g.drawLine(dx / 2, dy + shift, dx, shift);
89  
90          // Horizontal line. 
91          if (descending) {
92              g.setColor(color.darker().darker());
93          }
94          else {
95              g.setColor(color.brighter().brighter());
96          }
97  
98          g.drawLine(dx, 0, 0, 0);
99  
100         g.setColor(color);
101         g.translate(-x, -y);
102     }
103 }