KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > images > ImageFactory


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.images;
15
16 import java.awt.*;
17 import java.awt.image.*;
18 import javax.swing.*;
19 import javax.swing.plaf.*;
20 import java.net.*;
21 import org.compiere.util.*;
22 import org.compiere.plaf.*;
23
24 /**
25  * Icon Factory based on Metal Color Schema (Themes are automatically considered)
26  *
27  * @author Jorg Janke
28  * @version $Id: ImageFactory.java,v 1.6 2002/03/14 02:45:52 jjanke Exp $
29  */

30 public class ImageFactory
31 {
32     /**
33      * Get Image Icon or null if not exists
34      * @param name file name in org.compiere.images
35      * @return image
36      */

37     public static ImageIcon getImageIcon (String JavaDoc name)
38     {
39         URL url = org.compiere.Compiere.class.getResource("images/" + name);
40         if (url == null)
41         {
42             Log.error("ImageFactory.getImageIcon - not found: " + name);
43             return null;
44         }
45         return new ImageIcon(url);
46     } // getImageIcon
47

48     /** Home Icon ************************************************************/
49     private static Icon s_HomeIcon = null;
50
51     /**
52      * Get Home Icon (little house) 18*18
53      * @return image
54      */

55     public static Icon getHomeIcon()
56     {
57         if (s_HomeIcon == null)
58             s_HomeIcon = new HomeIcon();
59         return s_HomeIcon;
60     } // getHomeIcon
61

62     /**
63      * 18*18 Home Icon
64      */

65     private static class HomeIcon implements Icon, UIResource
66     {
67         public void paintIcon(Component c, Graphics g, int x, int y)
68         {
69             g.translate(x, y);
70             // Draw outside edge of house
71
g.setColor(CompiereLookAndFeel.getControlInfo()); // black
72
g.drawLine(8,1, 1,8); // left edge of roof
73
g.drawLine(8,1, 15,8); // right edge of roof
74
g.drawLine(11,2, 11,3); // left edge of chimney
75
g.drawLine(12,2, 12,4); // right edge of chimney
76
g.drawLine(3,7, 3,15); // left edge of house
77
g.drawLine(13,7, 13,15); // right edge of house
78
g.drawLine(4,15, 12,15); // bottom edge of house
79
// Draw door frame
80
// same color as edge of house
81
g.drawLine( 6,9, 6,14); // left
82
g.drawLine(10,9, 10,14); // right
83
g.drawLine( 7,9, 9, 9); // top
84
// Draw roof body
85
g.setColor(CompiereLookAndFeel.getControlDarkShadow()); // secondary1
86
g.fillRect(8,2, 1,1); //top toward bottom
87
g.fillRect(7,3, 3,1);
88             g.fillRect(6,4, 5,1);
89             g.fillRect(5,5, 7,1);
90             g.fillRect(4,6, 9,2);
91             // Draw doornob
92
// same color as roof body
93
g.drawLine(9,12, 9,12);
94             // Paint the house
95
g.setColor(CompiereLookAndFeel.getPrimaryControl()); // primary3
96
g.drawLine(4,8, 12,8); // above door
97
g.fillRect(4,9, 2,6); // left of door
98
g.fillRect(11,9, 2,6); // right of door
99
g.translate(-x, -y);
100         }
101         public int getIconWidth()
102         {
103             return 18;
104         }
105         public int getIconHeight()
106         {
107             return 18;
108         }
109     } // HomeIcon
110

111     /** Folder Icon **********************************************************/
112     private static Icon s_FolderIcon = null;
113     /** 16*16 dimension */
114     private static final Dimension s_icon16Size = new Dimension(16, 16);
115
116     /**
117      * Folder Icon
118      * @return icon
119      */

120     public static Icon getFolderIcon()
121     {
122         if (s_FolderIcon == null)
123             s_FolderIcon = new FolderIcon();
124         return s_FolderIcon;
125     } // getFolderIcon
126

127     /**
128      * FolderIcon usable for Tree (18*16) spacing
129      */

130     private static class FolderIcon extends FolderIcon16
131     {
132         public int getShift()
133         {
134             return -1;
135         }
136         public int getAdditionalHeight()
137         {
138             return 2;
139         }
140     } // FolderIcon
141

142     /**
143      * Scaleable 16*16 Folder Icon
144      */

145     public static class FolderIcon16 implements Icon
146     {
147         transient Image image;
148
149         public void paintIcon (Component c, Graphics g, int x, int y)
150         {
151             if (image == null)
152             {
153                 image = new BufferedImage(getIconWidth(), getIconHeight(),
154                     BufferedImage.TYPE_INT_ARGB);
155                 Graphics imageG = image.getGraphics();
156                 paintMe (c,imageG);
157                 imageG.dispose();
158             }
159             g.drawImage(image, x, y+getShift(), null);
160         }
161         private void paintMe(Component c, Graphics g)
162         {
163             int right = s_icon16Size.width - 1;
164             int bottom = s_icon16Size.height - 1;
165             // Draw tab top
166
g.setColor(CompiereLookAndFeel.getPrimaryControlDarkShadow()); // primary1
167
g.drawLine(right - 5, 3, right, 3);
168             g.drawLine(right - 6, 4, right, 4);
169             // Draw folder front
170
g.setColor(CompiereLookAndFeel.getPrimaryControl()); // primary3
171
g.fillRect(2, 7, 13, 8);
172             // Draw tab bottom
173
g.setColor(CompiereLookAndFeel.getPrimaryControlShadow()); // primary2
174
g.drawLine(right - 6, 5, right - 1, 5);
175             // Draw outline
176
g.setColor(CompiereLookAndFeel.getPrimaryControlInfo()); // black
177
g.drawLine(0, 6, 0, bottom); // left side
178
g.drawLine(1, 5, right - 7, 5); // first part of top
179
g.drawLine(right - 6, 6, right - 1, 6); // second part of top
180
g.drawLine(right, 5, right, bottom); // right side
181
g.drawLine(0, bottom, right, bottom); // bottom
182
// Draw highlight
183
g.setColor(CompiereLookAndFeel.getPrimaryControlHighlight()); // white
184
g.drawLine(1, 6, 1, bottom - 1);
185             g.drawLine(1, 6, right - 7, 6);
186             g.drawLine(right - 6, 7, right - 1, 7);
187         }
188         public int getShift()
189         {
190             return 0;
191         }
192         public int getAdditionalHeight()
193         {
194             return 0;
195         }
196         public int getIconWidth()
197         {
198             return s_icon16Size.width;
199         }
200         public int getIconHeight()
201         {
202             return s_icon16Size.height + getAdditionalHeight();
203         }
204     } // FolderIcon16
205

206 } // ImageFactory
207
Popular Tags