hutattedonmyarm 12 years ago
parent
commit
037c745a4c
1 changed files with 130 additions and 741 deletions
  1. 130
    741
      Cube Control/layerEditFrame.java

+ 130
- 741
Cube Control/layerEditFrame.java View File

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

Loading…
Cancel
Save