src/demo/share/jfc/SwingSet2/ListDemo.java
author tvaleev
Tue, 09 Oct 2018 18:25:57 -0700
changeset 52252 de9486d74a74
parent 49495 f46bfa7a2956
permissions -rw-r--r--
8211693: Convert C-style array declarations in client demos and jdk.accessibility Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     1
/*
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     2
 *
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
     3
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     4
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     7
 * are met:
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     8
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     9
 *   - Redistributions of source code must retain the above copyright
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    10
 *     notice, this list of conditions and the following disclaimer.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    11
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    12
 *   - Redistributions in binary form must reproduce the above copyright
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    13
 *     notice, this list of conditions and the following disclaimer in the
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    14
 *     documentation and/or other materials provided with the distribution.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    15
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    16
 *   - Neither the name of Oracle nor the names of its
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    17
 *     contributors may be used to endorse or promote products derived
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    18
 *     from this software without specific prior written permission.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    19
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    21
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    22
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    23
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    31
 */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    32
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    33
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    34
import javax.swing.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    35
import javax.swing.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    36
import javax.swing.text.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    37
import javax.swing.border.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    38
import javax.swing.colorchooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    39
import javax.swing.filechooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    40
import javax.accessibility.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    41
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    42
import java.awt.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    43
import java.awt.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    44
import java.beans.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    45
import java.util.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    46
import java.io.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    47
import java.applet.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    48
import java.net.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    49
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    50
/**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    51
 * List Demo. This demo shows that it is not
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    52
 * always necessary to have an array of objects
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    53
 * as big as the size of the list stored.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    54
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    55
 * Indeed, in this example, there is no array
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    56
 * kept for the list data, rather it is generated
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    57
 * on the fly as only those elements are needed.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    58
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    59
 * @author Jeff Dinkins
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    60
 */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    61
