Skip to content

Commit d101233

Browse files
author
Luis Gustavo Nardin
committed
Update ScenarioEditor
1 parent fbf23f4 commit d101233

File tree

1 file changed

+32
-54
lines changed

1 file changed

+32
-54
lines changed

modules/gis2/src/gis2/scenario/ScenarioEditor.java

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ public class ScenarioEditor extends JPanel {
7070
private GMLObjectInspector inspector;
7171
private DecoratorOverlay fireOverlay;
7272
private DecoratorOverlay centreOverlay;
73-
private AgentOverlay agentOverlay;
73+
private transient AgentOverlay agentOverlay;
7474
private GisScenario scenario;
7575
private Tool currentTool;
7676
private JLabel statusLabel;
7777

7878
private boolean changed;
7979

8080
private UndoManager undoManager;
81-
private Action undoAction;
82-
private Action redoAction;
81+
private transient Action undoAction;
82+
private transient Action redoAction;
8383

8484
private File baseDir;
8585
private File saveFile;
@@ -99,8 +99,6 @@ public class ScenarioEditor extends JPanel {
9999
private FilledShapeDecorator hydrantDecorator = new FilledShapeDecorator(null,
100100
HYDRANT_COLOUR, null);
101101

102-
private static Config config = new Config();
103-
104102
/**
105103
* Construct a new ScenarioEditor.
106104
*
@@ -295,47 +293,37 @@ public void load(String filename)
295293
/**
296294
* Load a map and scenario from a directory.
297295
*
298-
* @param dir The directory to read.
299-
* @throws CancelledByUserException If the user cancels
300-
* the change due to
301-
* unsaved changes.
302-
* @throws MapException If there is a
303-
* problem reading the
304-
* map.
305-
* @throws ScenarioException If there is a
306-
* problem reading the
307-
* scenario.
296+
* @param dir
297+
* The directory to read.
298+
*
299+
* @throws CancelledByUserException
300+
* If the user cancels
301+
* the change due to
302+
* unsaved changes.
303+
* @throws MapException
304+
* If there is a
305+
* problem reading the
306+
* map.
307+
* @throws ScenarioException
308+
* If there is a
309+
* problem reading the
310+
* scenario.
308311
* @throws rescuecore2.scenario.exceptions.ScenarioException
309312
*/
310-
public void load(File dir) throws CancelledByUserException, MapException, ScenarioException,
311-
rescuecore2.scenario.exceptions.ScenarioException {
312-
FileReader r = null;
313-
try {
313+
public void load(File dir) throws CancelledByUserException, MapException,
314+
ScenarioException, rescuecore2.scenario.exceptions.ScenarioException {
315+
316+
try (FileReader r = new FileReader(new File(dir, "scenario.xml"))) {
314317
GMLMap newMap = (GMLMap) MapReader.readMap(new File(dir, "map.gml"));
315-
File f = new File(dir, "scenario.xml");
318+
316319
SAXReader saxReader = new SAXReader();
317-
r = new FileReader(f);
318320
Document doc = saxReader.read(r);
319-
<<<<<<< HEAD
320321
GisScenario newScenario = new GisScenario(doc, new Config());
321-
=======
322-
GisScenario newScenario = new GisScenario(doc, config);
323-
>>>>>>> protobuf-v6
324322
setScenario(newMap, newScenario);
325323
baseDir = dir;
326-
saveFile = f;
327-
} catch (IOException e) {
328-
throw new ScenarioException(e);
329-
} catch (DocumentException e) {
324+
saveFile = new File(dir, "scenario.xml");
325+
} catch (IOException | DocumentException e) {
330326
throw new ScenarioException(e);
331-
} finally {
332-
if (r != null) {
333-
try {
334-
r.close();
335-
} catch (IOException e) {
336-
throw new ScenarioException(e);
337-
}
338-
}
339327
}
340328
}
341329

@@ -415,11 +403,9 @@ public void save() throws ScenarioException {
415403
try {
416404
if (!saveFile.exists()) {
417405
File parent = saveFile.getParentFile();
418-
if (!parent.exists()) {
419-
if (!saveFile.getParentFile().mkdirs()) {
420-
throw new ScenarioException(
421-
"Couldn't create file " + saveFile.getPath());
422-
}
406+
if ((!parent.exists()) && (!saveFile.getParentFile().mkdirs())) {
407+
throw new ScenarioException(
408+
"Couldn't create file " + saveFile.getPath());
423409
}
424410
if (!saveFile.createNewFile()) {
425411
throw new ScenarioException(
@@ -558,7 +544,6 @@ public void actionPerformed(ActionEvent e) {
558544
checkForChanges();
559545
setScenario(map, new GisScenario());
560546
} catch (CancelledByUserException ex) {
561-
return;
562547
}
563548
}
564549
};
@@ -568,17 +553,12 @@ public void actionPerformed(ActionEvent e) {
568553
public void actionPerformed(ActionEvent e) {
569554
try {
570555
checkForChanges();
571-
try {
572-
load();
573-
} catch (rescuecore2.scenario.exceptions.ScenarioException ex) {
574-
ex.printStackTrace();
575-
}
556+
load();
576557
} catch (CancelledByUserException ex) {
577-
return;
578-
} catch (MapException ex) {
579-
JOptionPane.showMessageDialog(null, ex);
580-
} catch (ScenarioException ex) {
558+
} catch (MapException | ScenarioException ex) {
581559
JOptionPane.showMessageDialog(null, ex);
560+
} catch (rescuecore2.scenario.exceptions.ScenarioException ex) {
561+
ex.printStackTrace();
582562
}
583563
}
584564
};
@@ -654,8 +634,6 @@ public void actionPerformed(ActionEvent e) {
654634
private void createToolActions(JMenu menu, JToolBar toolbar) {
655635
ButtonGroup toolbarGroup = new ButtonGroup();
656636
ButtonGroup menuGroup = new ButtonGroup();
657-
// addTool(new InspectTool(this), menu, toolbar, menuGroup,
658-
// toolbarGroup);
659637
menu.addSeparator();
660638
toolbar.addSeparator();
661639
addTool(new PlaceFireTool(this), menu, toolbar, menuGroup, toolbarGroup);

0 commit comments

Comments
 (0)