Browse Source

Renamed the Frame.class to AFrame.class to avoid compatibility issues on Windows.

Note: the makefile now won't work! (Yep, I DID change it in there, too!)
Max Nuding 12 years ago
parent
commit
3e013b7594
2 changed files with 260 additions and 260 deletions
  1. 256
    256
      Cube Control/cubeWorker.java
  2. 4
    4
      Cube Control/makefile

+ 256
- 256
Cube Control/cubeWorker.java View File

@@ -45,20 +45,20 @@ public class cubeWorker {
45 45
 // Fields
46 46
 // --------------------
47 47
 
48
-	private ArrayList<Animation> animations = new ArrayList<Animation>();
49
-	private int selectedAnimation = 0;
50
-	private int selectedFrame = 0;
51
-	private int framesRemaining = 2016; // (128 * 1024) / 65 = 2016,...
52
-	private boolean changedState = false;
48
+  private ArrayList<Animation> animations = new ArrayList<Animation>();
49
+  private int selectedAnimation = 0;
50
+  private int selectedFrame = 0;
51
+  private int framesRemaining = 2016; // (128 * 1024) / 65 = 2016,...
52
+  private boolean changedState = false;
53 53
 
54 54
 // --------------------
55 55
 
56 56
   cubeWorker() {
57
-	animations.add(new Animation());
57
+  animations.add(new Animation());
58 58
   }
59 59
 
60 60
   cubeWorker(ArrayList<Animation> anims) {
61
-	  animations = anims;
61
+    animations = anims;
62 62
   }
63 63
 
64 64
 // --------------------
@@ -68,8 +68,8 @@ public class cubeWorker {
68 68
   // Returns how many animations are defined
69 69
     public int numOfAnimations() {
70 70
            return animations.size();
71
-    }   
72
-    
71
+    }
72
+
73 73
     // Returns how many frames are in the current animation
74 74
     public int numOfFrames() {
75 75
            return animations.get(selectedAnimation).size();
@@ -88,145 +88,145 @@ public class cubeWorker {
88 88
   // Selects an animation on wich the animation specific functions operate
89 89
     // Returns -1 if it does not exist, else its index
90 90
     public int selectAnimation(int index) {
91
-		if (animations.size() <= index) {
92
-			return -1;
93
-		} else {
94
-			selectedAnimation = index;
95
-			return index;
96
-		}
91
+    if (animations.size() <= index) {
92
+      return -1;
93
+    } else {
94
+      selectedAnimation = index;
95
+      return index;
96
+    }
97 97
     }
98 98
 
99 99
   // Adds a new Animation
100 100
     // Returns id if ok, -1 if error or not enough space for
101 101
     // another animation
102 102
     public int addAnimation() {
103
-		changedState = true;
104
-		if (framesRemaining <= 0) {
105
-        	return -1;
106
-		} else {
107
-			int s = animations.size();
108
-			animations.add(s + 1, new Animation());
109
-			return s;
110
-		}
111
-    }
112
-    
103
+    changedState = true;
104
+    if (framesRemaining <= 0) {
105
+          return -1;
106
+    } else {
107
+      int s = animations.size();
108
+      animations.add(s + 1, new Animation());
109
+      return s;
110
+    }
111
+    }
112
+
113 113
     // Removes an animation
114 114
     public void removeAnimation() {
115
-		changedState = true;
116
-		animations.remove(selectedAnimation);
117
-		selectedAnimation = 0;
115
+    changedState = true;
116
+    animations.remove(selectedAnimation);
117
+    selectedAnimation = 0;
118 118
     }
119
-    
119
+
120 120
   public String getAnimationName() {
121
-    	return animations.get(selectedAnimation).getName();
121
+      return animations.get(selectedAnimation).getName();
122 122
     }
123 123
 
124 124
   public void setAnimationName(String s) {
125
-	    changedState = true;
126
-		animations.get(selectedAnimation).setName(s);
125
+      changedState = true;
126
+    animations.get(selectedAnimation).setName(s);
127 127
     }
128 128
 
129 129
   public void moveAnimation(int dir) {
130
-	changedState = true;
130
+  changedState = true;
131 131
     if (dir == UP){
132 132
         //animation moved up
133
-    	if (selectedAnimation > 0) {
134
-			Animation tmp = animations.get(selectedAnimation);
135
-			animations.set(selectedAnimation, animations.get(selectedAnimation - 1));
136
-			animations.set(selectedAnimation - 1, tmp);
137
-		}
133
+      if (selectedAnimation > 0) {
134
+      Animation tmp = animations.get(selectedAnimation);
135
+      animations.set(selectedAnimation, animations.get(selectedAnimation - 1));
136
+      animations.set(selectedAnimation - 1, tmp);
137
+    }
138 138
     } else if (dir == DOWN){
139 139
       //animation moved down
140
-		if (selectedAnimation < (animations.size() - 1)) {
141
-			Animation tmp = animations.get(selectedAnimation);
142
-			animations.set(selectedAnimation, animations.get(selectedAnimation + 1));
143
-			animations.set(selectedAnimation + 1, tmp);
144
-		}
140
+    if (selectedAnimation < (animations.size() - 1)) {
141
+      Animation tmp = animations.get(selectedAnimation);
142
+      animations.set(selectedAnimation, animations.get(selectedAnimation + 1));
143
+      animations.set(selectedAnimation + 1, tmp);
144
+    }
145 145
     }
146 146
   }
147 147
 
148 148
 // --------------------
149 149
 // Frame Specific
150 150
 // --------------------
151
-  
151
+
152 152
   // Selects an animation on wich the frame specific functions operate
153 153
     // Returns -1 if it does not exist, else its index
154 154
   public int selectFrame(int index) {
155
-	if (animations.get(selectedAnimation).size() <= index) {
156
-		return -1;
157
-	} else {
158
-		selectedFrame = index;
159
-		return index;
160
-	}
155
+  if (animations.get(selectedAnimation).size() <= index) {
156
+    return -1;
157
+  } else {
158
+    selectedFrame = index;
159
+    return index;
160
+  }
161 161
   }
162 162
 
163 163
   public String getFrameName() {
164
-    	return animations.get(selectedAnimation).get(selectedFrame).getName();
164
+      return animations.get(selectedAnimation).get(selectedFrame).getName();
165 165
     }
166 166
 
167 167
     public void setFrameName(String s) {
168
-		changedState = true;
169
-		animations.get(selectedAnimation).get(selectedFrame).setName(s);
168
+    changedState = true;
169
+    animations.get(selectedAnimation).get(selectedFrame).setName(s);
170 170
     }
171
-    
171
+
172 172
     // Adds a Frame to the current animation.
173 173
     // Returns id if okay, -1 if error
174 174
     public int addFrame() {
175
-		changedState = true;
176
-		if (framesRemaining <= 0) {
177
-			return -1;
178
-		}
179
-		framesRemaining--;
180
-		int s = animations.get(selectedAnimation).size();
181
-		animations.get(selectedAnimation).add(s);
182
-		return s;
183
-    }
184
-    
175
+    changedState = true;
176
+    if (framesRemaining <= 0) {
177
+      return -1;
178
+    }
179
+    framesRemaining--;
180
+    int s = animations.get(selectedAnimation).size();
181
+    animations.get(selectedAnimation).add(s);
182
+    return s;
183
+    }
184
+
185 185
     // Remove the frame
186 186
     public void removeFrame() {
187
-		changedState = true;
188
-		animations.get(selectedAnimation).remove(selectedFrame);
189
-		selectedFrame = 0;
187
+    changedState = true;
188
+    animations.get(selectedAnimation).remove(selectedFrame);
189
+    selectedFrame = 0;
190 190
     }
191
-    
191
+
192 192
     // Returns array with 64 bytes with led values
193 193
     public byte[] getFrame() {
194
-		return animations.get(selectedAnimation).get(selectedFrame).getData();
195
-	}
196
-    
194
+    return animations.get(selectedAnimation).get(selectedFrame).getData();
195
+  }
196
+
197 197
     public void setFrame(byte[] data) {
198
-		changedState = true;
199
-		animations.get(selectedAnimation).get(selectedFrame).setData(data);
198
+    changedState = true;
199
+    animations.get(selectedAnimation).get(selectedFrame).setData(data);
200 200
     }
