src/demo/share/jfc/SwingSet2/TabbedPaneDemo.java
author weijun
Tue, 29 Oct 2019 09:34:21 +0800
changeset 58830 fa0b9f9c597a
parent 52252 de9486d74a74
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
 *
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
     3
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     4
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     7
 * are met:
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     8
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     9
 *   - Redistributions of source code must retain the above copyright
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    10
 *     notice, this list of conditions and the following disclaimer.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    11
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    12
 *   - Redistributions in binary form must reproduce the above copyright
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    13
 *     notice, this list of conditions and the following disclaimer in the
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    14
 *     documentation and/or other materials provided with the distribution.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    15
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    16
 *   - Neither the name of Oracle nor the names of its
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    17
 *     contributors may be used to endorse or promote products derived
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    18
 *     from this software without specific prior written permission.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    19
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    21
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    22
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    23
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    31
 */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    32
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    33
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    34
import javax.swing.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    35
import javax.swing.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    36
import javax.swing.text.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    37
import javax.swing.border.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    38
import javax.swing.colorchooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    39
import javax.swing.filechooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    40
import javax.accessibility.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    41
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    42
import java.awt.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    43
import java.awt.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    44
import java.beans.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    45
import java.util.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    46
import java.io.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    47
import java.applet.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    48
import java.net.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    49
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    50
/**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    51
 * JTabbedPane Demo
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    52
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    53
 * @author Jeff Dinkins
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
public class TabbedPaneDemo extends DemoModule implements ActionListener {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    56
    HeadSpin spin;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    57
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    58
    JTabbedPane tabbedpane;
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
    ButtonGroup group;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    61
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    62
    JRadioButton top;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    63
    JRadioButton bottom;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    64
    JRadioButton left;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    65
    JRadioButton right;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    66
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    67
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    68
     * main method allows us to run as a standalone demo.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    69
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    70
    public static void main(String[] args) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    71
        TabbedPaneDemo demo = new TabbedPaneDemo(null);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    72
        demo.mainImpl();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    73
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    74
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    75
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    76
     * TabbedPaneDemo Constructor
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
    public TabbedPaneDemo(SwingSet2 swingset) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    79
        // Set the title for this demo, and an icon used to represent this
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    80
        // demo inside the SwingSet2 app.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    81
        super(swingset, "TabbedPaneDemo", "toolbar/JTabbedPane.gif");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    82
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    83
        // create tab position controls
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    84
        JPanel tabControls = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    85
        tabControls.add(new JLabel(getString("TabbedPaneDemo.label")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    86
        top    = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.top")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    87
        left   = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.left")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    88
        bottom = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.bottom")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    89
        right  = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.right")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    90
        getDemoPanel().add(tabControls, BorderLayout.NORTH);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    91
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    92
        group = new ButtonGroup();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    93
        group.add(top);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    94
        group.add(bottom);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    95
        group.add(left);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    96
        group.add(right);
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
        top.setSelected(true);
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
        top.addActionListener(this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   101
        bottom.addActionListener(this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   102
        left.addActionListener(this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   103
        right.addActionListener(this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   104
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   105
        // create tab
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   106
        tabbedpane = new JTabbedPane();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   107
        getDemoPanel().add(tabbedpane, BorderLayout.CENTER);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   108
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   109
        String name = getString("TabbedPaneDemo.laine");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   110
        JLabel pix = new JLabel(createImageIcon("tabbedpane/laine.jpg", name));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   111
        tabbedpane.add(name, pix);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   112
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   113
        name = getString("TabbedPaneDemo.ewan");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   114
        pix = new JLabel(createImageIcon("tabbedpane/ewan.jpg", name));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   115
        tabbedpane.add(name, pix);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   116
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   117
        name = getString("TabbedPaneDemo.hania");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   118
        pix = new JLabel(createImageIcon("tabbedpane/hania.jpg", name));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   119
        tabbedpane.add(name, pix);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   120
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   121
        name = getString("TabbedPaneDemo.bounce");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   122
        spin = new HeadSpin();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   123
        tabbedpane.add(name, spin);
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
        tabbedpane.getModel().addChangeListener(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   126
           new ChangeListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   127
              public void stateChanged(ChangeEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   128
                  SingleSelectionModel model = (SingleSelectionModel) e.getSource();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   129
                  if(model.getSelectedIndex() == tabbedpane.getTabCount()-1) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   130
                      spin.go();
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
              }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   133
           }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   134
        );
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   135
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   136
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   137
    public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   138
        if(e.getSource() == top) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   139
            tabbedpane.setTabPlacement(JTabbedPane.TOP);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   140
        } else if(e.getSource() == left) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   141
            tabbedpane.setTabPlacement(JTabbedPane.LEFT);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   142
        } else if(e.getSource() == bottom) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   143
            tabbedpane.setTabPlacement(JTabbedPane.BOTTOM);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   144
        } else if(e.getSource() == right) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   145
            tabbedpane.setTabPlacement(JTabbedPane.RIGHT);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   146
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   147
    }
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
    class HeadSpin extends JComponent implements ActionListener {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   150
        javax.swing.Timer animator;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   151
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   152
        ImageIcon[] icon = new ImageIcon[6];
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   153
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   154
        int tmpScale;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   155
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   156
        static final int numImages = 6;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   157
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   158
        double[] x = new double[numImages];
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   159
        double[] y = new double[numImages];
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   160
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   161
        int[] xh = new int[numImages];
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   162
        int[] yh = new int[numImages];
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   163
52252
de9486d74a74 8211693: Convert C-style array declarations in client demos and jdk.accessibility
tvaleev
parents: 49495
diff changeset
   164
        double[] scale = new double[numImages];
49495
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
        public HeadSpin() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   167
            setBackground(Color.black);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   168
            icon[0] = createImageIcon("tabbedpane/ewan.gif", getString("TabbedPaneDemo.ewan"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   169
            icon[1] = createImageIcon("tabbedpane/stephen.gif", getString("TabbedPaneDemo.stephen"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   170
            icon[2] = createImageIcon("tabbedpane/david.gif", getString("TabbedPaneDemo.david"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   171
            icon[3] = createImageIcon("tabbedpane/matthew.gif", getString("TabbedPaneDemo.matthew"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   172
            icon[4] = createImageIcon("tabbedpane/blake.gif", getString("TabbedPaneDemo.blake"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   173
            icon[5] = createImageIcon("tabbedpane/brooke.gif", getString("TabbedPaneDemo.brooke"));
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
            /*
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   176
            for(int i = 0; i < 6; i++) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   177
                x[i] = (double) rand.nextInt(500);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   178
                y[i] = (double) rand.nextInt(500);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   179
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   180
            */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   181
        }
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
        public void go() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   184
            animator = new javax.swing.Timer(22 + 22 + 22, this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   185
            animator.start();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   186
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   187
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   188
        public void paint(Graphics g) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   189
            g.setColor(getBackground());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   190
            g.fillRect(0, 0, getWidth(), getHeight());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   191
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   192
            for(int i = 0; i < numImages; i++) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   193
                if(x[i] > 3*i) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   194
                    nudge(i);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   195
                    squish(g, icon[i], xh[i], yh[i], scale[i]);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   196
                } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   197
                    x[i] += .05;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   198
                    y[i] += .05;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   199
                }
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
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   202
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   203
        Random rand = new Random();
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
        public void nudge(int i) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   206
            x[i] += (double) rand.nextInt(1000) / 8756;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   207
            y[i] += (double) rand.nextInt(1000) / 5432;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   208
            int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   209
            scale[i] = (double) tmpScale / 10;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   210
            int nudgeX = (int) (((double) getWidth()/2) * .8);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   211
            int nudgeY = (int) (((double) getHeight()/2) * .60);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   212
            xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   213
            yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   214
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   215
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   216
        public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   217
            if(isVisible()) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   218
                g.drawImage(icon.getImage(), x, y,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   219
                            (int) (icon.getIconWidth()*scale),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   220
                            (int) (icon.getIconHeight()*scale),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   221
                            this);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   222
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   223
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   224
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   225
        public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   226
            if(isVisible()) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   227
                repaint();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   228
            } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   229
                animator.stop();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   230
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   231
        }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   232
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   233
}