jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthComboPopup.java
author alexsch
Wed, 18 Nov 2015 19:13:42 +0400
changeset 34407 2b40f400a30b
parent 25859 3317bb8137f4
permissions -rw-r--r--
8081411: Add an API for painting an icon with a SynthContext Reviewed-by: serb, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2014, 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
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    39
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class SynthComboPopup extends BasicComboPopup {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23697
diff changeset
    41
    public SynthComboPopup( JComboBox<Object> combo ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        super(combo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Configures the list which is used to hold the combo box items in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * popup. This method is called when the UI class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @see #createList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
12405
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    52
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected void configureList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        list.setFont( comboBox.getFont() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        list.setCellRenderer( comboBox.getRenderer() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        list.setFocusable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        int selectedIndex = comboBox.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if ( selectedIndex == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            list.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            list.setSelectedIndex( selectedIndex );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            list.ensureIndexIsVisible( selectedIndex );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        installListListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
12405
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
    /**
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    70
     * @inheritDoc
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    71
     *
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    72
     * Overridden to take into account any popup insets specified in
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    73
     * SynthComboBoxUI
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    74
     */
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    75
    @Override
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    76
    protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    77
        ComboBoxUI ui = comboBox.getUI();
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    78
        if (ui instanceof SynthComboBoxUI) {
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    79
            SynthComboBoxUI sui = (SynthComboBoxUI) ui;
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    80
            if (sui.popupInsets != null) {
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    81
                Insets i = sui.popupInsets;
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    82
                return super.computePopupBounds(
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    83
                        px + i.left,
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    84
                        py + i.top,
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    85
                        pw - i.left - i.right,
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    86
                        ph - i.top - i.bottom);
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
        }
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    89
        return super.computePopupBounds(px, py, pw, ph);
3a06b392a805 7158712: Synth Property "ComboBox.popupInsets" is ignored
rupashka
parents: 5506
diff changeset
    90
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}