201 201
 
202
-	// Frame duration in 1/24th of a second
203
-	public byte getFrameTime() {
204
-		return animations.get(selectedAnimation).get(selectedFrame).getTime();
205
-	}
202
+  // Frame duration in 1/24th of a second
203
+  public byte getFrameTime() {
204
+    return animations.get(selectedAnimation).get(selectedFrame).getTime();
205
+  }
206 206
 
207
-	public void setFrameTime(byte time) {
208
-		changedState = true;
209
-		animations.get(selectedAnimation).get(selectedFrame).setTime(time);
210
-	}
207
+  public void setFrameTime(byte time) {
208
+    changedState = true;
209
+    animations.get(selectedAnimation).get(selectedFrame).setTime(time);
210
+  }
211 211
 
212 212
   public void moveFrame(int dir){
213
-	changedState = true;
213
+  changedState = true;
214 214
     if (dir == UP){
215 215
         // frame moved up
216
-      	if (selectedFrame > 0) {
217
-			Frame tmp = animations.get(selectedAnimation).get(selectedFrame);
218
-			animations.get(selectedAnimation).set(animations.get(selectedAnimation).get(selectedFrame - 1), selectedFrame);
219
-			animations.get(selectedAnimation).set(tmp, selectedFrame - 1);
220
-			selectedFrame--;
221
-		}
216
+        if (selectedFrame > 0) {
217
+      AFrame tmp = animations.get(selectedAnimation).get(selectedFrame);
218
+      animations.get(selectedAnimation).set(animations.get(selectedAnimation).get(selectedFrame - 1), selectedFrame);
219
+      animations.get(selectedAnimation).set(tmp, selectedFrame - 1);
220
+      selectedFrame--;
221
+    }
222 222
     } else if (dir == DOWN){
223 223
       // frame moved down
224
-		if (selectedFrame < (animations.get(selectedAnimation).size() - 1)) {
225
-			Frame tmp = animations.get(selectedAnimation).get(selectedFrame);
226
-			animations.get(selectedAnimation).set(animations.get(selectedAnimation).get(selectedFrame + 1), selectedFrame);
227
-			animations.get(selectedAnimation).set(tmp, selectedFrame + 1);
228
-			selectedFrame++;
229
-		}
224
+    if (selectedFrame < (animations.get(selectedAnimation).size() - 1)) {
225
+      AFrame tmp = animations.get(selectedAnimation).get(selectedFrame);
226
+      animations.get(selectedAnimation).set(animations.get(selectedAnimation).get(selectedFrame + 1), selectedFrame);
227
+      animations.get(selectedAnimation).set(tmp, selectedFrame + 1);
228
+      selectedFrame++;
229
+    }
230 230
     }
231 231
   }
