|
@@ -0,0 +1,417 @@
|
|
1
|
+import java.awt.*;
|
|
2
|
+import java.awt.event.*;
|
|
3
|
+import javax.swing.*;
|
|
4
|
+
|
|
5
|
+/**
|
|
6
|
+ *
|
|
7
|
+ * Beschreibung
|
|
8
|
+ *
|
|
9
|
+ * @version 1.0 vom 14.11.2011
|
|
10
|
+ * @author
|
|
11
|
+ */
|
|
12
|
+
|
|
13
|
+public class frame extends JFrame {
|
|
14
|
+ // Anfang Variablen
|
|
15
|
+ private Canvas cubeCanvas = new Canvas();
|
|
16
|
+ private JButton editA = new JButton();
|
|
17
|
+ private JButton editB = new JButton();
|
|
18
|
+ private JButton editC = new JButton();
|
|
19
|
+ private JButton editD = new JButton();
|
|
20
|
+ private JButton editE = new JButton();
|
|
21
|
+ private JButton editF = new JButton();
|
|
22
|
+ private JButton editG = new JButton();
|
|
23
|
+ private JButton editH = new JButton();
|
|
24
|
+ private DefaultListModel frameListModel = new DefaultListModel();
|
|
25
|
+ private JList frameList = new JList(frameListModel);
|
|
26
|
+ private JButton frameUp = new JButton();
|
|
27
|
+ private JButton frameDown = new JButton();
|
|
28
|
+ private JButton frameAdd = new JButton();
|
|
29
|
+ private JButton frameRemove = new JButton();
|
|
30
|
+ private DefaultListModel animationListModel = new DefaultListModel();
|
|
31
|
+ private JList jList2 = new JList(animationListModel);
|
|
32
|
+ private JButton animUp = new JButton();
|
|
33
|
+ private JButton animDown = new JButton();
|
|
34
|
+ private JButton animAdd = new JButton();
|
|
35
|
+ private JButton animRemove = new JButton();
|
|
36
|
+ private JTextField animPath = new JTextField();
|
|
37
|
+ private JButton load = new JButton();
|
|
38
|
+ private JButton save = new JButton();
|
|
39
|
+ private String[] jComboBox1Daten = {"Select serial port..."};
|
|
40
|
+ private JComboBox jComboBox1 = new JComboBox(jComboBox1Daten);
|
|
41
|
+ private JButton upload = new JButton();
|
|
42
|
+ private JButton download = new JButton();
|
|
43
|
+ private JLabel jLabel4 = new JLabel();
|
|
44
|
+ private JTextField frameRemaining = new JTextField();
|
|
45
|
+
|
|
46
|
+ private cubeWorker worker = new cubeWorker();
|
|
47
|
+ // Ende Variablen
|
|
48
|
+
|
|
49
|
+ private int saveExitDialog() {
|
|
50
|
+ String[] Optionen = {"Yes", "No"};
|
|
51
|
+ int Auswahl = JOptionPane.showOptionDialog(this, "Save?", "Yes/No", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
|
|
52
|
+ if (Auswahl == JOptionPane.YES_OPTION) {
|
|
53
|
+ worker.saveState(animPath.getText());
|
|
54
|
+ return 1;
|
|
55
|
+ } else {
|
|
56
|
+ return 0;
|
|
57
|
+ }
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ public frame(String title) {
|
|
61
|
+ // Frame-Initialisierung
|
|
62
|
+ super(title);
|
|
63
|
+
|
|
64
|
+ frameListModel.add(0, "Frame 1");
|
|
65
|
+ frameListModel.add(1, "Frame 2");
|
|
66
|
+ frameListModel.add(2, "Frame 3");
|
|
67
|
+ animationListModel.add(0, "Animation 1");
|
|
68
|
+ animationListModel.add(1, "Animation 2");
|
|
69
|
+ animationListModel.add(2, "Animation 3");
|
|
70
|
+
|
|
71
|
+ addWindowListener(new WindowAdapter() {
|
|
72
|
+ public void windowClosing(WindowEvent evt) {
|
|
73
|
+ if (worker.changedStateSinceSave()) {
|
|
74
|
+ saveExitDialog();
|
|
75
|
+ }
|
|
76
|
+ System.exit(0);
|
|
77
|
+ }
|
|
78
|
+ });
|
|
79
|
+ int frameWidth = 662;
|
|
80
|
+ int frameHeight = 416;
|
|
81
|
+ setSize(frameWidth, frameHeight);
|
|
82
|
+ Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
|
83
|
+ int x = (d.width - getSize().width) / 2;
|
|
84
|
+ int y = (d.height - getSize().height) / 2 ;
|
|
85
|
+ setLocation(x, y);
|
|
86
|
+ Container cp = getContentPane();
|
|
87
|
+ cp.setLayout(null);
|
|
88
|
+ // Anfang Komponenten
|
|
89
|
+
|
|
90
|
+ cubeCanvas.setBounds(8, 8, 250, 250);
|
|
91
|
+ cubeCanvas.setBackground(Color.GRAY);
|
|
92
|
+ cp.add(cubeCanvas);
|
|
93
|
+ editA.setBounds(264, 8, 107, 25);
|
|
94
|
+ editA.setText("Layer A");
|
|
95
|
+ cp.add(editA);
|
|
96
|
+ editA.addActionListener(new ActionListener() {
|
|
97
|
+ public void actionPerformed(ActionEvent evt) {
|
|
98
|
+ editAActionPerformed(evt);
|
|
99
|
+ }
|
|
100
|
+ });
|
|
101
|
+
|
|
102
|
+ editB.setBounds(264, 40, 107, 25);
|
|
103
|
+ editB.setText("Layer B");
|
|
104
|
+ cp.add(editB);
|
|
105
|
+ editB.addActionListener(new ActionListener() {
|
|
106
|
+ public void actionPerformed(ActionEvent evt) {
|
|
107
|
+ editBActionPerformed(evt);
|
|
108
|
+ }
|
|
109
|
+ });
|
|
110
|
+
|
|
111
|
+ editC.setBounds(264, 72, 107, 25);
|
|
112
|
+ editC.setText("Layer C");
|
|
113
|
+ cp.add(editC);
|
|
114
|
+ editC.addActionListener(new ActionListener() {
|
|
115
|
+ public void actionPerformed(ActionEvent evt) {
|
|
116
|
+ editCActionPerformed(evt);
|
|
117
|
+ }
|
|
118
|
+ });
|
|
119
|
+
|
|
120
|
+ editD.setBounds(264, 104, 107, 25);
|
|
121
|
+ editD.setText("Layer D");
|
|
122
|
+ cp.add(editD);
|
|
123
|
+ editD.addActionListener(new ActionListener() {
|
|
124
|
+ public void actionPerformed(ActionEvent evt) {
|
|
125
|
+ editDActionPerformed(evt);
|
|
126
|
+ }
|
|
127
|
+ });
|
|
128
|
+
|
|
129
|
+ editE.setBounds(264, 136, 107, 25);
|
|
130
|
+ editE.setText("Layer E");
|
|
131
|
+ cp.add(editE);
|
|
132
|
+ editE.addActionListener(new ActionListener() {
|
|
133
|
+ public void actionPerformed(ActionEvent evt) {
|
|
134
|
+ editEActionPerformed(evt);
|
|
135
|
+ }
|
|
136
|
+ });
|
|
137
|
+
|
|
138
|
+ editF.setBounds(264, 168, 107, 25);
|
|
139
|
+ editF.setText("Layer F");
|
|
140
|
+ cp.add(editF);
|
|
141
|
+ editF.addActionListener(new ActionListener() {
|
|
142
|
+ public void actionPerformed(ActionEvent evt) {
|
|
143
|
+ editFActionPerformed(evt);
|
|
144
|
+ }
|
|
145
|
+ });
|
|
146
|
+
|
|
147
|
+ editG.setBounds(264, 200, 107, 25);
|
|
148
|
+ editG.setText("Layer G");
|
|
149
|
+ cp.add(editG);
|
|
150
|
+ editG.addActionListener(new ActionListener() {
|
|
151
|
+ public void actionPerformed(ActionEvent evt) {
|
|
152
|
+ editGActionPerformed(evt);
|
|
153
|
+ }
|
|
154
|
+ });
|
|
155
|
+
|
|
156
|
+ editH.setBounds(264, 232, 107, 25);
|
|
157
|
+ editH.setText("Layer H");
|
|
158
|
+ cp.add(editH);
|
|
159
|
+ editH.addActionListener(new ActionListener() {
|
|
160
|
+ public void actionPerformed(ActionEvent evt) {
|
|
161
|
+ editHActionPerformed(evt);
|
|
162
|
+ }
|
|
163
|
+ });
|
|
164
|
+
|
|
165
|
+ frameList.setBounds(384, 8, 145, 249);
|
|
166
|
+ cp.add(frameList);
|
|
167
|
+ frameUp.setBounds(544, 8, 107, 33);
|
|
168
|
+ frameUp.setText("Move up");
|
|
169
|
+ cp.add(frameUp);
|
|
170
|
+ frameUp.addActionListener(new ActionListener() {
|
|
171
|
+ public void actionPerformed(ActionEvent evt) {
|
|
172
|
+ frameUpActionPerformed(evt);
|
|
173
|
+ }
|
|
174
|
+ });
|
|
175
|
+
|
|
176
|
+ frameDown.setBounds(544, 152, 107, 33);
|
|
177
|
+ frameDown.setText("Move down");
|
|
178
|
+ cp.add(frameDown);
|
|
179
|
+ frameDown.addActionListener(new ActionListener() {
|
|
180
|
+ public void actionPerformed(ActionEvent evt) {
|
|
181
|
+ frameDownActionPerformed(evt);
|
|
182
|
+ }
|
|
183
|
+ });
|
|
184
|
+
|
|
185
|
+ frameAdd.setBounds(544, 56, 107, 33);
|
|
186
|
+ frameAdd.setText("Add");
|
|
187
|
+ cp.add(frameAdd);
|
|
188
|
+ frameAdd.addActionListener(new ActionListener() {
|
|
189
|
+ public void actionPerformed(ActionEvent evt) {
|
|
190
|
+ frameAddActionPerformed(evt);
|
|
191
|
+ }
|
|
192
|
+ });
|
|
193
|
+
|
|
194
|
+ frameRemove.setBounds(544, 104, 107, 33);
|
|
195
|
+ frameRemove.setText("Remove");
|
|
196
|
+ cp.add(frameRemove);
|
|
197
|
+ frameRemove.addActionListener(new ActionListener() {
|
|
198
|
+ public void actionPerformed(ActionEvent evt) {
|
|
199
|
+ frameRemoveActionPerformed(evt);
|
|
200
|
+ }
|
|
201
|
+ });
|
|
202
|
+
|
|
203
|
+ jList2.setBounds(8, 264, 209, 121);
|
|
204
|
+ cp.add(jList2);
|
|
205
|
+ animUp.setBounds(224, 264, 99, 25);
|
|
206
|
+ animUp.setText("Move up");
|
|
207
|
+ cp.add(animUp);
|
|
208
|
+ animUp.addActionListener(new ActionListener() {
|
|
209
|
+ public void actionPerformed(ActionEvent evt) {
|
|
210
|
+ animUpActionPerformed(evt);
|
|
211
|
+ }
|
|
212
|
+ });
|
|
213
|
+
|
|
214
|
+ animDown.setBounds(224, 360, 99, 25);
|
|
215
|
+ animDown.setText("Move down");
|
|
216
|
+ cp.add(animDown);
|
|
217
|
+ animDown.addActionListener(new ActionListener() {
|
|
218
|
+ public void actionPerformed(ActionEvent evt) {
|
|
219
|
+ animDownActionPerformed(evt);
|
|
220
|
+ }
|
|
221
|
+ });
|
|
222
|
+
|
|
223
|
+ animAdd.setBounds(224, 296, 99, 25);
|
|
224
|
+ animAdd.setText("Add");
|
|
225
|
+ cp.add(animAdd);
|
|
226
|
+ animAdd.addActionListener(new ActionListener() {
|
|
227
|
+ public void actionPerformed(ActionEvent evt) {
|
|
228
|
+ animAddActionPerformed(evt);
|
|
229
|
+ }
|
|
230
|
+ });
|
|
231
|
+
|
|
232
|
+ animRemove.setBounds(224, 328, 99, 25);
|
|
233
|
+ animRemove.setText("Remove");
|
|
234
|
+ cp.add(animRemove);
|
|
235
|
+ animRemove.addActionListener(new ActionListener() {
|
|
236
|
+ public void actionPerformed(ActionEvent evt) {
|
|
237
|
+ animRemoveActionPerformed(evt);
|
|
238
|
+ }
|
|
239
|
+ });
|
|
240
|
+
|
|
241
|
+ animPath.setBounds(344, 264, 305, 24);
|
|
242
|
+ animPath.setEditable(false);
|
|
243
|
+ animPath.setText("Load/Save an animation file...");
|
|
244
|
+ cp.add(animPath);
|
|
245
|
+ load.setBounds(344, 296, 147, 25);
|
|
246
|
+ load.setText("Load");
|
|
247
|
+ cp.add(load);
|
|
248
|
+ load.addActionListener(new ActionListener() {
|
|
249
|
+ public void actionPerformed(ActionEvent evt) {
|
|
250
|
+ loadActionPerformed(evt);
|
|
251
|
+ }
|
|
252
|
+ });
|
|
253
|
+
|
|
254
|
+ save.setBounds(504, 296, 147, 25);
|
|
255
|
+ save.setText("Save");
|
|
256
|
+ cp.add(save);
|
|
257
|
+ save.addActionListener(new ActionListener() {
|
|
258
|
+ public void actionPerformed(ActionEvent evt) {
|
|
259
|
+ saveActionPerformed(evt);
|
|
260
|
+ }
|
|
261
|
+ });
|
|
262
|
+
|
|
263
|
+ jComboBox1.setBounds(344, 328, 305, 24);
|
|
264
|
+ cp.add(jComboBox1);
|
|
265
|
+ upload.setBounds(344, 360, 147, 25);
|
|
266
|
+ upload.setText("Upload");
|
|
267
|
+ cp.add(upload);
|
|
268
|
+ upload.addActionListener(new ActionListener() {
|
|
269
|
+ public void actionPerformed(ActionEvent evt) {
|
|
270
|
+ uploadActionPerformed(evt);
|
|
271
|
+ }
|
|
272
|
+ });
|
|
273
|
+
|
|
274
|
+ download.setBounds(504, 360, 147, 25);
|
|
275
|
+ download.setText("Download");
|
|
276
|
+ cp.add(download);
|
|
277
|
+ download.addActionListener(new ActionListener() {
|
|
278
|
+ public void actionPerformed(ActionEvent evt) {
|
|
279
|
+ downloadActionPerformed(evt);
|
|
280
|
+ }
|
|
281
|
+ });
|
|
282
|
+
|
|
283
|
+ jLabel4.setBounds(536, 208, 111, 16);
|
|
284
|
+ jLabel4.setText("Frames remaining:");
|
|
285
|
+ jLabel4.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
|
|
286
|
+ cp.add(jLabel4);
|
|
287
|
+ frameRemaining.setBounds(536, 232, 113, 24);
|
|
288
|
+ frameRemaining.setEditable(false);
|
|
289
|
+ frameRemaining.setText("2048");
|
|
290
|
+ cp.add(frameRemaining);
|
|
291
|
+ // Ende Komponenten
|
|
292
|
+
|
|
293
|
+ setResizable(false);
|
|
294
|
+ setVisible(true);
|
|
295
|
+ }
|
|
296
|
+
|
|
297
|
+ // Anfang Ereignisprozeduren
|
|
298
|
+ public void editAActionPerformed(ActionEvent evt) {
|
|
299
|
+
|
|
300
|
+ }
|
|
301
|
+
|
|
302
|
+ public void editBActionPerformed(ActionEvent evt) {
|
|
303
|
+
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+ public void editCActionPerformed(ActionEvent evt) {
|
|
307
|
+
|
|
308
|
+ }
|
|
309
|
+
|
|
310
|
+ public void editDActionPerformed(ActionEvent evt) {
|
|
311
|
+
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+ public void editEActionPerformed(ActionEvent evt) {
|
|
315
|
+
|
|
316
|
+ }
|
|
317
|
+
|
|
318
|
+ public void editFActionPerformed(ActionEvent evt) {
|
|
319
|
+
|
|
320
|
+ }
|
|
321
|
+
|
|
322
|
+ public void editGActionPerformed(ActionEvent evt) {
|
|
323
|
+
|
|
324
|
+ }
|
|
325
|
+
|
|
326
|
+ public void editHActionPerformed(ActionEvent evt) {
|
|
327
|
+
|
|
328
|
+ }
|
|
329
|
+
|
|
330
|
+ public void frameUpActionPerformed(ActionEvent evt) {
|
|
331
|
+ int i = frameList.getSelectedIndex();
|
|
332
|
+ if ((i > 0) && (frameListModel.getSize() >= 2)) {
|
|
333
|
+ Object tmp = frameListModel.get(i);
|
|
334
|
+ frameListModel.set(i, frameListModel.get(i - 1));
|
|
335
|
+ frameListModel.set(i - 1, tmp);
|
|
336
|
+ frameList.setSelectedIndex(i - 1);
|
|
337
|
+ }
|
|
338
|
+ }
|
|
339
|
+
|
|
340
|
+ public void frameDownActionPerformed(ActionEvent evt) {
|
|
341
|
+ int i = frameList.getSelectedIndex();
|
|
342
|
+ if ((i >= 0) && (frameListModel.getSize() >= 2) && (i < (frameListModel.getSize() - 1))) {
|
|
343
|
+ Object tmp = frameListModel.get(i);
|
|
344
|
+ frameListModel.set(i, frameListModel.get(i + 1));
|
|
345
|
+ frameListModel.set(i + 1, tmp);
|
|
346
|
+ frameList.setSelectedIndex(i + 1);
|
|
347
|
+ }
|
|
348
|
+ }
|
|
349
|
+
|
|
350
|
+ public void frameAddActionPerformed(ActionEvent evt) {
|
|
351
|
+
|
|
352
|
+ }
|
|
353
|
+
|
|
354
|
+ public void frameRemoveActionPerformed(ActionEvent evt) {
|
|
355
|
+
|
|
356
|
+ }
|
|
357
|
+
|
|
358
|
+ public void animUpActionPerformed(ActionEvent evt) {
|
|
359
|
+ int i = jList2.getSelectedIndex();
|
|
360
|
+ if ((i > 0) && (animationListModel.getSize() >= 2)) {
|
|
361
|
+ Object tmp = animationListModel.get(i);
|
|
362
|
+ animationListModel.set(i, animationListModel.get(i - 1));
|
|
363
|
+ animationListModel.set(i - 1, tmp);
|
|
364
|
+ jList2.setSelectedIndex(i - 1);
|
|
365
|
+ }
|
|
366
|
+ }
|
|
367
|
+
|
|
368
|
+ public void animDownActionPerformed(ActionEvent evt) {
|
|
369
|
+ int i = jList2.getSelectedIndex();
|
|
370
|
+ if ((i >= 0) && (animationListModel.getSize() >= 2) && (i < (animationListModel.getSize() - 1))) {
|
|
371
|
+ Object tmp = animationListModel.get(i);
|
|
372
|
+ animationListModel.set(i, animationListModel.get(i + 1));
|
|
373
|
+ animationListModel.set(i + 1, tmp);
|
|
374
|
+ jList2.setSelectedIndex(i + 1);
|
|
375
|
+ }
|
|
376
|
+ }
|
|
377
|
+
|
|
378
|
+ public void animAddActionPerformed(ActionEvent evt) {
|
|
379
|
+
|
|
380
|
+ }
|
|
381
|
+
|
|
382
|
+ public void animRemoveActionPerformed(ActionEvent evt) {
|
|
383
|
+
|
|
384
|
+ }
|
|
385
|
+
|
|
386
|
+ public void loadActionPerformed(ActionEvent evt) {
|
|
387
|
+
|
|
388
|
+ }
|
|
389
|
+
|
|
390
|
+ public void saveActionPerformed(ActionEvent evt) {
|
|
391
|
+
|
|
392
|
+ }
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+ public void uploadActionPerformed(ActionEvent evt) {
|
|
396
|
+ if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
|
|
397
|
+ JOptionPane.showMessageDialog(this, "No serial port selected...");
|
|
398
|
+ } else {
|
|
399
|
+ worker.uploadState((String)jComboBox1.getSelectedItem());
|
|
400
|
+ }
|
|
401
|
+ }
|
|
402
|
+
|
|
403
|
+ public void downloadActionPerformed(ActionEvent evt) {
|
|
404
|
+ if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
|
|
405
|
+ JOptionPane.showMessageDialog(this, "No serial port selected...");
|
|
406
|
+ } else {
|
|
407
|
+ worker.downloadState((String)jComboBox1.getSelectedItem());
|
|
408
|
+ }
|
|
409
|
+ }
|
|
410
|
+
|
|
411
|
+ // Ende Ereignisprozeduren
|
|
412
|
+
|
|
413
|
+ public static void main(String[] args) {
|
|
414
|
+ new frame("Cube Control");
|
|
415
|
+ }
|
|
416
|
+}
|
|
417
|
+
|