Browse Source

Added the layereditor.

Note: Clicking the LED-Buttons does nothin yet, I don't wanna add 64 methods, and I couldn't figure it out how to do it in one.

Signed-off-by: Max Nuding <the.short.german@gmail.com>
Max Nuding 12 years ago
parent
commit
92121ec045

BIN
Cube Control/LEDoff.png View File


BIN
Cube Control/LEDon.png View File


+ 116
- 62
Cube Control/cubeWorker.java View File

@@ -21,68 +21,115 @@
21 21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22 22
  */
23 23
 
24
+/*
25
+ * This class handles one animation file. This file can contain
26
+ * many animations, but has to be only 1Mbit in size (128*1024 Byte).
27
+ */
28
+
24 29
 public class cubeWorker {
25
-    final int UP = 0;
30
+
31
+// --------------------
32
+// Definitions
33
+// --------------------
34
+
35
+	final int UP = 0;
26 36
     final int DOWN = 1;
27
-    cubeWorker() {
28 37
 
29
-    }
38
+// --------------------
39
+// Fields
40
+// --------------------
30 41
 
31
-    // Adds a new Animation
32
-    // Returns id if ok, -1 if error or not enough space for
33
-    // another animation
34
-    public int addAnimation() {
42
+// --------------------
35 43
 
36
-           return -1;
37
-    }
38
-    
39
-    // Removes an animation
40
-    public void removeAnimation(int index) {
44
+	cubeWorker() {
41 45
 
42 46
     }
43
-    
44
-    // Returns how many animations are defined
47
+
48
+// --------------------
49
+// Misc. Methods
50
+// --------------------
51
+
52
+	// Returns how many animations are defined
45 53
     public int numOfAnimations() {
46 54
 
47 55
            return 3;
48
-    }
56
+    }   
49 57
     
50
-    // Selects an animation, on which the frame specific functions operate
51
-    // Returns -1 if it does not exist
58
+    // Returns how many frames are in the current animation
59
+    public int numOfFrames() {
60
+
61
+           return 3;
62
+    }
63
+
64
+	// Tells how many Frames you can add until you reached 1 Mbit...
65
+    public int framesRemaining() {
66
+
67
+           return 0;
68
+    }
69
+
70
+
71
+// --------------------
72
+// Animation Specific
73
+// --------------------
74
+
75
+	// Selects an animation on wich the animation specific functions operate
76
+    // Returns -1 if it does not exist, else its index
52 77
     public int selectAnimation(int index) {
53
-           System.out.println("Animation " + index + " selected");
54
-           return -1;
78
+           System.out.println("Animation " + index + " selected.");
79
+           
80
+		   return index;
55 81
     }
56
-    
57
-    public String getAnimationName(int index) {
58 82
 
59
-           return "TestAnim";
83
+	// Adds a new Animation
84
+    // Returns id if ok, -1 if error or not enough space for
85
+    // another animation
86
+    public int addAnimation() {
87
+
88
+           return -1;
60 89
     }
61 90
     
62
-    public void setAnimationName(int index, String s) {
91
+    // Removes an animation
92
+    public void removeAnimation() {
63 93
 
64 94
     }
65 95
     
66
-    public void moveAnimation(int dir){
67
-      if (dir == UP){
68
-        //animation moved up
69
-      } else if (dir == DOWN){
70
-        //animation moved down
71
-      }
96
+	public String getAnimationName() {
97
+
98
+           return "TestAnim";
72 99
     }
73
-    
74
-    // Returns how many frames are in the current animation
75
-    public int numOfFrames() {
76 100
 
77
-           return 3;
101
+	public void setAnimationName(String s) {
102
+
78 103
     }
79
-    
80
-    public String getFrameName(int index) {
104
+
105
+	public void moveAnimation(int dir) {
106
+		if (dir == UP){
107
+    		//animation moved up
108
+		
109
+		} else if (dir == DOWN){
110
+			//animation moved down
111
+
112
+		}
113
+	}
114
+
115
+// --------------------
116
+// Frame Specific
117
+// --------------------
118
+	
119
+	// Selects an animation on wich the frame specific functions operate
120
+    // Returns -1 if it does not exist, else its index
121
+	public int selectFrame(int index) {
122
+		System.out.println("Frame " + index + " selected.");
123
+
124
+		return index;
125
+	}
126
+
127
+	public String getFrameName() {
81 128
 
82 129
            return "Test";
83 130
     }
84 131
 
85
-    public void setFrameName(int index, String s) {
132
+    public void setFrameName(String s) {
86 133
 
87 134
     }
88 135
     
@@ -93,29 +140,35 @@ public class cubeWorker {
93 140
            return -1;
94 141
     }
95 142
     
96
-    // Remove a frame
97
-    public void removeFrame(int index) {
143
+    // Remove the frame
144
+    public void removeFrame() {
98 145
 
99 146
     }
100 147
     
101 148
     // Returns array with 64 bytes with led values
102
-    public byte[] getFrame(int index) {
149
+    public byte[] getFrame() {
103 150
 
104 151
            return null;
105 152
     }
106 153
     
107
-    public void setFrame(int index, byte[] data) {
154
+    public void setFrame(byte[] data) {
108 155
 
109 156
     }
110
-    
111
-    public void moveFrame(int dir){
112
-      if (dir == UP){
113
-        //animation moved up
114
-      } else if (dir == DOWN){
115
-        //animation moved down
116
-      }
117
-    }
118
-    
157
+
158
+	public void moveFrame(int dir){
159
+		if (dir == UP){
160
+    		// frame moved up
161
+      
162
+		} else if (dir == DOWN){
163
+			// frame moved down
164
+
165
+		}
166
+	}
167
+
168
+// --------------------
169
+// File Specific
170
+// --------------------
171
+
119 172
     // Loads an animation file into this object
120 173
     public int loadState(String path) {
121 174
 
@@ -127,6 +180,16 @@ public class cubeWorker {
127 180
            System.out.println("Saving to " + path);
128 181
            return 0;
129 182
     }
183
+
184
+	// Returns true if last saved state != current state
185
+    public boolean changedStateSinceSave() {
186
+
187
+           return true;
188
+    }
189
+
190
+// --------------------
191
+// Serial Port Specific
192
+// --------------------
130 193
     
131 194
     // sends state of object to led cube
132 195
     public int uploadState(String port) {
@@ -139,22 +202,13 @@ public class cubeWorker {
139 202
 
140 203
            return 0;
141 204
     }
142
-    
143
-    // Tells how many Frames you can add until you reached 1 Mbit...
144
-    public int framesRemaining() {
145
-
146
-           return 0;
147
-    }
148
-    
205
+        
149 206
     public String[] getSerialPorts() {
150 207
 
151
-           String[] sPorts = {"Select serial port..."};
208
+           String[] sPorts = { "Select serial port..." }; // Has to be the first entry
152 209
            return sPorts;
153 210
     }
154
-    
155
-    // Returns true if last saved state != current state
156
-    public boolean changedStateSinceSave() {
157 211
 
158
-           return true;
159
-    }
212
+// --------------------
213
+
160 214
 }

+ 26
- 25
Cube Control/frame.java View File

@@ -47,9 +47,10 @@ public class frame extends JFrame {
47 47
   private JButton frameDown = new JButton();
48 48
   private JButton frameAdd = new JButton();
49 49
   private JButton frameRemove = new JButton();
50
-  private JList jList2 = new JList();
51
-  private DefaultListModel jList2Model = new DefaultListModel();
52
-  private JScrollPane jList2ScrollPane = new JScrollPane(jList2);
50
+  private JButton frame = new JButton();
51
+  private JList animList = new JList();
52
+  private DefaultListModel animModel = new DefaultListModel();
53
+  private JScrollPane animScrollPane = new JScrollPane(animList);
53 54
   private JButton animUp = new JButton();
54 55
   private JButton animDown = new JButton();
55 56
   private JButton animAdd = new JButton();
@@ -93,10 +94,10 @@ public class frame extends JFrame {
93 94
     }
94 95
     
95 96
     for(int i = 0; i < worker.numOfAnimations(); i++){
96
-      jList2Model.addElement(worker.getAnimationName(i));
97
+      animModel.addElement(worker.getAnimationName());
97 98
     }
98 99
     for(int i = 0; i < worker.numOfFrames(); i++){
99
-      frameListModel.add(i, worker.getFrameName(i));
100
+      frameListModel.add(i, worker.getFrameName());
100 101
     }
101 102
 
102 103
     addWindowListener(new WindowAdapter() {
@@ -245,10 +246,10 @@ public class frame extends JFrame {
245 246
       }
246 247
     });
247 248
 
248
-    jList2ScrollPane.setBounds(8, 264, 209, 121);
249
-    jList2.setModel(jList2Model);
249
+    animScrollPane.setBounds(8, 264, 209, 121);
250
+    animList.setModel(animModel);
250 251
     //jList2Model.addElement("");
251
-    cp.add(jList2ScrollPane);
252
+    cp.add(animScrollPane);
252 253
     animUp.setBounds(224, 264, 99, 25);
253 254
     animUp.setText("Move up");
254 255
     animUp.setFont(new Font("Dialog", Font.PLAIN, 13));
@@ -346,10 +347,10 @@ public class frame extends JFrame {
346 347
     frameRemaining.setText("2048");
347 348
     frameRemaining.setFont(new Font("Dialog", Font.PLAIN, 13));
348 349
     cp.add(frameRemaining);
349
-    jList2.setFont(new Font("Dialog", Font.PLAIN, 13));
350
+    animList.setFont(new Font("Dialog", Font.PLAIN, 13));
350 351
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
351 352
     // Ende Komponenten
352
-    jList2.addListSelectionListener(new MyListSelectionListener(jList2, worker));
353
+    animList.addListSelectionListener(new MyListSelectionListener(animList, worker));
353 354
     setResizable(false);
354 355
     setVisible(true);
355 356
   }
@@ -358,7 +359,7 @@ public class frame extends JFrame {
358 359
 
359 360
   // Anfang Ereignisprozeduren
360 361
   public void editA_ActionPerformed(ActionEvent evt) {
361
-
362
+     layerEditFrame layerFrame1 = new layerEditFrame();
362 363
   }
363 364
 
364 365
   public void editB_ActionPerformed(ActionEvent evt) {
@@ -417,28 +418,28 @@ public class frame extends JFrame {
417 418
   }
418 419
 
419 420
   public void frameRemove_ActionPerformed(ActionEvent evt) {
420
-         worker.removeFrame(jList2.getSelectedIndex());
421
+         worker.removeFrame();
421 422
          frameRemaining.setText(Integer.toString(worker.framesRemaining()));
422 423
   }
423 424
 
424 425
   public void animUp_ActionPerformed(ActionEvent evt) {
425
-         int i = jList2.getSelectedIndex();
426
-         if ((i > 0) && (jList2Model.getSize() >= 2)) {
427
-            Object tmp = jList2Model.get(i);
428
-            jList2Model.set(i, jList2Model.get(i - 1));
429
-            jList2Model.set(i - 1, tmp);
430
-            jList2.setSelectedIndex(i - 1);
426
+         int i = animList.getSelectedIndex();
427
+         if ((i > 0) && (animModel.getSize() >= 2)) {
428
+            Object tmp = animModel.get(i);
429
+            animModel.set(i, animModel.get(i - 1));
430
+            animModel.set(i - 1, tmp);
431
+            animList.setSelectedIndex(i - 1);
431 432
             worker.moveAnimation(worker.UP);
432 433
          }
433 434
   }
434 435
 
435 436
   public void animDown_ActionPerformed(ActionEvent evt) {
436
-         int i = jList2.getSelectedIndex();
437
-         if ((i >= 0) && (jList2Model.getSize() >= 2) && (i < (jList2Model.getSize() - 1))) {
438
-            Object tmp = jList2Model.get(i);
439
-            jList2Model.set(i, jList2Model.get(i + 1));
440
-            jList2Model.set(i + 1, tmp);
441
-            jList2.setSelectedIndex(i + 1);
437
+         int i = animList.getSelectedIndex();
438
+         if ((i >= 0) && (animModel.getSize() >= 2) && (i < (animModel.getSize() - 1))) {
439
+            Object tmp = animModel.get(i);
440
+            animModel.set(i, animModel.get(i + 1));
441
+            animModel.set(i + 1, tmp);
442
+            animList.setSelectedIndex(i + 1);
442 443
             worker.moveAnimation(worker.DOWN);
443 444
          }
444 445
   }
@@ -451,7 +452,7 @@ public class frame extends JFrame {
451 452
   }
452 453
 
453 454
   public void animRemove_ActionPerformed(ActionEvent evt) {
454
-     worker.removeAnimation(jList2.getSelectedIndex());
455
+     worker.removeAnimation();
455 456
   }
456 457
 
457 458
   public void load_ActionPerformed(ActionEvent evt) {

+ 0
- 1032
Cube Control/frame.jfm
File diff suppressed because it is too large
View File


+ 112
- 0
Cube Control/layerEditFrame.java View File

@@ -0,0 +1,112 @@
1
+import java.awt.*;
2
+import java.awt.event.*;
3
+import javax.swing.*;
4
+import javax.swing.event.*;
5
+
6
+/**
7
+  *
8
+  * Beschreibung
9
+  *
10
+  * @version 1.0 vom 11/16/2011
11
+  * @author
12
+  */
13
+
14
+public class layerEditFrame extends JFrame {
15
+  // Anfang Attribute
16
+  private JPanel panelLED1 = new JPanel(null, true);
17
+  public static ImageIcon on = new ImageIcon("LEDon.png");
18
+  public static ImageIcon off = new ImageIcon("LEDoff.png");
19
+  JButton[][] ledPanels = new JButton[8][8];
20
+
21
+  // Ende Attribute
22
+
23
+  public layerEditFrame() {
24
+    // Frame-Initialisierung
25
+    super("Layer Edit");
26
+    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
27
+    int frameWidth = 180;
28
+    int frameHeight = 230;
29
+    setSize(frameWidth, frameHeight);
30
+    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
31
+    int x = (d.width - getSize().width) / 2;
32
+    int y = (d.height - getSize().height) / 2;
33
+    setLocation(x, y);
34
+    setResizable(false);
35
+    Container cp = getContentPane();
36
+    cp.setLayout(null);
37
+
38
+    for(int i = 0; i < 8; i++){
39
+      for(int j = 0; j < 8; j++){
40
+         System.out.println(x);
41
+         System.out.println(y);
42
+         ledPanels[i][j] = new JButton(on);
43
+         ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
44
+         ledPanels[i][j].setVisible(true);
45
+         cp.add(ledPanels[i][j]);
46
+      }
47
+    }
48
+    JButton saveBtn = new JButton("Save");
49
+    JButton cancelBtn = new JButton("Cancel");
50
+    
51
+    saveBtn.setBounds(5, 170, 70, 25);
52
+    saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
53
+    cp.add(saveBtn);
54
+    cancelBtn.setBounds(80, 170, 80, 25);
55
+    cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
56
+    cp.add(cancelBtn);
57
+    setVisible(true);
58
+    
59
+
60
+    
61
+    saveBtn.addActionListener(new ActionListener() {
62
+      public void actionPerformed(ActionEvent evt) {
63
+        save();
64
+      }
65
+    });
66
+
67
+    cancelBtn.addActionListener(new ActionListener() {
68
+      public void actionPerformed(ActionEvent evt) {
69
+        cancel();
70
+      }
71
+    });
72
+
73
+    
74
+    addWindowListener(new WindowAdapter() {
75
+      public void windowClosing(WindowEvent evt) {
76
+
77
+             saveExitDialog();
78
+             dispose();
79
+      }
80
+    });
81
+  }
82
+    // Anfang Komponenten
83
+
84
+    // Ende Komponenten
85
+  /*public void btnClicked(){
86
+    if (getIcon() == on){
87
+      setIcon(off);
88
+    } else {
89
+      setIcon(on);
90
+    }
91
+  } */
92
+
93
+  public void cancel(){
94
+    dispose();
95
+  }
96
+
97
+  
98
+  public void save(){
99
+
100
+  }
101
+
102
+  private int saveExitDialog() {
103
+    String[] Optionen = {"Yes", "No"};
104
+    int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
105
+    if (Auswahl == JOptionPane.YES_OPTION) {
106
+       save();
107
+       return 1;
108
+    } else {
109
+       return 0;
110
+    }
111
+  }
112
+}

+ 56
- 0
Cube Control/layerEditFrame.jfm View File

@@ -0,0 +1,56 @@
1
+object layerEditFrame: TFGUIFormular
2
+  Left = 459
3
+  Top = 62
4
+  BorderIcons = [biSystemMenu, biMinimize]
5
+  Caption = 'layerEditFrame'
6
+  ClientHeight = 396
7
+  ClientWidth = 458
8
+  Color = clBtnFace
9
+  Font.Charset = DEFAULT_CHARSET
10
+  Font.Color = clWindowText
11
+  Font.Height = -10
12
+  Font.Name = 'MS Sans Serif'
13
+  Font.Style = []
14
+  FormStyle = fsMDIChild
15
+  OldCreateOrder = True
16
+  Position = poDesigned
17
+  Visible = True
18
+  OnClose = FormClose
19
+  OnCloseQuery = FormCloseQuery
20
+  OnResize = FormResize
21
+  FrameType = 5
22
+  Resizable = False
23
+  Undecorated = False
24
+  Background = clBtnFace
25
+  PixelsPerInch = 96
26
+  TextHeight = 13
27
+  object panelLED1: TJPanel
28
+    Tag = 12
29
+    Left = 16
30
+    Top = 24
31
+    Width = 57
32
+    Height = 57
33
+    Foreground = 3355443
34
+    Background = 15658734
35
+    Font.Charset = DEFAULT_CHARSET
36
+    Font.Color = clWindowText
37
+    Font.Height = -12
38
+    Font.Name = 'Dialog'
39
+    Font.Style = [fsBold]
40
+    Border.BorderType = NoBorder
41
+    Border.LineColor = clBlack
42
+    Border.LineThickness = 0
43
+    Border.LineRounded = False
44
+    Border.EtchHighlightColor = clBlack
45
+    Border.EtchShadowColor = clBlack
46
+    Border.Etchtype = 0
47
+    Border.BevelHighlightColor = clBlack
48
+    Border.BevelShadowColor = clBlack
49
+    Border.Beveltype = 0
50
+    Border.MatteColor = clBlack
51
+    Border.MatteTop = 0
52
+    Border.MatteLeft = 0
53
+    Border.MatteBottom = 0
54
+    Border.MatteRight = 0
55
+  end
56
+end

Loading…
Cancel
Save