summaryrefslogtreecommitdiff
path: root/sources/prefs/editors/VSProcessEditor.java
blob: 1632ff1d59812c4fe035b4dd2a91a6ee42fe5328 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package prefs.editors;

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

import simulator.*;
import utils.*;
import core.*;
import protocols.*;
import events.*;
import prefs.VSPrefs;

public class VSProcessEditor extends VSBetterEditor {
    private VSProcess process;
    private String title;

    public VSProcessEditor(VSPrefs prefs, VSProcess process) {
        super(prefs, process, prefs.getString("name") + " - " + prefs.getString("lang.prefs.process"));;
        this.process = process;
        init();
    }

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

        this.process = process;
        init();
    }

    private void init() {
        infoArea.setText(prefs.getString("lang.prefs.process.info!"));
        VSFrame frame = getFrame();
        if (frame != null)
            frame.disposeWithParent();
        createButtonPanel();
    }

    public String getTitle() {
        return title;
    }

    protected void addToEditPanelFront(JPanel editPanel) {
        super.addToEditPanelFront(editPanel);

        if (prefsCategory != SIMULATION_PREFERENCES)
            return;

    }

    protected void resetEditPanel() {
        super.resetEditPanel();
    }

    protected void savePrefs() {
        super.savePrefs();
    }

    private JPanel createButtonPanel() {
        JPanel buttonPanel = super.buttonPanel;

        JButton cancelButton = new JButton(
            prefs.getString("lang.takeover"));
        cancelButton.setMnemonic(prefs.getInteger("keyevent.takeover"));
        cancelButton.addActionListener(this);
        buttonPanel.add(cancelButton);

        return buttonPanel;
    }

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

        if (actionCommand.equals(prefs.getString("lang.ok"))) {
            savePrefs();
            process.updateFromVSPrefs();
            disposeFrameIfExists();

        } else if (actionCommand.equals(prefs.getString("lang.takeover"))) {
            savePrefs();
            process.updateFromVSPrefs();

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

    public void newVSEditorInstance(VSPrefs prefs, VSPrefs prefsToEdit, int prefsCategory) {
        if (prefsToEdit instanceof VSProcess) {
            VSProcess process = (VSProcess) prefsToEdit;
            new VSEditorFrame(prefs, getFrame(), new VSProcessEditor(prefs, process, prefsCategory));
        }
    }
}