1 // 2 // $Id: SortArrowIcon.java 95 2007-05-02 03:27:05Z 3 // /C=DE/ST=Baden-Wuerttemberg/O=ISDN4Linux/OU=Fritz 4 // Elfert/CN=svn-felfert@isdn4linux.de/emailAddress=fritz@fritz-elfert.de $ 5 // 6 // jupload - A file upload applet. 7 // Copyright 2007 The JUpload Team 8 // 9 // Created: ? 10 // Creator: William JinHua Kwong 11 // Last modified: $Date: 2015-03-10 20:59:42 +0100 (mar., 10 mars 2015) $ 12 // 13 // This program is free software; you can redistribute it and/or modify it under 14 // the terms of the GNU General Public License as published by the Free Software 15 // Foundation; either version 2 of the License, or (at your option) any later 16 // version. This program is distributed in the hope that it will be useful, but 17 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 19 // details. You should have received a copy of the GNU General Public License 20 // along with this program; if not, write to the Free Software Foundation, Inc., 21 // 675 Mass Ave, Cambridge, MA 02139, USA. 22 23 package wjhk.jupload2.gui.filepanel; 24 25 import java.awt.Color; 26 import java.awt.Component; 27 import java.awt.Graphics; 28 29 import javax.swing.Icon; 30 31 /** 32 * Icon implementation, to control and indicate the current sort order, into the 33 * {@link wjhk.jupload2.gui.filepanel.FilePanelJFlatTable}. 34 */ 35 public class SortArrowIcon implements Icon { 36 /** 37 * Don't draw an arrow. 38 */ 39 public static final int NONE = 0; 40 41 /** 42 * Draw arrow, representing descending sort order. 43 */ 44 public static final int DESCENDING = 1; 45 46 /** 47 * Draw arrow, representing ascending sort order. 48 */ 49 public static final int ASCENDING = 2; 50 51 protected int direction; 52 53 protected int width = 8; 54 55 protected int height = 8; 56 57 /** 58 * Creates a new instance. 59 * 60 * @param direction The desired direction, either {@link #ASCENDING}, 61 * {@link #DESCENDING} or {@link #NONE} 62 */ 63 public SortArrowIcon(int direction) { 64 this.direction = direction; 65 } 66 67 /** 68 * @see javax.swing.Icon#getIconWidth() 69 */ 70 public int getIconWidth() { 71 return this.width; 72 } 73 74 /** 75 * @see javax.swing.Icon#getIconHeight() 76 */ 77 public int getIconHeight() { 78 return this.height; 79 } 80 81 /** 82 * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics, 83 * int, int) 84 */ 85 public void paintIcon(Component c, Graphics g, int x, int y) { 86 final Color bg = c.getBackground(); 87 final Color light = bg.brighter().brighter(); 88 final Color shade = bg.darker().darker(); 89 90 final int w = this.width; 91 final int h = this.height; 92 final int m = w / 2; 93 switch (this.direction) { 94 case ASCENDING: 95 g.setColor(shade); 96 g.drawLine(x, y, x + w, y); 97 g.drawLine(x, y, x + m, y + h); 98 g.setColor(light); 99 g.drawLine(x + w, y, x + m, y + h); 100 break; 101 case DESCENDING: 102 g.setColor(shade); 103 g.drawLine(x + m, y, x, y + h); 104 g.setColor(light); 105 g.drawLine(x, y + h, x + w, y + h); 106 g.drawLine(x + m, y, x + w, y + h); 107 break; 108 } 109 } 110 }