KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SynthTextAreaUI.java 1.8 04/06/24
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 javax.swing.*;
11 import javax.swing.text.*;
12 import javax.swing.event.*;
13 import javax.swing.plaf.*;
14 import javax.swing.plaf.basic.BasicTextAreaUI JavaDoc;
15 import java.awt.*;
16 import java.beans.PropertyChangeEvent JavaDoc;
17 import sun.swing.plaf.synth.SynthUI;
18
19 /**
20  * Provides the look and feel for a plain text editor in the
21  * Synth look and feel. In this implementation the default UI
22  * is extended to act as a simple view factory.
23  * <p>
24  * <strong>Warning:</strong>
25  * Serialized objects of this class will not be compatible with
26  * future Swing releases. The current serialization support is
27  * appropriate for short term storage or RMI between applications running
28  * the same version of Swing. As of 1.4, support for long term storage
29  * of all JavaBeans<sup><font size="-2">TM</font></sup>
30  * has been added to the <code>java.beans</code> package.
31  * Please see {@link java.beans.XMLEncoder}.
32  *
33  * @author Shannon Hickey
34  * @version 1.8 06/24/04
35  */

36 class SynthTextAreaUI extends BasicTextAreaUI JavaDoc implements SynthUI {
37     private SynthStyle JavaDoc style;
38
39     /**
40      * Creates a UI for a JTextArea.
41      *
42      * @param ta a text area
43      * @return the UI
44      */

45     public static ComponentUI createUI(JComponent ta) {
46         return new SynthTextAreaUI JavaDoc();
47     }
48
49     protected void installDefaults() {
50         updateStyle((JTextComponent)getComponent());
51     }
52
53     protected void uninstallDefaults() {
54         SynthContext JavaDoc context = getContext(getComponent(), ENABLED);
55
56         getComponent().putClientProperty("caretAspectRatio", null);
57
58         style.uninstallDefaults(context);
59         context.dispose();
60         style = null;
61         super.uninstallDefaults();
62     }
63
64     public void installUI(JComponent c) {
65         super.installUI(c);
66     }
67
68     private void updateStyle(JTextComponent comp) {
69         SynthContext JavaDoc context = getContext(comp, ENABLED);
70         SynthStyle JavaDoc oldStyle = style;
71
72         style = SynthLookAndFeel.updateStyle(context, this);
73
74         if (style != oldStyle) {
75             SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix());
76
77             if (oldStyle != null) {
78                 uninstallKeyboardActions();
79                 installKeyboardActions();
80             }
81         }
82         context.dispose();
83     }
84
85     public SynthContext JavaDoc getContext(JComponent c) {
86         return getContext(c, getComponentState(c));
87     }
88
89     private SynthContext JavaDoc getContext(JComponent c, int state) {
90         return SynthContext.getContext(SynthContext JavaDoc.class, c,
91                     SynthLookAndFeel.getRegion(c), style, state);
92     }
93
94     private int getComponentState(JComponent c) {
95         return SynthLookAndFeel.getComponentState(c);
96     }
97
98     public void update(Graphics g, JComponent c) {
99         SynthContext JavaDoc context = getContext(c);
100
101         SynthLookAndFeel.update(context, g);
102         context.getPainter().paintTextAreaBackground(context,
103                           g, 0, 0, c.getWidth(), c.getHeight());
104         paint(context, g);
105         context.dispose();
106     }
107
108     protected void paint(SynthContext JavaDoc context, Graphics g) {
109         super.paint(g, getComponent());
110     }
111
112     protected void paintBackground(Graphics g) {
113         // Overriden to do nothing, all our painting is done from update/paint.
114
}
115
116     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
117                             int y, int w, int h) {
118         context.getPainter().paintTextAreaBorder(context, g, x, y, w, h);
119     }
120
121     /**
122      * This method gets called when a bound property is changed
123      * on the associated JTextComponent. This is a hook
124      * which UI implementations may change to reflect how the
125      * UI displays bound properties of JTextComponent subclasses.
126      * This is implemented to rebuild the View when the
127      * <em>WrapLine</em> or the <em>WrapStyleWord</em> property changes.
128      *
129      * @param evt the property change event
130      */

131     protected void propertyChange(PropertyChangeEvent JavaDoc evt) {
132         if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
133             updateStyle((JTextComponent)evt.getSource());
134         }
135         super.propertyChange(evt);
136     }
137 }
138
Popular Tags