src/java.desktop/unix/classes/sun/awt/X11/XListPeer.java
author serb
Wed, 18 Apr 2018 14:07:41 -0700
changeset 49998 9070717a16a1
parent 47216 71c04702a3d5
child 52248 2e330da7cbf4
permissions -rw-r--r--
8187392: Deprecated methods in the peers can be removed Reviewed-by: prr, kaddepalli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
// Very much based on XListPeer from javaos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.peer.*;
21270
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
    34
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.image.*;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 445
diff changeset
    37
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
// TODO: some input actions should do nothing if Shift or Control are down
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 445
diff changeset
    43
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XListPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    45
    public static final int     MARGIN = 2;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    46
    public static final int     SPACE = 1;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    47
    public static final int     SCROLLBAR_AREA = 17;  // Area reserved for the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                                                      // scrollbar
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    49
    public static final int     SCROLLBAR_WIDTH = 13; // Actual width of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                                                      // scrollbar
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    51
    public static final int     NONE = -1;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    52
    public static final int     WINDOW = 0;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    53
    public static final int     VERSCROLLBAR = 1;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    54
    public static final int     HORSCROLLBAR = 2;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    55
    public static final int     DEFAULT_VISIBLE_ROWS = 4; // From java.awt.List,
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    56
    public static final int     HORIZ_SCROLL_AMT = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    58
    private static final int    PAINT_VSCROLL = 2;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    59
    private static final int    PAINT_HSCROLL = 4;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    60
    private static final int    PAINT_ITEMS = 8;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    61
    private static final int    PAINT_FOCUS = 16;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    62
    private static final int    PAINT_BACKGROUND = 32;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    63
    private static final int    PAINT_HIDEFOCUS = 64;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    64
    private static final int    PAINT_ALL =
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
    65
        PAINT_VSCROLL | PAINT_HSCROLL | PAINT_ITEMS | PAINT_FOCUS | PAINT_BACKGROUND;
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 30948
diff changeset
    66
    private static final int    COPY_AREA = 128;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    XVerticalScrollbar       vsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    XHorizontalScrollbar     hsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    ListPainter painter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // TODO: ick - Vector?
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
    73
    Vector<String>              items;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    boolean                     multipleSelections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    int                         active = NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Holds the array of the indexes of the elements which is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // This array should be kept sorted, low to high.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    int                         selected[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    int                         fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    int                         fontAscent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    int                         fontLeading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Holds the index of the item used in the previous operation (selectItem, deselectItem)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // Adding of an item or clearing of the list sets this index to -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // The index is used at the moment of the post of ACTION_PERFORMED event after the mouse double click event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    int                         currentIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Used for tracking selection/deselection between mousePress/Release
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // and for ItemEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    int                         eventIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    int                         eventType = NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // Holds the index of the item that receive focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // This variable is reasonable only for multiple list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // since 'focusIndex' and 'selected[0]' are equal for single-selection list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    int                         focusIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    int                         maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    boolean                     vsbVis;  // visibility of scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    boolean                     hsbVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int                         listWidth;  // Width of list portion of List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    int                         listHeight; // Height of list portion of List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // (i.e. without scrollbars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private int firstTimeVisibleIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // Motif Lists don't seem to inherit the background color from their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // parent when an app is first started up.  So, we track if the colors have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // been set.  See getListBackground()/getListForeground().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    boolean bgColorSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    boolean fgColorSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // Holds the true if mouse is dragging outside of the area of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // The flag is used at the moment of the dragging and releasing mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // See 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    boolean mouseDraggedOutHorizontally = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    boolean mouseDraggedOutVertically = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // Holds the true if a mouse event was originated on the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // See 6300527 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    boolean isScrollBarOriginated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    // This variable is set to true after the "mouse pressed" event and to false after the "mouse released" event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // Fixed 6293432: Key events ('SPACE', 'UP', 'DOWN') aren't blocked if mouse is kept in 'PRESSED' state for List, XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    boolean isMousePressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Create a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    XListPeer(List target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Overridden from XWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // Stuff that must be initialized before layout() is called
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
   142
        items = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        createVerScrollbar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        createHorScrollbar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        painter = new ListPainter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // See 6246467 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        bgColorSet = target.isBackgroundSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        fgColorSet = target.isForegroundSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        initFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // TODO: more efficient way?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        //       do we really want/need a copy of all the items?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // get all items from target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        List l = (List)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int stop = l.getItemCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        for (int i = 0 ; i < stop; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            items.addElement(l.getItem(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        /* make the visible position visible. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int index = l.getVisibleIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            // Can't call makeVisible since it check scroll bar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            // initialize scroll bar instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            vsb.setValues(index, 0, 0, items.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // NOTE: needs to have target set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        maxLength = maxLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // get the index containing all indexes to selected items
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        int sel[] = l.getSelectedIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        selected = new int[sel.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // TODO: shouldn't this be arraycopy()?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        for (int i = 0 ; i < sel.length ; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            selected[i] = sel[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        // The select()ed item should become the focused item, but we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // get the select() call because the peer generally hasn't yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // created during app initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // TODO: For multi-select lists, it should be the highest selected index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (sel.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            setFocusIndex(sel[sel.length - 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            setFocusIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        multipleSelections = l.isMultipleMode();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * add Vertical Scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    void createVerScrollbar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        vsb = new XVerticalScrollbar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        vsb.setValues(0, 0, 0, 0, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * add Horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    void createHorScrollbar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        hsb = new XHorizontalScrollbar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        hsb.setValues(0, 0, 0, 0, HORIZ_SCROLL_AMT, HORIZ_SCROLL_AMT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public void add(String item, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        addItem(item, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        maxLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public void setMultipleMode (boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        setMultipleSelections(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
   228
    public Dimension getMinimumSize() {
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
   229
        return getMinimumSize(DEFAULT_VISIBLE_ROWS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
   232
    public Dimension getPreferredSize(int rows) {
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
   233
        return getMinimumSize(rows);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
   236
    public Dimension getMinimumSize(int rows) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        FontMetrics fm = getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        initFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return new Dimension(20 + fm.stringWidth("0123456789abcde"),
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
   240
                             getItemHeight() * rows + (2*MARGIN));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Calculate font metrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    void initFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        FontMetrics fm = getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        fontHeight = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        fontAscent = fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        fontLeading = fm.getLeading();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * return the length of the largest item in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    int maxLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        FontMetrics fm = getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        int m = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        int end = items.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        for(int i = 0 ; i < end ; i++) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
   262
            int l = fm.stringWidth(items.elementAt(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            m = Math.max(m, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Calculates the width of item's label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    int getItemWidth(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        FontMetrics fm = getFontMetrics(getFont());
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
   273
        return fm.stringWidth(items.elementAt(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * return the on-screen width of the given string "str"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    int stringLength(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        FontMetrics fm = getFontMetrics(target.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return fm.stringWidth(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        fgColorSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        super.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        bgColorSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Returns the color that should be used to paint the background of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * the list of items.  Note that this is not the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * target.getBackground() which is the color of the scrollbars, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * lower-right corner of the Component when the scrollbars are displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private Color getListBackground(Color[] colors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (bgColorSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return colors[BACKGROUND_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return SystemColor.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Returns the color that should be used to paint the list item text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private Color getListForeground(Color[] colors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (fgColorSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            return colors[FOREGROUND_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return SystemColor.textText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    Rectangle getVScrollBarRec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return new Rectangle(width - (SCROLLBAR_WIDTH), 0, SCROLLBAR_WIDTH+1, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    Rectangle getHScrollBarRec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return new Rectangle(0, height - SCROLLBAR_WIDTH, width, SCROLLBAR_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    int getFirstVisibleItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (vsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            return vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    int getLastVisibleItem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (vsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            return Math.min(items.size()-1, vsb.getValue() + itemsInWindow() -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            return Math.min(items.size()-1, itemsInWindow()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public void repaintScrollbarRequest(XScrollbar scrollbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (scrollbar == hsb)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            repaint(PAINT_HSCROLL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        else if (scrollbar == vsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            repaint(PAINT_VSCROLL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Overridden for performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        repaint(getFirstVisibleItem(), getLastVisibleItem(), PAINT_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   359
    private void repaint(int options) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        repaint(getFirstVisibleItem(), getLastVisibleItem(), options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   363
    private void repaint(int firstItem, int lastItem, int options) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   364
        repaint(firstItem, lastItem, options, null, null);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   365
    }
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   366
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   367
    /**
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   368
     * In most cases the entire area of the component doesn't have
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   369
     * to be repainted. The method repaints the particular areas of
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   370
     * the component. The areas to repaint is specified by the option
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   371
     * parameter. The possible values of the option parameter are:
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   372
     * PAINT_VSCROLL, PAINT_HSCROLL, PAINT_ITEMS, PAINT_FOCUS,
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   373
     * PAINT_HIDEFOCUS, PAINT_BACKGROUND, PAINT_ALL, COPY_AREA.
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   374
     *
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   375
     * Note that the COPY_AREA value initiates copy of a source area
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   376
     * of the component by a distance by means of the copyArea method
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   377
     * of the Graphics class.
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   378
     *
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   379
     * @param firstItem the position of the first item of the range to repaint
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   380
     * @param lastItem the position of the last item of the range to repaint
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   381
     * @param options specifies the particular area of the component to repaint
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   382
     * @param source the area of the component to copy
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   383
     * @param distance the distance to copy the source area
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   384
     */
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
   385
    private void repaint(int firstItem, int lastItem, int options, Rectangle source, Point distance) {
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   386
        final Graphics g = getGraphics();
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   387
        if (g != null) {
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   388
            try {
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   389
                painter.paint(g, firstItem, lastItem, options, source, distance);
21270
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
   390
                postPaintEvent(target, 0, 0, getWidth(), getHeight());
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   391
            } finally {
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   392
                g.dispose();
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   393
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   396
    @Override
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9472
diff changeset
   397
    void paintPeer(final Graphics g) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        painter.paint(g, getFirstVisibleItem(), getLastVisibleItem(), PAINT_ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public boolean isFocusable() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    // TODO: share/promote the Focus methods?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Layout the sub-components of the List - that is, the scrollbars and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * list of items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public void layout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        int vis, maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        boolean vsbWasVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        int origVSBVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        assert(target != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // Start with assumption there is not a horizontal scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // see if we need a vertical scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // Bug: If the list DOES have a horiz scrollbar and the value is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        // the very bottom value, value is reset in setValues() because it isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        // a valid value for cases when the list DOESN'T have a horiz scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        // This is currently worked-around with origVSGVal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        origVSBVal = vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        vis = itemsInWindow(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        maximum = items.size() < vis ? vis : items.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        vsb.setValues(vsb.getValue(), vis, vsb.getMinimum(), maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        vsbVis = vsbWasVisible = vsbIsVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        listHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // now see if we need a horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        listWidth = getListWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        vis = listWidth - ((2 * SPACE) + (2 * MARGIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        maximum = maxLength < vis ? vis : maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        hsb.setValues(hsb.getValue(), vis, hsb.getMinimum(), maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        hsbVis = hsbIsVisible(vsbVis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (hsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            // do need a horizontal scrollbar, so recalculate height of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            // vertical s crollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            listHeight = height - SCROLLBAR_AREA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            vis = itemsInWindow(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            maximum = items.size() < vis ? vis : items.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            vsb.setValues(origVSBVal, vis, vsb.getMinimum(), maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            vsbVis = vsbIsVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        // now check to make sure we haven't changed need for vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        // scrollbar - if we have, we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        // recalculate horizontal scrollbar width - then we're done...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (vsbWasVisible != vsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            listWidth = getListWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            vis = listWidth - ((2 * SPACE) + (2 * MARGIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            maximum = maxLength < vis ? 0 : maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            hsb.setValues(hsb.getValue(), vis, hsb.getMinimum(), maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            hsbVis = hsbIsVisible(vsbVis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        vsb.setSize(SCROLLBAR_WIDTH, listHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        hsb.setSize(listWidth, SCROLLBAR_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        vsb.setBlockIncrement(itemsInWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        hsb.setBlockIncrement(width - ((2 * SPACE) + (2 * MARGIN) + (vsbVis ? SCROLLBAR_AREA : 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    int getItemWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return width - ((2 * MARGIN) + (vsbVis ? SCROLLBAR_AREA : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /* Returns height of an item in the list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    int getItemHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return (fontHeight - fontLeading) + (2*SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    int getItemX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return MARGIN + SPACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    int getItemY(int item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return index2y(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    int getFocusIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return focusIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    void setFocusIndex(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        focusIndex = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Update and return the focus rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Focus is around the focused item, if it is visible, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * around the border of the list if the focused item is scrolled off the top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * or bottom of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    Rectangle getFocusRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        Rectangle focusRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // width is always only based on presence of vert sb
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        focusRect.x = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        focusRect.width = getListWidth() - 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // if focused item is not currently displayed in the list,  paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        // focus around entire list (not including scrollbars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (isIndexDisplayed(getFocusIndex())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // focus rect is around the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            focusRect.y = index2y(getFocusIndex()) - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            focusRect.height = getItemHeight()+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            // focus rect is around the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            focusRect.y = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            focusRect.height = hsbVis ? height - SCROLLBAR_AREA : height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            focusRect.height -= 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return focusRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public void handleConfigureNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        super.handleConfigureNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        // Update buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        painter.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public boolean handlesWheelScrolling() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    // FIXME: need to support MouseWheel scrolling, too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    void handleJavaMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        super.handleJavaMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        int i = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        switch (i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
              mousePressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
              mouseReleased(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
              mouseDragged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    void handleJavaMouseWheelEvent(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (ListHelper.doWheelScroll(vsbVis ? vsb : null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                                     hsbVis ? hsb : null, e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 32865
diff changeset
   554
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    void mousePressed(MouseEvent mouseEvent) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   556
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   557
            log.finer(mouseEvent.toString() + ", hsb " + hsbVis + ", vsb " + vsbVis);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   558
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (isEnabled() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            if (inWindow(mouseEvent.getX(), mouseEvent.getY())) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   561
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   562
                    log.fine("Mouse press in items area");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   563
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                active = WINDOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                int i = y2index(mouseEvent.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    if (multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                        if (isSelected(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                            // See 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                            deselectItem(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                            eventIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                            eventType = ItemEvent.DESELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                            selectItem(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                            eventIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                            eventType = ItemEvent.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    // Backward-compatible bug: even if a single-select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    // item is already selected, we send an ITEM_STATE_CHANGED/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    // SELECTED event.  Engineer's Toolbox appears to rely on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    // this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    //else if (!isSelected(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                        selectItem(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        eventIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                        eventType = ItemEvent.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    // Restoring Windows behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    // We should update focus index after "mouse pressed" event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    setFocusIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    // 6426186: reset variable to prevent action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    // if user clicks on unoccupied area of list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    currentIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            } else if (inVerticalScrollbar(mouseEvent.getX(), mouseEvent.getY())) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   600
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   601
                    log.fine("Mouse press in vertical scrollbar");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   602
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                active = VERSCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                vsb.handleMouseEvent(mouseEvent.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                                     mouseEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                                     mouseEvent.getX() - (width - SCROLLBAR_WIDTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                     mouseEvent.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            } else if (inHorizontalScrollbar(mouseEvent.getX(), mouseEvent.getY())) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   609
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   610
                    log.fine("Mouse press in horizontal scrollbar");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   611
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                active = HORSCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                hsb.handleMouseEvent(mouseEvent.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                                     mouseEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                     mouseEvent.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                                     mouseEvent.getY() - (height - SCROLLBAR_WIDTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            isMousePressed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 32865
diff changeset
   622
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    void mouseReleased(MouseEvent mouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (isEnabled() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            //winReleaseCursorFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            int clickCount = mouseEvent.getClickCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            if (active == VERSCROLLBAR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                vsb.handleMouseEvent(mouseEvent.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                     mouseEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                     mouseEvent.getX()-(width-SCROLLBAR_WIDTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                     mouseEvent.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            } else if(active == HORSCROLLBAR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                hsb.handleMouseEvent(mouseEvent.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                     mouseEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                     mouseEvent.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                                     mouseEvent.getY()-(height-SCROLLBAR_WIDTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            } else if ( ( currentIndex >= 0 ) && ( clickCount >= 2 ) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        ( clickCount % 2 == 0 ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                postEvent(new ActionEvent(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                          ActionEvent.ACTION_PERFORMED,
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
   641
                                          items.elementAt(currentIndex),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                          mouseEvent.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                          mouseEvent.getModifiers()));  // No ext mods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            } else if (active == WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                // See 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                trackMouseReleasedScroll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                if (eventType == ItemEvent.DESELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    assert multipleSelections : "Shouldn't get a deselect for a single-select List";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    // Paint deselection the release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                    deselectItem(eventIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                if (eventType != NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                                ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                                Integer.valueOf(eventIndex),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                                eventType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            active = NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            eventIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            eventType = NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            isMousePressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 32865
diff changeset
   667
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    void mouseDragged(MouseEvent mouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        // TODO: can you drag w/ any other buttons?  what about multiple buttons?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        if (isEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            (mouseEvent.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if ((active == VERSCROLLBAR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                vsb.handleMouseEvent(mouseEvent.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                                     mouseEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                     mouseEvent.getX()-(width-SCROLLBAR_WIDTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                                     mouseEvent.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            } else if ((active == HORSCROLLBAR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                hsb.handleMouseEvent(mouseEvent.getID(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                                     mouseEvent.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                     mouseEvent.getX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                     mouseEvent.getY()-(height-SCROLLBAR_WIDTH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            } else if (active == WINDOW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                int i = y2index(mouseEvent.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                if (multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    // Multi-select only:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    // If a selected item was pressed on and then dragged off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    // of, cancel the pending deselect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    if (eventType == ItemEvent.DESELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        if (i != eventIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                            eventType = NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                            eventIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                else if (eventType == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    // Single-select only:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    // If an unselected item was pressed on, track the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    // and select the item under the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    // See 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    trackMouseDraggedScroll(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    if (i >= 0 && !isSelected(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        int oldSel = eventIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                        selectItem(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        eventIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                        repaint(oldSel, eventIndex, PAINT_ITEMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                // Restoring Windows behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                // We should update focus index after "mouse dragged" event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    setFocusIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Helper method for XListPeer with integrated vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * Start or stop vertical scrolling when mouse dragged in / out the area of the list if it's required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Restoring Motif behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * See 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    void trackMouseDraggedScroll(MouseEvent mouseEvent){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (vsb.beforeThumb(mouseEvent.getX(), mouseEvent.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            vsb.setMode(AdjustmentEvent.UNIT_DECREMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            vsb.setMode(AdjustmentEvent.UNIT_INCREMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        if(mouseEvent.getY() < 0 || mouseEvent.getY() >= listHeight){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            if (!mouseDraggedOutVertically){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                mouseDraggedOutVertically = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                vsb.startScrollingInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            if (mouseDraggedOutVertically){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                mouseDraggedOutVertically = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                vsb.stopScrollingInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        if (hsb.beforeThumb(mouseEvent.getX(), mouseEvent.getY())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            hsb.setMode(AdjustmentEvent.UNIT_DECREMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            hsb.setMode(AdjustmentEvent.UNIT_INCREMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (mouseEvent.getX() < 0 || mouseEvent.getX() >= listWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if (!mouseDraggedOutHorizontally){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                mouseDraggedOutHorizontally = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                hsb.startScrollingInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        }else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (mouseDraggedOutHorizontally){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                mouseDraggedOutHorizontally = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                hsb.stopScrollingInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Helper method for XListPeer with integrated vertical scrollbar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * Stop vertical scrolling when mouse released in / out the area of the list if it's required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * Restoring Motif behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * see 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    void trackMouseReleasedScroll(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        if (mouseDraggedOutVertically){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            mouseDraggedOutVertically = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            vsb.stopScrollingInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if (mouseDraggedOutHorizontally){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            mouseDraggedOutHorizontally = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            hsb.stopScrollingInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    void handleJavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        switch(e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
              if (!isMousePressed){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                  keyPressed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
43722
25ba19c20260 8143077: Deprecate InputEvent._MASK in favor of InputEvent._DOWN_MASK
serb
parents: 32865
diff changeset
   793
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    void keyPressed(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        int keyCode = e.getKeyCode();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   796
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   797
            log.fine(e.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   798
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        switch(keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
          case KeyEvent.VK_UP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
          case KeyEvent.VK_KP_UP: // TODO: I assume we also want this, too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
              if (getFocusIndex() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                  setFocusIndex(getFocusIndex()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                  repaint(PAINT_HIDEFOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                  // If single-select, select the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                  if (!multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                      selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                      postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                              ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                                              Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                                              ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                  if (isItemHidden(getFocusIndex())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                      makeVisible(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                      repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
          case KeyEvent.VK_DOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
          case KeyEvent.VK_KP_DOWN: // TODO: I assume we also want this, too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
              if (getFocusIndex() < items.size() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                  setFocusIndex(getFocusIndex()+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                  repaint(PAINT_HIDEFOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                  // If single-select, select the item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                  if (!multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                      selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                      postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                                              ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                                              Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                              ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                  if (isItemHidden(getFocusIndex())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                      makeVisible(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                      repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
          case KeyEvent.VK_PAGE_UP: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
              // Assumes that scrollbar does its own bounds-checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
              int previousValue = vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
              vsb.setValue(vsb.getValue() - vsb.getBlockIncrement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
              int currentValue = vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
              // 6190768 pressing pg-up on AWT multiple selection lists the items but no item event is triggered, on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
              // Restoring Motif behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
              if (previousValue!=currentValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                  setFocusIndex(Math.max(getFocusIndex()-itemsInWindow(), 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                  if (!multipleSelections){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                      selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                      postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                                              ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                                              Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                                              ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
              repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
          case KeyEvent.VK_PAGE_DOWN: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
              // Assumes that scrollbar does its own bounds-checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
              int previousValue = vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
              vsb.setValue(vsb.getValue() + vsb.getBlockIncrement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
              int currentValue = vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
              // 6190768 pressing pg-down on AWT multiple selection list selects the items but no item event is triggered, on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
              // Restoring Motif behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
              if (previousValue!=currentValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                  setFocusIndex(Math.min(getFocusIndex() + itemsInWindow(), items.size()-1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                  if (!multipleSelections){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                      selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                      postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                                              ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                                              Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                                              ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
              repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
          case KeyEvent.VK_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
          case KeyEvent.VK_KP_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
              if (hsbVis & hsb.getValue() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                  hsb.setValue(hsb.getValue() - HORIZ_SCROLL_AMT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
          case KeyEvent.VK_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
          case KeyEvent.VK_KP_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
              if (hsbVis) { // Should check if already at end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                  hsb.setValue(hsb.getValue() + HORIZ_SCROLL_AMT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                  repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
          // 6190778 CTRL + HOME, CTRL + END keys do not work properly for list on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
          // Restoring Motif behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
          case KeyEvent.VK_HOME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
              if (!e.isControlDown() || ((List)target).getItemCount() <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
              if (vsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                  vsb.setValue(vsb.getMinimum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
              setFocusIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
              if (!multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                  selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                  postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                                          ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                                          Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                                          ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
              repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
          case KeyEvent.VK_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
              if (!e.isControlDown() || ((List)target).getItemCount() <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
              if (vsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                  vsb.setValue(vsb.getMaximum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
              setFocusIndex(items.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
              if (!multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                  selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                  postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                                          ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                          Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                          ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
              repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
          case KeyEvent.VK_SPACE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
              // Fixed 6299853: XToolkit: Pressing space triggers ItemStateChanged event after List.removeAll called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
              // If getFocusIndex() is less than 0, the event will not be triggered when space pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
              if (getFocusIndex() < 0 || ((List)target).getItemCount() <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
              boolean isSelected = isSelected(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
              // Spacebar only deselects for multi-select Lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
              if (multipleSelections && isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                  deselectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                  postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                                          ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                                          Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                                          ItemEvent.DESELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
              else if (!isSelected) { // Note: this changes the Solaris/Linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                  // behavior to match that of win32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                  // That is, pressing space bar on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                  // single-select list when the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                  // item is already selected does NOT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                  // send an ItemEvent.SELECTED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                  selectItem(getFocusIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                  postEvent(new ItemEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                                          ItemEvent.ITEM_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                                          Integer.valueOf(getFocusIndex()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                                          ItemEvent.SELECTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
          case KeyEvent.VK_ENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
              // It looks to me like there are bugs as well as inconsistencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
              // in the way the Enter key is handled by both Solaris and Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
              // So for now in XAWT, I'm going to simply go by what the List docs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
              // say: "AWT also generates an action event when the user presses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
              // the return key while an item in the list is selected."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
              if (selected.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                  postEvent(new ActionEvent((List)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                            ActionEvent.ACTION_PERFORMED,
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
   969
                                            items.elementAt(getFocusIndex()),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                            e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                            e.getModifiers()));  // ActionEvent doesn't have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                  // extended modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * return value from the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   983
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   984
            log.fine("Notify value changed on " + obj + " to " + v);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
   985
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        int value = obj.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        if (obj == vsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            scrollVertical(v - value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            // See 6243382 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            int oldSel = eventIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            int newSel = eventIndex+v-value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            if (mouseDraggedOutVertically && !isSelected(newSel)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                selectItem(newSel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                eventIndex = newSel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                repaint(oldSel, eventIndex, PAINT_ITEMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                // Scrolling select() should also set the focus index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                // Otherwise, the updating of the 'focusIndex' variable will be incorrect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                // if user drag mouse out of the area of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                setFocusIndex(newSel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        } else if ((XHorizontalScrollbar)obj == hsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            scrollHorizontal(v - value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * deselect all items in List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    private void deselectAllItems() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        selected = new int [0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        repaint(PAINT_ITEMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * set multiple selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public void setMultipleSelections(boolean v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        if (multipleSelections != v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            if ( !v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                int selPos = ( isSelected( focusIndex )) ? focusIndex: -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                deselectAllItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                if (selPos != -1){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                    selectItem(selPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            multipleSelections = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * add an item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * if the index of the item is < 0 or >= than items.size()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * then add the item to the end of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    public void addItem(String item, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        int oldMaxLength = maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        boolean hsbWasVis = hsbVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        boolean vsbWasVis = vsbVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        int addedIndex = 0; // Index where the new item ended up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        if (i < 0 || i >= items.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            i = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        // Why we set this variable to -1 in spite of the fact that selected[] is changed in other way?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        // It's not clear how to reproduce incorrect behaviour based on this assignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        // since before using this variable (mouseReleased) we certainly update it to correct value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        // So we don't modify this behaviour now
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        currentIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        if (i == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            items.addElement(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            i = 0;              // fix the math for the paintItems test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            addedIndex = items.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            items.insertElementAt(item, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            addedIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            for (int j = 0 ; j < selected.length ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                if (selected[j] >= i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                    selected[j] += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1068
        if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1069
            log.finer("Adding item '" + item + "' to " + addedIndex);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1070
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // Update maxLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        boolean repaintItems = !isItemHidden(addedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        maxLength = Math.max(maxLength, getItemWidth(addedIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        int options = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if (vsbVis != vsbWasVis || hsbVis != hsbWasVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            // Scrollbars are being added or removed, so we must repaint all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            options = PAINT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            options = (repaintItems ? (PAINT_ITEMS):0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                | ((maxLength != oldMaxLength || (hsbWasVis ^ hsbVis))?(PAINT_HSCROLL):0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                | ((vsb.needsRepaint())?(PAINT_VSCROLL):0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1088
        if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1089
            log.finest("Last visible: " + getLastVisibleItem() +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1090
            ", hsb changed : " + (hsbWasVis ^ hsbVis) + ", items changed " + repaintItems);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1091
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        repaint(addedIndex, getLastVisibleItem(), options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * delete items starting with s (start position) to e (end position) including s and e
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * if s < 0 then s = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * if e >= items.size() then e = items.size() - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    public void delItems(int s, int e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        // save the current state of the scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        boolean hsbWasVisible = hsbVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        boolean vsbWasVisible = vsbVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        int oldLastDisplayed = lastItemDisplayed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1106
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1107
            log.fine("Deleting from " + s + " to " + e);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1108
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1110
        if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1111
            log.finest("Last displayed item: " + oldLastDisplayed + ", items in window " + itemsInWindow() +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1112
            ", size " + items.size());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1113
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if (items.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        // if user passed in flipped args, reverse them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        if (s > e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            int tmp = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            s = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            e = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        // check for starting point less than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (s < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        // check for end point greater than the size of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        if (e >= items.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            e = items.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        // determine whether we're going to delete any visible elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        // repaint must also be done if scrollbars appear/disappear, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        // can happen from removing a non-showing list item
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
          boolean repaintNeeded =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
          ((s <= lastItemDisplayed()) && (e >= vsb.getValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        boolean repaintNeeded = (s >= getFirstVisibleItem() && s <= getLastVisibleItem());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        // delete the items out of the items list and out of the selected list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        for (int i = s ; i <= e ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            items.removeElementAt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            int j = posInSel(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            if (j != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                int newsel[] = new int[selected.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                System.arraycopy(selected, 0, newsel, 0, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                System.arraycopy(selected, j + 1, newsel, j, selected.length - (j + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                selected = newsel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        // update the indexes in the selected array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        int diff = (e - s) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        for (int i = 0 ; i < selected.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            if (selected[i] > e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                selected[i] -= diff;
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
        int options = PAINT_VSCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        // focusedIndex updating according to native (Window, Motif) behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        if (getFocusIndex() > e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            setFocusIndex(getFocusIndex() - (e - s + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            options |= PAINT_FOCUS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        } else if (getFocusIndex() >= s && getFocusIndex() <= e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            // Fixed 6299858: PIT. Focused border not shown on List if selected item is removed, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            // We should set focus to new first item if the current first item was removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            // except if the list is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            int focusBound = (items.size() > 0) ? 0 : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            setFocusIndex(Math.max(s-1, focusBound));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            options |= PAINT_FOCUS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1180
        if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1181
            log.finest("Multiple selections: " + multipleSelections);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1182
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        // update vsb.val
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        if (vsb.getValue() >= s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            if (vsb.getValue() <= e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                vsb.setValue(e+1 - diff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                vsb.setValue(vsb.getValue() - diff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        int oldMaxLength = maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        maxLength = maxLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        if (maxLength != oldMaxLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            // Width of the items changed affecting the range of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            // horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            options |= PAINT_HSCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        repaintNeeded |= (vsbWasVisible ^ vsbVis) || (hsbWasVisible ^ hsbVis); // If scrollbars visibility changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        if (repaintNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            options |= PAINT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        repaint(s, oldLastDisplayed, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * ListPeer method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public void select(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        // Programmatic select() should also set the focus index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        setFocusIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        repaint(PAINT_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        selectItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * select the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * redraw the list to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    void selectItem(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        // NOTE: instead of recalculating and the calling repaint(), painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        // is done immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        // 6190746 List does not trigger ActionEvent when double clicking a programmatically selected item, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        // If we invoke select(int) before setVisible(boolean), then variable currentIndex will equals -1. At the same time isSelected may be true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        // Restoring Motif behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        currentIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        if (isSelected(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        if (!multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            if (selected.length == 0) { // No current selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                selected = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                selected[0] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                int oldSel = selected[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                selected[0] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                if (!isItemHidden(oldSel)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                    // Only bother painting if item is visible (4895367)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                    repaint(oldSel, oldSel, PAINT_ITEMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            // insert "index" into the selection array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            int newsel[] = new int[selected.length + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            while (i < selected.length && index > selected[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                newsel[i] = selected[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            newsel[i] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            System.arraycopy(selected, i, newsel, i+1, selected.length - i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            selected = newsel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        if (!isItemHidden(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            // Only bother painting if item is visible (4895367)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            repaint(index, index, PAINT_ITEMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * ListPeer method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * focusedIndex isn't updated according to native (Window, Motif) behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    public void deselect(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        deselectItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * deselect the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * redraw the list to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    void deselectItem(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        if (!isSelected(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        if (!multipleSelections) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            // TODO: keep an int[0] and int[1] around and just use them instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            // creating new ones all the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            selected = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            int i = posInSel(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            int newsel[] = new int[selected.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            System.arraycopy(selected, 0, newsel, 0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            selected = newsel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        currentIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        if (!isItemHidden(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            // Only bother repainting if item is visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            repaint(index, index, PAINT_ITEMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * ensure that the given index is visible, scrolling the List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * if necessary, or doing nothing if the item is already visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * The List must be repainted for changes to be visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    public void makeVisible(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        if (index < 0 || index >= items.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        if (isItemHidden(index)) {  // Do I really need to call this?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            // If index is above the top, scroll up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            if (index < vsb.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                scrollVertical(index - vsb.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            // If index is below the bottom, scroll down
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            else if (index > lastItemDisplayed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                int val = index - lastItemDisplayed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                scrollVertical(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * clear
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        selected = new int[0];
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
  1326
        items = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        currentIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        // Fixed 6291736: ITEM_STATE_CHANGED triggered after List.removeAll(), XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        // We should update 'focusIndex' variable more carefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        setFocusIndex(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        vsb.setValue(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        maxLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * return the selected indexes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    public int[] getSelectedIndexes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        return selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * return the y value of the given index "i".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * the y value represents the top of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * NOTE: index can be larger than items.size as long
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * as it can fit the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    int index2y(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        int h = getItemHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        //if (index < vsb.getValue() || index > vsb.getValue() + itemsInWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        return MARGIN + ((index - vsb.getValue()) * h) + SPACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    /* return true if the y is a valid y coordinate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *  a VISIBLE list item, otherwise returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    boolean validY(int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        int shown = itemsDisplayed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        int lastY = shown * getItemHeight() + MARGIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        if (shown == itemsInWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            lastY += MARGIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        if (y < 0 || y >= lastY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * return the position of the index in the selected array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * if the index isn't in the array selected return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    int posInSel(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        for (int i = 0 ; i < selected.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            if (index == selected[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    boolean isIndexDisplayed(int idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        int lastDisplayed = lastItemDisplayed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        return idx <= lastDisplayed &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            idx >= Math.max(0, lastDisplayed - itemsInWindow() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * returns index of last item displayed in the List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    int lastItemDisplayed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        int n = itemsInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        return (Math.min(items.size() - 1, (vsb.getValue() + n) - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * returns whether the given index is currently scrolled off the top or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * bottom of the List.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    boolean isItemHidden(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        return index < vsb.getValue() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            index >= vsb.getValue() + itemsInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * returns the width of the list portion of the component (accounts for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * presence of vertical scrollbar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    int getListWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        return vsbVis ? width - SCROLLBAR_AREA : width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * returns number of  items actually displayed in the List
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    int itemsDisplayed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        return (Math.min(items.size()-vsb.getValue(), itemsInWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * scrollVertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * y is the number of items to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    void scrollVertical(int y) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1435
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1436
            log.fine("Scrolling vertically by " + y);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1437
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        int itemsInWin = itemsInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        int h = getItemHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        int pixelsToScroll = y * h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        if (vsb.getValue() < -y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            y = -vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        vsb.setValue(vsb.getValue() + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1447
        Rectangle source = null;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1448
        Point distance = null;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1449
        int firstItem = 0, lastItem = 0;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1450
        int options = PAINT_HIDEFOCUS | PAINT_ITEMS | PAINT_VSCROLL | PAINT_FOCUS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        if (y > 0) {
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1452
            if (y < itemsInWin) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1453
                source = new Rectangle(MARGIN, MARGIN + pixelsToScroll, width - SCROLLBAR_AREA, h * (itemsInWin - y - 1)-1);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1454
                distance = new Point(0, -pixelsToScroll);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1455
                options |= COPY_AREA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            }
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1457
            firstItem = vsb.getValue() + itemsInWin - y - 1;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1458
            lastItem = vsb.getValue() + itemsInWin - 1;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1459
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1460
        } else if (y < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            if (y + itemsInWindow() > 0) {
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1462
                source = new Rectangle(MARGIN, MARGIN, width - SCROLLBAR_AREA, h * (itemsInWin + y));
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1463
                distance = new Point(0, -pixelsToScroll);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1464
                options |= COPY_AREA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1466
            firstItem = vsb.getValue();
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1467
            lastItem = Math.min(getLastVisibleItem(), vsb.getValue() + -y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1469
        repaint(firstItem, lastItem, options, source, distance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * scrollHorizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * x is the number of pixels to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    void scrollHorizontal(int x) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1477
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1478
            log.fine("Scrolling horizontally by " + y);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1479
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        int w = getListWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        w -= ((2 * SPACE) + (2 * MARGIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        int h = height - (SCROLLBAR_AREA + (2 * MARGIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        hsb.setValue(hsb.getValue() + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
9472
9f1950d3b025 7036733: Regression : NullPointerException when scrolling horizontally on AWT List
dav
parents: 5506
diff changeset
  1485
        int options = PAINT_ITEMS | PAINT_HSCROLL;
9f1950d3b025 7036733: Regression : NullPointerException when scrolling horizontally on AWT List
dav
parents: 5506
diff changeset
  1486
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1487
        Rectangle source = null;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1488
        Point distance = null;
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1489
        if (x < 0) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1490
            source = new Rectangle(MARGIN + SPACE, MARGIN, w + x, h);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1491
            distance = new Point(-x, 0);
9472
9f1950d3b025 7036733: Regression : NullPointerException when scrolling horizontally on AWT List
dav
parents: 5506
diff changeset
  1492
            options |= COPY_AREA;
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1493
        } else if (x > 0) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1494
            source = new Rectangle(MARGIN + SPACE + x, MARGIN, w - x, h);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1495
            distance = new Point(-x, 0);
9472
9f1950d3b025 7036733: Regression : NullPointerException when scrolling horizontally on AWT List
dav
parents: 5506
diff changeset
  1496
            options |= COPY_AREA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        }
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1498
        repaint(vsb.getValue(), lastItemDisplayed(), options, source, distance);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * return the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    int y2index(int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        if (!validY(y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        int i = (y - MARGIN) / getItemHeight() + vsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        int last = lastItemDisplayed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        if (i > last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            i = last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * is the index "index" selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    boolean isSelected(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        if (eventType == ItemEvent.SELECTED && index == eventIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        for (int i = 0 ; i < selected.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            if (selected[i] == index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * return the number of items that can fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * in the current window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    int itemsInWindow(boolean scrollbarVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        int h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        if (scrollbarVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            h = height - ((2 * MARGIN) + SCROLLBAR_AREA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            h = height - 2*MARGIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        return (h / getItemHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    int itemsInWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        return itemsInWindow(hsbVis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * return true if the x and y position is in the horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    boolean inHorizontalScrollbar(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        int w = getListWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        int h = height - SCROLLBAR_WIDTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        return (hsbVis &&  (x >= 0) && (x <= w) && (y > h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * return true if the x and y position is in the verticalscrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    boolean inVerticalScrollbar(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        int w = width - SCROLLBAR_WIDTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        int h = hsbVis ? height - SCROLLBAR_AREA : height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        return (vsbVis && (x > w) && (y >= 0) && (y <= h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * return true if the x and y position is in the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    boolean inWindow(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        int w = getListWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        int h = hsbVis ? height - SCROLLBAR_AREA : height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        return ((x >= 0) && (x <= w)) && ((y >= 0) && (y <= h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * return true if vertical scrollbar is visible and false otherwise;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * hsbVisible is the visibility of the horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    boolean vsbIsVisible(boolean hsbVisible){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        return (items.size() > itemsInWindow(hsbVisible));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * return true if horizontal scrollbar is visible and false otherwise;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * vsbVisible is the visibility of the vertical scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    boolean hsbIsVisible(boolean vsbVisible){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        int w = width - ((2*SPACE) + (2*MARGIN) + (vsbVisible ? SCROLLBAR_AREA : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        return (maxLength > w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * Returns true if the event has been handled and should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * posted to Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    boolean prePostEvent(final AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        if (e instanceof MouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            return prePostMouseEvent((MouseEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        return super.prePostEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * Fixed 6240151: XToolkit: Dragging the List scrollbar initiates DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * To be compatible with Motif, MouseEvent originated on the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * should be sent into Java in this way:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * - post: MOUSE_ENTERED, MOUSE_EXITED, MOUSE_MOVED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * - don't post: MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_CLICKED, MOUSE_DRAGGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    boolean prePostMouseEvent(final MouseEvent me){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        if (getToplevelXWindow().isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        int eventId = me.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        if (eventId == MouseEvent.MOUSE_MOVED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            // only for performance improvement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        }else if((eventId == MouseEvent.MOUSE_DRAGGED ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                  eventId == MouseEvent.MOUSE_RELEASED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                 isScrollBarOriginated)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            if (eventId == MouseEvent.MOUSE_RELEASED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                isScrollBarOriginated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            handleJavaMouseEventOnEDT(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        }else if ((eventId == MouseEvent.MOUSE_PRESSED ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                   eventId == MouseEvent.MOUSE_CLICKED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                  (inVerticalScrollbar(me.getX(), me.getY()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                   inHorizontalScrollbar(me.getX(), me.getY())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            if (eventId == MouseEvent.MOUSE_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                isScrollBarOriginated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            handleJavaMouseEventOnEDT(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * Do handleJavaMouseEvent on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    void handleJavaMouseEventOnEDT(final MouseEvent me){
18520
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
  1652
        InvocationEvent ev = new InvocationEvent(target, new Runnable() {
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
  1653
            public void run() {
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
  1654
                handleJavaMouseEvent(me);
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
  1655
            }
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
  1656
        });
7fad3f87d731 8014264: The applet pathguy_TimeDead throws java.lang.NullPointerException in java console once click drop-down check box.
leonidr
parents: 16839
diff changeset
  1657
        postEvent(ev);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * Fixed 5010944: List's rows overlap one another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * The bug is due to incorrent caching of the list item size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * So we should recalculate font metrics on setFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     */
21270
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1665
    public void setFont(Font f) {
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1666
        if (!Objects.equals(getFont(), f)) {
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1667
            super.setFont(f);
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1668
            initFontMetrics();
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1669
            layout();
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1670
            repaint();
8a0fc12b81a2 7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents: 18525
diff changeset
  1671
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * Sometimes painter is called on Toolkit thread, so the lock sequence is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     *     awtLock -> Painter -> awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * Sometimes it is called on other threads:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     *     Painter -> awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     * Since we can't guarantee the sequence, use awtLock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
    class ListPainter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        VolatileImage buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        Color[] colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        private Color getListForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            if (fgColorSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                return colors[FOREGROUND_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            return SystemColor.textText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        private Color getListBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            if (bgColorSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                return colors[BACKGROUND_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                return SystemColor.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        private Color getDisabledColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
            Color backgroundColor = getListBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            Color foregroundColor = getListForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            return (backgroundColor.equals(Color.BLACK)) ? foregroundColor.darker() : backgroundColor.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        private boolean createBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            VolatileImage localBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                localBuffer = buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            if (localBuffer == null) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1718
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1719
                    log.fine("Creating buffer " + width + "x" + height);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1720
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                // use GraphicsConfig.cCVI() instead of Component.cVI(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                // because the latter may cause a deadlock with the tree lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                localBuffer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                    graphicsConfig.createCompatibleVolatileImage(width+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                                                                 height+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                if (buffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                    buffer = localBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                if (buffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                    buffer.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        private void paint(Graphics listG, int firstItem, int lastItem, int options) {
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1752
            paint(listG, firstItem, lastItem, options, null, null);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1753
        }
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1754
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1755
        private void paint(Graphics listG, int firstItem, int lastItem, int options,
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1756
                           Rectangle source, Point distance) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1757
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1758
                log.finer("Repaint from " + firstItem + " to " + lastItem + " options " + options);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1759
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            if (firstItem > lastItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                int t = lastItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                lastItem = firstItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                firstItem = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            if (firstItem < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                firstItem = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            colors = getGUIcolors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            VolatileImage localBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                    if (createBuffer()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                        // First time created buffer should be painted over at full.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                        options = PAINT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                    localBuffer = buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                    XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                switch (localBuffer.validate(getGraphicsConfiguration())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                  case VolatileImage.IMAGE_INCOMPATIBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                      invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                      options = PAINT_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                      continue;
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1786
                  case VolatileImage.IMAGE_RESTORED:
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1787
                      options = PAINT_ALL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                Graphics g = localBuffer.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1791
                // Note that the order of the following painting operations
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1792
                // should not be modified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                    g.setFont(getFont());
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1795
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1796
                    // hiding the focus rectangle must be done prior to copying
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1797
                    // area and so this is the first action to be performed
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1798
                    if ((options & (PAINT_HIDEFOCUS)) != 0) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1799
                        paintFocus(g, PAINT_HIDEFOCUS);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1800
                    }
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1801
                    /*
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1802
                     * The shift of the component contents occurs while someone
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1803
                     * scrolls the component, the only purpose of the shift is to
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1804
                     * increase the painting performance. The shift should be done
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1805
                     * prior to painting any area (except hiding focus) and actually
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1806
                     * it should never be done jointly with erase background.
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1807
                     */
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1808
                    if ((options & COPY_AREA) != 0) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1809
                        g.copyArea(source.x, source.y, source.width, source.height,
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1810
                            distance.x, distance.y);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1811
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                    if ((options & PAINT_BACKGROUND) != 0) {
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1813
                        paintBackground(g);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                        // Since we made full erase update items
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                        firstItem = getFirstVisibleItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                        lastItem = getLastVisibleItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                    if ((options & PAINT_ITEMS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                        paintItems(g, firstItem, lastItem, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                    if ((options & PAINT_VSCROLL) != 0 && vsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                        g.setClip(getVScrollBarRec());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                        paintVerScrollbar(g, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    if ((options & PAINT_HSCROLL) != 0 && hsbVis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                        g.setClip(getHScrollBarRec());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                        paintHorScrollbar(g, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    }
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1829
                    if ((options & (PAINT_FOCUS)) != 0) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1830
                        paintFocus(g, PAINT_FOCUS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            } while (localBuffer.contentsLost());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            listG.drawImage(localBuffer, 0, 0, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
445
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1839
        private void paintBackground(Graphics g) {
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1840
            g.setColor(SystemColor.window);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1841
            g.fillRect(0, 0, width, height);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1842
            g.setColor(getListBackground());
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1843
            g.fillRect(0, 0, listWidth, listHeight);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1844
            draw3DRect(g, getSystemColors(), 0, 0, listWidth - 1, listHeight - 1, false);
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1845
        }
6f717a8cacfb 6471693: Moving the vertical scroll bar of List in FileDialog leads Flickering in solaris
dcherepanov
parents: 2
diff changeset
  1846
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        private void paintItems(Graphics g, int firstItem, int lastItem, int options) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1848
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1849
                log.finer("Painting items from " + firstItem + " to " + lastItem + ", focused " + focusIndex + ", first " + getFirstVisibleItem() + ", last " + getLastVisibleItem());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1850
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            firstItem = Math.max(getFirstVisibleItem(), firstItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            if (firstItem > lastItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                int t = lastItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                lastItem = firstItem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                firstItem = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            firstItem = Math.max(getFirstVisibleItem(), firstItem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
            lastItem = Math.min(lastItem, items.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1861
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1862
                log.finer("Actually painting items from " + firstItem + " to " + lastItem +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1863
                          ", items in window " + itemsInWindow());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1864
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            for (int i = firstItem; i <= lastItem; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                paintItem(g, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        private void paintItem(Graphics g, int index) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1871
            if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1872
                log.finest("Painting item " + index);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1873
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            // 4895367 - only paint items which are visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            if (!isItemHidden(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                Shape clip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                int w = getItemWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                int h = getItemHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                int y = getItemY(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                int x = getItemX();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1881
                if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1882
                    log.finest("Setting clip " + new Rectangle(x, y, w - (SPACE*2), h-(SPACE*2)));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1883
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                g.setClip(x, y, w - (SPACE*2), h-(SPACE*2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                // Always paint the background so that focus is unpainted in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                // multiselect mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                if (isSelected(index)) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1889
                    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1890
                        log.finest("Painted item is selected");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1891
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                    g.setColor(getListForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                    g.setColor(getListBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1896
                if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1897
                    log.finest("Filling " + new Rectangle(x, y, w, h));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1898
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                g.fillRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                if (index <= getLastVisibleItem() && index < items.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                    if (!isEnabled()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                        g.setColor(getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                    } else if (isSelected(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                        g.setColor(getListBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                        g.setColor(getListForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                    }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 21270
diff changeset
  1909
                    String str = items.elementAt(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                    g.drawString(str, x - hsb.getValue(), y + fontAscent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                    // Clear the remaining area around the item - focus area and the rest of border
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                    g.setClip(x, y, listWidth, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                    g.setColor(getListBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                    g.fillRect(x, y, listWidth, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                g.setClip(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        void paintScrollBar(XScrollbar scr, Graphics g, int x, int y, int width, int height, boolean paintAll) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1922
            if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1923
                log.finest("Painting scrollbar " + scr + " width " +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1924
                width + " height " + height + ", paintAll " + paintAll);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1925
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            scr.paint(g, getSystemColors(), paintAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
         * Paint the horizontal scrollbar to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
         * @param g the graphics context to draw into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
         * @param paintAll paint the whole scrollbar if true, just the thumb if false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        void paintHorScrollbar(Graphics g, boolean paintAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            int w = getListWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            paintScrollBar(hsb, g, 0, height - (SCROLLBAR_WIDTH), w, SCROLLBAR_WIDTH, paintAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
         * Paint the vertical scrollbar to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
         * @param g the graphics context to draw into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
         * @param paintAll paint the whole scrollbar if true, just the thumb if false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        void paintVerScrollbar(Graphics g, boolean paintAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            int h = height - (hsbVis ? (SCROLLBAR_AREA-2) : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            paintScrollBar(vsb, g, width - SCROLLBAR_WIDTH, 0, SCROLLBAR_WIDTH - 2, h, paintAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
        private Rectangle prevFocusRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        private void paintFocus(Graphics g, int options) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            boolean paintFocus = (options & PAINT_FOCUS) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            if (paintFocus && !hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                paintFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
            }
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1960
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1961
                log.fine("Painting focus, focus index " + getFocusIndex() + ", focus is " +
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1962
                         (isItemHidden(getFocusIndex())?("invisible"):("visible")) + ", paint focus is " + paintFocus);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1963
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            Shape clip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            g.setClip(0, 0, listWidth, listHeight);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1966
            if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1967
                log.finest("Setting focus clip " + new Rectangle(0, 0, listWidth, listHeight));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1968
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            Rectangle rect = getFocusRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            if (prevFocusRect != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                // Erase focus rect
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1972
                if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1973
                    log.finest("Erasing previous focus rect " + prevFocusRect);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1974
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                g.setColor(getListBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                g.drawRect(prevFocusRect.x, prevFocusRect.y, prevFocusRect.width, prevFocusRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                prevFocusRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            if (paintFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                // Paint new
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
  1981
                if (log.isLoggable(PlatformLogger.Level.FINEST)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1982
                    log.finest("Painting focus rect " + rect);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 10096
diff changeset
  1983
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                g.setColor(getListForeground());  // Focus color is always black on Linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                g.drawRect(rect.x, rect.y, rect.width, rect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                prevFocusRect = rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            g.setClip(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
}