Browse Source

Fixed byte problems in layereditor

Signed-off-by: Max Nuding <the.short.german@gmail.com>
Max Nuding 12 years ago
parent
commit
0f1f771db8
2 changed files with 81 additions and 59 deletions
  1. 35
    33
      Cube Control/frame.java
  2. 46
    26
      Cube Control/layerEditFrame.java

+ 35
- 33
Cube Control/frame.java View File

@@ -9,28 +9,28 @@ import javax.media.j3d.*;
9 9
 import javax.vecmath.*;
10 10
 
11 11
 /*
12
- * frame.java
13
- *
14
- *
15
- * Copyright 2011 Thomas Buck <xythobuz@me.com>
16
- * Copyright 2011 Max Nuding <max.nuding@gmail.com>
17
- * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
18
- *
19
- * This file is part of LED-Cube.
20
- *
21
- * LED-Cube is free software: you can redistribute it and/or modify
22
- * it under the terms of the GNU General Public License as published by
23
- * the Free Software Foundation, either version 3 of the License, or
24
- * (at your option) any later version.
25
- *
26
- * LED-Cube is distributed in the hope that it will be useful,
27
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
- * GNU General Public License for more details.
30
- *
31
- * You should have received a copy of the GNU General Public License
32
- * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
33
- */
12
+* frame.java
13
+*
14
+*
15
+* Copyright 2011 Thomas Buck <xythobuz@me.com>
16
+* Copyright 2011 Max Nuding <max.nuding@gmail.com>
17
+* Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
18
+*
19
+* This file is part of LED-Cube.
20
+*
21
+* LED-Cube is free software: you can redistribute it and/or modify
22
+* it under the terms of the GNU General Public License as published by
23
+* the Free Software Foundation, either version 3 of the License, or
24
+* (at your option) any later version.
25
+*
26
+* LED-Cube is distributed in the hope that it will be useful,
27
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+* GNU General Public License for more details.
30
+*
31
+* You should have received a copy of the GNU General Public License
32
+* along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
33
+*/
34 34
 
35 35
 public class frame extends JFrame implements ListSelectionListener {
36 36
   // Anfang Variablen
@@ -154,7 +154,7 @@ public class frame extends JFrame implements ListSelectionListener {
154 154
     for(int i = 0; i < sPorts.length; i++){
155 155
       jComboBox1.addItem(sPorts[i]);
156 156
     }
157
-    
157
+
158 158
     for(int i = 0; i < worker.numOfAnimations(); i++){
159 159
       animModel.addElement(worker.getAnimationName(i));
160 160
     }
@@ -171,7 +171,7 @@ public class frame extends JFrame implements ListSelectionListener {
171 171
              System.exit(0);
172 172
       }
173 173
     });
174
-    int frameWidth = 661; 
174
+    int frameWidth = 661;
175 175
     int frameHeight = 417;
176 176
     setSize(frameWidth, frameHeight);
177 177
     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
@@ -198,9 +198,9 @@ public class frame extends JFrame implements ListSelectionListener {
198 198
     branchgroup = new BranchGroup();
199 199
     branchgroup.addChild(transroot);
200 200
     universe.addBranchGraph(branchgroup);
201
-    
202
-    
203
-    
201
+
202
+
203
+
204 204
     //-------------
205 205
 
206 206
     editA.setBounds(264, 8, 107, 25);
@@ -354,12 +354,12 @@ public class frame extends JFrame implements ListSelectionListener {
354 354
         frameRemove_ActionPerformed(evt);
355 355
       }
356 356
     });
357
-    
357
+
358 358
     frmLngthLbl.setBounds(536, 160, 113, 24);
359 359
     frmLngthLbl.setText("Length of a frame");
360 360
     frmLngthLbl.setFont(new Font("Dialog", Font.PLAIN, 13));
361 361
     cp.add(frmLngthLbl);
362
-    
362
+
363 363
     frmLngthTxt.setBounds(536, 184, 113, 24);
364 364
     frmLngthTxt.setText("0");
365 365
     frmLngthTxt.setFont(new Font("Dialog", Font.PLAIN, 13));
@@ -511,11 +511,11 @@ public class frame extends JFrame implements ListSelectionListener {
511 511
   }
512 512
 
513 513
   public void editB_ActionPerformed(ActionEvent evt) {
514
-     // layerEditFrame layerFrame1 = new layerEditFrame(worker.getLayer(1));
514
+     layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 1, worker);
515 515
   }
516 516
 
517 517
   public void editC_ActionPerformed(ActionEvent evt) {
518
-    // layerEditFrame layerFrame1 = new layerEditFrame(worker.getLayer(2));
518
+    layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 2, worker);
519 519
   }
520 520
 
