KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SynthEditorPaneUI.java 1.8 04/07/23
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.text.*;
13 import javax.swing.plaf.*;
14 import javax.swing.plaf.basic.BasicEditorPaneUI JavaDoc;
15 import java.beans.PropertyChangeEvent JavaDoc;
16 import sun.swing.plaf.synth.SynthUI;
17
18 /**
19  * Provides the look and feel for a JEditorPane in the
20  * Synth look and feel.
21  *
22  * @author Shannon Hickey
23  * @version 1.8 07/23/04
24  */

25 class SynthEditorPaneUI extends BasicEditorPaneUI JavaDoc implements SynthUI {
26     private SynthStyle JavaDoc style;
27     /*
28      * I would prefer to use UIResource instad of this.
29      * Unfortunately Boolean is a final class
30      */

31     private Boolean JavaDoc localTrue = new Boolean JavaDoc(true);
32     private Boolean JavaDoc localFalse = new Boolean JavaDoc(false);
33
34     /**
35      * Creates a UI for the JTextPane.
36      *
37      * @param c the JTextPane component
38      * @return the UI
39      */

40     public static ComponentUI createUI(JComponent c) {
41         return new SynthEditorPaneUI JavaDoc();
42     }
43
44     protected void installDefaults() {
45         JComponent c = getComponent();
46         Object JavaDoc clientProperty =
47             c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
48         if (clientProperty == null
49             || clientProperty == localFalse) {
50             c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
51                                 localTrue);
52         }
53         updateStyle((JTextComponent)getComponent());
54     }
55
56     protected void uninstallDefaults() {
57         SynthContext JavaDoc context = getContext(getComponent(), ENABLED);
58         JComponent c = getComponent();
59         c.putClientProperty("caretAspectRatio", null);
60
61         style.uninstallDefaults(context);
62         context.dispose();
63         style = null;
64
65         Object JavaDoc clientProperty =
66             c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
67         if (clientProperty == localTrue) {
68             getComponent().putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
69                                              Boolean.FALSE);
70         }
71         super.uninstallDefaults();
72     }
73
74     /**
75      * This method gets called when a bound property is changed
76      * on the associated JTextComponent. This is a hook
77      * which UI implementations may change to reflect how the
78      * UI displays bound properties of JTextComponent subclasses.
79      * This is implemented to rebuild the ActionMap based upon an
80      * EditorKit change.
81      *
82      * @param evt the property change event
83      */

84     protected void propertyChange(PropertyChangeEvent JavaDoc evt) {
85         if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
86             updateStyle((JTextComponent)evt.getSource());
87         }
88         super.propertyChange(evt);
89     }
90
91     private void updateStyle(JTextComponent comp) {
92         SynthContext JavaDoc context = getContext(comp, ENABLED);
93         SynthStyle JavaDoc oldStyle = style;
94
95         style = SynthLookAndFeel.updateStyle(context, this);
96
97         if (style != oldStyle) {
98             SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix());
99
100             if (oldStyle != null) {
101                 uninstallKeyboardActions();
102                 installKeyboardActions();
103             }
104         }
105         context.dispose();
106     }
107
108     public SynthContext JavaDoc getContext(JComponent c) {
109         return getContext(c, getComponentState(c));
110     }
111
112     private SynthContext JavaDoc getContext(JComponent c, int state) {
113         return SynthContext.getContext(SynthContext JavaDoc.class, c,
114                     SynthLookAndFeel.getRegion(c), style, state);
115     }
116
117     private int getComponentState(JComponent c) {
118         return SynthLookAndFeel.getComponentState(c);
119     }
120
121     public void update(Graphics g, JComponent c) {
122         SynthContext JavaDoc context = getContext(c);
123
124         SynthLookAndFeel.update(context, g);
125         paintBackground(context, g, c);
126         paint(context, g);
127         context.dispose();
128     }
129
130     protected void paint(SynthContext JavaDoc context, Graphics g) {
131         super.paint(g, getComponent());
132     }
133
134     protected void paintBackground(Graphics g) {
135         // Overriden to do nothing, all our painting is done from update/paint.
136
}
137
138     void paintBackground(SynthContext JavaDoc context, Graphics g, JComponent c) {
139         context.getPainter().paintEditorPaneBackground(context, g, 0, 0,
140                                                   c.getWidth(), c.getHeight());
141     }
142
143     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
144                             int y, int w, int h) {
145         context.getPainter().paintEditorPaneBorder(context, g, x, y, w, h);
146     }
147 }
148
Popular Tags