1   package org.wcb.gui.component;
2   
3   import javax.swing.Icon;
4   import java.awt.Color;
5   import java.awt.Graphics;
6   import java.awt.Component;
7   
8   /**
9    * <small>
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23   * <p/>
24   * $File:  $ <br>
25   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 29, 2006 4:03:35 PM $ <br>
26   * </small>
27   *
28   * @author jonnathan simmon
29   * @version 1
30   *          Date: Mar 29, 2006
31   *          Time: 4:03:35 PM
32   */
33  
34  public class TriangleSquareCornerWindowIcon implements Icon {
35  
36      //RGB values discovered using ZoomIn
37      private static final Color THREE_D_EFFECT_COLOR = new Color(255, 255, 255);
38      private static final Color SQUARE_COLOR_LEFT = new Color(184, 180, 163);
39      private static final Color SQUARE_COLOR_TOP_RIGHT = new Color(184, 180, 161);
40      private static final Color SQUARE_COLOR_BOTTOM_RIGHT = new Color(184, 181, 161);
41  
42      //Dimensions
43      private static final int WIDTH = 12;
44      private static final int HEIGHT = 12;
45  
46      /**
47       * The image height.
48       * @return  height
49       */
50      public int getIconHeight() {
51          return WIDTH;
52      }
53  
54      /**
55       * the image width.
56       * @return width.
57       */
58      public int getIconWidth() {
59          return HEIGHT;
60      }
61  
62      /**
63       * Reference to painting component.
64       * @param c component
65       * @param g graphics object.
66       * @param x x coord.
67       * @param y y coord.
68       */
69      public void paintIcon(Component c, Graphics g, int x, int y) {
70  
71          //Layout a row and column "grid"
72          int firstRow = 0;
73          int firstColumn = 0;
74          int rowDiff = 4;
75          int columnDiff = 4;
76  
77          int secondRow = firstRow + rowDiff;
78          int secondColumn = firstColumn + columnDiff;
79          int thirdRow = secondRow + rowDiff;
80          int thirdColumn = secondColumn + columnDiff;
81  
82  
83          //Draw the white squares first, so the gray squares will overlap
84          draw3dSquare(g, firstColumn + 1, thirdRow + 1);
85  
86          draw3dSquare(g, secondColumn + 1, secondRow + 1);
87          draw3dSquare(g, secondColumn + 1, thirdRow + 1);
88  
89          draw3dSquare(g, thirdColumn + 1, firstRow + 1);
90          draw3dSquare(g, thirdColumn + 1, secondRow + 1);
91          draw3dSquare(g, thirdColumn + 1, thirdRow + 1);
92  
93          //draw the gray squares overlapping the white background squares
94          drawSquare(g, firstColumn, thirdRow);
95  
96          drawSquare(g, secondColumn, secondRow);
97          drawSquare(g, secondColumn, thirdRow);
98  
99          drawSquare(g, thirdColumn, firstRow);
100         drawSquare(g, thirdColumn, secondRow);
101         drawSquare(g, thirdColumn, thirdRow);
102 
103     }
104 
105     /**
106      * Painting 3d square.
107      * @param g Graphics reference.
108      * @param x x coord.
109      * @param y y coord.
110      */
111     private void draw3dSquare(Graphics g, int x, int y) {
112         Color oldColor = g.getColor(); //cache the old color
113         g.setColor(THREE_D_EFFECT_COLOR); //set the white color
114         g.fillRect(x, y, 2, 2); //draw the square
115         g.setColor(oldColor); //reset the old color
116     }
117 
118      /**
119      * Painting square.
120      * @param g Graphics reference.
121      * @param x x coord.
122      * @param y y coord.
123      */
124     private void drawSquare(Graphics g, int x, int y) {
125         Color oldColor = g.getColor();
126         g.setColor(SQUARE_COLOR_LEFT);
127         g.drawLine(x, y, x, y + 1);
128         g.setColor(SQUARE_COLOR_TOP_RIGHT);
129         g.drawLine(x + 1, y, x + 1, y);
130         g.setColor(SQUARE_COLOR_BOTTOM_RIGHT);
131         g.drawLine(x + 1, y + 1, x + 1, y + 1);
132         g.setColor(oldColor);
133     }
134 
135 }