summaryrefslogtreecommitdiff
path: root/sources/prefs/editors/VSSimulationEditor.java
blob: b4566efc97806f806ed6a336f873b0ed2b14279d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package prefs.editors;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.*;
import java.util.*;
import java.io.File;

import simulator.*;
import utils.*;
import prefs.*;

public class VSSimulationEditor extends VSBetterEditor {
    private boolean startNewSimulation;
    private VSSimulatorFrame simulatorFrame;

    public VSSimulationEditor(VSPrefs prefs, VSSimulatorFrame simulatorFrame) {
        super(prefs, prefs, prefs.getString("name")
              + " - " + prefs.getString("lang.prefs"));
        this.simulatorFrame = simulatorFrame;

        startNewSimulation = true;
        init();
    }

    public VSSimulationEditor(VSPrefs prefs, int prefsCategory) {
        super(prefs, prefs, prefs.getString("name")
              + " - " + prefs.getString("lang.prefs"
                                        + (prefsCategory == ALL_PREFERENCES ? ".ext" : "")),
              prefsCategory);

        startNewSimulation = false;
        init();
    }

    private void init() {
        infoArea.setText(prefs.getString("lang.prefs.info!"));
    }

    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();

        if (actionCommand.equals(prefs.getString("lang.ok"))) {
            super.actionPerformed(e);
            prefsToEdit.saveFile();

            VSFrame frame = getFrame();
            if (frame != null)
                frame.dispose();

            if (startNewSimulation)
                simulatorFrame.addSimulation(
                    new VSSimulation(prefs, simulatorFrame));

        } else {
            super.actionPerformed(e);
        }
    }

    public void newVSEditorInstance(VSPrefs prefs, VSPrefs prefsToEdit, int prefsCategory) {
        VSPrefs newPrefs = VSDefaultPrefs.init();
        new VSEditorFrame(newPrefs, getFrame(), new VSSimulationEditor(prefs, prefsCategory));
    }
}