public class ListDemo extends DemoModule {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    62
    JList list;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    63
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    64
    JPanel prefixList;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    65
    JPanel suffixList;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    66
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    67
    Action prefixAction;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    68
    Action suffixAction;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    69
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    70
    GeneratedListModel listModel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    71
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    72
    Vector checkboxes = new Vector();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    73
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    74
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    75
     * main method allows us to run as a standalone demo.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    76
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    77
    public static void main(String[] args) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    78
        ListDemo demo = new ListDemo(null);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    79
        demo.mainImpl();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    80
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    81
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    82
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    83
     * ListDemo Constructor
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    84
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    85
    public ListDemo(SwingSet2 swingset) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    86
        super(swingset, "ListDemo", "toolbar/JList.gif");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    87
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    88
        loadImages();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    89
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    90
        JLabel description = new JLabel(getString("ListDemo.description"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    91
        getDemoPanel().add(description, BorderLayout.NORTH);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    92
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    93
        JPanel centerPanel = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    94
        centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.X_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    95
        centerPanel.add(Box.createRigidArea(HGAP10));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    96
        getDemoPanel().add(centerPanel, BorderLayout.CENTER);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    97
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    98
        JPanel listPanel = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    99
        listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   100
        listPanel.add(Box.createRigidArea(VGAP10));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   101
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   102
        centerPanel.add(listPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   103
        centerPanel.add(Box.createRigidArea(HGAP30));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   104
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   105
        // Create the list
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   106
        list = new JList();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   107
        list.setCellRenderer(new CompanyLogoListCellRenderer());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   108
        listModel = new GeneratedListModel(this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   109
        list.setModel(listModel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   110
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   111
        // Set the preferred row count. This affects the preferredSize
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   112
        // of the JList when it's in a scrollpane.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   113
        list.setVisibleRowCount(22);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   114
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   115
        // Add list to a scrollpane
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   116
        JScrollPane scrollPane = new JScrollPane(list);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   117
        listPanel.add(scrollPane);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   118
        listPanel.add(Box.createRigidArea(VGAP10));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   119
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   120
        // Add the control panel (holds the prefix/suffix list and prefix/suffix checkboxes)
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   121
        centerPanel.add(createControlPanel());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   122
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   123
        // create prefixes and suffixes
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   124
        addPrefix("Tera", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   125
        addPrefix("Micro", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   126
        addPrefix("Southern", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   127
        addPrefix("Net", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   128
        addPrefix("YoYo", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   129
        addPrefix("Northern", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   130
        addPrefix("Tele", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   131
        addPrefix("Eastern", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   132
        addPrefix("Neo", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   133
        addPrefix("Digi", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   134
        addPrefix("National", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   135
        addPrefix("Compu", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   136
        addPrefix("Meta", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   137
        addPrefix("Info", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   138
        addPrefix("Western", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   139
        addPrefix("Data", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   140
        addPrefix("Atlantic", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   141
        addPrefix("Advanced", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   142
        addPrefix("Euro", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   143
        addPrefix("Pacific", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   144
        addPrefix("Mobile", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   145
        addPrefix("In", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   146
        addPrefix("Computa", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   147
        addPrefix("Digital", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   148
        addPrefix("Analog", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   149
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   150
        addSuffix("Tech", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   151
        addSuffix("Soft", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   152
        addSuffix("Telecom", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   153
        addSuffix("Solutions", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   154
        addSuffix("Works", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   155
        addSuffix("Dyne", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   156
        addSuffix("Services", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   157
        addSuffix("Vers", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   158
        addSuffix("Devices", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   159
        addSuffix("Software", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   160
        addSuffix("Serv", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   161
        addSuffix("Systems", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   162
        addSuffix("Dynamics", true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   163
        addSuffix("Net", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   164
        addSuffix("Sys", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   165
        addSuffix("Computing", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   166
        addSuffix("Scape", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   167
        addSuffix("Com", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   168
        addSuffix("Ware", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   169
        addSuffix("Widgets", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   170
        addSuffix("Media", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   171
        addSuffix("Computer", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   172
        addSuffix("Hardware", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   173
        addSuffix("Gizmos", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   174
        addSuffix("Concepts", false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   175
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   176
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   177
    void updateDragEnabled(boolean dragEnabled) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   178
        list.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   179
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   180
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   181
    public JPanel createControlPanel() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   182
        JPanel controlPanel = new JPanel() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   183
            Insets insets = new Insets(0, 4, 10, 10);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   184
            public Insets getInsets() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   185
                return insets;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   186
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   187
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   188
        controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   189
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   190
        JPanel prefixPanel = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   191
        prefixPanel.setLayout(new BoxLayout(prefixPanel, BoxLayout.Y_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   192
        prefixPanel.add(new JLabel(getString("ListDemo.prefixes")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   193
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   194
        JPanel suffixPanel = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   195
        suffixPanel.setLayout(new BoxLayout(suffixPanel, BoxLayout.Y_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   196
        suffixPanel.add(new JLabel(getString("ListDemo.suffixes")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   197
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   198
        prefixList = new JPanel() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   199
            Insets insets = new Insets(0, 4, 0, 0);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   200
            public Insets getInsets() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   201
                return insets;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   202
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   203
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   204
        prefixList.setLayout(new BoxLayout(prefixList, BoxLayout.Y_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   205
        JScrollPane scrollPane = new JScrollPane(prefixList);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   206
        scrollPane.getVerticalScrollBar().setUnitIncrement(10);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   207
        prefixPanel.add(scrollPane);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   208
        prefixPanel.add(Box.createRigidArea(HGAP10));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   209
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   210
        suffixList = new JPanel() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   211
            Insets insets = new Insets(0, 4, 0, 0);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   212
            public Insets getInsets() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   213
                return insets;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   214
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   215
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   216
        suffixList.setLayout(new BoxLayout(suffixList, BoxLayout.Y_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   217
        scrollPane = new JScrollPane(suffixList);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   218
        scrollPane.getVerticalScrollBar().setUnitIncrement(10);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   219
        suffixPanel.add(scrollPane);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   220
        suffixPanel.add(Box.createRigidArea(HGAP10));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   221
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   222
        controlPanel.add(prefixPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   223
        controlPanel.add(Box.createRigidArea(HGAP15));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   224
        controlPanel.add(suffixPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   225
        return controlPanel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   226
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   227
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   228
    private FocusListener listFocusListener = new FocusAdapter() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   229
        public void focusGained(FocusEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   230
            JComponent c = (JComponent)e.getComponent();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   231
            c.scrollRectToVisible(new Rectangle(0, 0, c.getWidth(), c.getHeight()));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   232
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   233
    };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   234
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   235
    public void addPrefix(String prefix, boolean selected) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   236
        if(prefixAction == null) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   237
            prefixAction = new UpdatePrefixListAction(listModel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   238
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   239
        final JCheckBox cb = (JCheckBox) prefixList.add(new JCheckBox(prefix));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   240
        checkboxes.addElement(cb);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   241
        cb.setSelected(selected);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   242
        cb.addActionListener(prefixAction);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   243
        if(selected) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   244
            listModel.addPrefix(prefix);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   245
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   246
        cb.addFocusListener(listFocusListener);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   247
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   248
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   249
    public void addSuffix(String suffix, boolean selected) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   250
        if(suffixAction == null) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   251
            suffixAction = new UpdateSuffixListAction(listModel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   252
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   253
        final JCheckBox cb = (JCheckBox) suffixList.add(new JCheckBox(suffix));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   254
        checkboxes.addElement(cb);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   255
        cb.setSelected(selected);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   256
        cb.addActionListener(suffixAction);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   257
        if(selected) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   258
            listModel.addSuffix(suffix);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   259
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   260
        cb.addFocusListener(listFocusListener);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   261
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   262
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   263
    class UpdatePrefixListAction extends AbstractAction {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   264
        GeneratedListModel listModel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   265
        protected UpdatePrefixListAction(GeneratedListModel listModel) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   266
            this.listModel = listModel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   267
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   268
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   269
        public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   270
            JCheckBox cb = (JCheckBox) e.getSource();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   271
            if(cb.isSelected()) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   272
                listModel.addPrefix(cb.getText());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   273
            } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   274
                listModel.removePrefix(cb.getText());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   275
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   276
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   277
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   278
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   279
    class UpdateSuffixListAction extends AbstractAction {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   280
        GeneratedListModel listModel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   281
        protected UpdateSuffixListAction(GeneratedListModel listModel) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   282
            this.listModel = listModel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   283
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   284
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   285
        public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   286
            JCheckBox cb = (JCheckBox) e.getSource();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   287
            if(cb.isSelected()) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   288
                listModel.addSuffix(cb.getText());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   289
            } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   290
                listModel.removeSuffix(cb.getText());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   291
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   292
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   293
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   294
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   295
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   296
    class GeneratedListModel extends AbstractListModel {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   297
        ListDemo demo;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   298
        Permuter permuter;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   299
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   300
        public Vector prefix = new Vector();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   301
        public Vector suffix = new Vector();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   302
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   303
        public GeneratedListModel (ListDemo demo) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   304
            this.demo = demo;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   305
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   306
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   307
        private void update() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   308
            permuter = new Permuter(getSize());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   309
            fireContentsChanged(this, 0, getSize());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   310
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   311
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   312
        public void addPrefix(String s) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   313
            if(!prefix.contains(s)) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   314
                prefix.addElement(s);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   315
                update();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   316
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   317
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   318
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   319
        public void removePrefix(String s) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   320
            prefix.removeElement(s);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   321
            update();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   322
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   323
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   324
        public void addSuffix(String s) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   325
            if(!suffix.contains(s)) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   326
                suffix.addElement(s);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   327
                update();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   328
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   329
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   330
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   331
        public void removeSuffix(String s) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   332
            suffix.removeElement(s);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   333
            update();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   334
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   335
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   336
        public int getSize() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   337
            return prefix.size() * suffix.size();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   338
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   339
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   340
        public Object getElementAt(int index) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   341
            if(permuter == null) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   342
                update();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   343
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   344
            // morph the index to another int -- this has the benefit of
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   345
            // causing the list to look random.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   346
            int j = permuter.map(index);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   347
            int ps = prefix.size();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   348
            int ss = suffix.size();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   349
            return (String) prefix.elementAt(j%ps) + (String) suffix.elementAt((j/ps)%ss);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   350
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   351
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   352
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   353
    ImageIcon[] images = new ImageIcon[7];
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   354
    void loadImages() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   355
            images[0] = createImageIcon("list/red.gif",  getString("ListDemo.red"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   356
            images[1] = createImageIcon("list/blue.gif",  getString("ListDemo.blue"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   357
            images[2] = createImageIcon("list/yellow.gif",  getString("ListDemo.yellow"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   358
            images[3] = createImageIcon("list/green.gif",  getString("ListDemo.green"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   359
            images[4] = createImageIcon("list/gray.gif",  getString("ListDemo.gray"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   360
            images[5] = createImageIcon("list/cyan.gif",  getString("ListDemo.cyan"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   361
            images[6] = createImageIcon("list/magenta.gif",  getString("ListDemo.magenta"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   362
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   363
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   364
    class CompanyLogoListCellRenderer extends DefaultListCellRenderer {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   365
       public Component getListCellRendererComponent(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   366
            JList list,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   367
            Object value,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   368
            int index,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   369
            boolean isSelected,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   370
            boolean cellHasFocus)
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   371
        {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   372
            Component retValue = super.getListCellRendererComponent(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   373
                list, value, index, isSelected, cellHasFocus
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   374
            );
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   375
            setIcon(images[index%7]);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   376
            return retValue;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   377
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   378
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   379
}