Browse Source

Fixed bugs in frame and created some new ones....

Max Nuding 12 years ago
parent
commit
425a13be14
3 changed files with 119 additions and 90 deletions
  1. 64
    62
      Cube Control/cubeWorker.java
  2. 50
    24
      Cube Control/frame.java
  3. 5
    4
      Cube Control/makefile

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

54
 
54
 
55
   cubeWorker() {
55
   cubeWorker() {
56
   animations.add(new Animation());
56
   animations.add(new Animation());
57
+  animations.get(0).setName("Animation 1");
57
   }
58
   }
58
 
59
 
59
   cubeWorker(ArrayList<Animation> anims) {
60
   cubeWorker(ArrayList<Animation> anims) {
93
           return -1;
94
           return -1;
94
     } else {
95
     } else {
95
       int s = animations.size();
96
       int s = animations.size();
96
-      animations.add(s + 1, new Animation());
97
+      animations.add(s, new Animation());
98
+      animations.get(s).setName("Animation " + animations.size());
97
       return s;
99
       return s;
98
     }
100
     }
99
     }
101
     }
156
     framesRemaining--;
158
     framesRemaining--;
157
     int s = animations.get(anim).size();
159
     int s = animations.get(anim).size();
158
     animations.get(anim).add(s);
160
     animations.get(anim).add(s);
159
-	animations.get(anim).get(s).setName("Frame " + (2016 - framesRemaining));
161
+  animations.get(anim).get(s).setName("Frame " + (2016 - framesRemaining));
160
     return s;
162
     return s;
161
     }
163
     }
162
 
164
 
