KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > plaf > CompierePanelUI


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.plaf;
15
16 import java.awt.Graphics JavaDoc;
17
18 import javax.swing.JComponent JavaDoc;
19 import javax.swing.JPanel JavaDoc;
20 import javax.swing.plaf.ComponentUI JavaDoc;
21 import javax.swing.plaf.basic.BasicPanelUI JavaDoc;
22
23 /**
24  * Panel UI.
25  * The default properties can be set via
26  * <pre>
27  * CompierePanelUI.setDefaultBackground (new CompiereColor());
28  * </pre>
29  * The individual Panel can set the background type by setting the
30  * parameter via
31  * <pre>
32  * putClientProperty(CompierePanelUI.BACKGROUND, new CompiereColor());
33  * </pre>
34  * @see org.compiere.swing.CPanel
35  *
36  * @author Jorg Janke
37  * @version $Id: CompierePanelUI.java,v 1.13 2003/09/27 11:08:52 jjanke Exp $
38  */

39 public class CompierePanelUI extends BasicPanelUI JavaDoc
40 {
41     /**
42      * Static Create UI
43      * @param c Vomponent
44      * @return Compiere Panel UI
45      */

46     public static ComponentUI JavaDoc createUI (JComponent JavaDoc c)
47     {
48     // return new CompierePanelUI();
49
return s_panelUI;
50     } // createUI
51

52     /** UI */
53     private static CompierePanelUI s_panelUI = new CompierePanelUI();
54
55     /*************************************************************************/
56
57     /**
58      * Install Defaults
59      * @param p Panel
60      */

61     protected void installDefaults (JPanel JavaDoc p)
62     {
63         super.installDefaults(p);
64         if (s_setDefault && p.getClientProperty(CompierePLAF.BACKGROUND) == null)
65             p.putClientProperty (CompierePLAF.BACKGROUND, s_default);
66     } // installDefaults
67

68     /*************************************************************************/
69
70     /**
71      * Update -
72      * This method is invoked by <code>JComponent</code> when the specified
73      * component is being painted.
74      *
75      * By default this method will fill the specified component with
76      * its background color (if its <code>opaque</code> property is
77      * <code>true</code>) and then immediately call <code>paint</code>.
78      *
79      * @param g the <code>Graphics</code> context in which to paint
80      * @param c the component being painted
81      *
82      * @see #paint
83      * @see javax.swing.JComponent#paintComponent
84      */

85     public void update (Graphics JavaDoc g, JComponent JavaDoc c)
86     {
87     // CompiereUtils.printParents (c);
88
if (c.isOpaque())
89             updateIt (g, c);
90         paint (g, c); // does nothing
91
} // update
92

93     /**
94      * Print background based on CompiereColor or flat background if not found
95      * @param g
96      * @param c
97      */

98     static void updateIt (Graphics JavaDoc g, JComponent JavaDoc c)
99     {
100     // System.out.print("Panel " + c.getName());
101
// System.out.print(" Bounds=" + c.getBounds().toString());
102
// System.out.print(" - Background: ");
103

104         // Get CompiereColor
105
CompiereColor bg = null;
106         try
107         {
108             bg = (CompiereColor)c.getClientProperty(CompierePLAF.BACKGROUND);
109         }
110         catch (Exception JavaDoc e)
111         {
112             System.err.println("CompierePanelUI - ClientProperty: " + e.getMessage());
113         }
114         // paint compiere background
115
if (bg != null)
116         {
117     // System.out.print(bg);
118
bg.paint (g, c);
119         }
120         else
121         {
122     // System.out.print(c.getBackground());
123
g.setColor(c.getBackground());
124             g.fillRect(0,0, c.getWidth(), c.getHeight());
125         }
126     // System.out.println();
127
} // updateIt
128

129     /*************************************************************************/
130
131     /** Default Background */
132     private static CompiereColor s_default = new CompiereColor();
133     /** Set Background to default language */
134     private static boolean s_setDefault = false;
135
136
137     /**
138      * Set Default Background
139      * @param bg Background Color
140      */

141     public static void setDefaultBackground (CompiereColor bg)
142     {
143         if (bg == null)
144             return;
145         s_default.setColor(bg);
146     } // setBackground
147

148     /**
149      * Get Default Background
150      * @return Background
151      */

152     public static CompiereColor getDefaultBackground()
153     {
154         return s_default;
155     } // getBackground
156

157     /**
158      * Set Default Background
159      * @param setDefault if trie, the background will be set to the default color
160      */

161     public static void setSetDefault (boolean setDefault)
162     {
163         s_setDefault = setDefault;
164     } // setSetDefault
165

166     /**
167      * Is the Default Background set by default
168      * @return true if default background is set
169      */

170     public static boolean isSetDefault()
171     {
172         return s_setDefault;
173     } // isSetDefault
174

175 } // CompierePanel
176
Popular Tags