KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > swing > CPanel


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.swing;
15
16 import java.awt.Color JavaDoc;
17 import java.awt.LayoutManager JavaDoc;
18
19 import javax.swing.JPanel JavaDoc;
20
21 import org.compiere.plaf.CompiereColor;
22 import org.compiere.plaf.CompierePLAF;
23 import org.compiere.plaf.CompierePanelUI;
24 import org.compiere.util.Trace;
25
26 /**
27  * Compiere Panel supporting colored Backgrounds
28  *
29  * @author Jorg Janke
30  * @version $Id: CPanel.java,v 1.12 2003/09/27 11:08:51 jjanke Exp $
31  */

32 public class CPanel extends JPanel JavaDoc
33 {
34     /**
35      * Creates a new CompierePanel with the specified layout manager
36      * and buffering strategy.
37      * @param layout the LayoutManager to use
38      * @param isDoubleBuffered a boolean, true for double-buffering, which
39      * uses additional memory space to achieve fast, flicker-free updates
40      */

41     public CPanel (LayoutManager JavaDoc layout, boolean isDoubleBuffered)
42     {
43         super (layout, isDoubleBuffered);
44         init();
45     } // CPanel
46

47     /**
48      * Create a new buffered CPanel with the specified layout manager
49      * @param layout the LayoutManager to use
50      */

51     public CPanel (LayoutManager JavaDoc layout)
52     {
53         super (layout);
54         init();
55     } // CPanel
56

57     /**
58      * Creates a new <code>CPanel</code> with <code>FlowLayout</code>
59      * and the specified buffering strategy.
60      * If <code>isDoubleBuffered</code> is true, the <code>CPanel</code>
61      * will use a double buffer.
62      * @param isDoubleBuffered a boolean, true for double-buffering, which
63      * uses additional memory space to achieve fast, flicker-free updates
64      */

65     public CPanel (boolean isDoubleBuffered)
66     {
67         super (isDoubleBuffered);
68         init();
69     } // CPanel
70

71     /**
72      * Creates a new <code>CPanel</code> with a double buffer and a flow layout.
73      */

74     public CPanel()
75     {
76         super ();
77         init();
78     } // CPanel
79

80     /**
81      * Creates a new <code>CPanel</code> with a double buffer and a flow layout.
82      * @param bc Initial Background Color
83      */

84     public CPanel(CompiereColor bc)
85     {
86         this ();
87         init();
88         setBackgroundColor (bc);
89     } // CPanel
90

91     /**
92      * Common init
93      */

94     private void init()
95     {
96         setOpaque(false);
97     } // init
98

99     /*************************************************************************/
100
101     /**
102      * Set Background - ignored by UI -
103      * @param bg ignored
104      */

105     public void setBackground (Color JavaDoc bg)
106     {
107         if (bg.equals(getBackground()))
108             return;
109         super.setBackground (bg);
110         // ignore calls from javax.swing.LookAndFeel.installColors(LookAndFeel.java:61)
111
if (!Trace.getCallerClass(1).startsWith("javax"))
112             setBackgroundColor (new CompiereColor(bg));
113     } // setBackground
114

115     /**
116      * Set Background
117      * @param bg CompiereColor for Background, if null set standard background
118      */

119     public void setBackgroundColor (CompiereColor bg)
120     {
121         if (bg == null)
122             bg = CompierePanelUI.getDefaultBackground();
123         setOpaque(true);
124         putClientProperty(CompierePLAF.BACKGROUND, bg);
125         super.setBackground (bg.getFlatColor());
126     } // setBackground
127

128     /**
129      * Get Background
130      * @return Color for Background
131      */

132     public CompiereColor getBackgroundColor ()
133     {
134         try
135         {
136             return (CompiereColor)getClientProperty(CompierePLAF.BACKGROUND);
137         }
138         catch (Exception JavaDoc e)
139         {
140             System.err.println("CPanel - ClientProperty: " + e.getMessage());
141         }
142         return null;
143     } // getBackgroundColor
144

145     /*************************************************************************/
146
147     /**
148      * Set Tab Hierarchy Level.
149      * Has only effect, if tabs are on left or right side
150      *
151      * @param level
152      */

153     public void setTabLevel (int level)
154     {
155         if (level == 0)
156             putClientProperty(CompierePLAF.TABLEVEL, null);
157         else
158             putClientProperty(CompierePLAF.TABLEVEL, new Integer JavaDoc(level));
159     } // setTabLevel
160

161     /**
162      * Get Tab Hierarchy Level
163      * @return Tab Level
164      */

165     public int getTabLevel()
166     {
167         try
168         {
169             Integer JavaDoc ll = (Integer JavaDoc)getClientProperty(CompierePLAF.TABLEVEL);
170             if (ll != null)
171                 return ll.intValue();
172         }
173         catch (Exception JavaDoc e)
174         {
175             System.err.println("CPanel - ClientProperty: " + e.getMessage());
176         }
177         return 0;
178     } // getTabLevel
179

180     /*************************************************************************/
181
182     /**
183      * String representation
184      * @return String representation
185      */

186     public String JavaDoc toString()
187     {
188         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("CPanel [");
189         sb.append(super.toString());
190         CompiereColor bg = getBackgroundColor();
191         if (bg != null)
192             sb.append(bg.toString());
193         sb.append("]");
194         return sb.toString();
195     } // toString
196

197 } // CPanel
198
Popular Tags