Browse Source

Fixing filename...

Thomas Buck 12 years ago
parent
commit
d15463c346
1 changed files with 0 additions and 811 deletions
  1. 0
    811
      Cube Control/frame.java

+ 0
- 811
Cube Control/frame.java View File

@@ -1,811 +0,0 @@
1
-/*
2
-* Frame.java
3
-*
4
-*
5
-* Copyright 2011 Thomas Buck <xythobuz@me.com>
6
-* Copyright 2011 Max Nuding <max.nuding@gmail.com>
7
-* Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
8
-*
9
-* This file is part of LED-Cube.
10
-*
11
-* LED-Cube is free software: you can redistribute it and/or modify
12
-* it under the terms of the GNU General Public License as published by
13
-* the Free Software Foundation, either version 3 of the License, or
14
-* (at your option) any later version.
15
-*
16
-* LED-Cube is distributed in the hope that it will be useful,
17
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
-* GNU General Public License for more details.
20
-*
21
-* You should have received a copy of the GNU General Public License
22
-* along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
23
-*/
24
-
25
-import com.sun.j3d.utils.universe.*;
26
-import javax.media.j3d.*;
27
-import java.awt.*;
28
-import java.awt.event.*;
29
-import javax.swing.*;
30
-import javax.swing.event.*;
31
-import java.io.File;
32
-
33
-
34
-public class Frame extends JFrame implements ListSelectionListener {
35
-  // Anfang Variablen
36
-  private GraphicsConfiguration gConfig = SimpleUniverse.getPreferredConfiguration();
37
-  private Canvas3D cubeCanvas = new Canvas3D(gConfig);
38
-  private Led3D ledView = new Led3D(cubeCanvas);
39
-
40
-  // Anfang Attribute
41
-  private JButton editA = new JButton();
42
-  private JButton editB = new JButton();
43
-  private JButton editC = new JButton();
44
-  private JButton editD = new JButton();
45
-  private JButton editE = new JButton();
46
-  private JButton editF = new JButton();
47
-  private JButton editG = new JButton();
48
-  private JButton editH = new JButton();
49
-  private DefaultListModel frameListModel = new DefaultListModel();
50
-  public JList frameList = new JList();
51
-  private JScrollPane frameListScrollPane = new JScrollPane(frameList);
52
-  private JButton frameUp = new JButton();
53
-  private JButton frameDown = new JButton();
54
-  private JButton frameAdd = new JButton();
55
-  private JButton frameRemove = new JButton();
56
-  private JButton frameRename = new JButton();
57
-  private JButton Frame = new JButton();
58
-  private JList animList = new JList();
59
-  private DefaultListModel animModel = new DefaultListModel();
60
-  private JScrollPane animScrollPane = new JScrollPane(animList);
61
-  private JButton animUp = new JButton();
62
-  private JButton animDown = new JButton();
63
-  private JButton animAdd = new JButton();
64
-  private JButton animRemove = new JButton();
65
-  private JButton animRename = new JButton();
66
-  private JTextField animPath = new JTextField();
67
-  private JButton load = new JButton();
68
-  private JButton save = new JButton();
69
-  private JButton saveAs = new JButton();
70
-  private JComboBox jComboBox1 = new JComboBox();
71
-  private JButton upload = new JButton();
72
-  private JButton download = new JButton();
73
-  private JLabel jLabel4 = new JLabel();
74
-  private JTextField frameRemaining = new JTextField();
75
-  private JLabel frmLngthLbl = new JLabel();
76
-  private JTextField frmLngthTxt = new JTextField();
77
-  private JButton frameDuration = new JButton();
78
-  // Ende Attribute
79
-
80
-  private cubeWorker worker = new cubeWorker();
81
-  private boolean fileSelected = false;
82
-  // Ende Variablen
83
-
84
-  private int saveExitDialog() {
85
-    String[] Optionen = {"Yes", "No"};
86
-    int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
87
-    if (Auswahl == JOptionPane.YES_OPTION) {
88
-       return 1;
89
-    } else {
90
-       return 0;
91
-    }
92
-  }
93
-
94
-  private String askString(String title, String text) {
95
-    return JOptionPane.showInputDialog(null, text, title, JOptionPane.QUESTION_MESSAGE);
96
-  }
97
-
98
-  private void errorMessage(String s) {
99
-  String[] Optionen = {"OK"};
100
-  JOptionPane.showOptionDialog(this, s, "Error!", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
101
-  }
102
-
103
-  public void valueChanged(ListSelectionEvent evt) {
104
-  if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
105
-    // If animList or framsList is the source, we act...
106
-
107
-    // If both selections are valid, update Frame duration and set 3D data
108
-    if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
109
-      ledView.setData(worker.getFrame(animList.getSelectedIndex(), frameList.getSelectedIndex()));
110
-      frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
111
-    } else {
112
-      // clear Frame duration
113
-      frmLngthTxt.setText("");
114
-    }
115
-
116
-    if ((evt.getSource() == animList) && (animList.getSelectedIndex() != -1)) {
117
-      // animList selection changed, update frameList
118
-      frameListModel.clear();
119
-      for (int i = 0; i < worker.numOfFrames(animList.getSelectedIndex()); i++) {
120
-        frameListModel.addElement(worker.getFrameName(animList.getSelectedIndex(), i));
121
-      }
122
-      frameList.setModel(frameListModel);
123
-    }
124
-  }
125
-  }
126
-
127
-  private void save() {
128
-    if (fileSelected == false) {
129
-        JFileChooser fc = new JFileChooser();
130
-        int ret = fc.showSaveDialog(this);
131
-        if (ret == JFileChooser.APPROVE_OPTION) {
132
-          File file = fc.getSelectedFile();
133
-          fileSelected = true;
134
-          animPath.setText(file.getPath());
135
-          worker.saveState(animPath.getText());
136
-        }
137
-      } else {
138
-      worker.saveState(animPath.getText());
139
-      }
140
-  }
141
-
142
-  public Frame(String title) {
143
-    // Frame-Initialisierung
144
-    super(title);
145
-
146
-    String[] sPorts = worker.getSerialPorts();
147
-    for(int i = 0; i < sPorts.length; i++){
148
-      jComboBox1.addItem(sPorts[i]);
149
-    }
150
-
151
-    for(int i = 0; i < worker.numOfAnimations(); i++){
152
-      animModel.addElement(worker.getAnimationName(i));
153
-    }
154
-
155
-    addWindowListener(new WindowAdapter() {
156
-      public void windowClosing(WindowEvent evt) {
157
-             if (worker.changedStateSinceSave()) {
158
-                  if (saveExitDialog() == 1) {
159
-            save();
160
-          } else {
161
-            return;
162
-          }
163
-             }
164
-             System.exit(0);
165
-      }
166
-    });
167
-    int frameWidth = 661;
168
-    int frameHeight = 417;
169
-    setSize(frameWidth, frameHeight);
170
-    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
171
-    int x = (d.width - getSize().width) / 2;
172
-    int y = (d.height - getSize().height) / 2 ;
173
-    setLocation(x, y);
174
-    Container cp = getContentPane();
175
-    cp.setLayout(null);
176
-    // Anfang Komponenten
177
-
178
-    //----- 3D-----
179
-    //-------------
180
-    cubeCanvas.setBounds(8, 8, 250, 250);
181
-    cp.add(cubeCanvas);
182
-
183
-    //-------------
184
-
185
-    editA.setBounds(264, 8, 107, 25);
186
-    editA.setText("Layer A");
187
-    editA.setFont(new Font("Dialog", Font.PLAIN, 13));
188
-    cp.add(editA);
189
-    editA.addActionListener(new ActionListener() {
190
-      public void actionPerformed(ActionEvent evt) {
191
-        editA_ActionPerformed(evt);
192
-      }
193
-    });
194
-
195
-    editB.setBounds(264, 40, 107, 25);
196
-    editB.setText("Layer B");
197
-    editB.setFont(new Font("Dialog", Font.PLAIN, 13));
198
-    cp.add(editB);
199
-    editB.addActionListener(new ActionListener() {
200
-      public void actionPerformed(ActionEvent evt) {
201
-        editB_ActionPerformed(evt);
202
-      }
203
-    });
204
-
205
-    editC.setBounds(264, 72, 107, 25);
206
-    editC.setText("Layer C");
207
-    editC.setFont(new Font("Dialog", Font.PLAIN, 13));
208
-    cp.add(editC);
209
-    editC.addActionListener(new ActionListener() {
210
-      public void actionPerformed(ActionEvent evt) {
211
-        editC_ActionPerformed(evt);
212
-      }
213
-    });
214
-
215
-    editD.setBounds(264, 104, 107, 25);
216
-    editD.setText("Layer D");
217
-    editD.setFont(new Font("Dialog", Font.PLAIN, 13));
218
-    cp.add(editD);
219
-    editD.addActionListener(new ActionListener() {
220
-      public void actionPerformed(ActionEvent evt) {
221
-        editD_ActionPerformed(evt);
222
-      }
223
-    });
224
-
225
-    editE.setBounds(264, 136, 107, 25);
226
-    editE.setText("Layer E");
227
-    editE.setFont(new Font("Dialog", Font.PLAIN, 13));
228
-    cp.add(editE);
229
-    editE.addActionListener(new ActionListener() {
230
-      public void actionPerformed(ActionEvent evt) {
231
-        editE_ActionPerformed(evt);
232
-      }
233
-    });
234
-
235
-    editF.setBounds(264, 168, 107, 25);
236
-    editF.setText("Layer F");
237
-    editF.setFont(new Font("Dialog", Font.PLAIN, 13));
238
-    cp.add(editF);
239
-    editF.addActionListener(new ActionListener() {
240
-      public void actionPerformed(ActionEvent evt) {
241
-        editF_ActionPerformed(evt);
242
-      }
243
-    });
244
-
245
-    editG.setBounds(264, 200, 107, 25);
246
-    editG.setText("Layer G");
247
-    editG.setFont(new Font("Dialog", Font.PLAIN, 13));
248
-    cp.add(editG);
249
-    editG.addActionListener(new ActionListener() {
250
-      public void actionPerformed(ActionEvent evt) {
251
-        editG_ActionPerformed(evt);
252
-      }
253
-    });
254
-
255
-    editH.setBounds(264, 232, 107, 25);
256
-    editH.setText("Layer H");
257
-    editH.setFont(new Font("Dialog", Font.PLAIN, 13));
258
-    cp.add(editH);
259
-    editH.addActionListener(new ActionListener() {
260
-      public void actionPerformed(ActionEvent evt) {
261
-        editH_ActionPerformed(evt);
262
-      }
263
-    });
264
-
265
-    frameListScrollPane.setBounds(384, 8, 145, 249);
266
-    frameList.setModel(frameListModel);
267
-    cp.add(frameListScrollPane);
268
-
269
-    frameUp.setBounds(544, 8, 107, 28);
270
-    frameUp.setText("Move up");
271
-    frameUp.setFont(new Font("Dialog", Font.PLAIN, 13));
272
-    cp.add(frameUp);
273
-    frameUp.addActionListener(new ActionListener() {
274
-      public void actionPerformed(ActionEvent evt) {
275
-        frameUp_ActionPerformed(evt);
276
-      }
277
-    });
278
-
279
-  frameAdd.setBounds(544, 39, 107, 28);
280
-    frameAdd.setText("Add");
281
-    frameAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
282
-    cp.add(frameAdd);
283
-    frameAdd.addActionListener(new ActionListener() {
284
-      public void actionPerformed(ActionEvent evt) {
285
-        frameAdd_ActionPerformed(evt);
286
-      }
287
-    });
288
-
289
-  frameRemove.setBounds(544, 70, 107, 28);
290
-    frameRemove.setText("Remove");
291
-    frameRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
292
-    cp.add(frameRemove);
293
-    frameRemove.addActionListener(new ActionListener() {
294
-      public void actionPerformed(ActionEvent evt) {
295
-        frameRemove_ActionPerformed(evt);
296
-      }
297
-    });
298
-  
299
-  frameRename.setBounds(544, 101, 107, 28);
300
-  frameRename.setText("Rename");
301
-    frameRename.setFont(new Font("Dialog", Font.PLAIN, 13));
302
-    cp.add(frameRename);
303
-    frameRename.addActionListener(new ActionListener() {
304
-    public void actionPerformed(ActionEvent evt) {
305
-      int a = animList.getSelectedIndex();
306
-      if (a < 0) {
307
-        errorMessage("Select an animation!");
308
-        return;
309
-      }
310
-      int f = frameList.getSelectedIndex();
311
-      if (f < 0) {
312
-        errorMessage("Select a Frame!");
313
-        return;
314
-      }
315
-      worker.setFrameName(askString("Rename", "Rename " + frameList.getSelectedValue() + "?"), a, f);
316
-      frameListModel.set(f, worker.getFrameName(a, f));
317
-      frameList.setModel(frameListModel);
318
-    }
319
-  });
320
-
321
-    frameDown.setBounds(544, 132, 107, 28);
322
-    frameDown.setText("Move down");
323
-    frameDown.setFont(new Font("Dialog", Font.PLAIN, 13));
324
-    cp.add(frameDown);
325
-    frameDown.addActionListener(new ActionListener() {
326
-      public void actionPerformed(ActionEvent evt) {
327
-        frameDown_ActionPerformed(evt);
328
-      }
329
-    });
330
-
331
-    frmLngthLbl.setBounds(536, 160, 113, 24);
332
-    frmLngthLbl.setText("Time (1/24 sec)");
333
-    frmLngthLbl.setFont(new Font("Dialog", Font.PLAIN, 13));
334
-    cp.add(frmLngthLbl);
335
-
336
-    frmLngthTxt.setBounds(536, 184, 50, 24);
337
-    frmLngthTxt.setText("");
338
-    frmLngthTxt.setFont(new Font("Dialog", Font.PLAIN, 13));
339
-    cp.add(frmLngthTxt);
340
-
341
-  frameDuration.setBounds(590, 184, 50, 24);
342
-  frameDuration.setText("OK");
343
-  frameDuration.setFont(new Font("Dialog", Font.PLAIN, 13));
344
-  cp.add(frameDuration);
345
-  frameDuration.addActionListener(new ActionListener() {
346
-    public void actionPerformed(ActionEvent evt) {
347
-      if (frmLngthTxt.getText().equals("0")) {
348
-        errorMessage("0 is not a valid value!");
349
-        frmLngthTxt.setText("1");
350
-      } else if (Integer.parseInt(frmLngthTxt.getText()) > 256) {
351
-        errorMessage("Value too high. Max: 256");
352
-        frmLngthTxt.setText("256");
353
-        return;
354
-      } else {
355
-        if (animList.getSelectedIndex() == -1) {
356
-          errorMessage("Please select an animation!");
357
-          return;
358
-        }
359
-        if (frameList.getSelectedIndex() == -1) {
360
-          errorMessage("Please select a Frame!");
361
-          return;
362
-        }
363
-        worker.setFrameTime((byte)(Integer.parseInt(frmLngthTxt.getText()) - 1), animList.getSelectedIndex(), frameList.getSelectedIndex());
364
-      }
365
-    }
366
-  });
367
-
368
-    animScrollPane.setBounds(8, 264, 209, 121);
369
-    animList.setModel(animModel);
370
-    cp.add(animScrollPane);
371
-
372
-    animUp.setBounds(224, 264, 99, 25);
373
-    animUp.setText("Move up");
374
-    animUp.setFont(new Font("Dialog", Font.PLAIN, 13));
375
-    cp.add(animUp);
376
-    animUp.addActionListener(new ActionListener() {
377
-      public void actionPerformed(ActionEvent evt) {
378
-        animUp_ActionPerformed(evt);
379
-      }
380
-    });
381
-
382
-    animDown.setBounds(224, 368, 99, 25);
383
-    animDown.setText("Move down");
384
-    animDown.setFont(new Font("Dialog", Font.PLAIN, 13));
385
-    cp.add(animDown);
386
-    animDown.addActionListener(new ActionListener() {
387
-      public void actionPerformed(ActionEvent evt) {
388
-        animDown_ActionPerformed(evt);
389
-      }
390
-    });
391
-
392
-    animRename.setBounds(224, 342, 99, 25);
393
-    animRename.setText("Rename");
394
-    animRename.setFont(new Font("Dialog", Font.PLAIN, 13));
395
-    cp.add(animRename);
396
-    animRename.addActionListener(new ActionListener() {
397
-    public void actionPerformed(ActionEvent evt) {
398
-      int a = animList.getSelectedIndex();
399
-      if (a < 0) {
400
-        errorMessage("Select an animation!");
401
-        return;
402
-      }
403
-      worker.setAnimationName(askString("Rename", "Rename " + animList.getSelectedValue() + "?"), a);
404
-      animModel.set(a, worker.getAnimationName(a));
405
-      animList.setModel(animModel);
406
-    }
407
-  });
408
-
409
-    animAdd.setBounds(224, 290, 99, 25);
410
-    animAdd.setText("Add");
411
-    animAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
412
-    cp.add(animAdd);
413
-    animAdd.addActionListener(new ActionListener() {
414
-      public void actionPerformed(ActionEvent evt) {
415
-        animAdd_ActionPerformed(evt);
416
-      }
417
-    });
418
-
419
-    animRemove.setBounds(224, 316, 99, 25);
420
-    animRemove.setText("Remove");
421
-    animRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
422
-    cp.add(animRemove);
423
-    animRemove.addActionListener(new ActionListener() {
424
-      public void actionPerformed(ActionEvent evt) {
425
-        animRemove_ActionPerformed(evt);
426
-      }
427
-    });
428
-
429
-    animPath.setBounds(344, 264, 305, 24);
430
-    animPath.setEditable(false);
431
-    animPath.setText("Load/Save an animation file...");
432
-    animPath.setFont(new Font("Dialog", Font.PLAIN, 13));
433
-    cp.add(animPath);
434
-    load.setBounds(344, 296, 100, 25);
435
-    load.setText("Load");
436
-    load.setFont(new Font("Dialog", Font.PLAIN, 13));
437
-    cp.add(load);
438
-    load.addActionListener(new ActionListener() {
439
-      public void actionPerformed(ActionEvent evt) {
440
-        load_ActionPerformed(evt);
441
-      }
442
-    });
443
-
444
-    save.setBounds(454, 296, 100, 25);
445
-    save.setText("Save");
446
-    save.setFont(new Font("Dialog", Font.PLAIN, 13));
447
-    cp.add(save);
448
-    save.addActionListener(new ActionListener() {
449
-      public void actionPerformed(ActionEvent evt) {
450
-        save_ActionPerformed(evt);
451
-      }
452
-    });
453
-
454
-  saveAs.setBounds(564, 296, 90, 25);
455
-  saveAs.setText("Save As");
456
-  saveAs.setFont(new Font("Dialog", Font.PLAIN, 13));
457
-  cp.add(saveAs);
458
-  saveAs.addActionListener(new ActionListener() {
459
-    public void actionPerformed(ActionEvent evt) {
460
-      saveAs_ActionPerformed(evt);
461
-    }
462
-  });
463
-
464
-    jComboBox1.setBounds(344, 328, 305, 24);
465
-    jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 13));
466
-    cp.add(jComboBox1);
467
-    upload.setBounds(344, 360, 147, 25);
468
-    upload.setText("Upload");
469
-    upload.setFont(new Font("Dialog", Font.PLAIN, 13));
470
-    cp.add(upload);
471
-    upload.addActionListener(new ActionListener() {
472
-      public void actionPerformed(ActionEvent evt) {
473
-        upload_ActionPerformed(evt);
474
-      }
475
-    });
476
-
477
-    download.setBounds(504, 360, 147, 25);
478
-    download.setText("Download");
479
-    download.setFont(new Font("Dialog", Font.PLAIN, 13));
480
-    cp.add(download);
481
-    download.addActionListener(new ActionListener() {
482
-      public void actionPerformed(ActionEvent evt) {
483
-        download_ActionPerformed(evt);
484
-      }
485
-    });
486
-
487
-    jLabel4.setBounds(536, 208, 112, 20);
488
-    jLabel4.setText("Remaining:");
489
-    jLabel4.setFont(new Font("Dialog", Font.PLAIN, 13));
490
-    cp.add(jLabel4);
491
-    frameRemaining.setBounds(536, 232, 113, 24);
492
-    frameRemaining.setEditable(false);
493
-    frameRemaining.setText(String.valueOf(worker.framesRemaining()));
494
-    frameRemaining.setFont(new Font("Dialog", Font.PLAIN, 13));
495
-    cp.add(frameRemaining);
496
-    animList.setFont(new Font("Dialog", Font.PLAIN, 13));
497
-    frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
498
-    // Ende Komponenten
499
-    animList.addListSelectionListener(this);
500
-  frameList.addListSelectionListener(this);
501
-    setResizable(false);
502
-    setVisible(true);
503
-  }
504
-
505
-  // Anfang Methoden
506
-
507
-  // Anfang Ereignisprozeduren
508
-  public void editA_ActionPerformed(ActionEvent evt) {
509
-
510
-     if(animList.getSelectedIndex() == -1){
511
-       errorMessage("Please select an animation.");
512
-     } else if(frameList.getSelectedIndex() == -1){
513
-       errorMessage("Please select a Frame.");
514
-     } else {
515
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 0, worker, this);
516
-
517
-     }
518
-  }
519
-
520
-  public void editB_ActionPerformed(ActionEvent evt) {
521
-    if(animList.getSelectedIndex() == -1){
522
-       errorMessage("Please select an animation.");
523
-     } else if(frameList.getSelectedIndex() == -1){
524
-       errorMessage("Please select a Frame.");
525
-     } else {
526
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 1, worker, this);
527
-     }
528
-  }
529
-
530
-  public void editC_ActionPerformed(ActionEvent evt) {
531
-    if(animList.getSelectedIndex() == -1){
532
-       errorMessage("Please select an animation.");
533
-     } else if(frameList.getSelectedIndex() == -1){
534
-       errorMessage("Please select a Frame.");
535
-     } else {
536
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 2, worker, this);
537
-     }
538
-  }
539
-
540
-  public void editD_ActionPerformed(ActionEvent evt) {
541
-    if(animList.getSelectedIndex() == -1){
542
-       errorMessage("Please select an animation.");
543
-     } else if(frameList.getSelectedIndex() == -1){
544
-       errorMessage("Please select a Frame.");
545
-     } else {
546
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 3, worker, this);
547
-     }
548
-  }
549
-
550
-  public void editE_ActionPerformed(ActionEvent evt) {
551
-     if(animList.getSelectedIndex() == -1){
552
-       errorMessage("Please select an animation.");
553
-     } else if(frameList.getSelectedIndex() == -1){
554
-       errorMessage("Please select a Frame.");
555
-     } else {
556
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 4, worker, this);
557
-     }
558
-  }
559
-
560
-  public void editF_ActionPerformed(ActionEvent evt) {
561
-     if(animList.getSelectedIndex() == -1){
562
-       errorMessage("Please select an animation.");
563
-     } else if(frameList.getSelectedIndex() == -1){
564
-       errorMessage("Please select a Frame.");
565
-     } else {
566
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 5, worker, this);
567
-     }
568
-  }
569
-
570
-  public void editG_ActionPerformed(ActionEvent evt) {
571
-     if(animList.getSelectedIndex() == -1){
572
-       errorMessage("Please select an animation.");
573
-     } else if(frameList.getSelectedIndex() == -1){
574
-       errorMessage("Please select a Frame.");
575
-     } else {
576
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 6, worker, this);
577
-     }
578
-  }
579
-
580
-  public void editH_ActionPerformed(ActionEvent evt) {
581
-     if(animList.getSelectedIndex() == -1){
582
-       errorMessage("Please select an animation.");
583
-     } else if(frameList.getSelectedIndex() == -1){
584
-       errorMessage("Please select a Frame.");
585
-     } else {
586
-       layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 7, worker, this);
587
-     }
588
-  }
589
-
590
-  public void frameUp_ActionPerformed(ActionEvent evt) {
591
-         int i = frameList.getSelectedIndex();
592
-         if ((i > 0) && (frameListModel.getSize() >= 2)) {
593
-            Object tmp = frameListModel.get(i);
594
-            frameListModel.set(i, frameListModel.get(i - 1));
595
-            frameListModel.set(i - 1, tmp);
596
-            frameList.setSelectedIndex(i - 1);
597
-            worker.moveFrame(worker.UP, animList.getSelectedIndex(), frameList.getSelectedIndex());
598
-         }
599
-  }
600
-
601
-  public void frameDown_ActionPerformed(ActionEvent evt) {
602
-         int i = frameList.getSelectedIndex();
603
-         if ((i >= 0) && (frameListModel.getSize() >= 2) && (i < (frameListModel.getSize() - 1))) {
604
-            Object tmp = frameListModel.get(i);
605
-            frameListModel.set(i, frameListModel.get(i + 1));
606
-            frameListModel.set(i + 1, tmp);
607
-            frameList.setSelectedIndex(i + 1);
608
-            worker.moveFrame(worker.DOWN, animList.getSelectedIndex(), frameList.getSelectedIndex());
609
-         }
610
-  }
611
-
612
-  public void frameAdd_ActionPerformed(ActionEvent evt) {
613
-         if(animList.getSelectedIndex() == -1){
614
-            errorMessage("Please select an animation!");
615
-         } else {
616
-           worker.addFrame(animList.getSelectedIndex());
617
-           frameRemaining.setText(Integer.toString(worker.framesRemaining()));
618
-           int n = worker.numOfFrames(animList.getSelectedIndex()) - 1;
619
-           if (n < 0) {
620
-              n = 0;
621
-           }
622
-           frameListModel.add(n, worker.getFrameName(animList.getSelectedIndex(), n));
623
-           frameList.setModel(frameListModel);
624
-         }
625
-
626
-  }
627
-
628
-  public void frameRemove_ActionPerformed(ActionEvent evt) {
629
-     if(animList.getSelectedIndex() == -1){
630
-       errorMessage("Select an animation.");
631
-     } else if(frameList.getSelectedIndex() == -1){
632
-       errorMessage("Select a Frame.");
633
-     } else {
634
-       worker.removeFrame(animList.getSelectedIndex(), frameList.getSelectedIndex());
635
-       frameRemaining.setText(Integer.toString(worker.framesRemaining()));
636
-       frameListModel.removeElementAt(frameList.getSelectedIndex());
637
-       frameList.setModel(frameListModel);
638
-     }
639
-  }
640
-
641
-  public void animUp_ActionPerformed(ActionEvent evt) {
642
-         int i = animList.getSelectedIndex();
643
-         if ((i > 0) && (animModel.getSize() >= 2)) {
644
-            Object tmp = animModel.get(i);
645
-            animModel.set(i, animModel.get(i - 1));
646
-            animModel.set(i - 1, tmp);
647
-            animList.setSelectedIndex(i - 1);
648
-            worker.moveAnimation(worker.UP, animList.getSelectedIndex());
649
-         }
650
-  }
651
-
652
-  public void animDown_ActionPerformed(ActionEvent evt) {
653
-         int i = animList.getSelectedIndex();
654
-         if ((i >= 0) && (animModel.getSize() >= 2) && (i < (animModel.getSize() - 1))) {
655
-            Object tmp = animModel.get(i);
656
-            animModel.set(i, animModel.get(i + 1));
657
-            animModel.set(i + 1, tmp);
658
-            animList.setSelectedIndex(i + 1);
659
-            worker.moveAnimation(worker.DOWN, animList.getSelectedIndex());
660
-         }
661
-  }
662
-
663
-  public void animAdd_ActionPerformed(ActionEvent evt) {
664
-    if(worker.addAnimation() == -1){
665
-      errorMessage("Could not add animation!");
666
-    } else {
667
-    animModel.clear();
668
-    for (int i = 0; i < worker.numOfAnimations(); i++) {
669
-        animModel.add(i, worker.getAnimationName(i));
670
-    }
671
-    animList.setModel(animModel);
672
-    }
673
-
674
-  }
675
-
676
-  public void animRemove_ActionPerformed(ActionEvent evt) {
677
-   if(animList.getSelectedIndex() == -1){
678
-     errorMessage("Select an animation.");
679
-   } else {
680
-     worker.removeAnimation(animList.getSelectedIndex());
681
-     animModel.removeElementAt(animList.getSelectedIndex());
682
-     animList.setModel(animModel);
683
-   }
684
-  }
685
-
686
-  public void load_ActionPerformed(ActionEvent evt) {
687
-  JFileChooser fc = new JFileChooser();
688
-  int ret = fc.showOpenDialog(this);
689
-  if (ret == JFileChooser.APPROVE_OPTION) {
690
-    File file = fc.getSelectedFile();
691
-    if (fileSelected == false) {
692
-      fileSelected = true;
693
-    }
694
-    animPath.setText(file.getPath());
695
-    worker.loadState(animPath.getText());
696
-  animModel.clear();
697
-  for (int i = 0; i < worker.numOfAnimations(); i++) {
698
-    animModel.addElement(worker.getAnimationName(i));
699
-  }
700
-  animList.setModel(animModel);
701
-
702
-  frameListModel.clear();
703
-  frameList.setModel(frameListModel);
704
-  }
705
-  }
706
-
707
-  public void save_ActionPerformed(ActionEvent evt) {
708
-  if (fileSelected == false) {
709
-    JFileChooser fc = new JFileChooser();
710
-    int ret = fc.showSaveDialog(this);
711
-    if (ret == JFileChooser.APPROVE_OPTION) {
712
-      File file = fc.getSelectedFile();
713
-      fileSelected = true;
714
-      animPath.setText(file.getPath());
715
-      worker.saveState(animPath.getText());
716
-    }
717
-  } else {
718
-    worker.saveState(animPath.getText());
719
-  }
720
-  }
721
-
722
-  public void saveAs_ActionPerformed(ActionEvent evt) {
723
-  JFileChooser fc;
724
-  if (fileSelected == true) {
725
-    fc = new JFileChooser(new File(animPath.getText()).getParentFile());
726
-  } else {
727
-    fc = new JFileChooser();
728
-  }
729
-  int ret = fc.showSaveDialog(this);
730
-  if (ret == JFileChooser.APPROVE_OPTION) {
731
-    File file = fc.getSelectedFile();
732
-    if (fileSelected == false) {
733
-      fileSelected = true;
734
-    }
735
-    animPath.setText(file.getPath());
736
-    worker.saveState(animPath.getText());
737
-  }
738
-  }
739
-
740
-
741
-  public void upload_ActionPerformed(ActionEvent evt) {
742
-         if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
743
-            errorMessage("No serial port selected...");
744
-         } else {
745
-           worker.uploadState((String)jComboBox1.getSelectedItem());
746
-         }
747
-  }
748
-
749
-  public void download_ActionPerformed(ActionEvent evt) {
750
-         if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
751
-      errorMessage("No serial port selected...");
752
-         } else {
753
-           worker.downloadState((String)jComboBox1.getSelectedItem());
754
-         }
755
-  }
756
-
757
-  public Led3D get3D() {
758
-    return ledView;
759
-  }
760
-
761
-  public static void main(String[] args) {
762
-    Frame f = new Frame("Cube Control");
763
-  Led3D l = f.get3D();
764
-  java.util.Scanner sc = new java.util.Scanner(System.in);
765
-
766
-  System.out.println("#### Cube Control Debug Console ####");
767
-  System.out.println("## Enter a Command ('h' for help) ##");
768
-  System.out.print("$> ");
769
-
770
-  do {
771
-    if (sc.hasNext()) {
772
-      String s = sc.next();
773
-      
774
-      if (s.equals("p") || (s.equals("print")))
775
-        l.printTranslationData();
776
-
777
-      if (s.equals("q") || s.equals("quit"))
778
-        System.exit(0);
779
-
780
-      if (s.equals("on") || s.equals("1")) {
781
-        short[] d = new short[64];
782
-        for (int i = 0; i < d.length; i++) {
783
-          d[i] = 0xFF;
784
-        }
785
-        l.setData(d);
786
-        System.out.println("All LEDs on now...");
787
-      }
788
-
789
-      if (s.equals("off") || s.equals("0")) {
790
-        short[] d = new short[64];
791
-        for (int i = 0; i < d.length; i++) {
792
-          d[i] = 0x00;
793
-        }
794
-        l.setData(d);
795
-        System.out.println("All LEDs off now...");
796
-      }
797
-
798
-      if (s.equals("h") || (s.equals("help"))) {
799
-        System.out.println("Commands:");
800
-        System.out.println("\t'on'    / '1'\t:\tToggle all LEDs on");
801
-        System.out.println("\t'off'   / '0'\t:\tToggle all LEDs off");
802
-        System.out.println("\t'print' / 'p'\t:\tPrint 3D Translation Matrix Data");
803
-        System.out.println("\t'help'  / 'h'\t:\tShow this message");
804
-        System.out.println("\t'quit'  / 'q'\t:\tExit Cube Control");
805
-      }
806
-
807
-      System.out.print("$> ");
808
-    }
809
-  } while (true);
810
-  }
811
-}

Loading…
Cancel
Save