KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component JavaDoc;
18
19 import javax.swing.Icon JavaDoc;
20 import javax.swing.JPanel JavaDoc;
21 import javax.swing.JTabbedPane JavaDoc;
22
23 import org.compiere.plaf.CompiereColor;
24 import org.compiere.plaf.CompierePLAF;
25 import org.compiere.plaf.CompierePanelUI;
26 import org.compiere.util.Trace;
27
28 /**
29  * Compiere Color Tabbed Pane
30  *
31  * @author Jorg Janke
32  * @version $Id: CTabbedPane.java,v 1.11 2003/09/27 11:08:51 jjanke Exp $
33  */

34 public class CTabbedPane extends JTabbedPane JavaDoc
35 {
36     /**
37      * Creates an empty <code>TabbedPane</code> with a default
38      * tab placement of <code>JTabbedPane.TOP</code> and default
39      * tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
40      * @see #addTab
41      */

42     public CTabbedPane()
43     {
44         super();
45         init();
46     } // CTabbedPane
47

48     /**
49      * Creates an empty <code>TabbedPane</code> with the specified tab placement
50      * of either: <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
51      * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>, and a
52      * default tab layout policy of <code>JTabbedPane.WRAP_TAB_LAYOUT</code>.
53      *
54      * @param tabPlacement the placement for the tabs relative to the content
55      */

56     public CTabbedPane(int tabPlacement)
57     {
58         super(tabPlacement);
59         init();
60     } // CTabbedPane
61

62     /**
63      * Creates an empty <code>TabbedPane</code> with the specified tab placement
64      * and tab layout policy. Tab placement may be either:
65      * <code>JTabbedPane.TOP</code>, <code>JTabbedPane.BOTTOM</code>,
66      * <code>JTabbedPane.LEFT</code>, or <code>JTabbedPane.RIGHT</code>.
67      * Tab layout policy may be either: <code>JTabbedPane.WRAP_TAB_LAYOUT</code>
68      * or <code>JTabbedPane.SCROLL_TAB_LAYOUT</code>.
69      *
70      * @param tabPlacement the placement for the tabs relative to the content
71      * @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
72      * @exception IllegalArgumentException if tab placement or tab layout policy are not
73      * one of the above supported values
74      */

75     public CTabbedPane(int tabPlacement, int tabLayoutPolicy)
76     {
77         super (tabPlacement, tabLayoutPolicy);
78         init();
79     } // CTabbedPane
80

81     /**
82      * Creates an empty <code>TabbedPane</code> with a defaults and Color
83      * @param bg Color
84      */

85     public CTabbedPane (CompiereColor bg)
86     {
87         super();
88         init();
89         setBackgroundColor (bg);
90     } // CTabbedPane
91

92     /**
93      * Common Init
94      */

95     private void init()
96     {
97         setOpaque(false);
98         setFont(CompierePLAF.getFont_Label());
99         setForeground(CompierePLAF.getTextColor_Label());
100     } // init
101

102     /*************************************************************************/
103
104     /**
105      * Set Background - ignored by UI -
106      * @param bg ignored
107      */

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

118     /**
119      * Set Standard Background
120      */

121     public void setBackgroundColor ()
122     {
123         setBackgroundColor (null);
124     } // setBackground
125

126     /**
127      * Set Background
128      * @param bg CompiereColor for Background, if null set standard background
129      */

130     public void setBackgroundColor (CompiereColor bg)
131     {
132         if (bg == null)
133             bg = CompierePanelUI.getDefaultBackground();
134         setOpaque(true);
135         putClientProperty(CompierePLAF.BACKGROUND, bg);
136         super.setBackground (bg.getFlatColor());
137         //
138
repaint();
139     } // setBackground
140

141     /**
142      * Get Background
143      * @return Color for Background
144      */

145     public CompiereColor getBackgroundColor ()
146     {
147         try
148         {
149             return (CompiereColor)getClientProperty(CompierePLAF.BACKGROUND);
150         }
151         catch (Exception JavaDoc e)
152         {
153             System.err.println("CPanel - ClientProperty: " + e.getMessage());
154         }
155         return null;
156     } // getBackgroundColor
157

158     /*************************************************************************/
159
160     /**
161      * Insert tab.
162      * If the component is a JPanel, the backround is set to the default
163      * CompiereColor (and Opaque) if nothing was defined.
164      * Redquired as otherwise a gray background would be pained.
165      * <p>
166      * Inserts a <code>component</code>, at <code>index</code>,
167      * represented by a <code>title</code> and/or <code>icon</code>,
168      * either of which may be <code>null</code>. If <code>icon</code>
169      * is non-<code>null</code> and it implements
170      * <code>ImageIcon</code> a corresponding disabled icon will automatically
171      * be created and set on the tabbedpane.
172      * Uses java.util.Vector internally, see <code>insertElementAt</code>
173      * for details of insertion conventions.
174      *
175      * @param title the title to be displayed in this tab
176      * @param icon the icon to be displayed in this tab
177      * @param component The component to be displayed when this tab is clicked.
178      * @param tip the tooltip to be displayed for this tab
179      * @param index the position to insert this new tab
180      */

181     public void insertTab (String JavaDoc title, Icon JavaDoc icon, Component JavaDoc component, String JavaDoc tip, int index)
182     {
183         super.insertTab (title, icon, component, tip, index);
184         // Set component background
185
if (component instanceof JPanel JavaDoc)
186         {
187             JPanel JavaDoc p = (JPanel JavaDoc)component;
188             if (p.getClientProperty(CompierePLAF.BACKGROUND) == null)
189             {
190                 CompiereColor.setBackground(p);
191                 p.setOpaque(true);
192             }
193         }
194     } // insertTab
195

196     /**
197      * String representation
198      * @return String representation
199      */

200     public String JavaDoc toString()
201     {
202         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("CTabbedPane [");
203         sb.append(super.toString());
204         CompiereColor bg = getBackgroundColor();
205         if (bg != null)
206             sb.append(bg.toString());
207         sb.append("]");
208         return sb.toString();
209     } // toString
210

211 } // CTabbedPane
212
Popular Tags