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 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20168
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, 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 java.awt.*; |
|
29 |
import javax.swing.*; |
|
30 |
import javax.swing.text.*; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.BasicEditorPaneUI; |
|
33 |
import java.beans.PropertyChangeEvent; |
|
34 |
||
35 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
36 |
* Provides the Synth L&F UI delegate for |
4394 | 37 |
* {@link javax.swing.JEditorPane}. |
2 | 38 |
* |
39 |
* @author Shannon Hickey |
|
4394 | 40 |
* @since 1.7 |
2 | 41 |
*/ |
4394 | 42 |
public class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI { |
2 | 43 |
private SynthStyle style; |
44 |
/* |
|
45 |
* I would prefer to use UIResource instad of this. |
|
46 |
* Unfortunately Boolean is a final class |
|
47 |
*/ |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
48 |
private Boolean localTrue = Boolean.TRUE; |
2 | 49 |
|
50 |
/** |
|
4394 | 51 |
* Creates a new UI object for the given component. |
2 | 52 |
* |
4394 | 53 |
* @param c component to create UI object for |
54 |
* @return the UI object |
|
2 | 55 |
*/ |
56 |
public static ComponentUI createUI(JComponent c) { |
|
57 |
return new SynthEditorPaneUI(); |
|
58 |
} |
|
59 |
||
4394 | 60 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
61 |
* {@inheritDoc} |
4394 | 62 |
*/ |
63 |
@Override |
|
2 | 64 |
protected void installDefaults() { |
65 |
// Installs the text cursor on the component |
|
66 |
super.installDefaults(); |
|
67 |
JComponent c = getComponent(); |
|
68 |
Object clientProperty = |
|
69 |
c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); |
|
4394 | 70 |
if (clientProperty == null) { |
71 |
c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, localTrue); |
|
2 | 72 |
} |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
73 |
updateStyle(getComponent()); |
2 | 74 |
} |
75 |
||
4394 | 76 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
77 |
* {@inheritDoc} |
4394 | 78 |
*/ |
79 |
@Override |
|
2 | 80 |
protected void uninstallDefaults() { |
81 |
SynthContext context = getContext(getComponent(), ENABLED); |
|
82 |
JComponent c = getComponent(); |
|
83 |
c.putClientProperty("caretAspectRatio", null); |
|
84 |
||
85 |
style.uninstallDefaults(context); |
|
86 |
context.dispose(); |
|
87 |
style = null; |
|
88 |
||
89 |
Object clientProperty = |
|
90 |
c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); |
|
91 |
if (clientProperty == localTrue) { |
|
4394 | 92 |
c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, |
2 | 93 |
Boolean.FALSE); |
94 |
} |
|
95 |
super.uninstallDefaults(); |
|
96 |
} |
|
97 |
||
98 |
/** |
|
99 |
* This method gets called when a bound property is changed |
|
100 |
* on the associated JTextComponent. This is a hook |
|
101 |
* which UI implementations may change to reflect how the |
|
102 |
* UI displays bound properties of JTextComponent subclasses. |
|
103 |
* This is implemented to rebuild the ActionMap based upon an |
|
104 |
* EditorKit change. |
|
105 |
* |
|
106 |
* @param evt the property change event |
|
107 |
*/ |
|
4394 | 108 |
@Override |
2 | 109 |
protected void propertyChange(PropertyChangeEvent evt) { |
110 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
111 |
updateStyle((JTextComponent)evt.getSource()); |
|
112 |
} |
|
113 |
super.propertyChange(evt); |
|
114 |
} |
|
115 |
||
116 |
private void updateStyle(JTextComponent comp) { |
|
117 |
SynthContext context = getContext(comp, ENABLED); |
|
118 |
SynthStyle oldStyle = style; |
|
119 |
||
120 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
121 |
||
122 |
if (style != oldStyle) { |
|
123 |
SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix()); |
|
124 |
||
125 |
if (oldStyle != null) { |
|
126 |
uninstallKeyboardActions(); |
|
127 |
installKeyboardActions(); |
|
128 |
} |
|
129 |
} |
|
130 |
context.dispose(); |
|
131 |
} |
|
132 |
||
4394 | 133 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
134 |
* {@inheritDoc} |
4394 | 135 |
*/ |
136 |
@Override |
|
2 | 137 |
public SynthContext getContext(JComponent c) { |
138 |
return getContext(c, getComponentState(c)); |
|
139 |
} |
|
140 |
||
141 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 142 |
return SynthContext.getContext(c, style, state); |
2 | 143 |
} |
144 |
||
145 |
private int getComponentState(JComponent c) { |
|
146 |
return SynthLookAndFeel.getComponentState(c); |
|
147 |
} |
|
148 |
||
4394 | 149 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
150 |
* 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
|
151 |
* 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
|
152 |
* 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
|
153 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
154 |
* <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
|
155 |
* 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
|
156 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
157 |
* @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
|
158 |
* @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
|
159 |
* @see #paint(SynthContext,Graphics) |
4394 | 160 |
*/ |
161 |
@Override |
|
2 | 162 |
public void update(Graphics g, JComponent c) { |
163 |
SynthContext context = getContext(c); |
|
164 |
||
165 |
SynthLookAndFeel.update(context, g); |
|
166 |
paintBackground(context, g, c); |
|
167 |
paint(context, g); |
|
168 |
context.dispose(); |
|
169 |
} |
|
170 |
||
4394 | 171 |
/** |
172 |
* Paints the specified component. |
|
173 |
* |
|
174 |
* @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
|
175 |
* @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
|
176 |
* @see #update(Graphics,JComponent) |
4394 | 177 |
*/ |
2 | 178 |
protected void paint(SynthContext context, Graphics g) { |
179 |
super.paint(g, getComponent()); |
|
180 |
} |
|
181 |
||
4394 | 182 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
183 |
* {@inheritDoc} |
4394 | 184 |
*/ |
185 |
@Override |
|
2 | 186 |
protected void paintBackground(Graphics g) { |
187 |
// Overriden to do nothing, all our painting is done from update/paint. |
|
188 |
} |
|
189 |
||
190 |
void paintBackground(SynthContext context, Graphics g, JComponent c) { |
|
191 |
context.getPainter().paintEditorPaneBackground(context, g, 0, 0, |
|
192 |
c.getWidth(), c.getHeight()); |
|
193 |
} |
|
194 |
||
4394 | 195 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
196 |
* {@inheritDoc} |
4394 | 197 |
*/ |
198 |
@Override |
|
2 | 199 |
public void paintBorder(SynthContext context, Graphics g, int x, |
200 |
int y, int w, int h) { |
|
201 |
context.getPainter().paintEditorPaneBorder(context, g, x, y, w, h); |
|
202 |
} |
|
203 |
} |