KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthPanelUI


1 /*
2  * @(#)SynthPanelUI.java 1.12 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.synth;
9
10 import java.awt.*;
11 import javax.swing.*;
12 import javax.swing.border.*;
13 import javax.swing.plaf.*;
14 import javax.swing.plaf.basic.BasicPanelUI JavaDoc;
15 import java.awt.*;
16 import java.awt.event.*;
17 import java.beans.*;
18 import sun.swing.plaf.synth.SynthUI;
19
20 /**
21  * Synth's PanelUI.
22  *
23  * @version 1.12, 12/19/03
24  * @author Steve Wilson
25  */

26 class SynthPanelUI extends BasicPanelUI JavaDoc implements PropertyChangeListener,
27         SynthUI {
28     private SynthStyle JavaDoc style;
29
30     public static ComponentUI createUI(JComponent c) {
31         return new SynthPanelUI JavaDoc();
32     }
33
34     public void installUI(JComponent c) {
35         JPanel p = (JPanel)c;
36
37         super.installUI(c);
38         installListeners(p);
39     }
40
41     public void uninstallUI(JComponent c) {
42         JPanel p = (JPanel)c;
43
44         uninstallListeners(p);
45         super.uninstallUI(c);
46     }
47
48     protected void installListeners(JPanel p) {
49         p.addPropertyChangeListener(this);
50     }
51
52     protected void uninstallListeners(JPanel p) {
53         p.removePropertyChangeListener(this);
54     }
55
56     protected void installDefaults(JPanel p) {
57         updateStyle(p);
58     }
59
60     protected void uninstallDefaults(JPanel p) {
61         SynthContext JavaDoc context = getContext(p, ENABLED);
62
63         style.uninstallDefaults(context);
64         context.dispose();
65         style = null;
66     }
67
68     private void updateStyle(JPanel c) {
69         SynthContext JavaDoc context = getContext(c, ENABLED);
70         style = SynthLookAndFeel.updateStyle(context, this);
71         context.dispose();
72     }
73
74     public SynthContext JavaDoc getContext(JComponent c) {
75         return getContext(c, getComponentState(c));
76     }
77
78     private SynthContext JavaDoc getContext(JComponent c, int state) {
79         return SynthContext.getContext(SynthContext JavaDoc.class, c,
80                     SynthLookAndFeel.getRegion(c), style, state);
81     }
82
83     private Region JavaDoc getRegion(JComponent c) {
84         return SynthLookAndFeel.getRegion(c);
85     }
86
87     private int getComponentState(JComponent c) {
88         return SynthLookAndFeel.getComponentState(c);
89     }
90
91     public void update(Graphics g, JComponent c) {
92         SynthContext JavaDoc context = getContext(c);
93
94         SynthLookAndFeel.update(context, g);
95         context.getPainter().paintPanelBackground(context,
96                           g, 0, 0, c.getWidth(), c.getHeight());
97         paint(context, g);
98         context.dispose();
99     }
100
101     public void paint(Graphics g, JComponent c) {
102         SynthContext JavaDoc context = getContext(c);
103
104         paint(context, g);
105         context.dispose();
106     }
107
108     protected void paint(SynthContext JavaDoc context, Graphics g) {
109         // do actual painting
110
}
111
112     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
113                             int y, int w, int h) {
114         context.getPainter().paintPanelBorder(context, g, x, y, w, h);
115     }
116
117     public void propertyChange(PropertyChangeEvent pce) {
118         if (SynthLookAndFeel.shouldUpdateStyle(pce)) {
119             updateStyle((JPanel)pce.getSource());
120         }
121     }
122 }
123
Popular Tags