KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SynthRootPaneUI.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 java.awt.event.ActionEvent JavaDoc;
12 import java.beans.PropertyChangeEvent JavaDoc;
13 import java.beans.PropertyChangeListener JavaDoc;
14 import javax.swing.*;
15 import javax.swing.plaf.*;
16 import javax.swing.plaf.basic.BasicRootPaneUI JavaDoc;
17 import sun.swing.plaf.synth.SynthUI;
18
19 /**
20  * Synth's RootPaneUI.
21  *
22  * @version 1.12, 12/19/03
23  * @author Scott Violet
24  */

25 class SynthRootPaneUI extends BasicRootPaneUI JavaDoc implements SynthUI {
26     private SynthStyle JavaDoc style;
27
28     public static ComponentUI createUI(JComponent c) {
29         return new SynthRootPaneUI JavaDoc();
30     }
31
32     protected void installDefaults(JRootPane c){
33         updateStyle(c);
34     }
35
36     protected void uninstallDefaults(JRootPane root) {
37         SynthContext JavaDoc context = getContext(root, ENABLED);
38
39         style.uninstallDefaults(context);
40         context.dispose();
41         style = null;
42     }
43
44     public SynthContext JavaDoc getContext(JComponent c) {
45         return getContext(c, getComponentState(c));
46     }
47
48     private SynthContext JavaDoc getContext(JComponent c, int state) {
49         return SynthContext.getContext(SynthContext JavaDoc.class, c,
50                     SynthLookAndFeel.getRegion(c), style, state);
51     }
52
53     private Region JavaDoc getRegion(JComponent c) {
54         return SynthLookAndFeel.getRegion(c);
55     }
56
57     private int getComponentState(JComponent c) {
58         return SynthLookAndFeel.getComponentState(c);
59     }
60
61     private void updateStyle(JComponent c) {
62         SynthContext JavaDoc context = getContext(c, ENABLED);
63         SynthStyle JavaDoc oldStyle = style;
64         style = SynthLookAndFeel.updateStyle(context, this);
65         if (style != oldStyle) {
66             if (oldStyle != null) {
67                 uninstallKeyboardActions((JRootPane)c);
68                 installKeyboardActions((JRootPane)c);
69             }
70         }
71         context.dispose();
72     }
73
74     public void update(Graphics g, JComponent c) {
75         SynthContext JavaDoc context = getContext(c);
76
77         SynthLookAndFeel.update(context, g);
78         context.getPainter().paintRootPaneBackground(context,
79                           g, 0, 0, c.getWidth(), c.getHeight());
80         paint(context, g);
81         context.dispose();
82     }
83
84     public void paint(Graphics g, JComponent c) {
85         SynthContext JavaDoc context = getContext(c);
86
87         paint(context, g);
88         context.dispose();
89     }
90
91     protected void paint(SynthContext JavaDoc context, Graphics g) {
92     }
93
94     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
95                             int y, int w, int h) {
96         context.getPainter().paintRootPaneBorder(context, g, x, y, w, h);
97     }
98
99     /**
100      * Invoked when a property changes on the root pane. If the event
101      * indicates the <code>defaultButton</code> has changed, this will
102      * reinstall the keyboard actions.
103      */

104     public void propertyChange(PropertyChangeEvent JavaDoc e) {
105         if (SynthLookAndFeel.shouldUpdateStyle(e)) {
106             updateStyle((JRootPane)e.getSource());
107         }
108         super.propertyChange(e);
109     }
110 }
111
Popular Tags