jdk/test/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/togglebutton/DirectionPanel.java
author mrkam
Wed, 30 Mar 2016 19:05:58 -0700
changeset 36744 a00905527ec2
permissions -rw-r--r--
8153141: Develop initial set of tests for SwingSet Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36744
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     1
/*
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     2
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     4
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     8
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    13
 * accompanied this code).
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    14
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    18
 *
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    21
 * questions.
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    22
 */
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    23
package com.sun.swingset3.demos.togglebutton;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    24
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    25
import java.awt.event.ActionListener;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    26
import javax.swing.Box;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    27
import javax.swing.BoxLayout;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    28
import javax.swing.ButtonGroup;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    29
import javax.swing.Icon;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    30
import javax.swing.ImageIcon;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    31
import javax.swing.JPanel;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    32
import javax.swing.JRadioButton;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    33
import javax.swing.border.Border;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    34
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    35
/**
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    36
 * @version 1.8 11/17/05
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    37
 * @author Jeff Dinkins
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    38
 * @author Chester Rose
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    39
 * @author Brian Beck
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    40
 */
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    41
public class DirectionPanel extends JPanel {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    42
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    43
    private final ButtonGroup group;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    44
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    45
    public DirectionPanel(boolean enable, String selection, ActionListener l) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    46
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    47
        setAlignmentY(TOP_ALIGNMENT);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    48
        setAlignmentX(LEFT_ALIGNMENT);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    49
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    50
        Box firstThree = Box.createHorizontalBox();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    51
        Box secondThree = Box.createHorizontalBox();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    52
        Box thirdThree = Box.createHorizontalBox();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    53
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    54
        if (!enable) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    55
            selection = "None";
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    56
        }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    57
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    58
        group = new ButtonGroup();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    59
        DirectionButton b;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    60
        b = (DirectionButton) firstThree.add(new DirectionButton(tl_dot, tldn_dot, "NW", "Sets the orientation to the North-West", l, group, selection.equals("NW")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    61
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    62
        b = (DirectionButton) firstThree.add(new DirectionButton(tm_dot, tmdn_dot, "N", "Sets the orientation to the North", l, group, selection.equals("N")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    63
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    64
        b = (DirectionButton) firstThree.add(new DirectionButton(tr_dot, trdn_dot, "NE", "Sets the orientation to the North-East", l, group, selection.equals("NE")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    65
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    66
        b = (DirectionButton) secondThree.add(new DirectionButton(ml_dot, mldn_dot, "W", "Sets the orientation to the West", l, group, selection.equals("W")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    67
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    68
        b = (DirectionButton) secondThree.add(new DirectionButton(c_dot, cdn_dot, "C", "Sets the orientation to the Center", l, group, selection.equals("C")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    69
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    70
        b = (DirectionButton) secondThree.add(new DirectionButton(mr_dot, mrdn_dot, "E", "Sets the orientation to the East", l, group, selection.equals("E")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    71
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    72
        b = (DirectionButton) thirdThree.add(new DirectionButton(bl_dot, bldn_dot, "SW", "Sets the orientation to the South-West", l, group, selection.equals("SW")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    73
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    74
        b = (DirectionButton) thirdThree.add(new DirectionButton(bm_dot, bmdn_dot, "S", "Sets the orientation to the South", l, group, selection.equals("S")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    75
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    76
        b = (DirectionButton) thirdThree.add(new DirectionButton(br_dot, brdn_dot, "SE", "Sets the orientation to the South-East", l, group, selection.equals("SE")));
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    77
        b.setEnabled(enable);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    78
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    79
        add(firstThree);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    80
        add(secondThree);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    81
        add(thirdThree);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    82
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    83
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    84
    // Chester's way cool layout buttons
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    85
    private final ImageIcon bl_dot = loadImageIcon("bl.gif", "bottom left layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    86
    private final ImageIcon bldn_dot = loadImageIcon("bldn.gif", "selected bottom left layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    87
    private final ImageIcon bm_dot = loadImageIcon("bm.gif", "bottom middle layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    88
    private final ImageIcon bmdn_dot = loadImageIcon("bmdn.gif", "selected bottom middle layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    89
    private final ImageIcon br_dot = loadImageIcon("br.gif", "bottom right layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    90
    private final ImageIcon brdn_dot = loadImageIcon("brdn.gif", "selected bottom right layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    91
    private final ImageIcon c_dot = loadImageIcon("c.gif", "center layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    92
    private final ImageIcon cdn_dot = loadImageIcon("cdn.gif", "selected center layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    93
    private final ImageIcon ml_dot = loadImageIcon("ml.gif", "middle left layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    94
    private final ImageIcon mldn_dot = loadImageIcon("mldn.gif", "selected middle left layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    95
    private final ImageIcon mr_dot = loadImageIcon("mr.gif", "middle right layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    96
    private final ImageIcon mrdn_dot = loadImageIcon("mrdn.gif", "selected middle right layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    97
    private final ImageIcon tl_dot = loadImageIcon("tl.gif", "top left layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    98
    private final ImageIcon tldn_dot = loadImageIcon("tldn.gif", "selected top left layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
    99
    private final ImageIcon tm_dot = loadImageIcon("tm.gif", "top middle layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   100
    private final ImageIcon tmdn_dot = loadImageIcon("tmdn.gif", "selected top middle layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   101
    private final ImageIcon tr_dot = loadImageIcon("tr.gif", "top right layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   102
    private final ImageIcon trdn_dot = loadImageIcon("trdn.gif", "selected top right layout button");
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   103
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   104
    private ImageIcon loadImageIcon(String filename, String description) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   105
        String path = "resources/images/" + filename;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   106
        return new ImageIcon(getClass().getResource(path), description);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   107
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   108
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   109
    private static class DirectionButton extends JRadioButton {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   110
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   111
        /**
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   112
         * A layout direction button
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   113
         */
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   114
        public DirectionButton(Icon icon, Icon downIcon, String direction,
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   115
                String description, ActionListener l,
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   116
                ButtonGroup group, boolean selected) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   117
            super();
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   118
            this.addActionListener(l);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   119
            setFocusPainted(false);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   120
            setHorizontalTextPosition(CENTER);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   121
            group.add(this);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   122
            setIcon(icon);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   123
            setSelectedIcon(downIcon);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   124
            setActionCommand(direction);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   125
            getAccessibleContext().setAccessibleName(direction);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   126
            getAccessibleContext().setAccessibleDescription(description);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   127
            setSelected(selected);
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   128
        }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   129
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   130
        @Override
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   131
        @Deprecated
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   132
        public boolean isFocusTraversable() {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   133
            return false;
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   134
        }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   135
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   136
        @Override
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   137
        public void setBorder(Border b) {
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   138
        }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   139
    }
a00905527ec2 8153141: Develop initial set of tests for SwingSet
mrkam
parents:
diff changeset
   140
}