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