191
     if (dir == UP){
193
     if (dir == UP){
192
         // frame moved up
194
         // frame moved up
193
         if (frame > 0) {
195
         if (frame > 0) {
194
-      		AFrame tmp = animations.get(anim).get(frame);
195
-      		animations.get(anim).set(animations.get(anim).get(frame - 1), frame);
196
-      		animations.get(anim).set(tmp, frame - 1);
197
-    	}
196
+          AFrame tmp = animations.get(anim).get(frame);
197
+          animations.get(anim).set(animations.get(anim).get(frame - 1), frame);
198
+          animations.get(anim).set(tmp, frame - 1);
199
+      }
198
     } else if (dir == DOWN){
200
     } else if (dir == DOWN){
199
       // frame moved down
201
       // frame moved down
200
     if (frame < (animations.get(anim).size() - 1)) {
202
     if (frame < (animations.get(anim).size() - 1)) {
212
     // Loads an animation file into this object
214
     // Loads an animation file into this object
213
     public int loadState(String path) {
215
     public int loadState(String path) {
214
       changedState = false;
216
       changedState = false;
215
-		try {
216
-			animations = AnimationUtility.readFile(path);
217
-		} catch (Exception e) {
218
-			System.out.println(e.toString());
219
-			return -1;
220
-		}
221
-		int size = 0;
222
-		for (int i = 0; i < animations.size(); i++) {
223
-			size += animations.get(i).size();
224
-		}
225
-		framesRemaining = 2016 - size;
226
-		if (size > 2016) {
227
-			return -1;
228
-		}
217
+    try {
218
+      animations = AnimationUtility.readFile(path);
219
+    } catch (Exception e) {
220
+      System.out.println(e.toString());
221
+      return -1;
222
+    }
223
+    int size = 0;
224
+    for (int i = 0; i < animations.size(); i++) {
225
+      size += animations.get(i).size();
226
+    }
227
+    framesRemaining = 2016 - size;
228
+    if (size > 2016) {
229
+      return -1;
230
+    }
229
         return 0;
231
         return 0;
230
     }
232
     }
231
 
233
 
276
 
278
 
277
   public static ArrayList<Animation> readFile(String path) throws Exception {
279
   public static ArrayList<Animation> readFile(String path) throws Exception {
278
     Scanner sc = new Scanner(new File(path));
280
     Scanner sc = new Scanner(new File(path));
279
-	ArrayList<Animation> animations = new ArrayList<Animation>();
281
+  ArrayList<Animation> animations = new ArrayList<Animation>();
280
 
282
 
281
-	do {
282
-		animations.add(readAnimation(sc));
283
-	} while (sc.hasNextLine());
283
+  do {
284
+    animations.add(readAnimation(sc));
285
+  } while (sc.hasNextLine());
284
 
286
 
285
-	return animations;
287
+  return animations;
286
   }
288
   }
287
 
289
 
288
   public static void writeFile(String path, ArrayList<Animation> animations) {
290
   public static void writeFile(String path, ArrayList<Animation> animations) {
323
   }
325
   }
324
 
326
 
325
   private static Animation readAnimation(Scanner sc) {
327
   private static Animation readAnimation(Scanner sc) {
326
-	Animation anim = new Animation();
327
-	AFrame f = null;
328
-	int index = 0;
329
-	int size = sc.nextInt();
330
-	anim.setName(sc.nextLine());
331
-	while (size > 0) {
332
-		f = readFrame(sc, index);
333
-		anim.add(index);
334
-		anim.set(f, index);
335
-		index++;
336
-		size--;
337
-	}
338
-
339
-	return anim;
328
+  Animation anim = new Animation();
329
+  AFrame f = null;
330
+  int index = 0;
331
+  int size = sc.nextInt();
332
+  anim.setName(sc.nextLine());
333
+  while (size > 0) {
334
+    f = readFrame(sc, index);
335
+    anim.add(index);
336
+    anim.set(f, index);
337
+    index++;
338
+    size--;
339
+  }
340
+
341
+  return anim;
340
   }
342
   }
341
 
343
 
342
   private static AFrame readFrame(Scanner sc, int index) {
344
   private static AFrame readFrame(Scanner sc, int index) {
343
-	AFrame frame = new AFrame();
344
-	frame.setName("Frame " + index);
345
-	byte[] d = {};
346
-	for (int i = 0; i < 8; i++) {
347
-		byte[] data = hexConvert(sc.nextLine());
348
-		d = concat(data, d);
349
-	}
350
-	frame.setData(d);
351
-	d = hexConvert(sc.nextLine());
352
-	frame.setTime(d[0]);
353
-	return frame;
345
+  AFrame frame = new AFrame();
346
+  frame.setName("Frame " + index);
347
+  byte[] d = {};
348
+  for (int i = 0; i < 8; i++) {
349
+    byte[] data = hexConvert(sc.nextLine());
350
+    d = concat(data, d);
351
+  }
352
+  frame.setData(d);
353
+  d = hexConvert(sc.nextLine());
354
+  frame.setTime(d[0]);
355
+  return frame;
354
   }
356
   }
355
 
357
 
356
   private static byte[] concat(byte[] a, byte[] b) {
358
   private static byte[] concat(byte[] a, byte[] b) {
357
-	byte[] c = new byte[a.length + b.length];
358
-	System.arraycopy(a, 0, c, 0, a.length);
359
-	System.arraycopy(b, 0, c, a.length, b.length);
360
-	return c;
359
+  byte[] c = new byte[a.length + b.length];
360
+  System.arraycopy(a, 0, c, 0, a.length);
361
+  System.arraycopy(b, 0, c, a.length, b.length);
362
+  return c;
361
   }
363
   }
362
 
364
 
363
   private static byte[] hexConvert(String hex) {
365
   private static byte[] hexConvert(String hex) {
364
-	hex = hex.replaceAll("\\n", "");
365
-	int length = hex.length();
366
-	byte[] data = new byte[length / 2];
367
-	for (int i = 0; i < length; i += 2) {
368
-		data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
369
-	}
370
-	return data;
366
+  hex = hex.replaceAll("\\n", "");
367
+  int length = hex.length();
368
+  byte[] data = new byte[length / 2];
369
+  for (int i = 0; i < length; i += 2) {
370
+    data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
371
+  }
372
+  return data;
371
   }
373
   }
372
 
374
 
373
   private static void writeAnimation(Animation anim, FileWriter f) throws IOException {
375
   private static void writeAnimation(Animation anim, FileWriter f) throws IOException {
374
     f.write(anim.size() + "\n");
376
     f.write(anim.size() + "\n");
375
-	f.write(anim.getName() + "\n");
377
+  f.write(anim.getName() + "\n");
376
     for (int i = 0; i < anim.size(); i++) {
378
     for (int i = 0; i < anim.size(); i++) {
377
       writeFrame(anim.get(i), f);
379
       writeFrame(anim.get(i), f);
378
     }
380
     }

+ 50
- 24
Cube Control/frame.java View File

98
 
98
 
99
   public void valueChanged(ListSelectionEvent evt) {
99
   public void valueChanged(ListSelectionEvent evt) {
100
     if (!evt.getValueIsAdjusting()) {
100
     if (!evt.getValueIsAdjusting()) {
101
-	   int anim = animList.getSelectedIndex();
102
-	   for (int i = 0; i < worker.numOfFrames(anim); i++) {
103
-		   frameListModel.add(i, worker.getFrameName(anim, i));
104
-		}
105
-		frameList.setModel(frameListModel);
101
+     DefaultListModel model = (DefaultListModel)((JList)evt.getSource()).getModel();
102
+     int anim = animList.getSelectedIndex();
103
+     int max;
104
+     if(evt.getSource() == animList){
105
+       max = worker.numOfAnimations();
106
+       System.out.println(max);
107
+
108
+     } else {
109
+       max = worker.numOfFrames(animList.getSelectedIndex());
110
+
111
+     }
112
+
113
+     if (anim == -1){
114
+        anim = 0;
115
+     }
116
+     model.clear();
117
+     for (int i = 0; i < max; i++) {
118
+       if(evt.getSource() == animList){
119
+          model.add(i, worker.getAnimationName(i));
120
+       } else {
121
+         model.add(i, worker.getFrameName(anim, i));
122
+       }
123
+    }
124
+    frameList.setModel(model);
106
     }
125
     }
107
   }
126
   }
108
 
127
 
460
   }
479
   }
461
 
480
 
462
   public void frameAdd_ActionPerformed(ActionEvent evt) {
481
   public void frameAdd_ActionPerformed(ActionEvent evt) {
463
-         worker.addFrame(animList.getSelectedIndex());
464
-         frameRemaining.setText(Integer.toString(worker.framesRemaining()));
465
-		 int n = worker.numOfFrames(animList.getSelectedIndex()) - 1;
466
-		 if (n < 0) {
467
-			 n = 0;
468
-		 }
469
-		 frameListModel.add(n, worker.getFrameName(animList.getSelectedIndex(), n));
470
-		 frameList.setModel(frameListModel);
482
+         if(animList.getSelectedIndex() == -1){
483
+            errorMessage("Please select an animation!");
484
+         } else {
485
+           worker.addFrame(animList.getSelectedIndex());
486
+           frameRemaining.setText(Integer.toString(worker.framesRemaining()));
487
+           int n = worker.numOfFrames(animList.getSelectedIndex()) - 1;
488
+           if (n < 0) {
489
+              n = 0;
490
+           }
491
+           frameListModel.add(n, worker.getFrameName(animList.getSelectedIndex(), n));
492
+           frameList.setModel(frameListModel);
493
+         }
494
+
471
   }
495
   }
472
 
496
 
473
   public void frameRemove_ActionPerformed(ActionEvent evt) {
497
   public void frameRemove_ActionPerformed(ActionEvent evt) {
474
          worker.removeFrame(animList.getSelectedIndex(), frameList.getSelectedIndex());
498
          worker.removeFrame(animList.getSelectedIndex(), frameList.getSelectedIndex());
475
          frameRemaining.setText(Integer.toString(worker.framesRemaining()));
499
          frameRemaining.setText(Integer.toString(worker.framesRemaining()));
476
-		 frameListModel.removeElementAt(frameList.getSelectedIndex());
477
-		 frameList.setModel(frameListModel);
500
+     frameListModel.removeElementAt(frameList.getSelectedIndex());
501
+     frameList.setModel(frameListModel);
478
   }
502
   }
479
 
503
 
480
   public void animUp_ActionPerformed(ActionEvent evt) {
504
   public void animUp_ActionPerformed(ActionEvent evt) {
503
     if(worker.addAnimation() == -1){
527
     if(worker.addAnimation() == -1){
504
       errorMessage("Could not add animation!");
528
       errorMessage("Could not add animation!");
505
     } else {
529
     } else {
506
-		int n = worker.numOfAnimations() - 1;
507
-		if (n < 0) {
508
-			n = 0;
509
-		}
510
-		animModel.add(n, worker.getAnimationName(n));
511
-		animList.setModel(animModel);
512
-	}
530
+    int n = worker.numOfAnimations() - 1;
531
+    if (n < 0) {
532
+      n = 0;
533
+    }
534
+    animModel.clear();
535
+    System.out.println(n);
536
+    animModel.addElement(worker.getAnimationName(n));
537
+    animList.setModel(animModel);
538
+    }
513
 
539
 
514
   }
540
   }
515
 
541
 
516
   public void animRemove_ActionPerformed(ActionEvent evt) {
542
   public void animRemove_ActionPerformed(ActionEvent evt) {
517
      worker.removeAnimation(animList.getSelectedIndex());
543
      worker.removeAnimation(animList.getSelectedIndex());
518
-	 animModel.removeElementAt(animList.getSelectedIndex());
519
-	 animList.setModel(animModel);
544
+   animModel.removeElementAt(animList.getSelectedIndex());
545
+   animList.setModel(animModel);
520
   }
546
   }
521
 
547
 
522
   public void load_ActionPerformed(ActionEvent evt) {
548
   public void load_ActionPerformed(ActionEvent evt) {

+ 5
- 4
Cube Control/makefile View File

1
 JAVAC = javac
1
 JAVAC = javac
2
 CC = gcc
2
 CC = gcc
3
-TARGET = unix
4
-#TARGET = win
3
+#TARGET = unix
4
+TARGET = win
5
 
5
 
6
 JAVAFILES = cubeWorker.java layerEditFrame.java frame.java
6
 JAVAFILES = cubeWorker.java layerEditFrame.java frame.java
7
 
7
 
34
 	$(CC) -o serialHelper serialHelper.c
34
 	$(CC) -o serialHelper serialHelper.c
35
 
35
 
36
 clean:
36
 clean:
37
-	rm -f *.class
38
 ifeq ($(TARGET),win)
37
 ifeq ($(TARGET),win)
39
-	rm -f serialHelper.exe
38
+	del $(CLASSES)
39
+	del serialHelper.exe
40
 else
40
 else
41
+	rm -f *.class
41
 	rm -f serialHelper
42
 	rm -f serialHelper
42
 endif
43
 endif

Loading…
Cancel
Save