KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > TriangleSquareWindowsCornerIcon


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.gui.base;
19
20 import java.awt.Color JavaDoc;
21 import java.awt.Component JavaDoc;
22 import java.awt.Graphics JavaDoc;
23
24 import javax.swing.Icon JavaDoc;
25
26 public class TriangleSquareWindowsCornerIcon implements Icon JavaDoc {
27
28     //RGB values discovered using ZoomIn
29
private static final Color JavaDoc THREE_D_EFFECT_COLOR = new Color JavaDoc(255, 255, 255);
30     private static final Color JavaDoc SQUARE_COLOR_LEFT = new Color JavaDoc(184, 180, 163);
31     private static final Color JavaDoc SQUARE_COLOR_TOP_RIGHT = new Color JavaDoc(184, 180, 161);
32     private static final Color JavaDoc SQUARE_COLOR_BOTTOM_RIGHT = new Color JavaDoc(184, 181, 161);
33
34     //Dimensions
35
private static final int WIDTH = 12;
36     private static final int HEIGHT = 12;
37
38
39
40     public int getIconHeight() {
41         return WIDTH;
42     }
43
44     public int getIconWidth() {
45         return HEIGHT;
46     }
47
48     public void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y) {
49
50         //Layout a row and column "grid"
51
int firstRow = 0;
52         int firstColumn = 0;
53         int rowDiff = 4;
54         int columnDiff = 4;
55
56         int secondRow = firstRow + rowDiff;
57         int secondColumn = firstColumn + columnDiff;
58         int thirdRow = secondRow + rowDiff;
59         int thirdColumn = secondColumn + columnDiff;
60
61
62         //Draw the white squares first, so the gray squares will overlap
63
draw3dSquare(g, firstColumn+1, thirdRow+1);
64
65         draw3dSquare(g, secondColumn+1, secondRow+1);
66         draw3dSquare(g, secondColumn+1, thirdRow+1);
67
68         draw3dSquare(g, thirdColumn+1, firstRow+1);
69         draw3dSquare(g, thirdColumn+1, secondRow+1);
70         draw3dSquare(g, thirdColumn+1, thirdRow+1);
71
72         //draw the gray squares overlapping the white background squares
73
drawSquare(g, firstColumn, thirdRow);
74
75         drawSquare(g, secondColumn, secondRow);
76         drawSquare(g, secondColumn, thirdRow);
77
78         drawSquare(g, thirdColumn, firstRow);
79         drawSquare(g, thirdColumn, secondRow);
80         drawSquare(g, thirdColumn, thirdRow);
81
82     }
83
84     private void draw3dSquare(Graphics JavaDoc g, int x, int y){
85         Color JavaDoc oldColor = g.getColor(); //cache the old color
86
g.setColor(THREE_D_EFFECT_COLOR); //set the white color
87
g.fillRect(x,y,2,2); //draw the square
88
g.setColor(oldColor); //reset the old color
89
}
90
91
92     private void drawSquare(Graphics JavaDoc g, int x, int y){
93         Color JavaDoc oldColor = g.getColor();
94         g.setColor(SQUARE_COLOR_LEFT);
95         g.drawLine(x,y, x,y+1);
96         g.setColor(SQUARE_COLOR_TOP_RIGHT);
97         g.drawLine(x+1,y, x+1,y);
98         g.setColor(SQUARE_COLOR_BOTTOM_RIGHT);
99         g.drawLine(x+1,y+1, x+1,y+1);
100         g.setColor(oldColor);
101     }
102
103 }
Popular Tags