Skip to content

Commit fea4233

Browse files
committed
Allowed saving multiple AnglePanels.
1 parent 82266a8 commit fea4233

File tree

1 file changed

+20
-4
lines changed
  • aima-gui/src/main/java/aima/gui/swing/demo/robotics/components

1 file changed

+20
-4
lines changed

aima-gui/src/main/java/aima/gui/swing/demo/robotics/components/AnglePanel.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@
4343
*/
4444
public class AnglePanel extends Settings.SpecialSetting {
4545

46+
/**
47+
* The default key that is used to store the angles in the properties file when using the convenience constructor {@code AnglePanel(String title)}.
48+
*/
49+
public static final String DEFAULT_ANGLES_KEY = "ANGLES";
50+
4651
private static final long serialVersionUID = 1L;
47-
private static final String ANGLES_KEY = "ANGLES";
4852
private static final String JL_ANGLE_TEXT ="Selected Angle:";
4953
private static final String JL_NUMBER_OF_ANGLES_TEXT = "Angle Count: ";
5054
private static final String BTN_ADD_ANGLE_TEXT = "Add Angle";
@@ -53,6 +57,7 @@ public class AnglePanel extends Settings.SpecialSetting {
5357
private static final String ANGLES_COLUMN_NAME = "Angles";
5458
private static final int RADIUS = 75;
5559

60+
private final String anglesKey;
5661
private JLabel jLAngleCount;
5762
private JTextField jTFChangeAngle;
5863
private JButton btnDeleteAngle;
@@ -66,9 +71,20 @@ public class AnglePanel extends Settings.SpecialSetting {
6671
private ChangeListener listener;
6772

6873
/**
69-
* Default constructor with no parameters.
74+
* Convenience constructor using a default key for the properties file.
75+
* @param title the title of the angle panel.
7076
*/
7177
public AnglePanel(String title) {
78+
this(DEFAULT_ANGLES_KEY, title);
79+
}
80+
81+
/**
82+
* Default constructor with no parameters.
83+
* @param key the key identifying the angles in the properties.
84+
* @param title the title of the angle panel.
85+
*/
86+
public AnglePanel(String key, String title) {
87+
anglesKey = key;
7288
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
7389
JLabel jLTitle = new JLabel(title);
7490
jLTitle.setBorder(GuiBase.getClearanceBorder());
@@ -306,7 +322,7 @@ private void updateGui(int angleIndex) {
306322

307323
@Override
308324
public void loadSettings(Properties values) {
309-
String saveString = values.getProperty(ANGLES_KEY);
325+
String saveString = values.getProperty(anglesKey);
310326
if(saveString != null) {
311327
try {
312328
ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(saveString.getBytes()));
@@ -330,7 +346,7 @@ public void saveSettings(Properties values) {
330346
} catch (Exception e) {
331347
e.printStackTrace();
332348
}
333-
if(saveString != null) values.put(ANGLES_KEY, saveString);
349+
if(saveString != null) values.put(anglesKey, saveString);
334350
}
335351

336352
@Override

0 commit comments

Comments
 (0)