2 * Copyright (c) 2002 Erik Rasmussen - All Rights Reserverd
7 import java
.awt
.event
.ActionEvent
;
8 import java
.awt
.event
.ActionListener
;
11 * This class represents an object viewer panel to be used with the appletbots
12 * applet. It becomes active when an object in the world is selected.
14 * @author Erik Rasmussen
16 public class ObjectViewer
extends JPanel
19 * The location and velocity data of the selected object
21 protected WorldObjectData data
;
24 * The "Show Sight" check box
26 protected JCheckBox showSightCheckBox
;
28 * The "Show Velocity" check box
30 protected JCheckBox showVelocityCheckBox
;
32 * The "Show Acceleration" check box
34 protected JCheckBox showAccelerationCheckBox
;
37 * Creates a new object viewer panel
41 showSightCheckBox
= new JCheckBox();
42 showSightCheckBox
.setEnabled(false);
43 showSightCheckBox
.setSelected(false);
45 showVelocityCheckBox
= new JCheckBox();
46 showVelocityCheckBox
.setEnabled(false);
47 showVelocityCheckBox
.setSelected(false);
48 showVelocityCheckBox
.addActionListener(new java
.awt
.event
.ActionListener()
50 public void actionPerformed(final ActionEvent event
)
52 ObjectViewer
.this.showVelocityClicked(event
);
56 showAccelerationCheckBox
= new JCheckBox();
57 showAccelerationCheckBox
.setEnabled(false);
58 showAccelerationCheckBox
.setSelected(false);
59 showAccelerationCheckBox
.addActionListener(new ActionListener()
61 public void actionPerformed(final ActionEvent event
)
63 ObjectViewer
.this.showAccelerationClicked(event
);
67 setLayout(new java
.awt
.GridLayout(3, 2));
68 add(new JLabel("Show Sight"));
69 add(showSightCheckBox
);
70 add(new JLabel("Show Velocity"));
71 add(showVelocityCheckBox
);
72 add(new JLabel("Show Acceleration"));
73 add(showAccelerationCheckBox
);
77 * Sets a new selected object by passing the object's location and
80 * @param data The selected object's location and velocity data
82 public void setData(final WorldObjectData data
)
85 if (data
!= null && data
.getObject() instanceof Agent
)
87 final Agent agent
= (Agent
) data
.getObject();
88 showSightCheckBox
.setEnabled(true);
89 showVelocityCheckBox
.setEnabled(true);
90 showVelocityCheckBox
.setSelected(agent
.getShowVelocity());
91 showAccelerationCheckBox
.setEnabled(true);
92 showAccelerationCheckBox
.setSelected(agent
.getShowAcceleration());
96 showSightCheckBox
.setSelected(false);
97 showSightCheckBox
.setEnabled(false);
98 showVelocityCheckBox
.setSelected(false);
99 showVelocityCheckBox
.setEnabled(false);
100 showAccelerationCheckBox
.setSelected(false);
101 showAccelerationCheckBox
.setEnabled(false);
114 * Returns whether or not the "Show Sight" check box is checked
116 * @return Whether or not the "Show Sight" check box is checked
118 public boolean getShowSight()
120 return showSightCheckBox
.isSelected();
124 * The method invoked when the user selects or deselects the "Show
125 * Velocity" check box
127 * @param event The action event
129 public void showVelocityClicked(final ActionEvent event
)
131 if (data
!= null && data
.getObject() instanceof Agent
)
132 ((Agent
) data
.getObject()).setShowVelocity(showVelocityCheckBox
.isSelected());
136 * The method invoked when the user selects or deselects the "Show
137 * Acceleration" check box
139 * @param event The action event
141 public void showAccelerationClicked(final ActionEvent event
)
143 if (data
!= null && data
.getObject() instanceof Agent
)
144 ((Agent
) data
.getObject()).setShowAcceleration(showAccelerationCheckBox
.isSelected());