KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > wf > WFIcon


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-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps.wf;
15
16 import java.awt.*;
17 import javax.swing.*;
18
19 import org.compiere.util.*;
20 import org.compiere.model.*;
21
22
23 /**
24  * Work Flow Icon
25  *
26  * @author Jorg Janke
27  * @version $Id: WFIcon.java,v 1.3 2003/02/14 06:44:14 jjanke Exp $
28  */

29 public class WFIcon implements Icon
30 {
31     /**
32      * Constructor
33      * @param type see MTreeNode.TYPE_
34      */

35     public WFIcon (int type)
36     {
37         if (type > 0 && type < MTreeNode.IMAGES.length)
38             m_type = type;
39     } // WFIcon
40

41     /**
42      * Constructor
43      * @param action image indicator
44      */

45     public WFIcon (String JavaDoc action)
46     {
47         if (action != null)
48             m_type = MTreeNode.getImageIndex(action);
49     } // WFIcon
50

51
52     private static int WIDTH = 30;
53     private static int HEIGHT = 30;
54
55     /** Image Index */
56     private int m_type = 0;
57     private boolean m_selected = false;
58
59     /**
60      * Set Selected
61      * @param selected selected
62      */

63     public void setSelected (boolean selected)
64     {
65         m_selected = selected;
66     } // setSelected
67

68     /**
69      * Get Selected
70      * @return selected
71      */

72     public boolean isSelected()
73     {
74         return m_selected;
75     } // isSelected
76

77     /**
78      * Draw the icon at the specified location. Icon implementations
79      * may use the Component argument to get properties useful for
80      * painting, e.g. the foreground or background color.
81      *
82      * @param c Component
83      * @param g Graphics
84      * @param x X
85      * @param y Y
86      */

87     public void paintIcon (Component c, Graphics g, int x, int y)
88     {
89         Graphics2D g2D = (Graphics2D)g;
90
91         // Raised Border
92
if (m_selected)
93             g2D.setColor(c.getBackground().darker());
94         else
95             g2D.setColor(c.getBackground().brighter());
96         g2D.setColor (Color.white);
97         g2D.draw3DRect (x+1, y+1, WIDTH-2, HEIGHT-2, !m_selected);
98
99         Icon icon = MTreeNode.getIcon(m_type);
100         if (icon != null)
101         {
102             int xI = x + ((WIDTH - icon.getIconWidth()) / 2);
103             int yI = y + ((HEIGHT - icon.getIconHeight()) / 2);
104             icon.paintIcon(c, g, xI, yI);
105         }
106         else // draw dot
107
{
108             int size = 10;
109             int xI = x + ((WIDTH - size) / 2);
110             int yI = y + ((HEIGHT - size) / 2);
111             g2D.setColor(Color.magenta);
112             g2D.fillOval(xI, yI, size, size);
113         }
114     } // PaintIcon
115

116     /**
117      * Returns the icon's width.
118      * @return an int specifying the fixed width of the icon.
119      */

120     public int getIconWidth()
121     {
122         return WIDTH;
123     } // getIconWidth
124

125     /**
126      * Returns the icon's height.
127      * @return an int specifying the fixed height of the icon.
128      */

129     public int getIconHeight()
130     {
131         return HEIGHT;
132     } // getIconHeight
133

134 } // WFIcon
Popular Tags