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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
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 VSEditorFrame {
private VSProcess process;
public VSProcessEditor(VSPrefs prefs, Component relativeTo, VSProcess process) {
super(prefs, relativeTo, process, prefs.getString("name") + " - "
+ prefs.getString("lang.prefs.process"));
this.process = process;
init();
}
public VSProcessEditor(VSPrefs prefs, Component relativeTo, VSProcess process, int prefsCategory) {
super(prefs, relativeTo, process, prefs.getString("name") + " - "
+ prefs.getString("lang.prefs.process"
+ (prefsCategory == ALL_PREFERENCES ? ".ext" : "")),
prefsCategory);
this.process = process;
init();
}
private void init() {
super.infoArea.setText(prefs.getString("lang.prefs.process.info!"));
getFrame().disposeWithParent();
createButtonPanel();
}
protected void addToEditPanelFront(JPanel editPanel) {
super.addToEditPanelFront(editPanel);
if (prefsCategory != SIMULATION_PREFERENCES)
return;
editPanelConstraints.gridy = editPanelRow++;
editPanel.add(new JLabel(prefs.getString("lang.protocol.editor")), editPanelConstraints);
editPanelConstraints.insets = insets;
editPanelConstraints.gridy = editPanelRow++;
JPanel protocolSelectorPanel = createProtocolSelector();
editPanel.add(protocolSelectorPanel, editPanelConstraints);
editPanelConstraints.insets = insetsTopSpaceing;
editPanelConstraints.gridy = editPanelRow++;
}
private JPanel createProtocolSelector() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createLineBorder(Color.black));
Vector<String> registeredProtocols = VSRegisteredEvents.getProtocolNames();
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(5, 0, 5, 0);
constraints.ipadx = 10;
constraints.ipady = 10;
final JComboBox comboBox = new JComboBox(registeredProtocols);
comboBox.setBackground(Color.WHITE);
panel.add(comboBox, constraints);
constraints.gridy = 1;
JButton button = new JButton(prefs.getString("lang.edit"));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals(prefs.getString("lang.edit"))) {
String eventName = (String) comboBox.getSelectedItem();
String eventClassname = VSRegisteredEvents.getClassname(eventName);
VSProtocol protocol = null;
if (process.objectExists(eventClassname)) {
Object object = process.getObject(eventClassname);
if (object instanceof VSProtocol)
protocol = (VSProtocol) process.getObject(eventClassname);
else
return;
} else {
protocol = (VSProtocol) VSRegisteredEvents.createEventInstanceByName(eventName, process);
process.setObject(eventClassname, protocol);
}
new VSProtocolEditor(prefs, frame, protocol);
}
}
});
panel.add(button, constraints);
return panel;
}
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();
frame.dispose();
} 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 VSProcessEditor(prefs, frame, process, prefsCategory);
} else {
new VSProcessEditor(prefs, frame, process, prefsCategory);
}
}
}
|