232 232
 
@@ -236,19 +236,19 @@ public class cubeWorker {
236 236
 
237 237
     // Loads an animation file into this object
238 238
     public int loadState(String path) {
239
-			changedState = false;
239
+      changedState = false;
240 240
 
241
-    		return 0;
241
+        return 0;
242 242
     }
243
-    
243
+
244 244
     // Saves the state of this object in an animation file
245 245
     public int saveState(String path) {
246 246
            changedState = false;
247
-		   AnimationUtility.writeFile(path, animations);
248
-		   if (AnimationUtility.getLastError() != null) {
249
-			   System.out.println(AnimationUtility.getLastError());
250
-			   return -1;
251
-			}
247
+       AnimationUtility.writeFile(path, animations);
248
+       if (AnimationUtility.getLastError() != null) {
249
+         System.out.println(AnimationUtility.getLastError());
250
+         return -1;
251
+      }
252 252
            return 0;
253 253
     }
254 254
 
@@ -260,19 +260,19 @@ public class cubeWorker {
260 260
 // --------------------
261 261
 // Serial Port Specific
262 262
 // --------------------
263
-    
263
+
264 264
     // sends state of object to led cube
265 265
     public int uploadState(String port) {
266 266
 
267 267
            return 0;
268 268
     }
269
-    
269
+
270 270
     // loads all state from the cube into this object
271 271
     public int downloadState(String port) {
272 272
 
273 273
            return 0;
274 274
     }
275
-        
275
+
276 276
     public String[] getSerialPorts() {
277 277
 
278 278
            String[] sPorts = { "Select serial port..." }; // Has to be the first entry
@@ -284,159 +284,159 @@ public class cubeWorker {
284 284
 }
285 285
 
286 286
 class AnimationUtility {
287
-	private static String lastError = null;
288
-	
289
-	public static ArrayList<Animation> readFile(String path) {
290
-		return null;
291
-	}
292
-
293
-	public static void writeFile(String path, ArrayList<Animation> animations) {
294
-		File f = new File(path);
295
-		if (f.exists()) {
296
-			try {
297
-				f.delete();
298
-			} catch (Exception e) {
299
-				lastError = e.toString();
300
-				return;
301
-			}
302
-		}
303
-		FileWriter output = null;
304
-		try {
305
-			output = new FileWriter(f);
306
-			for (int i = 0; i < animations.size(); i++) {
307
-				writeAnimation(animations.get(i), output);
308
-			}
309
-		} catch (Exception e) {
310
-			lastError = e.toString();
311
-			return;
312
-		} finally {
313
-			if (output != null) {
314
-				try {
315
-					output.close();
316
-				} catch (Exception e) {
317
-					lastError = e.toString();
318
-				}
319
-			}
320
-		}
321
-
322
-	}
323
-
324
-	public static String getLastError() {
325
-		String tmp = lastError;
326
-		lastError = null;
327
-		return tmp;
328
-	}
329
-
330
-	private static void writeAnimation(Animation anim, FileWriter f) throws IOException {
331
-		f.write(anim.getName() + "\n");
332
-		for (int i = 0; i < anim.size(); i++) {
333
-			writeFrame(anim.get(i), f);
334
-		}
335
-		f.write("\n");
336
-	}
337
-
338
-	private static void writeFrame(Frame fr, FileWriter f) throws IOException {
339
-		for (int i = 0; i < 8; i++) {
340
-			writeLayer(fr.getLayer(i), f);
341
-		}
342
-		f.write(Integer.toString( (fr.getTime() & 0xff) + 0x100, 16).substring(1) + "\n");
343
-	}
344
-
345
-	private static void writeLayer(byte[] l, FileWriter f) throws IOException {
346
-		String hex = "";
347
-		for (int i = 0; i < l.length; i++) {
348
-			hex += Integer.toString( (l[i] & 0xff) + 0x100, 16).substring(1);
349
-		}
350
-		hex += "\n";
351
-
352
-		f.write(hex);
353
-	}
287
+  private static String lastError = null;
288
+
289
+  public static ArrayList<Animation> readFile(String path) {
290
+    return null;
291
+  }
292
+
293
+  public static void writeFile(String path, ArrayList<Animation> animations) {
294
+    File f = new File(path);
295
+    if (f.exists()) {
296
+      try {
297
+        f.delete();
298
+      } catch (Exception e) {
299
+        lastError = e.toString();
300
+        return;
301
+      }
302
+    }
303
+    FileWriter output = null;
304
+    try {
305
+      output = new FileWriter(f);
306
+      for (int i = 0; i < animations.size(); i++) {
307
+        writeAnimation(animations.get(i), output);
308
+      }
309
+    } catch (Exception e) {
310
+      lastError = e.toString();
311
+      return;
312
+    } finally {
313
+      if (output != null) {
314
+        try {
315
+          output.close();
316
+        } catch (Exception e) {
317
+          lastError = e.toString();
318
+        }
319
+      }
320
+    }
321
+
322
+  }
323
+
324
+  public static String getLastError() {
325
+    String tmp = lastError;
326
+    lastError = null;
327
+    return tmp;
328
+  }
329
+
330
+  private static void writeAnimation(Animation anim, FileWriter f) throws IOException {
331
+    f.write(anim.getName() + "\n");
332
+    for (int i = 0; i < anim.size(); i++) {
333
+      writeFrame(anim.get(i), f);
334
+    }
335
+    f.write("\n");
336
+  }
337
+
338
+  private static void writeFrame(AFrame fr, FileWriter f) throws IOException {
339
+    for (int i = 0; i < 8; i++) {
340
+      writeLayer(fr.getLayer(i), f);
341
+    }
342
+    f.write(Integer.toString( (fr.getTime() & 0xff) + 0x100, 16).substring(1) + "\n");
343
+  }
344
+
345
+  private static void writeLayer(byte[] l, FileWriter f) throws IOException {
346
+    String hex = "";
347
+    for (int i = 0; i < l.length; i++) {
348
+      hex += Integer.toString( (l[i] & 0xff) + 0x100, 16).substring(1);
349
+    }
350
+    hex += "\n";
351
+
352
+    f.write(hex);
353
+  }
354 354
 }
355 355
 
356
-class Frame {
357
-	private byte[] data = new byte[64];
358
-	private byte duration = 1;
359
-	private String name = "Frame";
360
-	
361
-	String getName() {
362
-		return name;
363
-	}
364
-
365
-	void setName(String s) {
366
-		name = s;
367
-	}
368
-
369
-	void setData(byte[] d) {
370
-		data = d;
371
-	}
372
-
373
-	byte[] getData() {
374
-		return data;
375
-	}
376
-
377
-	void setTime(byte t) {
378
-		duration = t;
379
-	}
380
-
381
-	byte getTime() {
382
-		return duration;
383
-	}
384
-
385
-	byte[] getLayer(int i) {
386
-		return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
387
-	}
356
+class AFrame {
357
+  private byte[] data = new byte[64];
358
+  private byte duration = 1;
359
+  private String name = "Frame";
360
+
361
+  String getName() {
362
+    return name;
363
+  }
364
+
365
+  void setName(String s) {
366
+    name = s;
367
+  }
368
+
369
+  void setData(byte[] d) {
370
+    data = d;
371
+  }
372
+
373
+  byte[] getData() {
374
+    return data;
375
+  }
376
+
377
+  void setTime(byte t) {
378
+    duration = t;
379
+  }
380
+
381
+  byte getTime() {
382
+    return duration;
383
+  }
384
+
385
+  byte[] getLayer(int i) {
386
+    return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
387
+  }
388 388
 }
389 389
 
390 390
 class Animation {
391
-	private ArrayList<Frame> frames = new ArrayList<Frame>();
392
-	private int lastFrameIndex = 0;
393
-	private String name = "Animation";
394
-
395
-	String getName() {
396
-		return name;
397
-	}
398
-
399
-	void setName(String s) {
400
-		name = s;
401
-	}
402
-
403
-	Frame get(int i) {
404
-		try {
405
-			return frames.get(i);
406
-		} catch (IndexOutOfBoundsException e) {
407
-			System.out.println(e.toString());
408
-			return null;
409
-		}
410
-	}
411
-
412
-	void set(Frame f, int i) {
413
-		if (lastFrameIndex <= i) {
414
-			try {
415
-				frames.set(i, f);
416
-			} catch (IndexOutOfBoundsException e) {
417
-				System.out.println(e.toString());
418
-			}
419
-		}
420
-	}
421
-
422
-	void remove(int i) {
423
-		try {
424
-			frames.remove(i);
425
-		} catch (IndexOutOfBoundsException e) {
426
-			System.out.println(e.toString());
427
-		}
428
-	}
429
-
430
-	void add(int i) {
431
-		try {
432
-			frames.add(i, new Frame());
433
-			lastFrameIndex++;
434
-		} catch (IndexOutOfBoundsException e)  {
435
-			System.out.println(e.toString());
436
-		}
437
-	}
438
-
439
-	int size() {
440
-		return frames.size();
441
-	}
442
-}
391
+  private ArrayList<AFrame> frames = new ArrayList<AFrame>();
392
+  private int lastFrameIndex = 0;
393
+  private String name = "Animation";
394
+
395
+  String getName() {
396
+    return name;
397
+  }
398
+
399
+  void setName(String s) {
400
+    name = s;
401
+  }
402
+
403
+  AFrame get(int i) {
404
+    try {
405
+      return frames.get(i);
406
+    } catch (IndexOutOfBoundsException e) {
407
+      System.out.println(e.toString());
408
+      return null;
409
+    }
410
+  }
411
+
412
+  void set(AFrame f, int i) {
413
+    if (lastFrameIndex <= i) {
414
+      try {
415
+        frames.set(i, f);
416
+      } catch (IndexOutOfBoundsException e) {
417
+        System.out.println(e.toString());
418
+      }
419
+    }
420
+  }
421
+
422
+  void remove(int i) {
423
+    try {
424
+      frames.remove(i);
425
+    } catch (IndexOutOfBoundsException e) {
426
+      System.out.println(e.toString());
427
+    }
428
+  }
429
+
430
+  void add(int i) {
431
+    try {
432
+      frames.add(i, new AFrame());
433
+      lastFrameIndex++;
434
+    } catch (IndexOutOfBoundsException e)  {
435
+      System.out.println(e.toString());
436
+    }
437
+  }
438
+
439
+  int size() {
440
+    return frames.size();
441
+  }
442
+}

+ 4
- 4
Cube Control/makefile View File

@@ -1,14 +1,14 @@
1 1
 JAVAC = javac
2 2
 CC = gcc
3
-TARGET = unix
4
-#TARGET = win
3
+#TARGET = unix
4
+TARGET = win
5 5
 
6 6
 JAVAFILES = cubeWorker.java layerEditFrame.java frame.java
7 7
 
8 8
 ifeq ($(TARGET),win)
9
-CLASSES = cubeWorker.class layerEditFrame.class layerEditFrame$$1.class layerEditFrame$$2.class layerEditFrame$$3.class layerEditFrame$$4.class frame.class frame$$1.class frame$$2.class frame$$3.class frame$$4.class frame$$5.class frame$$6.class frame$$7.class frame$$8.class frame$$9.class frame$$10.class frame$$11.class frame$$12.class frame$$13.class frame$$14.class frame$$15.class frame$$16.class frame$$17.class frame$$18.class frame$$19.class frame$$20.class frame$$21.class frame$$22.class MyListSelectionListener.class Frame.class Animation.class LEDoff.png LEDon.png
9
+CLASSES = cubeWorker.class layerEditFrame.class layerEditFrame$$1.class layerEditFrame$$2.class layerEditFrame$$3.class layerEditFrame$$4.class frame.class frame$$1.class frame$$2.class frame$$3.class frame$$4.class frame$$5.class frame$$6.class frame$$7.class frame$$8.class frame$$9.class frame$$10.class frame$$11.class frame$$12.class frame$$13.class frame$$14.class frame$$15.class frame$$16.class frame$$17.class frame$$18.class frame$$19.class frame$$20.class frame$$21.class frame$$22.class MyListSelectionListener.class AFrame.class Animation.class LEDoff.png LEDon.png
10 10
 else
11
-CLASSES = 'cubeWorker.class' 'layerEditFrame.class' 'layerEditFrame$$1.class' 'layerEditFrame$$2.class' 'layerEditFrame$$3.class' 'layerEditFrame$$4.class' 'frame.class' 'frame$$1.class' 'frame$$2.class' 'frame$$3.class' 'frame$$4.class' 'frame$$5.class' 'frame$$6.class' 'frame$$7.class' 'frame$$8.class' 'frame$$9.class' 'frame$$10.class' 'frame$$11.class' 'frame$$12.class' 'frame$$13.class' 'frame$$14.class' 'frame$$15.class' 'frame$$16.class' 'frame$$17.class' 'frame$$18.class' 'frame$$19.class' 'frame$$20.class' 'frame$$21.class' 'frame$$22.class' 'MyListSelectionListener.class' 'Frame.class' 'Animation.class' 'LEDoff.png' 'LEDon.png'
11
+CLASSES = 'cubeWorker.class' 'layerEditFrame.class' 'layerEditFrame$$1.class' 'layerEditFrame$$2.class' 'layerEditFrame$$3.class' 'layerEditFrame$$4.class' 'frame.class' 'frame$$1.class' 'frame$$2.class' 'frame$$3.class' 'frame$$4.class' 'frame$$5.class' 'frame$$6.class' 'frame$$7.class' 'frame$$8.class' 'frame$$9.class' 'frame$$10.class' 'frame$$11.class' 'frame$$12.class' 'frame$$13.class' 'frame$$14.class' 'frame$$15.class' 'frame$$16.class' 'frame$$17.class' 'frame$$18.class' 'frame$$19.class' 'frame$$20.class' 'frame$$21.class' 'frame$$22.class' 'MyListSelectionListener.class' 'AFrame.class' 'Animation.class' 'LEDoff.png' 'LEDon.png'
12 12
 endif
13 13
 
14 14
 all: build clean

Loading…
Cancel
Save