-
Notifications
You must be signed in to change notification settings - Fork 9
/
AttEditDialog.java
309 lines (272 loc) · 9.67 KB
/
AttEditDialog.java
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.Border;
import java.util.EventObject;
import java.util.Vector;
import java.io.*;
/* Package: GUI */
/******************************
* Copyright (c) 2003,2020 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
public class AttEditDialog extends JDialog
{ private JPanel bottom;
private JButton okButton, cancelButton;
private AttDialogPanel dialogPanel;
private String defaultName;
private String defaultType;
private int defaultKind;
private String defaultInit = null;
private boolean defaultUnique = false;
private boolean defaultFrozen = false;
private boolean defaultInstanceScope = true;
private String newName;
private String newType;
private int newKind;
private String newInit = null;
private boolean newUnique = false;
private boolean newFrozen = false;
private boolean newInstanceScope = true;
public AttEditDialog(JFrame owner)
{ super(owner, true);
setTitle("Edit Attribute Properties");
okButton = new JButton("Ok");
cancelButton = new JButton("Cancel");
ButtonHandler bHandler = new ButtonHandler();
okButton.addActionListener(bHandler);
cancelButton.addActionListener(bHandler);
bottom = new JPanel();
bottom.add(okButton);
bottom.add(cancelButton);
bottom.setBorder(BorderFactory.createEtchedBorder());
dialogPanel = new AttDialogPanel();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(bottom, BorderLayout.SOUTH);
getContentPane().add(dialogPanel, BorderLayout.CENTER); }
public void setOldFields(String nme, String typ,
int kind, String ini, boolean uniq,
boolean froz, boolean instS)
{ defaultName = nme;
defaultType = typ;
defaultKind = kind;
defaultInit = ini;
defaultUnique = uniq;
defaultFrozen = froz;
defaultInstanceScope = instS;
dialogPanel.setOldFields(nme,typ,kind,ini,uniq,froz,
instS);
}
public void setFields(String nme, String typ,
int kind, String ini, boolean uniq,
boolean froz, boolean instS)
{ newName = nme;
newType = typ;
newKind = kind;
newInit = ini;
newUnique = uniq;
newFrozen = froz;
newInstanceScope = instS;
}
public String getName() { return newName; }
public String getAttributeType() { return newType; }
public int getKind() { return newKind; }
public String getInit() { return newInit; }
public boolean getUnique() { return newUnique; }
public boolean getFrozen() { return newFrozen; }
public boolean getInstanceScope()
{ return newInstanceScope; }
class AttDialogPanel extends JPanel
{ private JLabel nameLabel;
JTextField nameField; /* name */
private JLabel typeLabel;
// JTextField typeField; /* type */
JComboBox typeCombo;
private JLabel initLabel;
JTextField initField; /* initial value */
JCheckBox senBox, intBox, actBox, derBox, sumBox, passBox;
private JPanel kindPanel;
private ButtonGroup kindGroup; /* kind */
JCheckBox uniqBox, notuniqBox;
private JPanel uniqPanel;
private ButtonGroup uniqGroup; /* unique */
JCheckBox frozBox, notfrozBox;
private JPanel frozenPanel;
private ButtonGroup frozenGroup; /* frozen */
JCheckBox instanceBox, classBox;
private JPanel scopePanel;
private ButtonGroup scopeGroup; /* scope */
public AttDialogPanel()
{ nameLabel = new JLabel("Name:");
nameField = new JTextField();
typeLabel = new JLabel("Type:");
// typeField = new JTextField();
typeCombo = new JComboBox();
typeCombo.addItem("int"); // Integer
typeCombo.addItem("boolean"); // Boolean
typeCombo.addItem("String"); // String
typeCombo.addItem("double"); // Real
typeCombo.addItem("long"); // Integer
typeCombo.setEditable(true);
initLabel = new JLabel("Initial value:");
initField = new JTextField();
kindPanel = new JPanel();
senBox = new JCheckBox("Input");
intBox = new JCheckBox("Internal",true);
actBox = new JCheckBox("Output");
derBox = new JCheckBox("Derived");
sumBox = new JCheckBox("Hidden");
passBox = new JCheckBox("Password");
kindPanel.add(senBox);
kindPanel.add(intBox);
kindPanel.add(actBox);
kindPanel.add(derBox);
kindPanel.add(sumBox);
kindPanel.add(passBox);
kindPanel.setBorder(
BorderFactory.createTitledBorder("Stereotype"));
kindGroup = new ButtonGroup();
kindGroup.add(senBox);
kindGroup.add(intBox);
kindGroup.add(actBox);
kindGroup.add(derBox);
kindGroup.add(sumBox);
kindGroup.add(passBox);
frozenPanel = new JPanel();
frozBox = new JCheckBox("Frozen");
notfrozBox = new JCheckBox("Modifiable",true);
frozenPanel.add(frozBox);
frozenPanel.add(notfrozBox);
frozenPanel.setBorder(
BorderFactory.createTitledBorder("Updateability"));
frozenGroup = new ButtonGroup();
frozenGroup.add(frozBox);
frozenGroup.add(notfrozBox);
scopePanel = new JPanel();
classBox = new JCheckBox("Class");
instanceBox = new JCheckBox("Instance",true);
scopePanel.add(classBox);
scopePanel.add(instanceBox);
scopePanel.setBorder(
BorderFactory.createTitledBorder("Scope"));
scopeGroup = new ButtonGroup();
scopeGroup.add(classBox);
scopeGroup.add(instanceBox);
uniqPanel = new JPanel();
uniqBox = new JCheckBox("Unique");
notuniqBox = new JCheckBox("Not unique",true);
uniqPanel.add(uniqBox);
uniqPanel.add(notuniqBox);
uniqPanel.setBorder(
BorderFactory.createTitledBorder("Uniqueness"));
uniqGroup = new ButtonGroup();
uniqGroup.add(uniqBox);
uniqGroup.add(notuniqBox);
add(nameLabel);
add(nameField);
add(typeLabel);
add(typeCombo);
add(initLabel);
add(initField);
add(kindPanel);
add(frozenPanel);
add(scopePanel);
add(uniqPanel);
}
public void setOldFields(String nme, String typ,
int kind, String init, boolean uniq,
boolean froz, boolean scpe)
{ nameField.setText(nme);
// typeField.setText(typ);
initField.setText(init);
if (froz)
{ frozBox.setSelected(true); }
else
{ notfrozBox.setSelected(true); }
if (scpe)
{ instanceBox.setSelected(true); }
else
{ classBox.setSelected(true); }
if (uniq)
{ uniqBox.setSelected(true); }
else
{ notuniqBox.setSelected(true); }
if (kind == ModelElement.SEN)
{ senBox.setSelected(true); }
else if (kind == ModelElement.INTERNAL)
{ intBox.setSelected(true); }
else if (kind == ModelElement.ACT)
{ actBox.setSelected(true); }
else if (kind == ModelElement.DERIVED)
{ derBox.setSelected(true); }
else if (kind == ModelElement.HIDDEN)
{ sumBox.setSelected(true); }
else if (kind == ModelElement.PASSWORD)
{ passBox.setSelected(true); }
}
public Dimension getPreferredSize()
{ return new Dimension(550,350); }
public Dimension getMinimumSize()
{ return new Dimension(550,650); }
public void doLayout()
{ nameLabel.setBounds(10,10,90,30);
nameField.setBounds(100,15,370,20);
typeLabel.setBounds(10,40,90,30);
typeCombo.setBounds(100,45,370,20);
initLabel.setBounds(10,70,90,30);
initField.setBounds(100,75,370,20);
kindPanel.setBounds(10,100,500,50);
frozenPanel.setBounds(10,160,500,50);
scopePanel.setBounds(10,210,500,50);
uniqPanel.setBounds(10,260,500,50);
}
public void reset()
{ nameField.setText("");
// typeField.setText("");
initField.setText("");
notfrozBox.setSelected(true);
intBox.setSelected(true);
instanceBox.setSelected(true);
notuniqBox.setSelected(true);
}
} /* inner class */
class ButtonHandler implements ActionListener
{ public void actionPerformed(ActionEvent ev)
{ JButton button = (JButton) ev.getSource();
String label = button.getText();
if ("Ok".equals(label))
{ int kind;
if (dialogPanel.senBox.isSelected())
{ kind = ModelElement.SEN; }
else if (dialogPanel.actBox.isSelected())
{ kind = ModelElement.ACT; }
else if (dialogPanel.derBox.isSelected())
{ kind = ModelElement.DERIVED; }
else if (dialogPanel.sumBox.isSelected())
{ kind = ModelElement.HIDDEN; }
else if (dialogPanel.passBox.isSelected())
{ kind = ModelElement.PASSWORD; }
else
{ kind = ModelElement.INTERNAL; }
setFields(dialogPanel.nameField.getText(),
(String) dialogPanel.typeCombo.getSelectedItem(),
kind,
dialogPanel.initField.getText(),
dialogPanel.uniqBox.isSelected(),
dialogPanel.frozBox.isSelected(),
dialogPanel.instanceBox.isSelected());
}
else
{ setFields(null,null,ModelElement.INTERNAL,
null,false,false,true);
}
dialogPanel.reset();
setVisible(false);
}
}
}