521 521
   public void editD_ActionPerformed(ActionEvent evt) {
@@ -612,8 +612,8 @@ public class frame extends JFrame implements ListSelectionListener {
612 612
     int n = worker.numOfAnimations() - 1;
613 613
     // would have 0 anims after successfully adding one...
614 614
   /*if (n < 0) {
615
-      n = 0;
616
-    }*/
615
+n = 0;
616
+}*/
617 617
     animModel.clear();
618 618
     for (int i = 0; i < (n + 1); i++) {
619 619
         animModel.add(i, worker.getAnimationName(i));
@@ -708,3 +708,5 @@ public class frame extends JFrame implements ListSelectionListener {
708 708
   // Ende Methoden
709 709
 }
710 710
 
711
+
712
+

+ 46
- 26
Cube Control/layerEditFrame.java View File

@@ -4,12 +4,12 @@ import javax.swing.*;
4 4
 import javax.swing.event.*;
5 5
 
6 6
 /**
7
-  *
8
-  * Beschreibung
9
-  *
10
-  * @version 1.0 vom 11/16/2011
11
-  * @author
12
-  */
7
+*
8
+* Beschreibung
9
+*
10
+* @version 1.0 vom 11/16/2011
11
+* @author
12
+*/
13 13
 
14 14
 public class layerEditFrame extends JFrame {
15 15
   // Anfang Attribute
@@ -19,7 +19,7 @@ public class layerEditFrame extends JFrame {
19 19
   ImageIcon off = new ImageIcon(getClass().getResource("LEDoff.png"));
20 20
   byte[][] ledStatus = new byte[8][8];
21 21
   boolean changedStateSinceSave = false;
22
-  byte[] frame;
22
+  short[] frame;
23 23
   int li;
24 24
   boolean finish = false;
25 25
   cubeWorker worker = null;
@@ -30,11 +30,11 @@ public class layerEditFrame extends JFrame {
30 30
 
31 31
   public layerEditFrame(int animIndex, int frameIndex, int layerIndex, cubeWorker work) {
32 32
     // Frame-Initialisierung
33
-	super("Layer Edit");
34
-	worker = work;
35
-	animI = animIndex;
36
-	frameI = frameIndex;
37
-    frame = worker.getFrame(animIndex, frameIndex);
33
+    super("Layer Edit");
34
+    worker = work;
35
+    animI = animIndex;
36
+    frameI = frameIndex;
37
+    frame =  byteToShortArray(worker.getFrame(animIndex, frameIndex));
38 38
     li = layerIndex;
39 39
     setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
40 40
     int frameWidth = 180;
@@ -66,7 +66,7 @@ public class layerEditFrame extends JFrame {
66 66
     loadData();
67 67
     JButton saveBtn = new JButton("Save");
68 68
     JButton cancelBtn = new JButton("Cancel");
69
-    
69
+
70 70
     saveBtn.setBounds(5, 170, 70, 25);
71 71
     saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
72 72
     cp.add(saveBtn);
@@ -74,9 +74,9 @@ public class layerEditFrame extends JFrame {
74 74
     cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
75 75
     cp.add(cancelBtn);
76 76
     setVisible(true);
77
-    
78 77
 
79
-    
78
+
79
+
80 80
     saveBtn.addActionListener(new ActionListener() {
81 81
       public void actionPerformed(ActionEvent evt) {
82 82
         save();
@@ -89,7 +89,7 @@ public class layerEditFrame extends JFrame {
89 89
       }
90 90
     });
91 91
 
92
-    
92
+
93 93
     addWindowListener(new WindowAdapter() {
94 94
       public void windowClosing(WindowEvent evt) {
95 95
              if(changedStateSinceSave){
@@ -128,10 +128,10 @@ public class layerEditFrame extends JFrame {
128 128
   }
129 129
 
130 130
    byte[] getFinalFrame(){
131
-	 if (finish == false) {
132
-		 return null;
133
-	 }
134
-	 return frame;
131
+      if (finish == false) {
132
+        return null;
133
+      }
134
+      return shortToByteArray(frame);
135 135
    }
136 136
 
137 137
   public void btnClicked(int i, int j){
@@ -150,23 +150,40 @@ public class layerEditFrame extends JFrame {
150 150
     dispose();
151 151
   }
152 152
 
153
-  
153
+
154 154
   public void save(){
155 155
     int ctr = 0;
156
-    byte[] tmpFrame = new byte[64];
156
+    short[] tmpFrame = new short[64];
157 157
     changedStateSinceSave = false;
158
-    int reihe = 0;
158
+    short reihe = 0;
159 159
     for(int j = 0; j < 8; j++){
160 160
       for(int i = 0; i < 8; i++){
161
-        reihe += ((int) Math.pow(2, i)) * ledStatus[i][j];
161
+        reihe += ((short) Math.pow(2, i)) * ledStatus[i][j];
162 162
         ctr++;
163 163
       }
164
-      tmpFrame[j] = (byte)reihe;
164
+      tmpFrame[j] = reihe;
165 165
       reihe = 0;
166 166
     }
167 167
       frame = tmpFrame;
168
+      worker.setFrame(shortToByteArray(frame), animI, frameI);
168 169
       dispose();
169
-	  worker.setFrame(frame, animI, frameI);
170
+  }
171
+  
172
+  public byte[] shortToByteArray(short[] shrt){
173
+     byte[] tmpByte = new byte[shrt.length];
174
+     short min = 128;
175
+     for(int i = 0; i < tmpByte.length; i++){
176
+       tmpByte[i] = (byte) (shrt[i] - min);
177
+     }
178
+     return tmpByte;
179
+  }
180
+  
181
+  public short[] byteToShortArray(byte[] tmpByte){
182
+     short[] tmpShrt = new short[tmpByte.length];
183
+     for(int i = 0; i < tmpByte.length; i++){
184
+       tmpShrt[i] = (short) (tmpByte[i] + 128);
185
+     }
186
+     return tmpShrt;
170 187
   }
171 188
 
172 189
   private int saveExitDialog() {
@@ -180,3 +197,6 @@ public class layerEditFrame extends JFrame {
180 197
     }
181 198
   }
182 199
 }
200
+
201
+
202
+

Loading…
Cancel
Save