1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
25
26 package com.sun.java.swing.plaf.windows;
27
28 import java.beans.PropertyChangeListener;
29 import java.beans.PropertyChangeEvent;
30 import javax.swing.plaf.basic.*;
31 import javax.swing.plaf.*;
32 import javax.swing.border.*;
33 import javax.swing.*;
34 import java.awt.event.*;
35 import java.awt.*;
36
37 import static com.sun.java.swing.plaf.windows.TMSchema.Part;
38 import static com.sun.java.swing.plaf.windows.TMSchema.State;
39 import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
40 import sun.swing.DefaultLookup;
41 import sun.swing.StringUIClientPropertyKey;
42
43
44 /**
45 * Windows combo box.
46 * <p>
47 * <strong>Warning:</strong>
48 * Serialized objects of this class will not be compatible with
49 * future Swing releases. The current serialization support is appropriate
50 * for short term storage or RMI between applications running the same
51 * version of Swing. A future release of Swing will provide support for
52 * long term persistence.
53 *
54 * @author Tom Santos
55 * @author Igor Kushnirskiy
56 */
57
58 public class WindowsComboBoxUI extends BasicComboBoxUI {
59
214 if (XPStyle.getXP() != null) {
215 paintXPComboBoxBackground(g, c);
216 }
217 super.paint(g, c);
218 }
219
220 State getXPComboBoxState(JComponent c) {
221 State state = State.NORMAL;
222 if (!c.isEnabled()) {
223 state = State.DISABLED;
224 } else if (isPopupVisible(comboBox)) {
225 state = State.PRESSED;
226 } else if (isRollover) {
227 state = State.HOT;
228 }
229 return state;
230 }
231
232 private void paintXPComboBoxBackground(Graphics g, JComponent c) {
233 XPStyle xp = XPStyle.getXP();
234 State state = getXPComboBoxState(c);
235 Skin skin = null;
236 if (! comboBox.isEditable()
237 && xp.isSkinDefined(c, Part.CP_READONLY)) {
238 skin = xp.getSkin(c, Part.CP_READONLY);
239 }
240 if (skin == null) {
241 skin = xp.getSkin(c, Part.CP_COMBOBOX);
242 }
243 skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state);
244 }
245
246 /**
247 * If necessary paints the currently selected item.
248 *
249 * @param g Graphics to paint to
250 * @param bounds Region to paint current value to
251 * @param hasFocus whether or not the JComboBox has focus
252 * @throws NullPointerException if any of the arguments are null.
253 * @since 1.5
383 * {@inheritDoc}
384 * @since 1.6
385 */
386 @Override
387 protected ListCellRenderer createRenderer() {
388 XPStyle xp = XPStyle.getXP();
389 if (xp != null && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
390 return new WindowsComboBoxRenderer();
391 } else {
392 return super.createRenderer();
393 }
394 }
395
396 /**
397 * Creates an button which will be used as the control to show or hide
398 * the popup portion of the combo box.
399 *
400 * @return a button which represents the popup control
401 */
402 protected JButton createArrowButton() {
403 if (XPStyle.getXP() != null) {
404 return new XPComboBoxButton();
405 } else {
406 return super.createArrowButton();
407 }
408 }
409
410 @SuppressWarnings("serial") // Superclass is not serializable across versions
411 private class XPComboBoxButton extends XPStyle.GlyphButton {
412 public XPComboBoxButton() {
413 super(null,
414 (! XPStyle.getXP().isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT))
415 ? Part.CP_DROPDOWNBUTTON
416 : (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
417 ? Part.CP_DROPDOWNBUTTONLEFT
418 : Part.CP_DROPDOWNBUTTONRIGHT
419 );
420 setRequestFocusEnabled(false);
421 }
422
423 @Override
424 protected State getState() {
425 State rv;
426 rv = super.getState();
427 if (rv != State.DISABLED
428 && comboBox != null && ! comboBox.isEditable()
429 && XPStyle.getXP().isSkinDefined(comboBox,
430 Part.CP_DROPDOWNBUTTONRIGHT)) {
431 /*
432 * for non editable ComboBoxes Vista seems to have the
433 * same glyph for all non DISABLED states
434 */
435 rv = State.NORMAL;
436 }
437 return rv;
438 }
439
440 public Dimension getPreferredSize() {
441 return new Dimension(17, 21);
442 }
443
444 void setPart(Part part) {
445 setPart(comboBox, part);
446 }
447
448 WindowsComboBoxUI getWindowsComboBoxUI() {
449 return WindowsComboBoxUI.this;
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
25
26 package com.sun.java.swing.plaf.windows;
27
28 import java.beans.PropertyChangeListener;
29 import java.beans.PropertyChangeEvent;
30 import javax.swing.plaf.basic.*;
31 import javax.swing.plaf.*;
32 import javax.swing.border.*;
33 import javax.swing.*;
34 import java.awt.event.*;
35 import java.awt.*;
36
37 import static com.sun.java.swing.plaf.windows.TMSchema.Part;
38 import static com.sun.java.swing.plaf.windows.TMSchema.State;
39 import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
40
41 import sun.swing.DefaultLookup;
42 import sun.swing.StringUIClientPropertyKey;
43
44
45 /**
46 * Windows combo box.
47 * <p>
48 * <strong>Warning:</strong>
49 * Serialized objects of this class will not be compatible with
50 * future Swing releases. The current serialization support is appropriate
51 * for short term storage or RMI between applications running the same
52 * version of Swing. A future release of Swing will provide support for
53 * long term persistence.
54 *
55 * @author Tom Santos
56 * @author Igor Kushnirskiy
57 */
58
59 public class WindowsComboBoxUI extends BasicComboBoxUI {
60
215 if (XPStyle.getXP() != null) {
216 paintXPComboBoxBackground(g, c);
217 }
218 super.paint(g, c);
219 }
220
221 State getXPComboBoxState(JComponent c) {
222 State state = State.NORMAL;
223 if (!c.isEnabled()) {
224 state = State.DISABLED;
225 } else if (isPopupVisible(comboBox)) {
226 state = State.PRESSED;
227 } else if (isRollover) {
228 state = State.HOT;
229 }
230 return state;
231 }
232
233 private void paintXPComboBoxBackground(Graphics g, JComponent c) {
234 XPStyle xp = XPStyle.getXP();
235 if (xp == null) {
236 return;
237 }
238 State state = getXPComboBoxState(c);
239 Skin skin = null;
240 if (! comboBox.isEditable()
241 && xp.isSkinDefined(c, Part.CP_READONLY)) {
242 skin = xp.getSkin(c, Part.CP_READONLY);
243 }
244 if (skin == null) {
245 skin = xp.getSkin(c, Part.CP_COMBOBOX);
246 }
247 skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state);
248 }
249
250 /**
251 * If necessary paints the currently selected item.
252 *
253 * @param g Graphics to paint to
254 * @param bounds Region to paint current value to
255 * @param hasFocus whether or not the JComboBox has focus
256 * @throws NullPointerException if any of the arguments are null.
257 * @since 1.5
387 * {@inheritDoc}
388 * @since 1.6
389 */
390 @Override
391 protected ListCellRenderer createRenderer() {
392 XPStyle xp = XPStyle.getXP();
393 if (xp != null && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
394 return new WindowsComboBoxRenderer();
395 } else {
396 return super.createRenderer();
397 }
398 }
399
400 /**
401 * Creates an button which will be used as the control to show or hide
402 * the popup portion of the combo box.
403 *
404 * @return a button which represents the popup control
405 */
406 protected JButton createArrowButton() {
407 XPStyle xp = XPStyle.getXP();
408 if (xp != null) {
409 return new XPComboBoxButton(xp);
410 } else {
411 return super.createArrowButton();
412 }
413 }
414
415 @SuppressWarnings("serial") // Superclass is not serializable across versions
416 private class XPComboBoxButton extends XPStyle.GlyphButton {
417 public XPComboBoxButton(XPStyle xp) {
418 super(null,
419 (! xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT))
420 ? Part.CP_DROPDOWNBUTTON
421 : (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
422 ? Part.CP_DROPDOWNBUTTONLEFT
423 : Part.CP_DROPDOWNBUTTONRIGHT
424 );
425 setRequestFocusEnabled(false);
426 }
427
428 @Override
429 protected State getState() {
430 State rv;
431 rv = super.getState();
432 XPStyle xp = XPStyle.getXP();
433 if (rv != State.DISABLED
434 && comboBox != null && ! comboBox.isEditable()
435 && xp != null && xp.isSkinDefined(comboBox,
436 Part.CP_DROPDOWNBUTTONRIGHT)) {
437 /*
438 * for non editable ComboBoxes Vista seems to have the
439 * same glyph for all non DISABLED states
440 */
441 rv = State.NORMAL;
442 }
443 return rv;
444 }
445
446 public Dimension getPreferredSize() {
447 return new Dimension(17, 21);
448 }
449
450 void setPart(Part part) {
451 setPart(comboBox, part);
452 }
453
454 WindowsComboBoxUI getWindowsComboBoxUI() {
455 return WindowsComboBoxUI.this;
|