jdk/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java
author rupashka
Mon, 02 Jun 2008 19:08:13 +0400
changeset 676 8cf833d60e87
parent 2 90ce3da70b43
child 3977 0da8e3baf0b5
permissions -rw-r--r--
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs Summary: Removed unnecessary code like unused variables, castings, imports etc Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.accessibility.AccessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.border.LineBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This is a basic implementation of the <code>ComboPopup</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class represents the ui for the popup portion of the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * All event handling is handled by listener classes created with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>createxxxListener()</code> methods and internal classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * You can change the behavior of this class by overriding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>createxxxListener()</code> methods and supplying your own
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * event listeners or subclassing from the ones supplied in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @author Mark Davidson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class BasicComboPopup extends JPopupMenu implements ComboPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // An empty ListMode, this is used when the UI changes to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // the JList to be gc'ed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static class EmptyListModelClass implements ListModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                                        Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        public int getSize() { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public Object getElementAt(int index) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        public void addListDataListener(ListDataListener l) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        public void removeListDataListener(ListDataListener l) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static final ListModel EmptyListModel = new EmptyListModelClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static Border LIST_BORDER = new LineBorder(Color.BLACK, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected JComboBox                comboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * or override. Use the accessor methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #getList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see #createList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected JList                    list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * or override. Use the create method instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see #createScroller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected JScrollPane              scroller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * As of Java 2 platform v1.4 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected boolean                  valueIsAdjusting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // Listeners that are required by the ComboPopup interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Implementation of all the listener classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * or override. Use the accessor or create methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #getMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #createMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected MouseMotionListener      mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * or override. Use the accessor or create methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see #getMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see #createMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected MouseListener            mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * or override. Use the accessor or create methods instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #getKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #createKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    protected KeyListener              keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * or override. Use the create method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #createListSelectionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected ListSelectionListener    listSelectionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // Listeners that are attached to the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * or override. Use the create method instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see #createListMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected MouseListener            listMouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * or override. Use the create method instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @see #createListMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected MouseMotionListener      listMouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    // Added to the combo box for bound properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * or override. Use the create method instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see #createPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    protected PropertyChangeListener   propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // Added to the combo box model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * or override. Use the create method instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @see #createListDataListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    protected ListDataListener         listDataListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * or override. Use the create method instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see #createItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    protected ItemListener             itemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * This protected field is implementation specific. Do not access directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected Timer                    autoscrollTimer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    protected boolean                  hasEntered = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected boolean                  isAutoScrolling = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    protected int                      scrollDirection = SCROLL_UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected static final int         SCROLL_UP = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    protected static final int         SCROLL_DOWN = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    //========================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // begin ComboPopup method implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Implementation of ComboPopup.show().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        setListSelection(comboBox.getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        Point location = getPopupLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        show( comboBox, location.x, location.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Implementation of ComboPopup.hide().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        MenuSelectionManager manager = MenuSelectionManager.defaultManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        MenuElement [] selection = manager.getSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for ( int i = 0 ; i < selection.length ; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if ( selection[i] == this ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                manager.clearSelectedPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (selection.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            comboBox.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Implementation of ComboPopup.getList().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public JList getList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Implementation of ComboPopup.getMouseListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return a <code>MouseListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @see ComboPopup#getMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public MouseListener getMouseListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (mouseListener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            mouseListener = createMouseListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return mouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Implementation of ComboPopup.getMouseMotionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return a <code>MouseMotionListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see ComboPopup#getMouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public MouseMotionListener getMouseMotionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (mouseMotionListener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            mouseMotionListener = createMouseMotionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return mouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Implementation of ComboPopup.getKeyListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return a <code>KeyListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see ComboPopup#getKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public KeyListener getKeyListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (keyListener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            keyListener = createKeyListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return keyListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Called when the UI is uninstalling.  Since this popup isn't in the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * tree, it won't get it's uninstallUI() called.  It removes the listeners that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * were added in addComboBoxListeners().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void uninstallingUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            comboBox.removePropertyChangeListener( propertyChangeListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (itemListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            comboBox.removeItemListener( itemListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        uninstallComboBoxModelListeners(comboBox.getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        uninstallListListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // We do this, otherwise the listener the ui installs on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // the model (the combobox model in this case) will keep a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // reference to the list, causing the list (and us) to never get gced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        list.setModel(EmptyListModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    // end ComboPopup method implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    //======================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Removes the listeners from the combo box model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param model The combo box model to install listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see #installComboBoxModelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    protected void uninstallComboBoxModelListeners( ComboBoxModel model ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (model != null && listDataListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            model.removeListDataListener(listDataListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // XXX - shouldn't call this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
//        comboBox.unregisterKeyboardAction( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    //===================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    // begin Initialization routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public BasicComboPopup( JComboBox combo ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        setName("ComboPopup.popup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        comboBox = combo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        setLightWeightPopupEnabled( comboBox.isLightWeightPopupEnabled() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // UI construction of the popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        list = createList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        list.setName("ComboBox.list");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        configureList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        scroller = createScroller();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        scroller.setName("ComboBox.scrollPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        configureScroller();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        configurePopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        installComboBoxListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    // Overriden PopupMenuListener notification methods to inform combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    // PopupMenuListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    protected void firePopupMenuWillBecomeVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        super.firePopupMenuWillBecomeVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        comboBox.firePopupMenuWillBecomeVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    protected void firePopupMenuWillBecomeInvisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        super.firePopupMenuWillBecomeInvisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        comboBox.firePopupMenuWillBecomeInvisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    protected void firePopupMenuCanceled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        super.firePopupMenuCanceled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        comboBox.firePopupMenuCanceled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Creates a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * that will watch for mouse-press and release events on the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * When overriding this method, make sure to maintain the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @return a <code>MouseListener</code> which will be added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * the combo box or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    protected MouseListener createMouseListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Creates the mouse motion listener which will be added to the combo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * When overriding this method, make sure to maintain the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @return a <code>MouseMotionListener</code> which will be added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *         the combo box or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    protected MouseMotionListener createMouseMotionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Creates the key listener that will be added to the combo box. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * this method returns null then it will not be added to the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @return a <code>KeyListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    protected KeyListener createKeyListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Creates a list selection listener that watches for selection changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * the popup's list.  If this method returns null then it will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * be added to the popup list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return an instance of a <code>ListSelectionListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    protected ListSelectionListener createListSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Creates a list data listener which will be added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <code>ComboBoxModel</code>. If this method returns null then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * it will not be added to the combo box model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return an instance of a <code>ListDataListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    protected ListDataListener createListDataListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Creates a mouse listener that watches for mouse events in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * the popup's list. If this method returns null then it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * not be added to the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @return an instance of a <code>MouseListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    protected MouseListener createListMouseListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Creates a mouse motion listener that watches for mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * events in the popup's list. If this method returns null then it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * not be added to the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @return an instance of a <code>MouseMotionListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    protected MouseMotionListener createListMouseMotionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Creates a <code>PropertyChangeListener</code> which will be added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * the combo box. If this method returns null then it will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * be added to the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @return an instance of a <code>PropertyChangeListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Creates an <code>ItemListener</code> which will be added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * combo box. If this method returns null then it will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * be added to the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * Subclasses may override this method to return instances of their own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * ItemEvent handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @return an instance of an <code>ItemListener</code> or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    protected ItemListener createItemListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Creates the JList used in the popup to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * the items in the combo box model. This method is called when the UI class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @return a <code>JList</code> used to display the combo box items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    protected JList createList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        return new JList( comboBox.getModel() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            public void processMouseEvent(MouseEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                if (e.isControlDown())  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    // Fix for 4234053. Filter out the Control Key from the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    // ie., don't allow CTRL key deselection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                       e.getModifiers() ^ InputEvent.CTRL_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                       e.getX(), e.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                       e.getXOnScreen(), e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                       e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                       e.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                       MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                super.processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Configures the list which is used to hold the combo box items in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * popup. This method is called when the UI class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @see #createList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    protected void configureList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        list.setFont( comboBox.getFont() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        list.setForeground( comboBox.getForeground() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        list.setBackground( comboBox.getBackground() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        list.setSelectionForeground( UIManager.getColor( "ComboBox.selectionForeground" ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        list.setSelectionBackground( UIManager.getColor( "ComboBox.selectionBackground" ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        list.setBorder( null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        list.setCellRenderer( comboBox.getRenderer() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        list.setFocusable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        setListSelection( comboBox.getSelectedIndex() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        installListListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Adds the listeners to the list control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    protected void installListListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if ((listMouseListener = createListMouseListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            list.addMouseListener( listMouseListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if ((listMouseMotionListener = createListMouseMotionListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            list.addMouseMotionListener( listMouseMotionListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if ((listSelectionListener = createListSelectionListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            list.addListSelectionListener( listSelectionListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    void uninstallListListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (listMouseListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            list.removeMouseListener(listMouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            listMouseListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (listMouseMotionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            list.removeMouseMotionListener(listMouseMotionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            listMouseMotionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (listSelectionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            list.removeListSelectionListener(listSelectionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            listSelectionListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Creates the scroll pane which houses the scrollable list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    protected JScrollPane createScroller() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        JScrollPane sp = new JScrollPane( list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        sp.setHorizontalScrollBar(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Configures the scrollable portion which holds the list within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * the combo box popup. This method is called when the UI class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    protected void configureScroller() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        scroller.setFocusable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        scroller.getVerticalScrollBar().setFocusable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        scroller.setBorder( null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Configures the popup portion of the combo box. This method is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * when the UI class is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    protected void configurePopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        setBorderPainted( true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        setBorder(LIST_BORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        setOpaque( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        add( scroller );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        setDoubleBuffered( true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        setFocusable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * This method adds the necessary listeners to the JComboBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    protected void installComboBoxListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if ((propertyChangeListener = createPropertyChangeListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            comboBox.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if ((itemListener = createItemListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            comboBox.addItemListener(itemListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        installComboBoxModelListeners(comboBox.getModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Installs the listeners on the combo box model. Any listeners installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * on the combo box model should be removed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <code>uninstallComboBoxModelListeners</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param model The combo box model to install listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see #uninstallComboBoxModelListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    protected void installComboBoxModelListeners( ComboBoxModel model ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        if (model != null && (listDataListener = createListDataListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            model.addListDataListener(listDataListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        /* XXX - shouldn't call this method. take it out for testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        ActionListener action = new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            public void actionPerformed(ActionEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        comboBox.registerKeyboardAction( action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                         KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                         JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    // end Initialization routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    //=================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    //===================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    // begin Event Listenters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * A listener to be registered upon the combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * (<em>not</em> its popup menu)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * to handle mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * that affect the state of the popup menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * The main purpose of this listener is to make the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * appear and disappear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * This listener also helps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * with click-and-drag scenarios by setting the selection if the mouse was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * released over the list during a drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * We recommend that you <em>not</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * create subclasses of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * If you absolutely must create a subclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * be sure to invoke the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * version of each method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see BasicComboPopup#createMouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    protected class InvocationMouseHandler extends MouseAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         * Responds to mouse-pressed events on the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
         * @param e the mouse-press event to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        public void mousePressed( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            getHandler().mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         * Responds to the user terminating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         * a click or drag that began on the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
         * @param e the mouse-release event to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        public void mouseReleased( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            getHandler().mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * This listener watches for dragging and updates the current selection in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * list if it is dragging over the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    protected class InvocationMouseMotionHandler extends MouseMotionAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        public void mouseDragged( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            getHandler().mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * As of Java 2 platform v 1.4, this class is now obsolete and is only included for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * backwards API compatibility. Do not instantiate or subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * All the functionality of this class has been included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * BasicComboBoxUI ActionMap/InputMap methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    public class InvocationKeyHandler extends KeyAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        public void keyReleased( KeyEvent e ) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * As of Java 2 platform v 1.4, this class is now obsolete, doesn't do anything, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * is only included for backwards API compatibility. Do not call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    protected class ListSelectionHandler implements ListSelectionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        public void valueChanged( ListSelectionEvent e ) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * As of 1.4, this class is now obsolete, doesn't do anything, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * is only included for backwards API compatibility. Do not call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * The functionality has been migrated into <code>ItemHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @see #createItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    public class ListDataHandler implements ListDataListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        public void contentsChanged( ListDataEvent e ) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        public void intervalAdded( ListDataEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        public void intervalRemoved( ListDataEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * This listener hides the popup when the mouse is released in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    protected class ListMouseHandler extends MouseAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        public void mousePressed( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        public void mouseReleased(MouseEvent anEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            getHandler().mouseReleased(anEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * This listener changes the selected item as you move the mouse over the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * The selection change is not committed to the model, this is for user feedback only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    protected class ListMouseMotionHandler extends MouseMotionAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        public void mouseMoved( MouseEvent anEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            getHandler().mouseMoved(anEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * This listener watches for changes to the selection in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    protected class ItemHandler implements ItemListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        public void itemStateChanged( ItemEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            getHandler().itemStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * This listener watches for bound properties that have changed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Subclasses which wish to listen to combo box property changes should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * call the superclass methods to ensure that the combo popup correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * handles property changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @see #createPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    protected class PropertyChangeHandler implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        public void propertyChange( PropertyChangeEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    private class AutoScrollActionHandler implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        private int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        AutoScrollActionHandler(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (direction == SCROLL_UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                autoScrollUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                autoScrollDown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    private class Handler implements ItemListener, MouseListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                          MouseMotionListener, PropertyChangeListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                          Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        // MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        // NOTE: this is added to both the JList and JComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            if (e.getSource() == list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            if (!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            if ( comboBox.isEditable() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                Component comp = comboBox.getEditor().getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                if ((!(comp instanceof JComponent)) || ((JComponent)comp).isRequestFocusEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            else if (comboBox.isRequestFocusEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                comboBox.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            togglePopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            if (e.getSource() == list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                if (list.getModel().getSize() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    // JList mouse listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    if (comboBox.getSelectedIndex() == list.getSelectedIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                        comboBox.getEditor().setItem(list.getSelectedValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    comboBox.setSelectedIndex(list.getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                comboBox.setPopupVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                // workaround for cancelling an edited item (bug 4530953)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                if (comboBox.isEditable() && comboBox.getEditor() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    comboBox.configureEditor(comboBox.getEditor(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                                             comboBox.getSelectedItem());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            // JComboBox mouse listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            Component source = (Component)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            Dimension size = source.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            Rectangle bounds = new Rectangle( 0, 0, size.width - 1, size.height - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            if ( !bounds.contains( e.getPoint() ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                MouseEvent newEvent = convertMouseEvent( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                Point location = newEvent.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                list.computeVisibleRect( r );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                if ( r.contains( location ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    if (comboBox.getSelectedIndex() == list.getSelectedIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                        comboBox.getEditor().setItem(list.getSelectedValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    comboBox.setSelectedIndex(list.getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                comboBox.setPopupVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            hasEntered = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            stopAutoScrolling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        // MouseMotionListener:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        // NOTE: this is added to both the List and ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        public void mouseMoved(MouseEvent anEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            if (anEvent.getSource() == list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                Point location = anEvent.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                list.computeVisibleRect( r );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                if ( r.contains( location ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    updateListBoxSelectionForEvent( anEvent, false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        public void mouseDragged( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            if (e.getSource() == list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            if ( isVisible() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                MouseEvent newEvent = convertMouseEvent( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                Rectangle r = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                list.computeVisibleRect( r );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                if ( newEvent.getPoint().y >= r.y && newEvent.getPoint().y <= r.y + r.height - 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                    hasEntered = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    if ( isAutoScrolling ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                        stopAutoScrolling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    Point location = newEvent.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                    if ( r.contains( location ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                        updateListBoxSelectionForEvent( newEvent, false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    if ( hasEntered ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                        int directionToScroll = newEvent.getPoint().y < r.y ? SCROLL_UP : SCROLL_DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                        if ( isAutoScrolling && scrollDirection != directionToScroll ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                            stopAutoScrolling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                            startAutoScrolling( directionToScroll );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                        else if ( !isAutoScrolling ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                            startAutoScrolling( directionToScroll );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                        if ( e.getPoint().y < 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                            hasEntered = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                            startAutoScrolling( SCROLL_UP );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            JComboBox comboBox = (JComboBox)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            if ( propertyName == "model" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                ComboBoxModel oldModel = (ComboBoxModel)e.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                ComboBoxModel newModel = (ComboBoxModel)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                uninstallComboBoxModelListeners(oldModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                installComboBoxModelListeners(newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                list.setModel(newModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                if ( isVisible() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                    hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            else if ( propertyName == "renderer" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                list.setCellRenderer( comboBox.getRenderer() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                if ( isVisible() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            else if (propertyName == "componentOrientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                // Pass along the new component orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                // to the list and the scroller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                ComponentOrientation o =(ComponentOrientation)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                JList list = getList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                if (list!=null && list.getComponentOrientation()!=o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                    list.setComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                if (scroller!=null && scroller.getComponentOrientation()!=o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                    scroller.setComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                if (o!=getComponentOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    setComponentOrientation(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            else if (propertyName == "lightWeightPopupEnabled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        // ItemListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        public void itemStateChanged( ItemEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            if (e.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                JComboBox comboBox = (JComboBox)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                setListSelection(comboBox.getSelectedIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    // end Event Listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    //=================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * Overridden to unconditionally return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    //===================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    // begin Autoscroll methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * This protected method is implementation specific and should be private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    protected void startAutoScrolling( int direction ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        // XXX - should be a private method within InvocationMouseMotionHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        // if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        if ( isAutoScrolling ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            autoscrollTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        isAutoScrolling = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        if ( direction == SCROLL_UP ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            scrollDirection = SCROLL_UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            Point convertedPoint = SwingUtilities.convertPoint( scroller, new Point( 1, 1 ), list );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            int top = list.locationToIndex( convertedPoint );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            list.setSelectedIndex( top );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            autoscrollTimer = new Timer( 100, new AutoScrollActionHandler(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                                             SCROLL_UP) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        else if ( direction == SCROLL_DOWN ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            scrollDirection = SCROLL_DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            Dimension size = scroller.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            Point convertedPoint = SwingUtilities.convertPoint( scroller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                                                new Point( 1, (size.height - 1) - 2 ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                                                list );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            int bottom = list.locationToIndex( convertedPoint );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            list.setSelectedIndex( bottom );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            autoscrollTimer = new Timer(100, new AutoScrollActionHandler(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                            SCROLL_DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        autoscrollTimer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * This protected method is implementation specific and should be private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    protected void stopAutoScrolling() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        isAutoScrolling = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        if ( autoscrollTimer != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            autoscrollTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            autoscrollTimer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * This protected method is implementation specific and should be private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    protected void autoScrollUp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        int index = list.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        if ( index > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            list.setSelectedIndex( index - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            list.ensureIndexIsVisible( index - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * This protected method is implementation specific and should be private.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    protected void autoScrollDown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        int index = list.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        int lastItem = list.getModel().getSize() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        if ( index < lastItem ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            list.setSelectedIndex( index + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            list.ensureIndexIsVisible( index + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    // end Autoscroll methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    //=================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    //===================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    // begin Utility methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * Gets the AccessibleContext associated with this BasicComboPopup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * The AccessibleContext will have its parent set to the ComboBox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * @return an AccessibleContext for the BasicComboPopup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        AccessibleContext context = super.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        context.setAccessibleParent(comboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * This is is a utility method that helps event handlers figure out where to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * send the focus when the popup is brought up.  The standard implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * delegates the focus to the editor (if the combo box is editable) or to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * the JComboBox if it is not editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    protected void delegateFocus( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if ( comboBox.isEditable() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            Component comp = comboBox.getEditor().getEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            if ((!(comp instanceof JComponent)) || ((JComponent)comp).isRequestFocusEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                comp.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        else if (comboBox.isRequestFocusEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            comboBox.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * Makes the popup visible if it is hidden and makes it hidden if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    protected void togglePopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        if ( isVisible() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * Sets the list selection index to the selectedIndex. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * method is used to synchronize the list selection with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * combo box selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * @param selectedIndex the index to set the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    private void setListSelection(int selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        if ( selectedIndex == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            list.clearSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            list.setSelectedIndex( selectedIndex );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            list.ensureIndexIsVisible( selectedIndex );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    protected MouseEvent convertMouseEvent( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        Point convertedPoint = SwingUtilities.convertPoint( (Component)e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                                                            e.getPoint(), list );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        MouseEvent newEvent = new MouseEvent( (Component)e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                                              e.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                                              e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                                              e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                              convertedPoint.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                              convertedPoint.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                              e.getXOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                                              e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                                              e.getClickCount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                                              e.isPopupTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                                              MouseEvent.NOBUTTON );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        return newEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * Retrieves the height of the popup based on the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * ListCellRenderer and the maximum row count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    protected int getPopupHeightForRowCount(int maxRowCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        // Set the cached value of the minimum row count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        int minRowCount = Math.min( maxRowCount, comboBox.getItemCount() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        ListCellRenderer renderer = list.getCellRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        Object value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        for ( int i = 0; i < minRowCount; ++i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            value = list.getModel().getElementAt( i );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            Component c = renderer.getListCellRendererComponent( list, value, i, false, false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            height += c.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        if (height == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            height = comboBox.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        Border border = scroller.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            Insets insets = border.getBorderInsets(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        border = scroller.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            Insets insets = border.getBorderInsets(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * Calculate the placement and size of the popup portion of the combo box based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * on the combo box location and the enclosing screen bounds. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * no transformations are required, then the returned rectangle will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * have the same values as the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @param px starting x location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @param py starting y location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @param pw starting width
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @param ph starting height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @return a rectangle which represents the placement and size of the popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    protected Rectangle computePopupBounds(int px,int py,int pw,int ph) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        Rectangle screenBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        // Calculate the desktop dimensions relative to the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        Point p = new Point();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        SwingUtilities.convertPointFromScreen(p, comboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        if (gc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            Insets screenInsets = toolkit.getScreenInsets(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            screenBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            screenBounds.width -= (screenInsets.left + screenInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            screenBounds.height -= (screenInsets.top + screenInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            screenBounds.x += (p.x + screenInsets.left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            screenBounds.y += (p.y + screenInsets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            screenBounds = new Rectangle(p, toolkit.getScreenSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        Rectangle rect = new Rectangle(px,py,pw,ph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        if (py+ph > screenBounds.y+screenBounds.height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            && ph < screenBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            rect.y = -rect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * Calculates the upper left location of the Popup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    private Point getPopupLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        Dimension popupSize = comboBox.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        // reduce the width of the scrollpane by the insets so that the popup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        // is the same width as the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        popupSize.setSize(popupSize.width - (insets.right + insets.left),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                          getPopupHeightForRowCount( comboBox.getMaximumRowCount()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        Rectangle popupBounds = computePopupBounds( 0, comboBox.getBounds().height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                                                    popupSize.width, popupSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        Dimension scrollSize = popupBounds.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        Point popupLocation = popupBounds.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        scroller.setMaximumSize( scrollSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        scroller.setPreferredSize( scrollSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        scroller.setMinimumSize( scrollSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        list.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        return popupLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * A utility method used by the event listeners.  Given a mouse event, it changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * the list selection to the list item below the mouse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    protected void updateListBoxSelectionForEvent(MouseEvent anEvent,boolean shouldScroll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        // XXX - only seems to be called from this class. shouldScroll flag is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        // never true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        Point location = anEvent.getPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        if ( list == null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        int index = list.locationToIndex(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        if ( index == -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            if ( location.y < 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                index = comboBox.getModel().getSize() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        if ( list.getSelectedIndex() != index ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            list.setSelectedIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            if ( shouldScroll )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                list.ensureIndexIsVisible(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    // end Utility methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    //=================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
}