src/demo/share/jfc/SwingSet2/TableDemo.java
author weijun
Tue, 29 Oct 2019 09:34:21 +0800
changeset 58830 fa0b9f9c597a
parent 49495 f46bfa7a2956
permissions -rw-r--r--
8228969: 2019-09-28 public suffix list update Reviewed-by: mullan
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
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     3
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
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.table.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    38
import javax.swing.border.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    39
import javax.swing.colorchooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    40
import javax.swing.filechooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    41
import javax.accessibility.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    42
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    43
import java.awt.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    44
import java.awt.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    45
import java.awt.print.PrinterException;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    46
import java.beans.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    47
import java.util.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    48
import java.io.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    49
import java.applet.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    50
import java.net.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    51
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    52
import java.text.MessageFormat;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    53
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
 * Table demo
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    56
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    57
 * @author Philip Milne
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    58
 * @author Steve Wilson
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    59
 */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    60
public class TableDemo extends DemoModule {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    61
    JTable      tableView;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    62
    JScrollPane scrollpane;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    63
    Dimension   origin = new Dimension(0, 0);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    64
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    65
    JCheckBox   isColumnReorderingAllowedCheckBox;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    66
    JCheckBox   showHorizontalLinesCheckBox;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    67
    JCheckBox   showVerticalLinesCheckBox;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    68
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    69
    JCheckBox   isColumnSelectionAllowedCheckBox;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    70
    JCheckBox   isRowSelectionAllowedCheckBox;
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
    JLabel      interCellSpacingLabel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    73
    JLabel      rowHeightLabel;
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
    JSlider     interCellSpacingSlider;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    76
    JSlider     rowHeightSlider;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    77
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    78
    JComboBox   selectionModeComboBox = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    79
    JComboBox   resizeModeComboBox = null;
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
    JLabel      headerLabel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    82
    JLabel      footerLabel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    83
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    84
    JTextField  headerTextField;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    85
    JTextField  footerTextField;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    86
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    87
    JCheckBox   fitWidth;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    88
    JButton     printButton;
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
    JPanel      controlPanel;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    91
    JScrollPane tableAggregate;
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
    String path = "food/";
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    94
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    95
    final int INITIAL_ROWHEIGHT = 33;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    96
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
     * main method allows us to run as a standalone demo.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    99
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   100
    public static void main(String[] args) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   101
        TableDemo demo = new TableDemo(null);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   102
        demo.mainImpl();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   103
    }
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
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   106
     * TableDemo Constructor
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   107
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   108
    public TableDemo(SwingSet2 swingset) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   109
        super(swingset, "TableDemo", "toolbar/JTable.gif");
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
        getDemoPanel().setLayout(new BorderLayout());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   112
        controlPanel = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   113
        controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   114
        JPanel cbPanel = new JPanel(new GridLayout(3, 2));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   115
        JPanel labelPanel = new JPanel(new GridLayout(2, 1)) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   116
            public Dimension getMaximumSize() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   117
                return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   118
            }
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
        JPanel sliderPanel = new JPanel(new GridLayout(2, 1)) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   121
            public Dimension getMaximumSize() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   122
                return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   123
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   124
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   125
        JPanel comboPanel = new JPanel(new GridLayout(2, 1));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   126
        JPanel printPanel = new JPanel(new ColumnLayout());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   127
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   128
        getDemoPanel().add(controlPanel, BorderLayout.NORTH);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   129
        Vector relatedComponents = new Vector();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   130
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   131
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   132
        // check box panel
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   133
        isColumnReorderingAllowedCheckBox = new JCheckBox(getString("TableDemo.reordering_allowed"), true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   134
        isColumnReorderingAllowedCheckBox.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   135
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   136
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   137
                tableView.getTableHeader().setReorderingAllowed(flag);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   138
                tableView.repaint();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   139
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   140
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   141
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   142
        showHorizontalLinesCheckBox = new JCheckBox(getString("TableDemo.horz_lines"), true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   143
        showHorizontalLinesCheckBox.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   144
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   145
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   146
                tableView.setShowHorizontalLines(flag); ;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   147
                tableView.repaint();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   148
            }
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
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   151
        showVerticalLinesCheckBox = new JCheckBox(getString("TableDemo.vert_lines"), true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   152
        showVerticalLinesCheckBox.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   153
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   154
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   155
                tableView.setShowVerticalLines(flag); ;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   156
                tableView.repaint();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   157
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   158
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   159
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   160
        // Show that showHorizontal/Vertical controls are related
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   161
        relatedComponents.removeAllElements();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   162
        relatedComponents.add(showHorizontalLinesCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   163
        relatedComponents.add(showVerticalLinesCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   164
        buildAccessibleGroup(relatedComponents);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   165
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   166
        isRowSelectionAllowedCheckBox = new JCheckBox(getString("TableDemo.row_selection"), true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   167
        isRowSelectionAllowedCheckBox.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   168
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   169
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   170
                tableView.setRowSelectionAllowed(flag); ;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   171
                tableView.repaint();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   172
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   173
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   174
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   175
        isColumnSelectionAllowedCheckBox = new JCheckBox(getString("TableDemo.column_selection"), false);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   176
        isColumnSelectionAllowedCheckBox.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   177
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   178
                boolean flag = ((JCheckBox)e.getSource()).isSelected();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   179
                tableView.setColumnSelectionAllowed(flag); ;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   180
                tableView.repaint();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   181
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   182
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   183
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   184
        // Show that row/column selections are related
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   185
        relatedComponents.removeAllElements();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   186
        relatedComponents.add(isColumnSelectionAllowedCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   187
        relatedComponents.add(isRowSelectionAllowedCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   188
        buildAccessibleGroup(relatedComponents);
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
        cbPanel.add(isColumnReorderingAllowedCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   191
        cbPanel.add(isRowSelectionAllowedCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   192
        cbPanel.add(showHorizontalLinesCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   193
        cbPanel.add(isColumnSelectionAllowedCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   194
        cbPanel.add(showVerticalLinesCheckBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   195
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   196
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   197
        // label panel
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   198
        interCellSpacingLabel = new JLabel(getString("TableDemo.intercell_spacing_colon"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   199
        labelPanel.add(interCellSpacingLabel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   200
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   201
        rowHeightLabel = new JLabel(getString("TableDemo.row_height_colon"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   202
        labelPanel.add(rowHeightLabel);
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
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   205
        // slider panel
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   206
        interCellSpacingSlider = new JSlider(JSlider.HORIZONTAL, 0, 10, 1);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   207
        interCellSpacingSlider.getAccessibleContext().setAccessibleName(getString("TableDemo.intercell_spacing"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   208
        interCellSpacingLabel.setLabelFor(interCellSpacingSlider);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   209
        sliderPanel.add(interCellSpacingSlider);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   210
        interCellSpacingSlider.addChangeListener(new ChangeListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   211
            public void stateChanged(ChangeEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   212
                int spacing = ((JSlider)e.getSource()).getValue();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   213
                tableView.setIntercellSpacing(new Dimension(spacing, spacing));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   214
                tableView.repaint();
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
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   217
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   218
        rowHeightSlider = new JSlider(JSlider.HORIZONTAL, 5, 100, INITIAL_ROWHEIGHT);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   219
        rowHeightSlider.getAccessibleContext().setAccessibleName(getString("TableDemo.row_height"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   220
        rowHeightLabel.setLabelFor(rowHeightSlider);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   221
        sliderPanel.add(rowHeightSlider);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   222
        rowHeightSlider.addChangeListener(new ChangeListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   223
            public void stateChanged(ChangeEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   224
                int height = ((JSlider)e.getSource()).getValue();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   225
                tableView.setRowHeight(height);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   226
                tableView.repaint();
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
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   229
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   230
        // Show that spacing controls are related
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   231
        relatedComponents.removeAllElements();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   232
        relatedComponents.add(interCellSpacingSlider);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   233
        relatedComponents.add(rowHeightSlider);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   234
        buildAccessibleGroup(relatedComponents);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   235
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   236
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   237
        // Create the table.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   238
        tableAggregate = createTable();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   239
        getDemoPanel().add(tableAggregate, BorderLayout.CENTER);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   240
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   241
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   242
        // ComboBox for selection modes.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   243
        JPanel selectMode = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   244
        selectMode.setLayout(new BoxLayout(selectMode, BoxLayout.X_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   245
        selectMode.setBorder(new TitledBorder(getString("TableDemo.selection_mode")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   246
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
        selectionModeComboBox = new JComboBox() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   249
            public Dimension getMaximumSize() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   250
                return getPreferredSize();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   251
            }
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
        selectionModeComboBox.addItem(getString("TableDemo.single"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   254
        selectionModeComboBox.addItem(getString("TableDemo.one_range"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   255
        selectionModeComboBox.addItem(getString("TableDemo.multiple_ranges"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   256
        selectionModeComboBox.setSelectedIndex(tableView.getSelectionModel().getSelectionMode());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   257
        selectionModeComboBox.addItemListener(new ItemListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   258
            public void itemStateChanged(ItemEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   259
                JComboBox source = (JComboBox)e.getSource();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   260
                tableView.setSelectionMode(source.getSelectedIndex());
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
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   264
        selectMode.add(Box.createHorizontalStrut(2));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   265
        selectMode.add(selectionModeComboBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   266
        selectMode.add(Box.createHorizontalGlue());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   267
        comboPanel.add(selectMode);
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
        // Combo box for table resize mode.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   270
        JPanel resizeMode = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   271
        resizeMode.setLayout(new BoxLayout(resizeMode, BoxLayout.X_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   272
        resizeMode.setBorder(new TitledBorder(getString("TableDemo.autoresize_mode")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   273
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   274
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   275
        resizeModeComboBox = new JComboBox() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   276
            public Dimension getMaximumSize() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   277
                return getPreferredSize();
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
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   280
        resizeModeComboBox.addItem(getString("TableDemo.off"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   281
        resizeModeComboBox.addItem(getString("TableDemo.column_boundaries"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   282
        resizeModeComboBox.addItem(getString("TableDemo.subsequent_columns"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   283
        resizeModeComboBox.addItem(getString("TableDemo.last_column"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   284
        resizeModeComboBox.addItem(getString("TableDemo.all_columns"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   285
        resizeModeComboBox.setSelectedIndex(tableView.getAutoResizeMode());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   286
        resizeModeComboBox.addItemListener(new ItemListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   287
            public void itemStateChanged(ItemEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   288
                JComboBox source = (JComboBox)e.getSource();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   289
                tableView.setAutoResizeMode(source.getSelectedIndex());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   290
            }
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
        resizeMode.add(Box.createHorizontalStrut(2));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   294
        resizeMode.add(resizeModeComboBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   295
        resizeMode.add(Box.createHorizontalGlue());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   296
        comboPanel.add(resizeMode);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   297
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   298
        // print panel
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   299
        printPanel.setBorder(new TitledBorder(getString("TableDemo.printing")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   300
        headerLabel = new JLabel(getString("TableDemo.header"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   301
        footerLabel = new JLabel(getString("TableDemo.footer"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   302
        headerTextField = new JTextField(getString("TableDemo.headerText"), 15);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   303
        footerTextField = new JTextField(getString("TableDemo.footerText"), 15);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   304
        fitWidth = new JCheckBox(getString("TableDemo.fitWidth"), true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   305
        printButton = new JButton(getString("TableDemo.print"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   306
        printButton.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   307
            public void actionPerformed(ActionEvent ae) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   308
                printTable();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   309
            }
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
        printPanel.add(headerLabel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   313
        printPanel.add(headerTextField);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   314
        printPanel.add(footerLabel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   315
        printPanel.add(footerTextField);
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
        JPanel buttons = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   318
        buttons.add(fitWidth);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   319
        buttons.add(printButton);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   320
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   321
        printPanel.add(buttons);
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
        // Show that printing controls are related
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   324
        relatedComponents.removeAllElements();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   325
        relatedComponents.add(headerTextField);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   326
        relatedComponents.add(footerTextField);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   327
        relatedComponents.add(printButton);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   328
        buildAccessibleGroup(relatedComponents);
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
        // wrap up the panels and add them
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   331
        JPanel sliderWrapper = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   332
        sliderWrapper.setLayout(new BoxLayout(sliderWrapper, BoxLayout.X_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   333
        sliderWrapper.add(labelPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   334
        sliderWrapper.add(sliderPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   335
        sliderWrapper.add(Box.createHorizontalGlue());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   336
        sliderWrapper.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   337
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   338
        JPanel leftWrapper = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   339
        leftWrapper.setLayout(new BoxLayout(leftWrapper, BoxLayout.Y_AXIS));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   340
        leftWrapper.add(cbPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   341
        leftWrapper.add(sliderWrapper);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   342
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   343
        // add everything
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   344
        controlPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   345
        controlPanel.add(leftWrapper);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   346
        controlPanel.add(comboPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   347
        controlPanel.add(printPanel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   348
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   349
        setTableControllers(); // Set accessibility information
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
        getDemoPanel().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   352
            .put(KeyStroke.getKeyStroke("ctrl P"), "print");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   353
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   354
        getDemoPanel().getActionMap().put("print", new AbstractAction() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   355
            public void actionPerformed(ActionEvent ae) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   356
                printTable();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   357
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   358
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   359
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   360
    } // TableDemo()
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   361
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
     * Sets the Accessibility MEMBER_OF property to denote that
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   364
     * these components work together as a group. Each object
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   365
     * is set to be a MEMBER_OF an array that contains all of
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   366
     * the objects in the group, including itself.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   367
     *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   368
     * @param components The list of objects that are related
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   369
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   370
    void buildAccessibleGroup(Vector components) {
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
        AccessibleContext context = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   373
        int numComponents = components.size();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   374
        Object[] group = components.toArray();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   375
        Object object = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   376
        for (int i = 0; i < numComponents; ++i) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   377
            object = components.elementAt(i);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   378
            if (object instanceof Accessible) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   379
                context = ((Accessible)components.elementAt(i)).
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   380
                                                 getAccessibleContext();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   381
                context.getAccessibleRelationSet().add(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   382
                    new AccessibleRelation(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   383
                        AccessibleRelation.MEMBER_OF, group));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   384
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   385
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   386
    } // buildAccessibleGroup()
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   387
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   388
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   389
     * This sets CONTROLLER_FOR on the controls that manipulate the
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   390
     * table and CONTROLLED_BY relationships on the table to point
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   391
     * back to the controllers.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   392
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   393
    private void setTableControllers() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   394
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   395
        // Set up the relationships to show what controls the table
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   396
        setAccessibleController(isColumnReorderingAllowedCheckBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   397
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   398
        setAccessibleController(showHorizontalLinesCheckBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   399
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   400
        setAccessibleController(showVerticalLinesCheckBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   401
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   402
        setAccessibleController(isColumnSelectionAllowedCheckBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   403
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   404
        setAccessibleController(isRowSelectionAllowedCheckBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   405
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   406
        setAccessibleController(interCellSpacingSlider,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   407
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   408
        setAccessibleController(rowHeightSlider,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   409
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   410
        setAccessibleController(selectionModeComboBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   411
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   412
        setAccessibleController(resizeModeComboBox,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   413
                                tableAggregate);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   414
    } // setTableControllers()
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   415
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   416
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   417
     * Sets up accessibility relationships to denote that one
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   418
     * object controls another. The CONTROLLER_FOR property is
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   419
     * set on the controller object, and the CONTROLLED_BY
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   420
     * property is set on the target object.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   421
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   422
    private void setAccessibleController(JComponent controller,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   423
                                        JComponent target) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   424
        AccessibleRelationSet controllerRelations =
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   425
            controller.getAccessibleContext().getAccessibleRelationSet();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   426
        AccessibleRelationSet targetRelations =
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   427
            target.getAccessibleContext().getAccessibleRelationSet();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   428
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   429
        controllerRelations.add(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   430
            new AccessibleRelation(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   431
                AccessibleRelation.CONTROLLER_FOR, target));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   432
        targetRelations.add(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   433
            new AccessibleRelation(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   434
                AccessibleRelation.CONTROLLED_BY, controller));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   435
    } // setAccessibleController()
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   436
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   437
    public JScrollPane createTable() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   438
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   439
        // final
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   440
        final String[] names = {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   441
          getString("TableDemo.first_name"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   442
          getString("TableDemo.last_name"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   443
          getString("TableDemo.favorite_color"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   444
          getString("TableDemo.favorite_movie"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   445
          getString("TableDemo.favorite_number"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   446
          getString("TableDemo.favorite_food")
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   447
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   448
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   449
        ImageIcon apple        = createImageIcon("food/apple.jpg",      getString("TableDemo.apple"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   450
        ImageIcon asparagus    = createImageIcon("food/asparagus.gif",  getString("TableDemo.asparagus"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   451
        ImageIcon banana       = createImageIcon("food/banana.gif",     getString("TableDemo.banana"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   452
        ImageIcon broccoli     = createImageIcon("food/broccoli.gif",   getString("TableDemo.broccoli"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   453
        ImageIcon cantaloupe   = createImageIcon("food/cantaloupe.gif", getString("TableDemo.cantaloupe"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   454
        ImageIcon carrot       = createImageIcon("food/carrot.gif",     getString("TableDemo.carrot"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   455
        ImageIcon corn         = createImageIcon("food/corn.gif",       getString("TableDemo.corn"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   456
        ImageIcon grapes       = createImageIcon("food/grapes.gif",     getString("TableDemo.grapes"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   457
        ImageIcon grapefruit   = createImageIcon("food/grapefruit.gif", getString("TableDemo.grapefruit"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   458
        ImageIcon kiwi         = createImageIcon("food/kiwi.gif",       getString("TableDemo.kiwi"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   459
        ImageIcon onion        = createImageIcon("food/onion.gif",      getString("TableDemo.onion"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   460
        ImageIcon pear         = createImageIcon("food/pear.gif",       getString("TableDemo.pear"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   461
        ImageIcon peach        = createImageIcon("food/peach.gif",      getString("TableDemo.peach"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   462
        ImageIcon pepper       = createImageIcon("food/pepper.gif",     getString("TableDemo.pepper"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   463
        ImageIcon pickle       = createImageIcon("food/pickle.gif",     getString("TableDemo.pickle"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   464
        ImageIcon pineapple    = createImageIcon("food/pineapple.gif",  getString("TableDemo.pineapple"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   465
        ImageIcon raspberry    = createImageIcon("food/raspberry.gif",  getString("TableDemo.raspberry"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   466
        ImageIcon sparegrass   = createImageIcon("food/asparagus.gif",  getString("TableDemo.sparegrass"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   467
        ImageIcon strawberry   = createImageIcon("food/strawberry.gif", getString("TableDemo.strawberry"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   468
        ImageIcon tomato       = createImageIcon("food/tomato.gif",     getString("TableDemo.tomato"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   469
        ImageIcon watermelon   = createImageIcon("food/watermelon.gif", getString("TableDemo.watermelon"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   470
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   471
        NamedColor aqua        = new NamedColor(new Color(127, 255, 212), getString("TableDemo.aqua"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   472
        NamedColor beige       = new NamedColor(new Color(245, 245, 220), getString("TableDemo.beige"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   473
        NamedColor black       = new NamedColor(Color.black, getString("TableDemo.black"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   474
        NamedColor blue        = new NamedColor(new Color(0, 0, 222), getString("TableDemo.blue"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   475
        NamedColor eblue       = new NamedColor(Color.blue, getString("TableDemo.eblue"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   476
        NamedColor jfcblue     = new NamedColor(new Color(204, 204, 255), getString("TableDemo.jfcblue"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   477
        NamedColor jfcblue2    = new NamedColor(new Color(153, 153, 204), getString("TableDemo.jfcblue2"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   478
        NamedColor cybergreen  = new NamedColor(Color.green.darker().brighter(), getString("TableDemo.cybergreen"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   479
        NamedColor darkgreen   = new NamedColor(new Color(0, 100, 75), getString("TableDemo.darkgreen"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   480
        NamedColor forestgreen = new NamedColor(Color.green.darker(), getString("TableDemo.forestgreen"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   481
        NamedColor gray        = new NamedColor(Color.gray, getString("TableDemo.gray"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   482
        NamedColor green       = new NamedColor(Color.green, getString("TableDemo.green"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   483
        NamedColor orange      = new NamedColor(new Color(255, 165, 0), getString("TableDemo.orange"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   484
        NamedColor purple      = new NamedColor(new Color(160, 32, 240),  getString("TableDemo.purple"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   485
        NamedColor red         = new NamedColor(Color.red, getString("TableDemo.red"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   486
        NamedColor rustred     = new NamedColor(Color.red.darker(), getString("TableDemo.rustred"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   487
        NamedColor sunpurple   = new NamedColor(new Color(100, 100, 255), getString("TableDemo.sunpurple"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   488
        NamedColor suspectpink = new NamedColor(new Color(255, 105, 180), getString("TableDemo.suspectpink"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   489
        NamedColor turquoise   = new NamedColor(new Color(0, 255, 255), getString("TableDemo.turquoise"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   490
        NamedColor violet      = new NamedColor(new Color(238, 130, 238), getString("TableDemo.violet"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   491
        NamedColor yellow      = new NamedColor(Color.yellow, getString("TableDemo.yellow"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   492
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   493
        // Create the dummy data (a few rows of names)
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   494
        final Object[][] data = {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   495
          {"Mike", "Albers",      green,       getString("TableDemo.brazil"), new Double(44.0), strawberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   496
          {"Mark", "Andrews",     blue,        getString("TableDemo.curse"), new Double(3), grapes},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   497
          {"Brian", "Beck",       black,       getString("TableDemo.bluesbros"), new Double(2.7182818285), raspberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   498
          {"Lara", "Bunni",       red,         getString("TableDemo.airplane"), new Double(15), strawberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   499
          {"Roger", "Brinkley",   blue,        getString("TableDemo.man"), new Double(13), peach},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   500
          {"Brent", "Christian",  black,       getString("TableDemo.bladerunner"), new Double(23), broccoli},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   501
          {"Mark", "Davidson",    darkgreen,   getString("TableDemo.brazil"), new Double(27), asparagus},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   502
          {"Jeff", "Dinkins",     blue,        getString("TableDemo.ladyvanishes"), new Double(8), kiwi},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   503
          {"Ewan", "Dinkins",     yellow,      getString("TableDemo.bugs"), new Double(2), strawberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   504
          {"Amy", "Fowler",       violet,      getString("TableDemo.reservoir"), new Double(3), raspberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   505
          {"Hania", "Gajewska",   purple,      getString("TableDemo.jules"), new Double(5), raspberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   506
          {"David", "Geary",      blue,        getString("TableDemo.pulpfiction"), new Double(3), watermelon},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   507
//        {"James", "Gosling",    pink,        getString("TableDemo.tennis"), new Double(21), donut},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   508
          {"Eric", "Hawkes",      blue,        getString("TableDemo.bladerunner"), new Double(.693), pickle},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   509
          {"Shannon", "Hickey",   green,       getString("TableDemo.shawshank"), new Double(2), grapes},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   510
          {"Earl", "Johnson",     green,       getString("TableDemo.pulpfiction"), new Double(8), carrot},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   511
          {"Robi", "Khan",        green,       getString("TableDemo.goodfellas"), new Double(89), apple},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   512
          {"Robert", "Kim",       blue,        getString("TableDemo.mohicans"), new Double(655321), strawberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   513
          {"Janet", "Koenig",     turquoise,   getString("TableDemo.lonestar"), new Double(7), peach},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   514
          {"Jeff", "Kesselman",   blue,        getString("TableDemo.stuntman"), new Double(17), pineapple},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   515
          {"Onno", "Kluyt",       orange,      getString("TableDemo.oncewest"), new Double(8), broccoli},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   516
          {"Peter", "Korn",       sunpurple,   getString("TableDemo.musicman"), new Double(12), sparegrass},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   517
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   518
          {"Rick", "Levenson",    black,       getString("TableDemo.harold"), new Double(1327), raspberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   519
          {"Brian", "Lichtenwalter", jfcblue,  getString("TableDemo.fifthelement"), new Double(22), pear},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   520
          {"Malini", "Minasandram", beige,     getString("TableDemo.joyluck"), new Double(9), corn},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   521
          {"Michael", "Martak",   green,       getString("TableDemo.city"), new Double(3), strawberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   522
          {"David", "Mendenhall", forestgreen, getString("TableDemo.schindlerslist"), new Double(7), peach},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   523
          {"Phil", "Milne",       suspectpink, getString("TableDemo.withnail"), new Double(3), banana},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   524
          {"Lynn", "Monsanto",    cybergreen,  getString("TableDemo.dasboot"), new Double(52), peach},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   525
          {"Hans", "Muller",      rustred,     getString("TableDemo.eraserhead"), new Double(0), pineapple},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   526
          {"Joshua", "Outwater",  blue,        getString("TableDemo.labyrinth"), new Double(3), pineapple},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   527
          {"Tim", "Prinzing",     blue,        getString("TableDemo.firstsight"), new Double(69), pepper},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   528
          {"Raj", "Premkumar",    jfcblue2,    getString("TableDemo.none"), new Double(7), broccoli},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   529
          {"Howard", "Rosen",     green,       getString("TableDemo.defending"), new Double(7), strawberry},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   530
          {"Ray", "Ryan",         black,       getString("TableDemo.buckaroo"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   531
           new Double(3.141592653589793238462643383279502884197169399375105820974944), banana},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   532
          {"Georges", "Saab",     aqua,        getString("TableDemo.bicycle"), new Double(290), cantaloupe},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   533
          {"Tom", "Santos",       blue,        getString("TableDemo.spinaltap"), new Double(241), pepper},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   534
          {"Rich", "Schiavi",     blue,        getString("TableDemo.repoman"), new Double(0xFF), pepper},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   535
          {"Nancy", "Schorr",     green,       getString("TableDemo.fifthelement"), new Double(47), watermelon},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   536
          {"Keith", "Sprochi",    darkgreen,   getString("TableDemo.2001"), new Double(13), watermelon},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   537
          {"Matt", "Tucker",      eblue,       getString("TableDemo.starwars"), new Double(2), broccoli},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   538
          {"Dmitri", "Trembovetski", red,      getString("TableDemo.aliens"), new Double(222), tomato},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   539
          {"Scott", "Violet",     violet,      getString("TableDemo.raiders"), new Double(-97), banana},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   540
          {"Kathy", "Walrath",    darkgreen,   getString("TableDemo.thinman"), new Double(8), pear},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   541
          {"Nathan", "Walrath",   black,       getString("TableDemo.chusingura"), new Double(3), grapefruit},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   542
          {"Steve", "Wilson",     green,       getString("TableDemo.raiders"), new Double(7), onion},
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   543
          {"Kathleen", "Zelony",  gray,        getString("TableDemo.dog"), new Double(13), grapes}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   544
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   545
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   546
        // Create a model of the data.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   547
        TableModel dataModel = new AbstractTableModel() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   548
            public int getColumnCount() { return names.length; }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   549
            public int getRowCount() { return data.length;}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   550
            public Object getValueAt(int row, int col) {return data[row][col];}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   551
            public String getColumnName(int column) {return names[column];}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   552
            public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   553
            public boolean isCellEditable(int row, int col) {return col != 5;}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   554
            public void setValueAt(Object aValue, int row, int column) { data[row][column] = aValue; }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   555
         };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   556
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   557
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   558
        // Create the table
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   559
        tableView = new JTable(dataModel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   560
        TableRowSorter sorter = new TableRowSorter(dataModel);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   561
        tableView.setRowSorter(sorter);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   562
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   563
        // Show colors by rendering them in their own color.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   564
        DefaultTableCellRenderer colorRenderer = new DefaultTableCellRenderer() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   565
            public void setValue(Object value) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   566
                if (value instanceof NamedColor) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   567
                    NamedColor c = (NamedColor) value;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   568
                    setBackground(c);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   569
                    setForeground(c.getTextColor());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   570
                    setText(c.toString());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   571
                } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   572
                    super.setValue(value);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   573
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   574
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   575
        };
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   576
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   577
        // Create a combo box to show that you can use one in a table.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   578
        JComboBox comboBox = new JComboBox();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   579
        comboBox.addItem(aqua);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   580
        comboBox.addItem(beige);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   581
        comboBox.addItem(black);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   582
        comboBox.addItem(blue);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   583
        comboBox.addItem(eblue);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   584
        comboBox.addItem(jfcblue);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   585
        comboBox.addItem(jfcblue2);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   586
        comboBox.addItem(cybergreen);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   587
        comboBox.addItem(darkgreen);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   588
        comboBox.addItem(forestgreen);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   589
        comboBox.addItem(gray);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   590
        comboBox.addItem(green);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   591
        comboBox.addItem(orange);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   592
        comboBox.addItem(purple);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   593
        comboBox.addItem(red);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   594
        comboBox.addItem(rustred);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   595
        comboBox.addItem(sunpurple);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   596
        comboBox.addItem(suspectpink);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   597
        comboBox.addItem(turquoise);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   598
        comboBox.addItem(violet);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   599
        comboBox.addItem(yellow);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   600
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   601
        TableColumn colorColumn = tableView.getColumn(getString("TableDemo.favorite_color"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   602
        // Use the combo box as the editor in the "Favorite Color" column.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   603
        colorColumn.setCellEditor(new DefaultCellEditor(comboBox));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   604
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   605
        colorRenderer.setHorizontalAlignment(JLabel.CENTER);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   606
        colorColumn.setCellRenderer(colorRenderer);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   607
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   608
        tableView.setRowHeight(INITIAL_ROWHEIGHT);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   609
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   610
        scrollpane = new JScrollPane(tableView);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   611
        return scrollpane;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   612
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   613
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   614
    private void printTable() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   615
        MessageFormat headerFmt;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   616
        MessageFormat footerFmt;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   617
        JTable.PrintMode printMode = fitWidth.isSelected() ?
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   618
                                     JTable.PrintMode.FIT_WIDTH :
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   619
                                     JTable.PrintMode.NORMAL;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   620
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   621
        String text;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   622
        text = headerTextField.getText();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   623
        if (text != null && text.length() > 0) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   624
            headerFmt = new MessageFormat(text);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   625
        } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   626
            headerFmt = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   627
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   628
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   629
        text = footerTextField.getText();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   630
        if (text != null && text.length() > 0) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   631
            footerFmt = new MessageFormat(text);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   632
        } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   633
            footerFmt = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   634
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   635
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   636
        try {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   637
            boolean status = tableView.print(printMode, headerFmt, footerFmt);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   638
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   639
            if (status) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   640
                JOptionPane.showMessageDialog(tableView.getParent(),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   641
                                              getString("TableDemo.printingComplete"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   642
                                              getString("TableDemo.printingResult"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   643
                                              JOptionPane.INFORMATION_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   644
            } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   645
                JOptionPane.showMessageDialog(tableView.getParent(),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   646
                                              getString("TableDemo.printingCancelled"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   647
                                              getString("TableDemo.printingResult"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   648
                                              JOptionPane.INFORMATION_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   649
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   650
        } catch (PrinterException pe) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   651
            String errorMessage = MessageFormat.format(getString("TableDemo.printingFailed"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   652
                                                       new Object[] {pe.getMessage()});
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   653
            JOptionPane.showMessageDialog(tableView.getParent(),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   654
                                          errorMessage,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   655
                                          getString("TableDemo.printingResult"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   656
                                          JOptionPane.ERROR_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   657
        } catch (SecurityException se) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   658
            String errorMessage = MessageFormat.format(getString("TableDemo.printingFailed"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   659
                                                       new Object[] {se.getMessage()});
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   660
            JOptionPane.showMessageDialog(tableView.getParent(),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   661
                                          errorMessage,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   662
                                          getString("TableDemo.printingResult"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   663
                                          JOptionPane.ERROR_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   664
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   665
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   666
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   667
    class NamedColor extends Color {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   668
        String name;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   669
        public NamedColor(Color color, String name) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   670
            super(color.getRGB());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   671
            this.name = name;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   672
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   673
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   674
        public Color getTextColor() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   675
            int r = getRed();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   676
            int g = getGreen();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   677
            int b = getBlue();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   678
            if(r > 240 || g > 240) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   679
                return Color.black;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   680
            } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   681
                return Color.white;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   682
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   683
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   684
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   685
        public String toString() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   686
            return name;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   687
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   688
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   689
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   690
    class ColumnLayout implements LayoutManager {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   691
        int xInset = 5;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   692
        int yInset = 5;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   693
        int yGap = 2;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   694
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   695
        public void addLayoutComponent(String s, Component c) {}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   696
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   697
        public void layoutContainer(Container c) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   698
            Insets insets = c.getInsets();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   699
            int height = yInset + insets.top;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   700
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   701
            Component[] children = c.getComponents();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   702
            Dimension compSize = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   703
            for (int i = 0; i < children.length; i++) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   704
                compSize = children[i].getPreferredSize();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   705
                children[i].setSize(compSize.width, compSize.height);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   706
                children[i].setLocation( xInset + insets.left, height);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   707
                height += compSize.height + yGap;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   708
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   709
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   710
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   711
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   712
        public Dimension minimumLayoutSize(Container c) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   713
            Insets insets = c.getInsets();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   714
            int height = yInset + insets.top;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   715
            int width = 0 + insets.left + insets.right;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   716
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   717
            Component[] children = c.getComponents();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   718
            Dimension compSize = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   719
            for (int i = 0; i < children.length; i++) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   720
                compSize = children[i].getPreferredSize();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   721
                height += compSize.height + yGap;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   722
                width = Math.max(width, compSize.width + insets.left + insets.right + xInset*2);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   723
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   724
            height += insets.bottom;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   725
            return new Dimension( width, height);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   726
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   727
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   728
        public Dimension preferredLayoutSize(Container c) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   729
            return minimumLayoutSize(c);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   730
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   731
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   732
        public void removeLayoutComponent(Component c) {}
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   733
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   734
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   735
    void updateDragEnabled(boolean dragEnabled) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   736
        tableView.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   737
        headerTextField.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   738
        footerTextField.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   739
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   740
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   741
}