Coverage Report - wjhk.jupload2.gui.filepanel.SortArrowIcon
 
Classes in this File Line Coverage Branch Coverage Complexity
SortArrowIcon
19 %
5/26
0 %
0/3
1,5
 
 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  3
     protected int width = 8;
 54  
 
 55  3
     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  3
     public SortArrowIcon(int direction) {
 64  3
         this.direction = direction;
 65  3
     }
 66  
 
 67  
     /**
 68  
      * @see javax.swing.Icon#getIconWidth()
 69  
      */
 70  
     public int getIconWidth() {
 71  0
         return this.width;
 72  
     }
 73  
 
 74  
     /**
 75  
      * @see javax.swing.Icon#getIconHeight()
 76  
      */
 77  
     public int getIconHeight() {
 78  0
         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  0
         final Color bg = c.getBackground();
 87  0
         final Color light = bg.brighter().brighter();
 88  0
         final Color shade = bg.darker().darker();
 89  
 
 90  0
         final int w = this.width;
 91  0
         final int h = this.height;
 92  0
         final int m = w / 2;
 93  0
         switch (this.direction) {
 94  
             case ASCENDING:
 95  0
                 g.setColor(shade);
 96  0
                 g.drawLine(x, y, x + w, y);
 97  0
                 g.drawLine(x, y, x + m, y + h);
 98  0
                 g.setColor(light);
 99  0
                 g.drawLine(x + w, y, x + m, y + h);
 100  0
                 break;
 101  
             case DESCENDING:
 102  0
                 g.setColor(shade);
 103  0
                 g.drawLine(x + m, y, x, y + h);
 104  0
                 g.setColor(light);
 105  0
                 g.drawLine(x, y + h, x + w, y + h);
 106  0
                 g.drawLine(x + m, y, x + w, y + h);
 107  
                 break;
 108  
         }
 109  0
     }
 110  
 }