38 */ 39 @SuppressWarnings("serial") // JDK-implementation class 40 public class SortArrowIcon implements Icon, UIResource, Serializable { 41 // Height of the arrow, the width is ARROW_HEIGHT 42 private static final int ARROW_HEIGHT = 5; 43 44 // Amount of pad to left of arrow 45 private static final int X_PADDING = 7; 46 47 // Sort direction 48 private boolean ascending; 49 50 // The Color to use, may be null indicating colorKey should be used 51 private Color color; 52 53 // If non-null indicates the color should come from the UIManager with 54 // this key. 55 private String colorKey; 56 57 /** 58 * Creates a <code>SortArrowIcon</code>. 59 * 60 * @param ascending if true, icon respresenting ascending sort, otherwise 61 * descending 62 * @param color the color to render the icon 63 */ 64 public SortArrowIcon(boolean ascending, Color color) { 65 this.ascending = ascending; 66 this.color = color; 67 if (color == null) { 68 throw new IllegalArgumentException(); 69 } 70 } 71 72 /** 73 * Creates a <code>SortArrowIcon</code>. 74 * 75 * @param ascending if true, icon respresenting ascending sort, otherwise 76 * descending 77 * @param colorKey the key used to find color in UIManager 78 */ 79 public SortArrowIcon(boolean ascending, String colorKey) { 80 this.ascending = ascending; 81 this.colorKey = colorKey; 82 if (colorKey == null) { 83 throw new IllegalArgumentException(); 84 } 85 } 86 87 public void paintIcon(Component c, Graphics g, int x, int y) { 88 g.setColor(getColor()); 89 int startX = X_PADDING + x + ARROW_HEIGHT / 2; 90 if (ascending) { 91 int startY = y; 92 g.fillRect(startX, startY, 1, 1); 93 for (int line = 1; line < ARROW_HEIGHT; line++) { | 38 */ 39 @SuppressWarnings("serial") // JDK-implementation class 40 public class SortArrowIcon implements Icon, UIResource, Serializable { 41 // Height of the arrow, the width is ARROW_HEIGHT 42 private static final int ARROW_HEIGHT = 5; 43 44 // Amount of pad to left of arrow 45 private static final int X_PADDING = 7; 46 47 // Sort direction 48 private boolean ascending; 49 50 // The Color to use, may be null indicating colorKey should be used 51 private Color color; 52 53 // If non-null indicates the color should come from the UIManager with 54 // this key. 55 private String colorKey; 56 57 /** 58 * Creates a {@code SortArrowIcon}. 59 * 60 * @param ascending if true, icon respresenting ascending sort, otherwise 61 * descending 62 * @param color the color to render the icon 63 */ 64 public SortArrowIcon(boolean ascending, Color color) { 65 this.ascending = ascending; 66 this.color = color; 67 if (color == null) { 68 throw new IllegalArgumentException(); 69 } 70 } 71 72 /** 73 * Creates a {@code SortArrowIcon}. 74 * 75 * @param ascending if true, icon respresenting ascending sort, otherwise 76 * descending 77 * @param colorKey the key used to find color in UIManager 78 */ 79 public SortArrowIcon(boolean ascending, String colorKey) { 80 this.ascending = ascending; 81 this.colorKey = colorKey; 82 if (colorKey == null) { 83 throw new IllegalArgumentException(); 84 } 85 } 86 87 public void paintIcon(Component c, Graphics g, int x, int y) { 88 g.setColor(getColor()); 89 int startX = X_PADDING + x + ARROW_HEIGHT / 2; 90 if (ascending) { 91 int startY = y; 92 g.fillRect(startX, startY, 1, 1); 93 for (int line = 1; line < ARROW_HEIGHT; line++) { |