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 |
/* |
23697 | 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.border.*; |
|
30 |
import javax.swing.plaf.*; |
|
31 |
import javax.swing.plaf.basic.*; |
|
32 |
import java.awt.*; |
|
33 |
import java.beans.PropertyChangeListener; |
|
34 |
import java.beans.PropertyChangeEvent; |
|
35 |
||
36 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
37 |
* Provides the Synth L&F UI delegate for |
4394 | 38 |
* {@link javax.swing.JList}. |
2 | 39 |
* |
40 |
* @author Scott Violet |
|
4394 | 41 |
* @since 1.7 |
2 | 42 |
*/ |
4394 | 43 |
public class SynthListUI extends BasicListUI |
44 |
implements PropertyChangeListener, SynthUI { |
|
2 | 45 |
private SynthStyle style; |
46 |
private boolean useListColors; |
|
47 |
private boolean useUIBorder; |
|
48 |
||
4394 | 49 |
/** |
50 |
* Creates a new UI object for the given component. |
|
51 |
* |
|
52 |
* @param list component to create UI object for |
|
53 |
* @return the UI object |
|
54 |
*/ |
|
2 | 55 |
public static ComponentUI createUI(JComponent list) { |
56 |
return new SynthListUI(); |
|
57 |
} |
|
58 |
||
4394 | 59 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
60 |
* 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
|
61 |
* 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
|
62 |
* the {@link #paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
63 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
64 |
* <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
|
65 |
* 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
|
66 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
67 |
* @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
|
68 |
* @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
|
69 |
* @see #paint |
4394 | 70 |
*/ |
71 |
@Override |
|
2 | 72 |
public void update(Graphics g, JComponent c) { |
73 |
SynthContext context = getContext(c); |
|
74 |
||
75 |
SynthLookAndFeel.update(context, g); |
|
76 |
context.getPainter().paintListBackground(context, |
|
77 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
78 |
context.dispose(); |
|
79 |
paint(g, c); |
|
80 |
} |
|
81 |
||
4394 | 82 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
83 |
* {@inheritDoc} |
4394 | 84 |
*/ |
85 |
@Override |
|
2 | 86 |
public void paintBorder(SynthContext context, Graphics g, int x, |
87 |
int y, int w, int h) { |
|
88 |
context.getPainter().paintListBorder(context, g, x, y, w, h); |
|
89 |
} |
|
90 |
||
4394 | 91 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
92 |
* {@inheritDoc} |
4394 | 93 |
*/ |
94 |
@Override |
|
2 | 95 |
protected void installListeners() { |
96 |
super.installListeners(); |
|
97 |
list.addPropertyChangeListener(this); |
|
98 |
} |
|
99 |
||
4394 | 100 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
101 |
* {@inheritDoc} |
4394 | 102 |
*/ |
103 |
@Override |
|
2 | 104 |
public void propertyChange(PropertyChangeEvent e) { |
105 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
106 |
updateStyle((JList)e.getSource()); |
|
107 |
} |
|
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 |
super.uninstallListeners(); |
|
116 |
list.removePropertyChangeListener(this); |
|
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 |
protected void installDefaults() { |
124 |
if (list.getCellRenderer() == null || |
|
125 |
(list.getCellRenderer() instanceof UIResource)) { |
|
126 |
list.setCellRenderer(new SynthListCellRenderer()); |
|
127 |
} |
|
128 |
updateStyle(list); |
|
129 |
} |
|
130 |
||
131 |
private void updateStyle(JComponent c) { |
|
132 |
SynthContext context = getContext(list, ENABLED); |
|
133 |
SynthStyle oldStyle = style; |
|
134 |
||
135 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
136 |
||
137 |
if (style != oldStyle) { |
|
138 |
context.setComponentState(SELECTED); |
|
139 |
Color sbg = list.getSelectionBackground(); |
|
140 |
if (sbg == null || sbg instanceof UIResource) { |
|
141 |
list.setSelectionBackground(style.getColor( |
|
142 |
context, ColorType.TEXT_BACKGROUND)); |
|
143 |
} |
|
144 |
||
145 |
Color sfg = list.getSelectionForeground(); |
|
146 |
if (sfg == null || sfg instanceof UIResource) { |
|
147 |
list.setSelectionForeground(style.getColor( |
|
148 |
context, ColorType.TEXT_FOREGROUND)); |
|
149 |
} |
|
150 |
||
151 |
useListColors = style.getBoolean(context, |
|
152 |
"List.rendererUseListColors", true); |
|
153 |
useUIBorder = style.getBoolean(context, |
|
154 |
"List.rendererUseUIBorder", true); |
|
155 |
||
156 |
int height = style.getInt(context, "List.cellHeight", -1); |
|
157 |
if (height != -1) { |
|
158 |
list.setFixedCellHeight(height); |
|
159 |
} |
|
160 |
if (oldStyle != null) { |
|
161 |
uninstallKeyboardActions(); |
|
162 |
installKeyboardActions(); |
|
163 |
} |
|
164 |
} |
|
165 |
context.dispose(); |
|
166 |
} |
|
167 |
||
4394 | 168 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
169 |
* {@inheritDoc} |
4394 | 170 |
*/ |
171 |
@Override |
|
2 | 172 |
protected void uninstallDefaults() { |
173 |
super.uninstallDefaults(); |
|
174 |
||
175 |
SynthContext context = getContext(list, ENABLED); |
|
176 |
||
177 |
style.uninstallDefaults(context); |
|
178 |
context.dispose(); |
|
179 |
style = null; |
|
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 |
public SynthContext getContext(JComponent c) { |
187 |
return getContext(c, getComponentState(c)); |
|
188 |
} |
|
189 |
||
190 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 191 |
return SynthContext.getContext(c, style, state); |
2 | 192 |
} |
193 |
||
194 |
private int getComponentState(JComponent c) { |
|
195 |
return SynthLookAndFeel.getComponentState(c); |
|
196 |
} |
|
197 |
||
23697 | 198 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 199 |
private class SynthListCellRenderer extends DefaultListCellRenderer.UIResource { |
4394 | 200 |
@Override public String getName() { |
2 | 201 |
return "List.cellRenderer"; |
202 |
} |
|
203 |
||
4394 | 204 |
@Override public void setBorder(Border b) { |
2 | 205 |
if (useUIBorder || b instanceof SynthBorder) { |
206 |
super.setBorder(b); |
|
207 |
} |
|
208 |
} |
|
209 |
||
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
25100
diff
changeset
|
210 |
@Override public Component getListCellRendererComponent(JList<?> list, Object value, |
2 | 211 |
int index, boolean isSelected, boolean cellHasFocus) { |
212 |
if (!useListColors && (isSelected || cellHasFocus)) { |
|
213 |
SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel. |
|
214 |
getUIOfType(getUI(), SynthLabelUI.class), |
|
215 |
isSelected, cellHasFocus, list.isEnabled(), false); |
|
216 |
} |
|
217 |
else { |
|
218 |
SynthLookAndFeel.resetSelectedUI(); |
|
219 |
} |
|
220 |
||
221 |
super.getListCellRendererComponent(list, value, index, |
|
222 |
isSelected, cellHasFocus); |
|
223 |
return this; |
|
224 |
} |
|
225 |
||
4394 | 226 |
@Override public void paint(Graphics g) { |
2 | 227 |
super.paint(g); |
228 |
SynthLookAndFeel.resetSelectedUI(); |
|
229 |
} |
|
230 |
} |
|
231 |
} |