jdk/test/javax/swing/JList/6823603/bug6823603.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4378
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4378
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
4378
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     4
 *
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     8
 *
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    13
 * accompanied this code).
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    14
 *
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4378
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4378
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4378
diff changeset
    21
 * questions.
4378
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    22
 */
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    23
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    24
/* @test
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    25
   @bug 6823603
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    26
   @summary Generics: JList
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    27
   @author Florian Brunner
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    28
   @run main bug6823603
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    29
 */
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    30
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    31
import java.util.Arrays;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    32
import java.util.List;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    33
import java.util.Vector;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    34
import java.util.Enumeration;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    35
import java.awt.*;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    36
import javax.swing.*;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    37
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    38
public class bug6823603 {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    39
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    40
    private static final String TEST_ELEMENT = "Test1";
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    41
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    42
    /**
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    43
     * @param args the command line arguments
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    44
     */
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    45
    @SuppressWarnings("unchecked")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    46
    public static void main(String[] args) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    47
        testRawSignatures();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    48
        testGenericSignatures();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    49
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    50
        testGetSelectedValuesList(); // new method
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    51
    }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    52
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    53
    @SuppressWarnings("unchecked")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    54
    private static void testRawSignatures() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    55
        // Test JList
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    56
        ListModel rawTestModel = new DefaultListModel();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    57
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    58
        new JList();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    59
        new JList(rawTestModel);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    60
        new JList(new Object[]{TEST_ELEMENT});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    61
        JList rawTestList = new JList(new Vector());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    62
        rawTestList.getPrototypeCellValue();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    63
        rawTestList.setPrototypeCellValue(TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    64
        rawTestList.getCellRenderer();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    65
        rawTestList.setCellRenderer(new DefaultListCellRenderer());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    66
        rawTestList.getModel();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    67
        rawTestList.setModel(rawTestModel);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    68
        rawTestList.setListData(new Object[]{TEST_ELEMENT});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    69
        rawTestList.setListData(new Vector());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    70
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    71
        @SuppressWarnings("deprecation")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    72
        Object[] selectedValues = rawTestList.getSelectedValues();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    73
        rawTestList.getSelectedValue();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    74
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    75
        // Test ListCellRenderer
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    76
        ListCellRenderer rawTestCellRenderer = new DefaultListCellRenderer();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    77
        String testEntry = "Test";
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    78
        @SuppressWarnings("unchecked")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    79
        JList rawJList = new JList(new Object[]{testEntry});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    80
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    81
        rawTestCellRenderer.getListCellRendererComponent(rawJList,
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    82
                testEntry, 0, true, true);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    83
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    84
        // Test ListModel
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    85
        DefaultListModel testModel = new DefaultListModel();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    86
        testModel.addElement(TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    87
        rawTestModel = testModel;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    88
        rawTestModel.getElementAt(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    89
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    90
        // Test DefaultListModel
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    91
        DefaultListModel defaultListModel = new DefaultListModel();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    92
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    93
        defaultListModel.addElement(TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    94
        defaultListModel.getElementAt(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    95
        defaultListModel.elements();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    96
        defaultListModel.elementAt(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    97
        defaultListModel.firstElement();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    98
        defaultListModel.lastElement();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
    99
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   100
        String testElement2 = "Test2";
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   101
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   102
        defaultListModel.setElementAt(testElement2, 0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   103
        defaultListModel.insertElementAt(TEST_ELEMENT, 0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   104
        defaultListModel.get(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   105
        defaultListModel.set(0, testElement2);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   106
        defaultListModel.add(0, TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   107
        defaultListModel.remove(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   108
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   109
        // Test AbstractListModel
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   110
        @SuppressWarnings("serial")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   111
        ListModel abstractListModel = new AbstractListModel() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   112
            public int getSize() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   113
                throw new UnsupportedOperationException("Not supported yet.");
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   114
            }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   115
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   116
            public Object getElementAt(int index) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   117
                throw new UnsupportedOperationException("Not supported yet.");
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   118
            }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   119
        };
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   120
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   121
        // Test DefaultListCellRenderer
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   122
        DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   123
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   124
        @SuppressWarnings("unchecked")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   125
        JList list = new JList(new Object[]{testEntry});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   126
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   127
        cellRenderer.getListCellRendererComponent(rawJList, testEntry, 0, true, true);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   128
    }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   129
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   130
    private static <E> void testGenericSignatures() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   131
        // Test JList
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   132
        ListModel<String> stringListModel = new DefaultListModel<String>();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   133
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   134
        new JList<String>();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   135
        new JList<String>(stringListModel);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   136
        new JList<String>(new String[]{TEST_ELEMENT});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   137
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   138
        JList<String> stringTestList = new JList<String>(new Vector<String>());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   139
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   140
        stringTestList.getPrototypeCellValue();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   141
        stringTestList.setPrototypeCellValue(TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   142
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   143
        ListCellRenderer<? super String> cellRenderer = stringTestList.getCellRenderer();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   144
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   145
        stringTestList.setCellRenderer(new DefaultListCellRenderer());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   146
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   147
        ListModel<String> model = stringTestList.getModel();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   148
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   149
        stringTestList.setModel(stringListModel);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   150
        stringTestList.setListData(new String[]{TEST_ELEMENT});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   151
        stringTestList.setListData(new Vector<String>());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   152
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   153
        @SuppressWarnings("deprecation")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   154
        Object[] selectedValues = stringTestList.getSelectedValues();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   155
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   156
        stringTestList.getSelectedValue();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   157
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   158
        // Test ListCellRenderer
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   159
        ListCellRenderer<Object> stringTestCellRenderer =
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   160
                new DefaultListCellRenderer();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   161
        String testEntry = "Test";
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   162
        JList<String> stringJList = new JList<String>(new String[]{testEntry});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   163
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   164
        Component listCellRendererComponent2 =
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   165
                stringTestCellRenderer.getListCellRendererComponent(stringJList,
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   166
                testEntry, 0, true, true);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   167
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   168
        // Test ListModel
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   169
        DefaultListModel<String> testModel = new DefaultListModel<String>();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   170
        testModel.addElement(TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   171
        stringListModel = testModel;
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   172
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   173
        String element1 = stringListModel.getElementAt(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   174
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   175
        // Test DefaultListModel
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   176
        DefaultListModel<String> stringTestModel = new DefaultListModel<String>();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   177
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   178
        stringTestModel.addElement(TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   179
        element1 = stringTestModel.getElementAt(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   180
        Enumeration<String> elements = stringTestModel.elements();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   181
        String element2 = stringTestModel.elementAt(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   182
        String firstElement = stringTestModel.firstElement();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   183
        String lastElement = stringTestModel.lastElement();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   184
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   185
        String testElement2 = "Test2";
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   186
        stringTestModel.setElementAt(testElement2, 0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   187
        stringTestModel.insertElementAt(TEST_ELEMENT, 0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   188
        String element3 = stringTestModel.get(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   189
        String element4 = stringTestModel.set(0, testElement2);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   190
        stringTestModel.add(0, TEST_ELEMENT);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   191
        String removedElement = stringTestModel.remove(0);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   192
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   193
        // Test AbstractListModel
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   194
        stringListModel = new AbstractListModel<String>() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   195
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   196
            public int getSize() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   197
                throw new UnsupportedOperationException("Not supported yet.");
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   198
            }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   199
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   200
            public String getElementAt(int index) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   201
                throw new UnsupportedOperationException("Not supported yet.");
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   202
            }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   203
        };
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   204
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   205
        @SuppressWarnings("serial")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   206
        ListModel<E> genericTestModel = new AbstractListModel<E>() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   207
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   208
            public int getSize() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   209
                throw new UnsupportedOperationException("Not supported yet.");
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   210
            }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   211
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   212
            public E getElementAt(int index) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   213
                throw new UnsupportedOperationException("Not supported yet.");
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   214
            }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   215
        };
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   216
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   217
        // Test DefaultListCellRenderer
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   218
        cellRenderer = new DefaultListCellRenderer();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   219
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   220
        stringJList = new JList<String>(new String[]{testEntry});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   221
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   222
        listCellRendererComponent2 = cellRenderer.getListCellRendererComponent(stringJList, testEntry, 0, true, true);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   223
    }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   224
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   225
    private static void testGetSelectedValuesList() {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   226
        Vector<Integer> data = new Vector<Integer>();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   227
        for (int i = 0; i < 10; i++) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   228
            data.add(i);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   229
        }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   230
        JList<Integer> list = new JList<Integer>(data);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   231
        list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   232
        list.setSelectedIndices(new int[]{1, 2, 3, 5, 6, 8});
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   233
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   234
        @SuppressWarnings("deprecation")
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   235
        Object[] expectedSelectedValues = list.getSelectedValues();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   236
        List<Integer> selectedValuesList = list.getSelectedValuesList();
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   237
        assertEquals(expectedSelectedValues, selectedValuesList.toArray());
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   238
    }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   239
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   240
    private static void assertEquals(Object[] expectedArray,
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   241
            Object[] actualArray) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   242
        if (!Arrays.equals(expectedArray, actualArray)) {
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   243
            throw new RuntimeException("Expected: " + Arrays.toString(
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   244
                    expectedArray) + " but was: " + Arrays.toString(actualArray));
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   245
        }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   246
    }
ef21a120cb18 6823603: Generics: JList
rupashka
parents:
diff changeset
   247
}