KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.awt.Graphics2D JavaDoc;
18
19 import javax.swing.AbstractButton JavaDoc;
20 import javax.swing.ButtonModel JavaDoc;
21 import javax.swing.JComponent JavaDoc;
22 import javax.swing.plaf.ComponentUI JavaDoc;
23 import javax.swing.plaf.metal.MetalToggleButtonUI JavaDoc;
24
25 /**
26  * Compiere Toggle Button UI
27  *
28  * @author Jorg Janke
29  * @version $Id: CompiereToggleButtonUI.java,v 1.5 2003/09/27 11:08:52 jjanke Exp $
30  */

31 public class CompiereToggleButtonUI extends MetalToggleButtonUI JavaDoc
32 {
33     /**
34      * Static Create UI
35      * @param c Component
36      * @return Compiere ToggleButton UI
37      */

38     public static ComponentUI JavaDoc createUI (JComponent JavaDoc c)
39     {
40         return s_toggleButtonUI;
41     } // createUI
42

43     /** UI shared */
44     private static CompiereToggleButtonUI s_toggleButtonUI = new CompiereToggleButtonUI();
45
46     /*************************************************************************/
47
48     /**
49      * Install Defaults
50      * @param b
51      */

52     public void installDefaults(AbstractButton JavaDoc b)
53     {
54         super.installDefaults(b);
55         b.setOpaque(false);
56     } // installDefaults
57

58     /**
59      * Update -
60      * This method is invoked by <code>JComponent</code> when the specified
61      * component is being painted.
62      *
63      * By default this method will fill the specified component with
64      * its background color (if its <code>opaque</code> property is
65      * <code>true</code>) and then immediately call <code>paint</code>.
66      *
67      * @param g the <code>Graphics</code> context in which to paint
68      * @param c the component being painted
69      *
70      * @see #paint
71      * @see javax.swing.JComponent#paintComponent
72      */

73     public void update(Graphics JavaDoc g, JComponent JavaDoc c)
74     {
75         if (c.isOpaque()) // flat background
76
CompiereUtils.fillRectange((Graphics2D JavaDoc)g, c, CompiereLookAndFeel.ROUND);
77         paint (g, c);
78     } // update
79

80     /**
81      * Paint 3D Box
82      * @param g Graphics
83      * @param c Component
84      */

85     public void paint(Graphics JavaDoc g, JComponent JavaDoc c)
86     {
87         super.paint(g, c);
88         AbstractButton JavaDoc b = (AbstractButton JavaDoc) c;
89         ButtonModel JavaDoc model = b.getModel();
90         boolean in = model.isPressed() || model.isSelected();
91         //
92
CompiereUtils.paint3Deffect((Graphics2D JavaDoc)g, c, CompiereLookAndFeel.ROUND, !in);
93     } // paint
94

95     /**
96      * Don't get selected Color - use default (otherwise the pressed button is gray)
97      * @param g
98      * @param b
99      */

100     protected void paintButtonPressed(Graphics JavaDoc g, AbstractButton JavaDoc b)
101     {
102     // if (b.isContentAreaFilled())
103
// {
104
// Dimension size = b.getSize();
105
// g.setColor(getSelectColor());
106
// g.fillRect(0, 0, size.width, size.height);
107
// }
108
} // paintButtonPressed
109

110 } // CompiereToggleButton
111
Popular Tags