author | alexsch |
Wed, 18 Nov 2015 19:13:42 +0400 | |
changeset 34407 | 2b40f400a30b |
parent 25859 | 3317bb8137f4 |
child 37698 | 4d798c873df0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
2 |
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.synth; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import javax.swing.text.*; |
|
30 |
import javax.swing.plaf.*; |
|
31 |
import javax.swing.plaf.basic.BasicTextAreaUI; |
|
32 |
import java.awt.*; |
|
2658 | 33 |
import java.awt.event.FocusListener; |
34 |
import java.awt.event.FocusEvent; |
|
2 | 35 |
import java.beans.PropertyChangeEvent; |
36 |
||
37 |
/** |
|
38 |
* Provides the look and feel for a plain text editor in the |
|
39 |
* Synth look and feel. In this implementation the default UI |
|
40 |
* is extended to act as a simple view factory. |
|
41 |
* <p> |
|
42 |
* <strong>Warning:</strong> |
|
43 |
* Serialized objects of this class will not be compatible with |
|
44 |
* future Swing releases. The current serialization support is |
|
45 |
* appropriate for short term storage or RMI between applications running |
|
46 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 47 |
* of all JavaBeans™ |
2 | 48 |
* has been added to the <code>java.beans</code> package. |
49 |
* Please see {@link java.beans.XMLEncoder}. |
|
50 |
* |
|
51 |
* @author Shannon Hickey |
|
4394 | 52 |
* @since 1.7 |
2 | 53 |
*/ |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
20458
diff
changeset
|
54 |
@SuppressWarnings("serial") // Same-version serialization only |
4394 | 55 |
public class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI { |
56 |
private Handler handler = new Handler(); |
|
2 | 57 |
private SynthStyle style; |
58 |
||
59 |
/** |
|
4394 | 60 |
* Creates a UI object for a JTextArea. |
2 | 61 |
* |
62 |
* @param ta a text area |
|
4394 | 63 |
* @return the UI object |
2 | 64 |
*/ |
65 |
public static ComponentUI createUI(JComponent ta) { |
|
66 |
return new SynthTextAreaUI(); |
|
67 |
} |
|
68 |
||
4394 | 69 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
70 |
* {@inheritDoc} |
4394 | 71 |
*/ |
72 |
@Override |
|
2 | 73 |
protected void installDefaults() { |
74 |
// Installs the text cursor on the component |
|
75 |
super.installDefaults(); |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
76 |
updateStyle(getComponent()); |
4394 | 77 |
getComponent().addFocusListener(handler); |
2 | 78 |
} |
79 |
||
4394 | 80 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
81 |
* {@inheritDoc} |
4394 | 82 |
*/ |
83 |
@Override |
|
2 | 84 |
protected void uninstallDefaults() { |
85 |
SynthContext context = getContext(getComponent(), ENABLED); |
|
86 |
||
87 |
getComponent().putClientProperty("caretAspectRatio", null); |
|
4394 | 88 |
getComponent().removeFocusListener(handler); |
2 | 89 |
|
90 |
style.uninstallDefaults(context); |
|
91 |
context.dispose(); |
|
92 |
style = null; |
|
93 |
super.uninstallDefaults(); |
|
94 |
} |
|
95 |
||
96 |
private void updateStyle(JTextComponent comp) { |
|
97 |
SynthContext context = getContext(comp, ENABLED); |
|
98 |
SynthStyle oldStyle = style; |
|
99 |
||
100 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
101 |
||
102 |
if (style != oldStyle) { |
|
103 |
SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix()); |
|
104 |
||
105 |
if (oldStyle != null) { |
|
106 |
uninstallKeyboardActions(); |
|
107 |
installKeyboardActions(); |
|
108 |
} |
|
109 |
} |
|
110 |
context.dispose(); |
|
111 |
} |
|
112 |
||
4394 | 113 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
114 |
* {@inheritDoc} |
4394 | 115 |
*/ |
116 |
@Override |
|
2 | 117 |
public SynthContext getContext(JComponent c) { |
4394 | 118 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 119 |
} |
120 |
||
121 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 122 |
return SynthContext.getContext(c, style, state); |
2 | 123 |
} |
124 |
||
4394 | 125 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
126 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
127 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
128 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
129 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
130 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
131 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
132 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
133 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
134 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
135 |
* @see #paint(SynthContext,Graphics) |
4394 | 136 |
*/ |
137 |
@Override |
|
2 | 138 |
public void update(Graphics g, JComponent c) { |
139 |
SynthContext context = getContext(c); |
|
140 |
||
141 |
SynthLookAndFeel.update(context, g); |
|
142 |
context.getPainter().paintTextAreaBackground(context, |
|
143 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
144 |
paint(context, g); |
|
145 |
context.dispose(); |
|
146 |
} |
|
147 |
||
4394 | 148 |
/** |
149 |
* Paints the specified component. |
|
150 |
* |
|
151 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
152 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
153 |
* @see #update(Graphics,JComponent) |
4394 | 154 |
*/ |
2 | 155 |
protected void paint(SynthContext context, Graphics g) { |
156 |
super.paint(g, getComponent()); |
|
157 |
} |
|
158 |
||
4394 | 159 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
160 |
* {@inheritDoc} |
4394 | 161 |
* |
162 |
* Overridden to do nothing. |
|
163 |
*/ |
|
164 |
@Override |
|
2 | 165 |
protected void paintBackground(Graphics g) { |
166 |
// Overriden to do nothing, all our painting is done from update/paint. |
|
167 |
} |
|
168 |
||
4394 | 169 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
170 |
* {@inheritDoc} |
4394 | 171 |
*/ |
172 |
@Override |
|
2 | 173 |
public void paintBorder(SynthContext context, Graphics g, int x, |
174 |
int y, int w, int h) { |
|
175 |
context.getPainter().paintTextAreaBorder(context, g, x, y, w, h); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* This method gets called when a bound property is changed |
|
180 |
* on the associated JTextComponent. This is a hook |
|
181 |
* which UI implementations may change to reflect how the |
|
182 |
* UI displays bound properties of JTextComponent subclasses. |
|
183 |
* This is implemented to rebuild the View when the |
|
184 |
* <em>WrapLine</em> or the <em>WrapStyleWord</em> property changes. |
|
185 |
* |
|
186 |
* @param evt the property change event |
|
187 |
*/ |
|
4394 | 188 |
@Override |
2 | 189 |
protected void propertyChange(PropertyChangeEvent evt) { |
190 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
191 |
updateStyle((JTextComponent)evt.getSource()); |
|
192 |
} |
|
193 |
super.propertyChange(evt); |
|
194 |
} |
|
4394 | 195 |
|
196 |
private final class Handler implements FocusListener { |
|
197 |
public void focusGained(FocusEvent e) { |
|
198 |
getComponent().repaint(); |
|
199 |
} |
|
200 |
||
201 |
public void focusLost(FocusEvent e) { |
|
202 |
getComponent().repaint(); |
|
203 |
} |
|
204 |
} |
|
2 | 205 |
} |