1 /*
   2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.swing.plaf.windows;
  26 
  27 import java.awt.Color;
  28 import java.awt.Component;
  29 import java.awt.Graphics;
  30 import java.io.Serializable;
  31 import javax.swing.Icon;
  32 import javax.swing.UIManager;
  33 import javax.swing.plaf.UIResource;
  34 
  35 /**
  36  * Classic sort icons.
  37  *
  38  */
  39 public class ClassicSortArrowIcon implements Icon, UIResource, Serializable{
  40     private static final int X_OFFSET = 9;
  41     private boolean ascending;
  42 
  43     public ClassicSortArrowIcon(boolean ascending) {
  44         this.ascending = ascending;
  45     }
  46 
  47     public void paintIcon(Component c, Graphics g, int x, int y) {
  48         x += X_OFFSET;
  49         if (ascending) {
  50             g.setColor(UIManager.getColor("Table.sortIconHighlight"));
  51             drawSide(g, x + 3, y, -1);
  52 
  53             g.setColor(UIManager.getColor("Table.sortIconLight"));
  54             drawSide(g, x + 4, y, 1);
  55 
  56             g.fillRect(x + 1, y + 6, 6, 1);
  57         }
  58         else {
  59             g.setColor(UIManager.getColor("Table.sortIconHighlight"));
  60             drawSide(g, x + 3, y + 6, -1);
  61             g.fillRect(x + 1, y, 6, 1);
  62 
  63             g.setColor(UIManager.getColor("Table.sortIconLight"));
  64             drawSide(g, x + 4, y + 6, 1);
  65         }
  66     }
  67 
  68     private void drawSide(Graphics g, int x, int y, int xIncrement) {
  69         int yIncrement = 2;
  70         if (ascending) {
  71             g.fillRect(x, y, 1, 2);
  72             y++;
  73         }
  74         else {
  75             g.fillRect(x, --y, 1, 2);
  76             yIncrement = -2;
  77             y -= 2;
  78         }
  79         x += xIncrement;
  80         for (int i = 0; i < 2; i++) {
  81             g.fillRect(x, y, 1, 3);
  82             x += xIncrement;
  83             y += yIncrement;
  84         }
  85         if (!ascending) {
  86             y++;
  87         }
  88         g.fillRect(x, y, 1, 2);
  89     }
  90 
  91     public int getIconWidth() {
  92         return X_OFFSET + 8;
  93     }
  94     public int getIconHeight() {
  95         return 9;
  96     }
  97 }