1 /*
2 * Copyright (c) 2002, 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
427 * size of the combo box. This is used in the case of the combo not having
428 * any data.
429 *
430 * @return the size of an empty display area
431 * @see #getDisplaySize
432 */
433 @Override
434 protected Dimension getDefaultSize() {
435 SynthComboBoxRenderer r = new SynthComboBoxRenderer();
436 Dimension d = getSizeForComponent(r.getListCellRendererComponent(listBox, " ", -1, false, false));
437 return new Dimension(d.width, d.height);
438 }
439
440 /**
441 * From BasicComboBoxRenderer v 1.18.
442 *
443 * Be aware that SynthFileChooserUIImpl relies on the fact that the default
444 * renderer installed on a Synth combo box is a JLabel. If this is changed,
445 * then an assert will fail in SynthFileChooserUIImpl
446 */
447 private class SynthComboBoxRenderer extends JLabel implements ListCellRenderer<Object>, UIResource {
448 public SynthComboBoxRenderer() {
449 super();
450 setText(" ");
451 }
452
453 @Override
454 public String getName() {
455 // SynthComboBoxRenderer should have installed Name while constructor is working.
456 // The setName invocation in the SynthComboBoxRenderer() constructor doesn't work
457 // because of the opaque property is installed in the constructor based on the
458 // component name (see GTKStyle.isOpaque())
459 String name = super.getName();
460
461 return name == null ? "ComboBox.renderer" : name;
462 }
463
464 @Override
465 public Component getListCellRendererComponent(JList<?> list, Object value,
466 int index, boolean isSelected, boolean cellHasFocus) {
518 private static class SynthComboBoxEditor
519 extends BasicComboBoxEditor.UIResource {
520
521 @Override public JTextField createEditorComponent() {
522 JTextField f = new JTextField("", 9);
523 f.setName("ComboBox.textField");
524 return f;
525 }
526 }
527
528
529 /**
530 * Handles all the logic for treating the combo as a button when it is
531 * not editable, and when shouldActLikeButton() is true. This class is a
532 * special ButtonModel, and installed on the arrowButton when appropriate.
533 * It also is installed as a mouse listener and mouse motion listener on
534 * the combo box. In this way, the state between the button and combo
535 * are in sync. Whenever one is "over" both are. Whenever one is pressed,
536 * both are.
537 */
538 private final class ButtonHandler extends DefaultButtonModel
539 implements MouseListener, PopupMenuListener {
540 /**
541 * Indicates that the mouse is over the combo or the arrow button.
542 * This field only has meaning if buttonWhenNotEnabled is true.
543 */
544 private boolean over;
545 /**
546 * Indicates that the combo or arrow button has been pressed. This
547 * field only has meaning if buttonWhenNotEnabled is true.
548 */
549 private boolean pressed;
550
551 //------------------------------------------------------------------
552 // State Methods
553 //------------------------------------------------------------------
554
555 /**
556 * <p>Updates the internal "pressed" state. If shouldActLikeButton()
557 * is true, and if this method call will change the internal state,
|
1 /*
2 * Copyright (c) 2002, 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
427 * size of the combo box. This is used in the case of the combo not having
428 * any data.
429 *
430 * @return the size of an empty display area
431 * @see #getDisplaySize
432 */
433 @Override
434 protected Dimension getDefaultSize() {
435 SynthComboBoxRenderer r = new SynthComboBoxRenderer();
436 Dimension d = getSizeForComponent(r.getListCellRendererComponent(listBox, " ", -1, false, false));
437 return new Dimension(d.width, d.height);
438 }
439
440 /**
441 * From BasicComboBoxRenderer v 1.18.
442 *
443 * Be aware that SynthFileChooserUIImpl relies on the fact that the default
444 * renderer installed on a Synth combo box is a JLabel. If this is changed,
445 * then an assert will fail in SynthFileChooserUIImpl
446 */
447 @SuppressWarnings("serial") // Superclass is not serializable across versions
448 private class SynthComboBoxRenderer extends JLabel implements ListCellRenderer<Object>, UIResource {
449 public SynthComboBoxRenderer() {
450 super();
451 setText(" ");
452 }
453
454 @Override
455 public String getName() {
456 // SynthComboBoxRenderer should have installed Name while constructor is working.
457 // The setName invocation in the SynthComboBoxRenderer() constructor doesn't work
458 // because of the opaque property is installed in the constructor based on the
459 // component name (see GTKStyle.isOpaque())
460 String name = super.getName();
461
462 return name == null ? "ComboBox.renderer" : name;
463 }
464
465 @Override
466 public Component getListCellRendererComponent(JList<?> list, Object value,
467 int index, boolean isSelected, boolean cellHasFocus) {
519 private static class SynthComboBoxEditor
520 extends BasicComboBoxEditor.UIResource {
521
522 @Override public JTextField createEditorComponent() {
523 JTextField f = new JTextField("", 9);
524 f.setName("ComboBox.textField");
525 return f;
526 }
527 }
528
529
530 /**
531 * Handles all the logic for treating the combo as a button when it is
532 * not editable, and when shouldActLikeButton() is true. This class is a
533 * special ButtonModel, and installed on the arrowButton when appropriate.
534 * It also is installed as a mouse listener and mouse motion listener on
535 * the combo box. In this way, the state between the button and combo
536 * are in sync. Whenever one is "over" both are. Whenever one is pressed,
537 * both are.
538 */
539 @SuppressWarnings("serial") // Superclass is not serializable across versions
540 private final class ButtonHandler extends DefaultButtonModel
541 implements MouseListener, PopupMenuListener {
542 /**
543 * Indicates that the mouse is over the combo or the arrow button.
544 * This field only has meaning if buttonWhenNotEnabled is true.
545 */
546 private boolean over;
547 /**
548 * Indicates that the combo or arrow button has been pressed. This
549 * field only has meaning if buttonWhenNotEnabled is true.
550 */
551 private boolean pressed;
552
553 //------------------------------------------------------------------
554 // State Methods
555 //------------------------------------------------------------------
556
557 /**
558 * <p>Updates the internal "pressed" state. If shouldActLikeButton()
559 * is true, and if this method call will change the internal state,
|