jdk/src/share/classes/javax/swing/plaf/synth/SynthComboPopup.java
author alexsch
Wed, 25 Sep 2013 17:08:31 +0400
changeset 20168 137788883a22
parent 12405 3a06b392a805
child 23010 6dadb192ad81
permissions -rw-r--r--
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth Reviewed-by: serb, alexsch Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
12405
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    29
import javax.swing.plaf.ComboBoxUI;
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    30
import javax.swing.plaf.basic.BasicComboPopup;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Synth's ComboPopup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
class SynthComboPopup extends BasicComboPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public SynthComboPopup( JComboBox combo ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        super(combo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Configures the list which is used to hold the combo box items in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * popup. This method is called when the UI class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @see #createList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
12405
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    51
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected void configureList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        list.setFont( comboBox.getFont() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        list.setCellRenderer( comboBox.getRenderer() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        list.setFocusable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        int selectedIndex = comboBox.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        if ( selectedIndex == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            list.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            list.setSelectedIndex( selectedIndex );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            list.ensureIndexIsVisible( selectedIndex );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        installListListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
12405
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    67
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    68
    /**
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    69
     * @inheritDoc
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    70
     *
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    71
     * Overridden to take into account any popup insets specified in
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    72
     * SynthComboBoxUI
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    73
     */
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    74
    @Override
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    75
    protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    76
        ComboBoxUI ui = comboBox.getUI();
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    77
        if (ui instanceof SynthComboBoxUI) {
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    78
            SynthComboBoxUI sui = (SynthComboBoxUI) ui;
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    79
            if (sui.popupInsets != null) {
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    80
                Insets i = sui.popupInsets;
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    81
                return super.computePopupBounds(
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    82
                        px + i.left,
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    83
                        py + i.top,
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    84
                        pw - i.left - i.right,
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    85
                        ph - i.top - i.bottom);
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    86
            }
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    87
        }
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    88
        return super.computePopupBounds(px, py, pw, ph);
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    89
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}