1 | /* |
2 | * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * |
8 | * -Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * |
11 | * -Redistribution in binary form must reproduct the above copyright |
12 | * notice, this list of conditions and the following disclaimer in |
13 | * the documentation and/or other materials provided with the distribution. |
14 | * |
15 | * Neither the name of Sun Microsystems, Inc. or the names of contributors |
16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. |
18 | * |
19 | * This software is provided "AS IS," without a warranty of any kind. ALL |
20 | * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING |
21 | * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
22 | * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT |
23 | * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT |
24 | * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS |
25 | * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST |
26 | * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, |
27 | * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY |
28 | * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN |
29 | * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
30 | * |
31 | * You acknowledge that Software is not designed, licensed or intended for |
32 | * use in the design, construction, operation or maintenance of any nuclear |
33 | * facility. |
34 | */ |
35 | |
36 | /* |
37 | * @(#)DirectionPanel.java 1.5 03/01/23 |
38 | */ |
39 | |
40 | import javax.swing.*; |
41 | import javax.swing.border.*; |
42 | |
43 | import java.awt.*; |
44 | import java.awt.event.*; |
45 | import java.util.*; |
46 | |
47 | |
48 | /** |
49 | * @version 1.5 01/23/03 |
50 | * @author Jeff Dinkins |
51 | * @author Chester Rose |
52 | * @author Brian Beck |
53 | */ |
54 | |
55 | public class DirectionPanel extends JPanel { |
56 | |
57 | private ButtonGroup group; |
58 | |
59 | public DirectionPanel(boolean enable, String selection, ActionListener l) { |
60 | setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
61 | setAlignmentY(TOP_ALIGNMENT); |
62 | setAlignmentX(LEFT_ALIGNMENT); |
63 | |
64 | Box firstThree = Box.createHorizontalBox(); |
65 | Box secondThree = Box.createHorizontalBox(); |
66 | Box thirdThree = Box.createHorizontalBox(); |
67 | |
68 | if(!enable) { |
69 | selection = "None"; |
70 | } |
71 | |
72 | group = new ButtonGroup(); |
73 | DirectionButton b; |
74 | b = (DirectionButton) firstThree.add(new DirectionButton( tl_dot, tldn_dot, "NW", "Sets the orientation to the North-West", l, group, selection.equals("NW"))); |
75 | b.setEnabled(enable); |
76 | b = (DirectionButton) firstThree.add(new DirectionButton( tm_dot, tmdn_dot, "N", "Sets the orientation to the North", l, group, selection.equals("N"))); |
77 | b.setEnabled(enable); |
78 | b = (DirectionButton) firstThree.add(new DirectionButton( tr_dot, trdn_dot, "NE", "Sets the orientation to the North-East", l, group, selection.equals("NE"))); |
79 | b.setEnabled(enable); |
80 | b = (DirectionButton) secondThree.add(new DirectionButton( ml_dot, mldn_dot, "W", "Sets the orientation to the West", l, group, selection.equals("W"))); |
81 | b.setEnabled(enable); |
82 | b = (DirectionButton) secondThree.add(new DirectionButton( c_dot, cdn_dot, "C", "Sets the orientation to the Center", l, group, selection.equals("C"))); |
83 | b.setEnabled(enable); |
84 | b = (DirectionButton) secondThree.add(new DirectionButton( mr_dot, mrdn_dot, "E", "Sets the orientation to the East", l, group, selection.equals("E"))); |
85 | b.setEnabled(enable); |
86 | b = (DirectionButton) thirdThree.add(new DirectionButton( bl_dot, bldn_dot, "SW", "Sets the orientation to the South-West", l, group, selection.equals("SW"))); |
87 | b.setEnabled(enable); |
88 | b = (DirectionButton) thirdThree.add(new DirectionButton( bm_dot, bmdn_dot, "S", "Sets the orientation to the South", l, group, selection.equals("S"))); |
89 | b.setEnabled(enable); |
90 | b = (DirectionButton) thirdThree.add(new DirectionButton( br_dot, brdn_dot, "SE", "Sets the orientation to the South-East", l, group, selection.equals("SE"))); |
91 | b.setEnabled(enable); |
92 | |
93 | add(firstThree); |
94 | add(secondThree); |
95 | add(thirdThree); |
96 | } |
97 | |
98 | public String getSelection() { |
99 | return group.getSelection().getActionCommand(); |
100 | } |
101 | |
102 | public void setSelection( String selection ) { |
103 | Enumeration e = group.getElements(); |
104 | while( e.hasMoreElements() ) { |
105 | JRadioButton b = (JRadioButton)e.nextElement(); |
106 | if( b.getActionCommand().equals(selection) ) { |
107 | b.setSelected(true); |
108 | } |
109 | } |
110 | } |
111 | |
112 | // Chester's way cool layout buttons |
113 | public ImageIcon bl_dot = loadImageIcon("bl.gif","bottom left layout button"); |
114 | public ImageIcon bldn_dot = loadImageIcon("bldn.gif","selected bottom left layout button"); |
115 | public ImageIcon bm_dot = loadImageIcon("bm.gif","bottom middle layout button"); |
116 | public ImageIcon bmdn_dot = loadImageIcon("bmdn.gif","selected bottom middle layout button"); |
117 | public ImageIcon br_dot = loadImageIcon("br.gif","bottom right layout button"); |
118 | public ImageIcon brdn_dot = loadImageIcon("brdn.gif","selected bottom right layout button"); |
119 | public ImageIcon c_dot = loadImageIcon("c.gif","center layout button"); |
120 | public ImageIcon cdn_dot = loadImageIcon("cdn.gif","selected center layout button"); |
121 | public ImageIcon ml_dot = loadImageIcon("ml.gif","middle left layout button"); |
122 | public ImageIcon mldn_dot = loadImageIcon("mldn.gif","selected middle left layout button"); |
123 | public ImageIcon mr_dot = loadImageIcon("mr.gif","middle right layout button"); |
124 | public ImageIcon mrdn_dot = loadImageIcon("mrdn.gif","selected middle right layout button"); |
125 | public ImageIcon tl_dot = loadImageIcon("tl.gif","top left layout button"); |
126 | public ImageIcon tldn_dot = loadImageIcon("tldn.gif","selected top left layout button"); |
127 | public ImageIcon tm_dot = loadImageIcon("tm.gif","top middle layout button"); |
128 | public ImageIcon tmdn_dot = loadImageIcon("tmdn.gif","selected top middle layout button"); |
129 | public ImageIcon tr_dot = loadImageIcon("tr.gif","top right layout button"); |
130 | public ImageIcon trdn_dot = loadImageIcon("trdn.gif","selected top right layout button"); |
131 | |
132 | public ImageIcon loadImageIcon(String filename, String description) { |
133 | String path = "/resources/images/buttons/" + filename; |
134 | return new ImageIcon(getClass().getResource(path), description); |
135 | } |
136 | |
137 | |
138 | public class DirectionButton extends JRadioButton { |
139 | |
140 | /** |
141 | * A layout direction button |
142 | */ |
143 | public DirectionButton(Icon icon, Icon downIcon, String direction, |
144 | String description, ActionListener l, |
145 | ButtonGroup group, boolean selected) |
146 | { |
147 | super(); |
148 | this.addActionListener(l); |
149 | setFocusPainted(false); |
150 | setHorizontalTextPosition(CENTER); |
151 | group.add(this); |
152 | setIcon(icon); |
153 | setSelectedIcon(downIcon); |
154 | setActionCommand(direction); |
155 | getAccessibleContext().setAccessibleName(direction); |
156 | getAccessibleContext().setAccessibleDescription(description); |
157 | setSelected(selected); |
158 | } |
159 | |
160 | public boolean isFocusTraversable() { |
161 | return false; |
162 | } |
163 | |
164 | public void setBorder(Border b) { |
165 | } |
166 | } |
167 | } |