author | alexsch |
Fri, 15 Apr 2016 19:15:12 +0400 | |
changeset 37698 | 4d798c873df0 |
parent 25859 | 3317bb8137f4 |
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 |
||
29 |
import javax.swing.*; |
|
30 |
import javax.swing.colorchooser.*; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.BasicColorChooserUI; |
|
33 |
import java.awt.*; |
|
34 |
import java.beans.PropertyChangeEvent; |
|
35 |
import java.beans.PropertyChangeListener; |
|
36 |
||
37 |
||
38 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
39 |
* Provides the Synth L&F UI delegate for |
4394 | 40 |
* {@link javax.swing.JColorChooser}. |
2 | 41 |
* |
42 |
* @author Tom Santos |
|
43 |
* @author Steve Wilson |
|
4394 | 44 |
* @since 1.7 |
2 | 45 |
*/ |
4394 | 46 |
public class SynthColorChooserUI extends BasicColorChooserUI implements |
2 | 47 |
PropertyChangeListener, SynthUI { |
48 |
private SynthStyle style; |
|
49 |
||
4394 | 50 |
/** |
51 |
* Creates a new UI object for the given component. |
|
52 |
* |
|
53 |
* @param c component to create UI object for |
|
54 |
* @return the UI object |
|
55 |
*/ |
|
2 | 56 |
public static ComponentUI createUI(JComponent c) { |
57 |
return new SynthColorChooserUI(); |
|
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 AbstractColorChooserPanel[] createDefaultChoosers() { |
65 |
SynthContext context = getContext(chooser, ENABLED); |
|
66 |
AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[]) |
|
67 |
context.getStyle().get(context, "ColorChooser.panels"); |
|
68 |
||
69 |
if (panels == null) { |
|
70 |
panels = ColorChooserComponentFactory.getDefaultChooserPanels(); |
|
71 |
} |
|
72 |
return panels; |
|
73 |
} |
|
74 |
||
4394 | 75 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
76 |
* {@inheritDoc} |
4394 | 77 |
*/ |
78 |
@Override |
|
2 | 79 |
protected void installDefaults() { |
3103
6c55d4ab4ebe
6827032: NIMBUS: Drag and drop throws a NPE in SwingSet2 ColorChooser
peterz
parents:
2
diff
changeset
|
80 |
super.installDefaults(); |
2 | 81 |
updateStyle(chooser); |
82 |
} |
|
83 |
||
84 |
private void updateStyle(JComponent c) { |
|
85 |
SynthContext context = getContext(c, ENABLED); |
|
86 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
87 |
} |
|
88 |
||
4394 | 89 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
90 |
* {@inheritDoc} |
4394 | 91 |
*/ |
92 |
@Override |
|
2 | 93 |
protected void uninstallDefaults() { |
94 |
SynthContext context = getContext(chooser, ENABLED); |
|
95 |
||
96 |
style.uninstallDefaults(context); |
|
97 |
style = null; |
|
98 |
super.uninstallDefaults(); |
|
99 |
} |
|
100 |
||
4394 | 101 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
102 |
* {@inheritDoc} |
4394 | 103 |
*/ |
104 |
@Override |
|
2 | 105 |
protected void installListeners() { |
106 |
super.installListeners(); |
|
107 |
chooser.addPropertyChangeListener(this); |
|
108 |
} |
|
109 |
||
4394 | 110 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
111 |
* {@inheritDoc} |
4394 | 112 |
*/ |
113 |
@Override |
|
2 | 114 |
protected void uninstallListeners() { |
115 |
chooser.removePropertyChangeListener(this); |
|
116 |
super.uninstallListeners(); |
|
117 |
} |
|
118 |
||
4394 | 119 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
120 |
* {@inheritDoc} |
4394 | 121 |
*/ |
122 |
@Override |
|
2 | 123 |
public SynthContext getContext(JComponent c) { |
124 |
return getContext(c, getComponentState(c)); |
|
125 |
} |
|
126 |
||
127 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 128 |
return SynthContext.getContext(c, style, state); |
2 | 129 |
} |
130 |
||
131 |
private int getComponentState(JComponent c) { |
|
132 |
return SynthLookAndFeel.getComponentState(c); |
|
133 |
} |
|
134 |
||
4394 | 135 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
136 |
* 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
|
137 |
* 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
|
138 |
* 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
|
139 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
140 |
* <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
|
141 |
* 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
|
142 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
143 |
* @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
|
144 |
* @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
|
145 |
* @see #paint(SynthContext,Graphics) |
4394 | 146 |
*/ |
147 |
@Override |
|
2 | 148 |
public void update(Graphics g, JComponent c) { |
149 |
SynthContext context = getContext(c); |
|
150 |
||
151 |
SynthLookAndFeel.update(context, g); |
|
152 |
context.getPainter().paintColorChooserBackground(context, g, 0, 0, |
|
153 |
c.getWidth(), c.getHeight()); |
|
154 |
paint(context, g); |
|
155 |
} |
|
156 |
||
4394 | 157 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
158 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
159 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
160 |
* Painting is handled by 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
|
161 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
162 |
* @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
|
163 |
* @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
|
164 |
* @see #paint(SynthContext,Graphics) |
4394 | 165 |
*/ |
166 |
@Override |
|
2 | 167 |
public void paint(Graphics g, JComponent c) { |
168 |
SynthContext context = getContext(c); |
|
169 |
||
170 |
paint(context, g); |
|
171 |
} |
|
172 |
||
4394 | 173 |
/** |
174 |
* Paints the specified component. |
|
175 |
* This implementation does not perform any actions. |
|
176 |
* |
|
177 |
* @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
|
178 |
* @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
|
179 |
* @see #update(Graphics,JComponent) |
4394 | 180 |
*/ |
2 | 181 |
protected void paint(SynthContext context, Graphics g) { |
182 |
} |
|
183 |
||
4394 | 184 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
185 |
* {@inheritDoc} |
4394 | 186 |
*/ |
187 |
@Override |
|
2 | 188 |
public void paintBorder(SynthContext context, Graphics g, int x, |
189 |
int y, int w, int h) { |
|
190 |
context.getPainter().paintColorChooserBorder(context, g, x, y,w,h); |
|
191 |
} |
|
192 |
||
4394 | 193 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
194 |
* {@inheritDoc} |
4394 | 195 |
*/ |
196 |
@Override |
|
2 | 197 |
public void propertyChange(PropertyChangeEvent e) { |
198 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
199 |
updateStyle((JColorChooser)e.getSource()); |
|
200 |
} |
|
201 |
} |
|
202 |
} |