1 7 8 package org.jdesktop.swing.icon; 9 10 import java.awt.Color ; 11 import java.awt.Component ; 12 import java.awt.Graphics ; 13 14 import javax.swing.Icon ; 15 16 public class SortArrowIcon implements Icon { 17 private boolean ascending = true; 18 private int width = 8; 20 private int height = 8; 21 22 public SortArrowIcon(boolean ascending) { 23 this.ascending = ascending; 24 } 25 26 public int getIconWidth() { 27 return width; 28 } 29 30 public int getIconHeight() { 31 return height; 32 } 33 34 public void paintIcon(Component c, Graphics g, int x, int y) { 35 Color base = c.getBackground(); 36 Color shadow = base.darker().darker(); 37 Color highlight = Color.white; 38 39 if (ascending) { 40 g.setColor(shadow); 41 int y1 = height-1; 42 for(int x1=0; x1 < width/2 ; x1++) { 43 g.drawLine(x + x1, y + y1, x + x1, y + y1 - 1); 44 y1 -= ((x1+1 == (width/2)-1)? 1 : 2); 45 } 46 g.setColor(highlight); 47 y1 = height-1; 48 for (int x1 = width-1; x1 >= width / 2; x1--) { 49 g.drawLine(x + x1, y + y1, x + x1, y + y1 - 1); 50 y1 -= ( (x1 - 1 == (width / 2)) ? 1 : 2); 51 } 52 g.drawLine(x + 1, y + height-1, x + width - 1, y + height-1); 53 } else { 54 g.setColor(shadow); 56 int y1 = 1; 57 for (int x1 = 0; x1 < width/2 ; x1++) { 58 g.drawLine(x + x1, y + y1, x + x1, y + y1 + 1); 59 y1 += (x1+1 == (width/2-1))? 1 : 2; 60 } 61 g.setColor(highlight); 62 y1 = 1; 63 for (int x1 = width - 1; x1 >= width/2; x1--) { 64 g.drawLine(x + x1, y + y1, x + x1, y + y1 + 1); 65 y1 += (x1-1 == width/2)? 1 : 2; 66 } 67 g.setColor(shadow); 68 g.drawLine(x + 1, y + 1, x + width - 1, y + 1); 69 } 70 } 71 } 72 | Popular Tags |