Browse Source

Cleaned up internal api

Thomas Buck 12 years ago
parent
commit
8e665acd4a

+ 4
- 43
CubeControl/AFrame.java View File

@@ -32,50 +32,10 @@ import java.util.Arrays;
32 32
  * @version 1.0
33 33
  */
34 34
 
35
-public class AFrame implements Comparable<AFrame> {
35
+public class AFrame {
36 36
 	private short[] data = new short[64];
37 37
 	private short duration = 1;
38 38
 	private String name = "Frame";
39
-	private int order;
40
-	private static int orderIndex = 0;
41
-
42
-	/**
43
-	 * Compare this frame to another frame.
44
-	 * Compares the order in the frame list.
45
-	 * @return 0 if equal, -1 if this one comes first, 1 if last
46
-	 */
47
-	public int compareTo(AFrame compareFrame) {
48
-		if (getOrder() < compareFrame.getOrder()) {
49
-			return -1;
50
-		} else if (getOrder() == compareFrame.getOrder()) {
51
-			return 0;
52
-		} else {
53
-			return 1;
54
-		} 
55
-	}
56
-
57
-	/**
58
-	 * Get index of frame in list of frames.
59
-	 * @return index
60
-	 */
61
-	public int getOrder() {
62
-		return order;
63
-	}
64
-
65
-	/**
66
-	 * Set index of frame in list of frames.
67
-	 * @param newOrder new index
68
-	 */
69
-	public void setOrder(int newOrder) {
70
-		order = newOrder;
71
-	}
72
-
73
-	/**
74
-	 * Inserts frane at end of frame list.
75
-	 */
76
-	public AFrame() {
77
-		order = orderIndex++;
78
-	}
79 39
 
80 40
 	/**
81 41
 	 * Gets the Name of this Frame
@@ -83,7 +43,7 @@ public class AFrame implements Comparable<AFrame> {
83 43
 	 * @return Name of the Frame
84 44
 	 */
85 45
 	public String getName() {
86
-		return name + " (" + order + ")";
46
+		return name;
87 47
 	}
88 48
 
89 49
 	/**
@@ -125,7 +85,8 @@ public class AFrame implements Comparable<AFrame> {
125 85
 	}
126 86
 
127 87
 	/**
128
-	 * Gets the Duration of this Frame
88
+	 * Gets the Duration of this Frame.
89
+	 * 0 means (1/24) seconds.
129 90
 	 * 
130 91
 	 * @return Duration of frame.
131 92
 	 * @see AFrame#setTime(short) setTime()

+ 92
- 102
CubeControl/Animation.java View File

@@ -33,99 +33,94 @@ import java.util.Collections;
33 33
  * @version 1.0
34 34
  */
35 35
 
36
-public class Animation implements Comparable<Animation> {
37
-	List<AFrame> frames = new ArrayList<AFrame>();
38
-	private int lastFrameIndex = 0;
36
+public class Animation {
37
+	AFrame frames[] = new AFrame[1];
39 38
 	private String name = "Animation";
40
-	private int order;
41
-	private static int orderIndex = 0;
42 39
 
43 40
 	/**
44
-	 * Compare this animation to another animation.
45
-	 * Compares the order in the animations list.
46
-	 * @return 0 if equal, -1 if this one comes first, 1 if last
41
+	 * Create an empty frame in this new animation.
47 42
 	 */
48
-	public int compareTo(Animation compareAnimation) {
49
-		if (getOrder() < compareAnimation.getOrder()) {
50
-			return -1;
51
-		} else if (getOrder() == compareAnimation.getOrder()) {
52
-			return 0;
53
-		} else {
54
-			return 1;
55
-		} 
43
+	public Animation() {
44
+		frames[0] = new AFrame();
56 45
 	}
57 46
 
58 47
 	/**
59
-	 * Get index of animation in list of animations.
60
-	 * @return index
48
+	 * Gets the specified frame in this animation
49
+	 * 
50
+	 * @param i Index of frame you want
51
+	 * @return The selected frame
61 52
 	 */
62
-	public int getOrder() {
63
-		return order;
53
+	public AFrame getFrame(int i) {
54
+		if (i >= frames.length) {
55
+			return null;
56
+		} else {
57
+			return frames[i];
58
+		}
64 59
 	}
65 60
 
66 61
 	/**
67
-	 * Set index of animation in list of animations.
68
-	 * @param newOrder new index
62
+	 * Move an frame up.
63
+	 * @param i the animation you want to move
69 64
 	 */
70
-	public void setOrder(int newOrder) {
71
-		order = newOrder;
65
+	public void moveFrameUp(int i) {
66
+		if (i > 0) {
67
+			AFrame tmp = frames[i];
68
+			frames[i] = frames[i - 1];
69
+			frames[i - 1] = tmp;
70
+		}
72 71
 	}
73 72
 
74 73
 	/**
75
-	 * Inserts animation at end of animation list.
74
+	 * Move an frame down.
75
+	 * @param i the animation you want to move
76 76
 	 */
77
-	public Animation() {
78
-		order = orderIndex++;
77
+	public void moveFrameDown(int i) {
78
+		if (i < (frames.length - 1)) {
79
+			AFrame tmp = frames[i];
80
+			frames[i] = frames[i + 1];
81
+			frames[i + 1] = tmp;
82
+		}
79 83
 	}
80 84
 
81 85
 	/**
82
-	 * Gets the name of this animation
86
+	 * Sets the selected Frame
83 87
 	 * 
84
-	 * @return name of this animation
88
+	 * @param f the frame you want to place in this animation
89
+	 * @param i Index of the frame you want to override
85 90
 	 */
86
-	public String getName() {
87
-		return name + " (" + order + ")";
91
+	public void setFrame(AFrame f, int i) {
92
+		if (i < frames.length) {
93
+			frames[i] = f;
94
+		} else {
95
+			addFrame(f);
96
+		}
88 97
 	}
89 98
 
90 99
 	/**
91
-	 * Sets the name of this animation
92
-	 * 
93
-	 * @param s
94
-	 *            new name
100
+	 * Add a new (empty) frame at the end
95 101
 	 */
96
-	public void setName(String s) {
97
-		name = s;
102
+	public void addFrame() {
103
+		extendArray();
104
+		frames[frames.length - 1] = new AFrame();
98 105
 	}
99 106
 
100 107
 	/**
101
-	 * Gets the specified frame in this animation
102
-	 * 
103
-	 * @param i Index of frame you want
104
-	 * @return The selected frame
108
+	 * Add a specified frame at the end
109
+	 *
110
+	 * @param f data for new frame
105 111
 	 */
106
-	public AFrame get(int i) {
107
-		try {
108
-			return frames.get(i);
109
-		} catch (IndexOutOfBoundsException e) {
110
-			System.out.println(e.toString());
111
-			return null;
112
-		}
112
+	public void addFrame(AFrame f) {
113
+		addFrame();
114
+		frames[frames.length - 1] = f;
113 115
 	}
114 116
 
115 117
 	/**
116
-	 * Sets the selected Frame
118
+	 * Return size of this animation, in number of frames.
117 119
 	 * 
118
-	 * @param f the frame you want to place in this animation
119
-	 * @param i Index of the frame you want to override
120
+	 * @return number of frames
120 121
 	 */
121
-	public void set(AFrame f, int i) {
122
-		if (lastFrameIndex <= i) {
123
-			try {
124
-				frames.set(i, f);
125
-			} catch (IndexOutOfBoundsException e) {
126
-				System.out.println(e.toString());
127
-			}
128
-		}
122
+	public int size() {
123
+		return frames.length;
129 124
 	}
130 125
 
131 126
 	/**
@@ -133,65 +128,60 @@ public class Animation implements Comparable<Animation> {
133 128
 	 * 
134 129
 	 * @param i Index of frame you want to remove
135 130
 	 */
136
-	public void remove(int i) {
137
-		try {
138
-			frames.remove(i);
139
-		} catch (IndexOutOfBoundsException e) {
140
-			System.out.println(e.toString());
141
-		}
131
+	public void removeFrame(int i) {
132
+		shiftOver(i);
133
+		shrinkArray();
142 134
 	}
143 135
 
144 136
 	/**
145
-	 * Add a new (empty) frame at the specified position
137
+	 * Gets the name of this animation
146 138
 	 * 
147
-	 * @param i Index you want to place the new frame in
148
-	 * @see Animation#size size()
139
+	 * @return name of this animation
149 140
 	 */
150
-	public void add(int i) {
151
-		try {
152
-			frames.add(i, new AFrame());
153
-			lastFrameIndex++;
154
-		} catch (IndexOutOfBoundsException e) {
155
-			System.out.println(e.toString());
156
-		}
141
+	public String getName() {
142
+		return name;
157 143
 	}
158 144
 
159 145
 	/**
160
-	 * Add a specified frame at the specified position
146
+	 * Sets the name of this animation
161 147
 	 * 
162
-	 * @param i Index for new frame
163
-	 * @param f data for new frame
148
+	 * @param s
149
+	 *            new name
164 150
 	 */
165
-	public void add(int i, AFrame f) {
166
-		try {
167
-			frames.add(i, f);
168
-			lastFrameIndex++;
169
-		} catch (IndexOutOfBoundsException e) {
170
-			System.out.println(e.toString());
151
+	public void setName(String s) {
152
+		name = s;
153
+	}
154
+
155
+	private void extendArray() {
156
+		AFrame newArray[] = new AFrame[frames.length + 1];
157
+		for (int i = 0; i < frames.length; i++) {
158
+			newArray[i] = frames[i];
171 159
 		}
160
+		frames = newArray;
172 161
 	}
173 162
 
174
-	// return true if damaged and fixed partially
175
-	private boolean checkFrameList() {
176
-		for (int i = 0; i < frames.size(); i++) {
177
-			if (frames.get(i).getOrder() != i) {
178
-				frames.get(i).setOrder(frames.size());
179
-				return true;
180
-			}
163
+	private void shrinkArray() {
164
+		AFrame newArray[] = new AFrame[frames.length - 1];
165
+		for (int i = 0; i < newArray.length; i++) {
166
+			newArray[i] = frames[i];
181 167
 		}
182
-		return false;
168
+		frames = newArray;
183 169
 	}
184 170
 
185
-	/**
186
-	 * Return size of this animation, in number of frames.
187
-	 * Also fixes the order of the frame list, if needed.
188
-	 * 
189
-	 * @return number of frames
190
-	 */
191
-	public int size() {
192
-		while(checkFrameList()) {
193
-			Collections.sort(frames);
171
+	/* private void shiftSpace(int newFree) {
172
+		AFrame temp = null;
173
+		for (int i = newFree; i < (frames.length - 1); i++) {
174
+			// Max i: vorletztes element
175
+			AFrame tmp = frames[i];
176
+			frames[i] = temp;
177
+			temp = frames[i + 1];
178
+			frames[i + 1] = tmp;
179
+		}
180
+	} */
181
+
182
+	private void shiftOver(int toForget) {
183
+		for (int i = (toForget + 1); i < frames.length; i++) {
184
+			frames[i - 1] = frames[i];
194 185
 		}
195
-		return frames.size();
196 186
 	}
197 187
 }

+ 18
- 11
CubeControl/AnimationUtility.java View File

@@ -46,9 +46,9 @@ public class AnimationUtility {
46 46
 	 * @return Populated ArrayList
47 47
 	 * @throws Excpetion When something goes wrong with the Scanner...
48 48
 	 */
49
-	public static List<Animation> readFile(String path) throws Exception {
49
+	public static Animation[] readFile(String path) throws Exception {
50 50
 		Scanner sc = new Scanner(new File(path));
51
-		List<Animation> animations = new ArrayList<Animation>();
51
+		Animation[] animations = new Animation[0];
52 52
 		do {
53 53
 			Animation tmp = readAnimation(sc);
54 54
 			if (tmp == null) {
@@ -57,20 +57,29 @@ public class AnimationUtility {
57 57
 			if (sc.hasNextLine()) {
58 58
 				sc.nextLine();
59 59
 			}
60
-			animations.add(tmp);
60
+			extendArray(animations);
61
+			animations[animations.length - 1] = tmp;
61 62
 		} while (sc.hasNextLine());
62 63
 
63 64
 		return animations;
64 65
 	}
65 66
 
67
+	private static void extendArray(Animation[] animations) {
68
+		Animation newArray[] = new Animation[animations.length + 1];
69
+		for (int i = 0; i < animations.length; i++) {
70
+			newArray[i] = animations[i];
71
+		}
72
+		animations = newArray;
73
+	}
74
+
66 75
 	/**
67 76
 	 * Write a file with all Animations of an ArrayList
68 77
 	 * 
69 78
 	 * @param path Path to write to
70
-	 * @param animations ArrayList with all animations to be saved
79
+	 * @param animations Array with all animations to be saved
71 80
 	 * @see AnimationUtility#getLastError() getLastError()
72 81
 	 */
73
-	public static void writeFile(String path, List<Animation> animations) {
82
+	public static void writeFile(String path, Animation[] animations) {
74 83
 		File f = new File(path);
75 84
 		if (f.exists()) {
76 85
 			try {
@@ -83,9 +92,8 @@ public class AnimationUtility {
83 92
 		FileWriter output = null;
84 93
 		try {
85 94
 			output = new FileWriter(f);
86
-			for (int i = 0; i < animations.size(); i++) {
87
-				writeAnimation(animations.get(i), output,
88
-						(i == (animations.size() - 1)));
95
+			for (int i = 0; i < animations.length; i++) {
96
+				writeAnimation(animations[i], output, (i == (animations.length - 1)));
89 97
 			}
90 98
 		} catch (Exception e) {
91 99
 			lastError = e.toString();
@@ -106,7 +114,6 @@ public class AnimationUtility {
106 114
 	 * Get the last error that occured while writing
107 115
 	 * 
108 116
 	 * @return Text of the exception that occured
109
-	 * @see AnimationUtility#writeFile(String, List) writeFile()
110 117
 	 */
111 118
 	public static String getLastError() {
112 119
 		String tmp = lastError;
@@ -127,7 +134,7 @@ public class AnimationUtility {
127 134
 		anim.setName(sc.nextLine());
128 135
 		while (size > 0) {
129 136
 			f = readFrame(sc, index);
130
-			anim.add(index, f);
137
+			anim.setFrame(f, index);
131 138
 			index++;
132 139
 			size--;
133 140
 		}
@@ -187,7 +194,7 @@ public class AnimationUtility {
187 194
 		f.write(anim.size() + "\n");
188 195
 		f.write(anim.getName() + "\n");
189 196
 		for (int i = 0; i < anim.size(); i++) {
190
-			writeFrame(anim.get(i), f);
197
+			writeFrame(anim.getFrame(i), f);
191 198
 		}
192 199
 		if (!last) {
193 200
 			f.write("\n");

+ 271
- 410
CubeControl/Frame.java View File

@@ -83,6 +83,7 @@ public class Frame extends JFrame implements ListSelectionListener {
83 83
 
84 84
 	public cubeWorker worker = new cubeWorker(this);
85 85
 	private boolean fileSelected = false;
86
+	private Frame thisFrame;
86 87
 
87 88
 	// Ende Variablen
88 89
 
@@ -125,25 +126,22 @@ public class Frame extends JFrame implements ListSelectionListener {
125 126
 					&& (animList.getSelectedIndex() != -1)) {
126 127
 				// animList selection changed, update frameList
127 128
 				frameListModel.clear();
128
-				for (int i = 0; i < worker.numOfFrames(animList
129
-						.getSelectedIndex()); i++) {
130
-				// Offending statement:
131
-				// worker.numOfFrames(animList.getSelectedIndex())
132
-					frameListModel.addElement(worker.getFrameName(
133
-							animList.getSelectedIndex(), i));
129
+
130
+				// System.out.println("Selected Animation: " + animList.getSelectedIndex());
131
+				int max = worker.getAnimation(animList.getSelectedIndex()).size();
132
+
133
+				for (int i = 0; i < max; i++) {
134
+					frameListModel.addElement(worker.getAnimation(
135
+							animList.getSelectedIndex()).getFrame(i).getName());
134 136
 				}
135 137
 				frameList.setModel(frameListModel);
136 138
 			}
137 139
 
138 140
 			// If both selections are valid, update Frame duration and set 3D
139 141
 			// data
140
-			if ((animList.getSelectedIndex() != -1)
141
-					&& (frameList.getSelectedIndex() != -1)) {
142
-				ledView.setData(worker.getFrame(animList.getSelectedIndex(),
143
-						frameList.getSelectedIndex()));
144
-				frameLengthText.setText(Integer.toString(worker.getFrameTime(
145
-						animList.getSelectedIndex(),
146
-						frameList.getSelectedIndex())));
142
+			if ((animList.getSelectedIndex() != -1)	&& (frameList.getSelectedIndex() != -1)) {
143
+				ledView.setData(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getData());
144
+				frameLengthText.setText(Integer.toString(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime()));
147 145
 			} else {
148 146
 				// clear Frame duration
149 147
 				frameLengthText.setText("");
@@ -169,15 +167,16 @@ public class Frame extends JFrame implements ListSelectionListener {
169 167
 	public Frame(String title) {
170 168
 		// Frame-Initialisierung
171 169
 		super(title);
170
+		thisFrame = this;
172 171
 		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
173 172
 
174
-		String[] sPorts = worker.getSerialPorts();
173
+		String[] sPorts = HelperUtility.getPorts();
175 174
 		for (int i = 0; i < sPorts.length; i++) {
176 175
 			jComboBox1.addItem(sPorts[i]);
177 176
 		}
178 177
 
179
-		for (int i = 0; i < worker.numOfAnimations(); i++) {
180
-			animModel.addElement(worker.getAnimationName(i));
178
+		for (int i = 0; i < worker.size(); i++) {
179
+			animModel.addElement(worker.getAnimation(i).getName());
181 180
 		}
182 181
 
183 182
 		addWindowListener(new WindowAdapter() {
@@ -216,7 +215,13 @@ public class Frame extends JFrame implements ListSelectionListener {
216 215
 		cp.add(editA);
217 216
 		editA.addActionListener(new ActionListener() {
218 217
 			public void actionPerformed(ActionEvent evt) {
219
-				editA_ActionPerformed(evt);
218
+				if (animList.getSelectedIndex() == -1) {
219
+					errorMessage("Please select an animation.");
220
+				} else if (frameList.getSelectedIndex() == -1) {
221
+					errorMessage("Please select a Frame.");
222
+				} else {
223
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 0, worker, thisFrame);
224
+				}
220 225
 			}
221 226
 		});
222 227
 
@@ -226,7 +231,13 @@ public class Frame extends JFrame implements ListSelectionListener {
226 231
 		cp.add(editB);
227 232
 		editB.addActionListener(new ActionListener() {
228 233
 			public void actionPerformed(ActionEvent evt) {
229
-				editB_ActionPerformed(evt);
234
+				if (animList.getSelectedIndex() == -1) {
235
+					errorMessage("Please select an animation.");
236
+				} else if (frameList.getSelectedIndex() == -1) {
237
+					errorMessage("Please select a Frame.");
238
+				} else {
239
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 1, worker, thisFrame);
240
+				}
230 241
 			}
231 242
 		});
232 243
 
@@ -236,7 +247,13 @@ public class Frame extends JFrame implements ListSelectionListener {
236 247
 		cp.add(editC);
237 248
 		editC.addActionListener(new ActionListener() {
238 249
 			public void actionPerformed(ActionEvent evt) {
239
-				editC_ActionPerformed(evt);
250
+				if (animList.getSelectedIndex() == -1) {
251
+					errorMessage("Please select an animation.");
252
+				} else if (frameList.getSelectedIndex() == -1) {
253
+					errorMessage("Please select a Frame.");
254
+				} else {
255
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 2, worker, thisFrame);
256
+				}
240 257
 			}
241 258
 		});
242 259
 
@@ -246,7 +263,13 @@ public class Frame extends JFrame implements ListSelectionListener {
246 263
 		cp.add(editD);
247 264
 		editD.addActionListener(new ActionListener() {
248 265
 			public void actionPerformed(ActionEvent evt) {
249
-				editD_ActionPerformed(evt);
266
+				if (animList.getSelectedIndex() == -1) {
267
+					errorMessage("Please select an animation.");
268
+				} else if (frameList.getSelectedIndex() == -1) {
269
+					errorMessage("Please select a Frame.");
270
+				} else {
271
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 3, worker, thisFrame);
272
+				}
250 273
 			}
251 274
 		});
252 275
 
@@ -256,7 +279,13 @@ public class Frame extends JFrame implements ListSelectionListener {
256 279
 		cp.add(editE);
257 280
 		editE.addActionListener(new ActionListener() {
258 281
 			public void actionPerformed(ActionEvent evt) {
259
-				editE_ActionPerformed(evt);
282
+				if (animList.getSelectedIndex() == -1) {
283
+					errorMessage("Please select an animation.");
284
+				} else if (frameList.getSelectedIndex() == -1) {
285
+					errorMessage("Please select a Frame.");
286
+				} else {
287
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 4, worker, thisFrame);
288
+				}
260 289
 			}
261 290
 		});
262 291
 
@@ -266,7 +295,13 @@ public class Frame extends JFrame implements ListSelectionListener {
266 295
 		cp.add(editF);
267 296
 		editF.addActionListener(new ActionListener() {
268 297
 			public void actionPerformed(ActionEvent evt) {
269
-				editF_ActionPerformed(evt);
298
+				if (animList.getSelectedIndex() == -1) {
299
+					errorMessage("Please select an animation.");
300
+				} else if (frameList.getSelectedIndex() == -1) {
301
+					errorMessage("Please select a Frame.");
302
+				} else {
303
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 5, worker, thisFrame);
304
+				}
270 305
 			}
271 306
 		});
272 307
 
@@ -276,7 +311,13 @@ public class Frame extends JFrame implements ListSelectionListener {
276 311
 		cp.add(editG);
277 312
 		editG.addActionListener(new ActionListener() {
278 313
 			public void actionPerformed(ActionEvent evt) {
279
-				editG_ActionPerformed(evt);
314
+				if (animList.getSelectedIndex() == -1) {
315
+					errorMessage("Please select an animation.");
316
+				} else if (frameList.getSelectedIndex() == -1) {
317
+					errorMessage("Please select a Frame.");
318
+				} else {
319
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 6, worker, thisFrame);
320
+				}
280 321
 			}
281 322
 		});
282 323
 
@@ -286,7 +327,13 @@ public class Frame extends JFrame implements ListSelectionListener {
286 327
 		cp.add(editH);
287 328
 		editH.addActionListener(new ActionListener() {
288 329
 			public void actionPerformed(ActionEvent evt) {
289
-				editH_ActionPerformed(evt);
330
+				if (animList.getSelectedIndex() == -1) {
331
+					errorMessage("Please select an animation.");
332
+				} else if (frameList.getSelectedIndex() == -1) {
333
+					errorMessage("Please select a Frame.");
334
+				} else {
335
+					layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 7, worker, thisFrame);
336
+				}
290 337
 			}
291 338
 		});
292 339
 
@@ -300,7 +347,14 @@ public class Frame extends JFrame implements ListSelectionListener {
300 347
 		cp.add(frameUp);
301 348
 		frameUp.addActionListener(new ActionListener() {
302 349
 			public void actionPerformed(ActionEvent evt) {
303
-				frameUp_ActionPerformed(evt);
350
+				int i = frameList.getSelectedIndex();
351
+				if ((i > 0) && (frameListModel.getSize() >= 2)) {
352
+					Object tmp = frameListModel.get(i);
353
+					frameListModel.set(i, frameListModel.get(i - 1));
354
+					frameListModel.set(i - 1, tmp);
355
+					frameList.setSelectedIndex(i - 1);
356
+					worker.getAnimation(animList.getSelectedIndex()).moveFrameUp(frameList.getSelectedIndex());
357
+				}
304 358
 			}
305 359
 		});
306 360
 
@@ -310,7 +364,16 @@ public class Frame extends JFrame implements ListSelectionListener {
310 364
 		cp.add(frameAdd);
311 365
 		frameAdd.addActionListener(new ActionListener() {
312 366
 			public void actionPerformed(ActionEvent evt) {
313
-				frameAdd_ActionPerformed(evt);
367
+				if (animList.getSelectedIndex() == -1) {
368
+					errorMessage("Please select an animation!");
369
+				} else {
370
+					int n = worker.getAnimation(animList.getSelectedIndex()).size();
371
+					worker.getAnimation(animList.getSelectedIndex()).addFrame();
372
+			// Not reaching past this comment if frame list empty
373
+					frameRemaining.setText(Integer.toString(worker.memoryRemaining()));
374
+					frameListModel.add(n, worker.getAnimation(animList.getSelectedIndex()).getFrame(n).getName());
375
+					frameList.setModel(frameListModel);
376
+				}
314 377
 			}
315 378
 		});
316 379
 
@@ -320,7 +383,16 @@ public class Frame extends JFrame implements ListSelectionListener {
320 383
 		cp.add(frameRemove);
321 384
 		frameRemove.addActionListener(new ActionListener() {
322 385
 			public void actionPerformed(ActionEvent evt) {
323
-				frameRemove_ActionPerformed(evt);
386
+				if (animList.getSelectedIndex() == -1) {
387
+					errorMessage("Select an animation.");
388
+				} else if (frameList.getSelectedIndex() == -1) {
389
+					errorMessage("Select a Frame.");
390
+				} else {
391
+					worker.getAnimation(animList.getSelectedIndex()).removeFrame(frameList.getSelectedIndex());
392
+					frameRemaining.setText(Integer.toString(worker.memoryRemaining()));
393
+					frameListModel.removeElementAt(frameList.getSelectedIndex());
394
+					frameList.setModel(frameListModel);
395
+				}
324 396
 			}
325 397
 		});
326 398
 
@@ -340,11 +412,8 @@ public class Frame extends JFrame implements ListSelectionListener {
340 412
 					errorMessage("Select a Frame!");
341 413
 					return;
342 414
 				}
343
-				worker.setFrameName(
344
-						askString("Rename",
345
-								"Rename " + frameList.getSelectedValue() + "?"),
346
-						a, f);
347
-				frameListModel.set(f, worker.getFrameName(a, f));
415
+				worker.getAnimation(a).getFrame(f).setName(askString("Rename", "Rename " + frameList.getSelectedValue() + "?"));
416
+				frameListModel.set(f, worker.getAnimation(a).getFrame(f).getName());
348 417
 				frameList.setModel(frameListModel);
349 418
 			}
350 419
 		});
@@ -355,7 +424,14 @@ public class Frame extends JFrame implements ListSelectionListener {
355 424
 		cp.add(frameDown);
356 425
 		frameDown.addActionListener(new ActionListener() {
357 426
 			public void actionPerformed(ActionEvent evt) {
358
-				frameDown_ActionPerformed(evt);
427
+				int i = frameList.getSelectedIndex();
428
+				if ((i >= 0) && (frameListModel.getSize() >= 2) && (i < (frameListModel.getSize() - 1))) {
429
+					Object tmp = frameListModel.get(i);
430
+					frameListModel.set(i, frameListModel.get(i + 1));
431
+					frameListModel.set(i + 1, tmp);
432
+					frameList.setSelectedIndex(i + 1);
433
+					worker.getAnimation(animList.getSelectedIndex()).moveFrameDown(frameList.getSelectedIndex());
434
+				}
359 435
 			}
360 436
 		});
361 437
 
@@ -375,7 +451,14 @@ public class Frame extends JFrame implements ListSelectionListener {
375 451
 		cp.add(fullScreenButton);
376 452
 		fullScreenButton.addActionListener(new ActionListener() {
377 453
 			public void actionPerformed(ActionEvent evt) {
378
-				enterFullscreen(evt);
454
+				ledView.enterFullscreen();
455
+				setLocation(0,0);
456
+				setSize(700, 700);
457
+				int w = Toolkit.getDefaultToolkit().getScreenSize().width;
458
+				int h = Toolkit.getDefaultToolkit().getScreenSize().height;
459
+				setSize(w - 5, h - 30);
460
+				playAnimationFullscreen.setVisible(true);
461
+				cubeCanvas.setBounds(0, 0, w - 5, h - 80);
379 462
 			}
380 463
 		});
381 464
 
@@ -384,18 +467,40 @@ public class Frame extends JFrame implements ListSelectionListener {
384 467
 		cp.add(exitButton);
385 468
 		exitButton.addActionListener(new ActionListener() {
386 469
 			public void actionPerformed(ActionEvent evt) {
387
-				exitFullscreen();
470
+				playAnimationFullscreen.setVisible(false);
471
+				setLocation(0,0);
472
+				setSize(661, 440);
473
+				ledView.leaveFullscreen();
474
+				cubeCanvas.setBounds(8,8, 250,250);
475
+				Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
476
+				int x = (d.width - getSize().width) / 2;
477
+				int y = (d.height - getSize().height) / 2;
478
+				setLocation(x, y);
388 479
 			}
389 480
 		});
390 481
 
391
-
392 482
 		playAnimation.setText("Play");
393 483
 		playAnimation.setBounds(344, 390, 147, 25);
394 484
 		playAnimation.setFont(new Font("Dialog", Font.PLAIN, 13));
395 485
 		cp.add(playAnimation);
396 486
 		playAnimation.addActionListener(new ActionListener() {
397 487
 			public void actionPerformed(ActionEvent evt){
398
-				playAnimation(evt);		
488
+				if (animList.getSelectedIndex() == -1) {
489
+					errorMessage("Please select an animation.");
490
+				} else if (frameList.getSelectedIndex() == -1) {
491
+					errorMessage("Please select a Frame.");
492
+				} else {
493
+					for(int i = 0; i < frameList.getModel().getSize(); i++){
494
+						frameList.setSelectedIndex(i);
495
+						short time1 = worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime();
496
+						long time = (long) (((time1+1) * 1/24) * 1000);
497
+						try {
498
+							Thread.sleep(time);
499
+						} catch(Exception e) {
500
+							System.out.println(e);
501
+						}
502
+					}	
503
+				}
399 504
 			}
400 505
 		});
401 506
 
@@ -406,11 +511,25 @@ public class Frame extends JFrame implements ListSelectionListener {
406 511
 		cp.add(playAnimationFullscreen);
407 512
 		playAnimationFullscreen.addActionListener(new ActionListener() {
408 513
 			public void actionPerformed(ActionEvent evt){
409
-				playAnimation(evt);		
514
+				if (animList.getSelectedIndex() == -1) {
515
+					errorMessage("Please select an animation.");
516
+				} else if (frameList.getSelectedIndex() == -1) {
517
+					errorMessage("Please select a Frame.");
518
+				} else {
519
+					for(int i = 0; i < frameList.getModel().getSize(); i++){
520
+						frameList.setSelectedIndex(i);
521
+						short time1 = worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime();
522
+						long time = (long) (((time1+1) * 1/24) * 1000);
523
+						try {
524
+							Thread.sleep(time);
525
+						} catch(Exception e) {
526
+							System.out.println(e);
527
+						}
528
+					}	
529
+				}
410 530
 			}
411 531
 		});
412 532
 
413
-
414 533
 		frameDuration.setBounds(590, 184, 60, 24);
415 534
 		frameDuration.setText("OK");
416 535
 		frameDuration.setFont(new Font("Dialog", Font.PLAIN, 13));
@@ -433,10 +552,7 @@ public class Frame extends JFrame implements ListSelectionListener {
433 552
 						errorMessage("Please select a Frame!");
434 553
 						return;
435 554
 					}
436
-					worker.setFrameTime(
437
-							(byte) (Integer.parseInt(frameLengthText.getText()) - 1),
438
-							animList.getSelectedIndex(),
439
-							frameList.getSelectedIndex());
555
+					worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).setTime((byte)(Integer.parseInt(frameLengthText.getText()) - 1));
440 556
 				}
441 557
 			}
442 558
 		});
@@ -452,7 +568,14 @@ public class Frame extends JFrame implements ListSelectionListener {
452 568
 		cp.add(animUp);
453 569
 		animUp.addActionListener(new ActionListener() {
454 570
 			public void actionPerformed(ActionEvent evt) {
455
-				animUp_ActionPerformed(evt);
571
+				int i = animList.getSelectedIndex();
572
+				if ((i > 0) && (animModel.getSize() >= 2)) {
573
+					Object tmp = animModel.get(i);
574
+					animModel.set(i, animModel.get(i - 1));
575
+					animModel.set(i - 1, tmp);
576
+					animList.setSelectedIndex(i - 1);
577
+					worker.moveAnimationUp(animList.getSelectedIndex());
578
+				}
456 579
 			}
457 580
 		});
458 581
 
@@ -462,7 +585,14 @@ public class Frame extends JFrame implements ListSelectionListener {
462 585
 		cp.add(animDown);
463 586
 		animDown.addActionListener(new ActionListener() {
464 587
 			public void actionPerformed(ActionEvent evt) {
465
-				animDown_ActionPerformed(evt);
588
+				int i = animList.getSelectedIndex();
589
+				if ((i >= 0) && (animModel.getSize() >= 2) && (i < (animModel.getSize() - 1))) {
590
+					Object tmp = animModel.get(i);
591
+					animModel.set(i, animModel.get(i + 1));
592
+					animModel.set(i + 1, tmp);
593
+					animList.setSelectedIndex(i + 1);
594
+					worker.moveAnimationDown(animList.getSelectedIndex());
595
+				}
466 596
 			}
467 597
 		});
468 598
 
@@ -477,11 +607,8 @@ public class Frame extends JFrame implements ListSelectionListener {
477 607
 					errorMessage("Select an animation!");
478 608
 					return;
479 609
 				}
480
-				worker.setAnimationName(
481
-						askString("Rename",
482
-								"Rename " + animList.getSelectedValue() + "?"),
483
-						a);
484
-				animModel.set(a, worker.getAnimationName(a));
610
+				worker.getAnimation(a).setName(askString("Rename", "Rename " + animList.getSelectedValue() + "?"));
611
+				animModel.set(a, worker.getAnimation(a).getName());
485 612
 				animList.setModel(animModel);
486 613
 			}
487 614
 		});
@@ -492,7 +619,15 @@ public class Frame extends JFrame implements ListSelectionListener {
492 619
 		cp.add(animAdd);
493 620
 		animAdd.addActionListener(new ActionListener() {
494 621
 			public void actionPerformed(ActionEvent evt) {
495
-				animAdd_ActionPerformed(evt);
622
+				if (worker.addAnimation() == -1) {
623
+					errorMessage("Could not add animation!");
624
+				} else {
625
+					animModel.clear();
626
+					for (int i = 0; i < worker.size(); i++) {
627
+						animModel.add(i, worker.getAnimation(i).getName());
628
+					}
629
+					animList.setModel(animModel);
630
+				}
496 631
 			}
497 632
 		});
498 633
 
@@ -502,7 +637,13 @@ public class Frame extends JFrame implements ListSelectionListener {
502 637
 		cp.add(animRemove);
503 638
 		animRemove.addActionListener(new ActionListener() {
504 639
 			public void actionPerformed(ActionEvent evt) {
505
-				animRemove_ActionPerformed(evt);
640
+				if (animList.getSelectedIndex() == -1) {
641
+					errorMessage("Select an animation.");
642
+				} else {
643
+					worker.removeAnimation(animList.getSelectedIndex());
644
+					animModel.removeElementAt(animList.getSelectedIndex());
645
+					animList.setModel(animModel);
646
+				}
506 647
 			}
507 648
 		});
508 649
 
@@ -517,7 +658,24 @@ public class Frame extends JFrame implements ListSelectionListener {
517 658
 		cp.add(load);
518 659
 		load.addActionListener(new ActionListener() {
519 660
 			public void actionPerformed(ActionEvent evt) {
520
-				load_ActionPerformed(evt);
661
+				JFileChooser fc = new JFileChooser();
662
+				int ret = fc.showOpenDialog(thisFrame);
663
+				if (ret == JFileChooser.APPROVE_OPTION) {
664
+					File file = fc.getSelectedFile();
665
+					if (fileSelected == false) {
666
+						fileSelected = true;
667
+					}
668
+					animPath.setText(file.getPath());
669
+					worker.loadState(animPath.getText());
670
+					animModel.clear();
671
+					for (int i = 0; i < worker.size(); i++) {
672
+						animModel.addElement(worker.getAnimation(i).getName());
673
+					}
674
+					animList.setModel(animModel);
675
+
676
+					frameListModel.clear();
677
+					frameList.setModel(frameListModel);
678
+				}
521 679
 			}
522 680
 		});
523 681
 
@@ -527,7 +685,18 @@ public class Frame extends JFrame implements ListSelectionListener {
527 685
 		cp.add(save);
528 686
 		save.addActionListener(new ActionListener() {
529 687
 			public void actionPerformed(ActionEvent evt) {
530
-				save_ActionPerformed(evt);
688
+				if (fileSelected == false) {
689
+					JFileChooser fc = new JFileChooser();
690
+					int ret = fc.showSaveDialog(thisFrame);
691
+					if (ret == JFileChooser.APPROVE_OPTION) {
692
+						File file = fc.getSelectedFile();
693
+						fileSelected = true;
694
+						animPath.setText(file.getPath());
695
+						worker.saveState(animPath.getText());
696
+					}
697
+				} else {
698
+					worker.saveState(animPath.getText());
699
+				}
531 700
 			}
532 701
 		});
533 702
 
@@ -537,7 +706,21 @@ public class Frame extends JFrame implements ListSelectionListener {
537 706
 		cp.add(saveAs);
538 707
 		saveAs.addActionListener(new ActionListener() {
539 708
 			public void actionPerformed(ActionEvent evt) {
540
-				saveAs_ActionPerformed(evt);
709
+				JFileChooser fc;
710
+				if (fileSelected == true) {
711
+					fc = new JFileChooser(new File(animPath.getText()).getParentFile());
712
+				} else {
713
+					fc = new JFileChooser();
714
+				}
715
+				int ret = fc.showSaveDialog(thisFrame);
716
+				if (ret == JFileChooser.APPROVE_OPTION) {
717
+					File file = fc.getSelectedFile();
718
+					if (fileSelected == false) {
719
+						fileSelected = true;
720
+					}
721
+					animPath.setText(file.getPath());
722
+					worker.saveState(animPath.getText());
723
+				}
541 724
 			}
542 725
 		});
543 726
 
@@ -550,7 +733,17 @@ public class Frame extends JFrame implements ListSelectionListener {
550 733
 		cp.add(upload);
551 734
 		upload.addActionListener(new ActionListener() {
552 735
 			public void actionPerformed(ActionEvent evt) {
553
-				upload_ActionPerformed(evt);
736
+				if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
737
+					// errorMessage("No serial port selected...");
738
+				} else {
739
+					if (worker.cubeProbeConnected((String) jComboBox1.getSelectedItem())) {
740
+						if (worker.cubeSendState((String) jComboBox1.getSelectedItem()) != 0) {
741
+							// errorMessage("Could not upload data!");
742
+						}
743
+					} else {
744
+						// errorMessage("Cube does not respond...");
745
+					}
746
+				}
554 747
 			}
555 748
 		});
556 749
 
@@ -560,7 +753,17 @@ public class Frame extends JFrame implements ListSelectionListener {
560 753
 		cp.add(download);
561 754
 		download.addActionListener(new ActionListener() {
562 755
 			public void actionPerformed(ActionEvent evt) {
563
-				download_ActionPerformed(evt);
756
+				if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
757
+					// errorMessage("No serial port selected...");
758
+				} else {
759
+					if (worker.cubeProbeConnected((String) jComboBox1.getSelectedItem())) {
760
+						if (worker.cubeGetState((String) jComboBox1.getSelectedItem()) != 0) {
761
+							// errorMessage("Could not download data!");
762
+						}
763
+					} else {
764
+						// errorMessage("Cube does not respond...");
765
+					}
766
+				}
564 767
 			}
565 768
 		});
566 769
 
@@ -570,7 +773,7 @@ public class Frame extends JFrame implements ListSelectionListener {
570 773
 		cp.add(jLabel4);
571 774
 		frameRemaining.setBounds(536, 232, 113, 24);
572 775
 		frameRemaining.setEditable(false);
573
-		frameRemaining.setText(String.valueOf(worker.framesRemaining()));
776
+		frameRemaining.setText(String.valueOf(worker.memoryRemaining()));
574 777
 		frameRemaining.setFont(new Font("Dialog", Font.PLAIN, 13));
575 778
 		cp.add(frameRemaining);
576 779
 		animList.setFont(new Font("Dialog", Font.PLAIN, 13));
@@ -582,348 +785,6 @@ public class Frame extends JFrame implements ListSelectionListener {
582 785
 		setVisible(true);
583 786
 	}
584 787
 
585
-	// Anfang Methoden
586
-
587
-	// Anfang Ereignisprozeduren
588
-	
589
-	public void playAnimation(ActionEvent evt){
590
-			if (animList.getSelectedIndex() == -1) {
591
-			errorMessage("Please select an animation.");
592
-		} else if (frameList.getSelectedIndex() == -1) {
593
-			errorMessage("Please select a Frame.");
594
-		} else {
595
-			for(int i = 0; i < frameList.getModel().getSize(); i++){
596
-				frameList.setSelectedIndex(i);
597
-				short time1 = worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex());
598
-				long time = (long) (((time1+1) * 1/24) * 1000);
599
-				try{
600
-					Thread.sleep(time);
601
-				}catch(Exception e){
602
-					System.out.println(e);
603
-				}
604
-			}	
605
-		}
606
-	
607
-	}
608
-	
609
-	public void enterFullscreen(ActionEvent evt) {
610
-		ledView.enterFullscreen();
611
-		//FullscreenWindow fw = new FullscreenWindow(worker, cubeCanvas, ledView, this);
612
-		setLocation(0,0);
613
-		setSize(700, 700);
614
-		int w = Toolkit.getDefaultToolkit().getScreenSize().width;
615
-		int h = Toolkit.getDefaultToolkit().getScreenSize().height;
616
-		System.out.println(w);
617
-		System.out.println(h);
618
-		setSize(w-5, h-30);
619
-
620
-		playAnimationFullscreen.setVisible(true);
621
-		//setSize(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
622
-		//Y U NO WORK????
623
-		cubeCanvas.setBounds(0,0,Toolkit.getDefaultToolkit().getScreenSize().width-5, Toolkit.getDefaultToolkit().getScreenSize().height-80);
624
-	
625
-	}
626
-	public void exitFullscreen(){
627
-	//661, 440
628
-		playAnimationFullscreen.setVisible(false);
629
-		setLocation(0,0);
630
-		setSize(661, 440);
631
-		ledView.leaveFullscreen();
632
-		cubeCanvas.setBounds(8,8, 250,250);
633
-		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
634
-		int x = (d.width - getSize().width) / 2;
635
-		int y = (d.height - getSize().height) / 2;
636
-		setLocation(x, y);
637
-	}
638
-	
639
-	public void editA_ActionPerformed(ActionEvent evt) {
640
-
641
-		if (animList.getSelectedIndex() == -1) {
642
-			errorMessage("Please select an animation.");
643
-		} else if (frameList.getSelectedIndex() == -1) {
644
-			errorMessage("Please select a Frame.");
645
-		} else {
646
-			@SuppressWarnings("unused")
647
-			layerEditFrame layerFrame1 = new layerEditFrame(
648
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
649
-					0, worker, this);
650
-
651
-		}
652
-	}
653
-
654
-	public void editB_ActionPerformed(ActionEvent evt) {
655
-		if (animList.getSelectedIndex() == -1) {
656
-			errorMessage("Please select an animation.");
657
-		} else if (frameList.getSelectedIndex() == -1) {
658
-			errorMessage("Please select a Frame.");
659
-		} else {
660
-			@SuppressWarnings("unused")
661
-			layerEditFrame layerFrame1 = new layerEditFrame(
662
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
663
-					1, worker, this);
664
-		}
665
-	}
666
-
667
-	public void editC_ActionPerformed(ActionEvent evt) {
668
-		if (animList.getSelectedIndex() == -1) {
669
-			errorMessage("Please select an animation.");
670
-		} else if (frameList.getSelectedIndex() == -1) {
671
-			errorMessage("Please select a Frame.");
672
-		} else {
673
-			@SuppressWarnings("unused")
674
-			layerEditFrame layerFrame1 = new layerEditFrame(
675
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
676
-					2, worker, this);
677
-		}
678
-	}
679
-
680
-	public void editD_ActionPerformed(ActionEvent evt) {
681
-		if (animList.getSelectedIndex() == -1) {
682
-			errorMessage("Please select an animation.");
683
-		} else if (frameList.getSelectedIndex() == -1) {
684
-			errorMessage("Please select a Frame.");
685
-		} else {
686
-			@SuppressWarnings("unused")
687
-			layerEditFrame layerFrame1 = new layerEditFrame(
688
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
689
-					3, worker, this);
690
-		}
691
-	}
692
-
693
-	public void editE_ActionPerformed(ActionEvent evt) {
694
-		if (animList.getSelectedIndex() == -1) {
695
-			errorMessage("Please select an animation.");
696
-		} else if (frameList.getSelectedIndex() == -1) {
697
-			errorMessage("Please select a Frame.");
698
-		} else {
699
-			@SuppressWarnings("unused")
700
-			layerEditFrame layerFrame1 = new layerEditFrame(
701
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
702
-					4, worker, this);
703
-		}
704
-	}
705
-
706
-	public void editF_ActionPerformed(ActionEvent evt) {
707
-		if (animList.getSelectedIndex() == -1) {
708
-			errorMessage("Please select an animation.");
709
-		} else if (frameList.getSelectedIndex() == -1) {
710
-			errorMessage("Please select a Frame.");
711
-		} else {
712
-			@SuppressWarnings("unused")
713
-			layerEditFrame layerFrame1 = new layerEditFrame(
714
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
715
-					5, worker, this);
716
-		}
717
-	}
718
-
719
-	public void editG_ActionPerformed(ActionEvent evt) {
720
-		if (animList.getSelectedIndex() == -1) {
721
-			errorMessage("Please select an animation.");
722
-		} else if (frameList.getSelectedIndex() == -1) {
723
-			errorMessage("Please select a Frame.");
724
-		} else {
725
-			@SuppressWarnings("unused")
726
-			layerEditFrame layerFrame1 = new layerEditFrame(
727
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
728
-					6, worker, this);
729
-		}
730
-	}
731
-
732
-	public void editH_ActionPerformed(ActionEvent evt) {
733
-		if (animList.getSelectedIndex() == -1) {
734
-			errorMessage("Please select an animation.");
735
-		} else if (frameList.getSelectedIndex() == -1) {
736
-			errorMessage("Please select a Frame.");
737
-		} else {
738
-			@SuppressWarnings("unused")
739
-			layerEditFrame layerFrame1 = new layerEditFrame(
740
-					animList.getSelectedIndex(), frameList.getSelectedIndex(),
741
-					7, worker, this);
742
-		}
743
-	}
744
-
745
-	public void frameUp_ActionPerformed(ActionEvent evt) {
746
-		int i = frameList.getSelectedIndex();
747
-		if ((i > 0) && (frameListModel.getSize() >= 2)) {
748
-			Object tmp = frameListModel.get(i);
749
-			frameListModel.set(i, frameListModel.get(i - 1));
750
-			frameListModel.set(i - 1, tmp);
751
-			frameList.setSelectedIndex(i - 1);
752
-			worker.moveFrame(worker.UP, animList.getSelectedIndex(),
753
-					frameList.getSelectedIndex());
754
-		}
755
-	}
756
-
757
-	public void frameDown_ActionPerformed(ActionEvent evt) {
758
-		int i = frameList.getSelectedIndex();
759
-		if ((i >= 0) && (frameListModel.getSize() >= 2)
760
-				&& (i < (frameListModel.getSize() - 1))) {
761
-			Object tmp = frameListModel.get(i);
762
-			frameListModel.set(i, frameListModel.get(i + 1));
763
-			frameListModel.set(i + 1, tmp);
764
-			frameList.setSelectedIndex(i + 1);
765
-			worker.moveFrame(worker.DOWN, animList.getSelectedIndex(),
766
-					frameList.getSelectedIndex());
767
-		}
768
-	}
769
-
770
-	public void frameAdd_ActionPerformed(ActionEvent evt) {
771
-		if (animList.getSelectedIndex() == -1) {
772
-			errorMessage("Please select an animation!");
773
-		} else {
774
-			int n = worker.numOfFrames(animList.getSelectedIndex());
775
-			worker.addFrame(animList.getSelectedIndex());
776
-			// Not reaching past this comment if frame list empty
777
-			frameRemaining.setText(Integer.toString(worker.framesRemaining()));
778
-			frameListModel.add(n,
779
-					worker.getFrameName(animList.getSelectedIndex(), n));
780
-			frameList.setModel(frameListModel);
781
-		}
782
-	}
783
-
784
-	public void frameRemove_ActionPerformed(ActionEvent evt) {
785
-		if (animList.getSelectedIndex() == -1) {
786
-			errorMessage("Select an animation.");
787
-		} else if (frameList.getSelectedIndex() == -1) {
788
-			errorMessage("Select a Frame.");
789
-		} else {
790
-			worker.removeFrame(animList.getSelectedIndex(),
791
-					frameList.getSelectedIndex());
792
-			frameRemaining.setText(Integer.toString(worker.framesRemaining()));
793
-			frameListModel.removeElementAt(frameList.getSelectedIndex());
794
-			frameList.setModel(frameListModel);
795
-		}
796
-	}
797
-
798
-	public void animUp_ActionPerformed(ActionEvent evt) {
799
-		int i = animList.getSelectedIndex();
800
-		if ((i > 0) && (animModel.getSize() >= 2)) {
801
-			Object tmp = animModel.get(i);
802
-			animModel.set(i, animModel.get(i - 1));
803
-			animModel.set(i - 1, tmp);
804
-			animList.setSelectedIndex(i - 1);
805
-			worker.moveAnimation(worker.UP, animList.getSelectedIndex());
806
-		}
807
-	}
808
-
809
-	public void animDown_ActionPerformed(ActionEvent evt) {
810
-		int i = animList.getSelectedIndex();
811
-		if ((i >= 0) && (animModel.getSize() >= 2)
812
-				&& (i < (animModel.getSize() - 1))) {
813
-			Object tmp = animModel.get(i);
814
-			animModel.set(i, animModel.get(i + 1));
815
-			animModel.set(i + 1, tmp);
816
-			animList.setSelectedIndex(i + 1);
817
-			worker.moveAnimation(worker.DOWN, animList.getSelectedIndex());
818
-		}
819
-	}
820
-
821
-	public void animAdd_ActionPerformed(ActionEvent evt) {
822
-		if (worker.addAnimation() == -1) {
823
-			errorMessage("Could not add animation!");
824
-		} else {
825
-			animModel.clear();
826
-			for (int i = 0; i < worker.numOfAnimations(); i++) {
827
-				animModel.add(i, worker.getAnimationName(i));
828
-			}
829
-			animList.setModel(animModel);
830
-		}
831
-
832
-	}
833
-
834
-	public void animRemove_ActionPerformed(ActionEvent evt) {
835
-		if (animList.getSelectedIndex() == -1) {
836
-			errorMessage("Select an animation.");
837
-		} else {
838
-			worker.removeAnimation(animList.getSelectedIndex());
839
-			animModel.removeElementAt(animList.getSelectedIndex());
840
-			animList.setModel(animModel);
841
-		}
842
-	}
843
-
844
-	public void load_ActionPerformed(ActionEvent evt) {
845
-		JFileChooser fc = new JFileChooser();
846
-		int ret = fc.showOpenDialog(this);
847
-		if (ret == JFileChooser.APPROVE_OPTION) {
848
-			File file = fc.getSelectedFile();
849
-			if (fileSelected == false) {
850
-				fileSelected = true;
851
-			}
852
-			animPath.setText(file.getPath());
853
-			worker.loadState(animPath.getText());
854
-			animModel.clear();
855
-			for (int i = 0; i < worker.numOfAnimations(); i++) {
856
-				animModel.addElement(worker.getAnimationName(i));
857
-			}
858
-			animList.setModel(animModel);
859
-
860
-			frameListModel.clear();
861
-			frameList.setModel(frameListModel);
862
-		}
863
-	}
864
-
865
-	public void save_ActionPerformed(ActionEvent evt) {
866
-		if (fileSelected == false) {
867
-			JFileChooser fc = new JFileChooser();
868
-			int ret = fc.showSaveDialog(this);
869
-			if (ret == JFileChooser.APPROVE_OPTION) {
870
-				File file = fc.getSelectedFile();
871
-				fileSelected = true;
872
-				animPath.setText(file.getPath());
873
-				worker.saveState(animPath.getText());
874
-			}
875
-		} else {
876
-			worker.saveState(animPath.getText());
877
-		}
878
-	}
879
-
880
-	public void saveAs_ActionPerformed(ActionEvent evt) {
881
-		JFileChooser fc;
882
-		if (fileSelected == true) {
883
-			fc = new JFileChooser(new File(animPath.getText()).getParentFile());
884
-		} else {
885
-			fc = new JFileChooser();
886
-		}
887
-		int ret = fc.showSaveDialog(this);
888
-		if (ret == JFileChooser.APPROVE_OPTION) {
889
-			File file = fc.getSelectedFile();
890
-			if (fileSelected == false) {
891
-				fileSelected = true;
892
-			}
893
-			animPath.setText(file.getPath());
894
-			worker.saveState(animPath.getText());
895
-		}
896
-	}
897
-
898
-	// We get detailed error messages from the SerialHelper...
899
-	public void upload_ActionPerformed(ActionEvent evt) {
900
-		if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
901
-			// errorMessage("No serial port selected...");
902
-		} else {
903
-			if (worker.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
904
-				if (worker.uploadState((String) jComboBox1.getSelectedItem()) != 0) {
905
-					// errorMessage("Could not upload data!");
906
-				}
907
-			} else {
908
-				// errorMessage("Cube does not respond...");
909
-			}
910
-		}
911
-	}
912
-
913
-	public void download_ActionPerformed(ActionEvent evt) {
914
-		if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
915
-			// errorMessage("No serial port selected...");
916
-		} else {
917
-			if (worker.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
918
-				if (worker.downloadState((String) jComboBox1.getSelectedItem()) != 0) {
919
-					// errorMessage("Could not download data!");
920
-				}
921
-			} else {
922
-				// errorMessage("Cube does not respond...");
923
-			}
924
-		}
925
-	}
926
-
927 788
 	public Led3D get3D() {
928 789
 		return ledView;
929 790
 	}
@@ -1003,26 +864,26 @@ public class Frame extends JFrame implements ListSelectionListener {
1003 864
 
1004 865
 				if (s.startsWith("frames ")) {
1005 866
 					int anim = Integer.parseInt(s.substring(7));
1006
-					if (anim >= f.worker.numOfAnimations()) {
1007
-						System.out.println("Animation does not exist! Max: " + (f.worker.numOfAnimations() - 1));
867
+					if (anim >= f.worker.size()) {
868
+						System.out.println("Animation does not exist! Max: " + (f.worker.size() - 1));
1008 869
 					} else {
1009
-						System.out.println("Animation: " + f.worker.getAnimationName(anim));
1010
-						for (int i = 0; i < f.worker.numOfFrames(anim); i++) {
1011
-							AFrame frame = f.worker.getAnimationList().get(anim).get(i);
1012
-							System.out.println("\tFrame " + frame.getOrder() + " (" + frame.getTime() + "): " + frame.getName());
870
+						System.out.println("Animation: " + f.worker.getAnimation(anim).getName());
871
+						for (int i = 0; i < f.worker.getAnimation(anim).size(); i++) {
872
+							AFrame frame = f.worker.getAnimation(anim).getFrame(i);
873
+							System.out.println("\tFrame (" + frame.getTime() + "): " + frame.getName());
1013 874
 						}
1014 875
 					}
1015 876
 				}
1016 877
 
1017 878
 				if (s.equals("a") || s.equals("anims")) {
1018
-					for (int i = 0; i < f.worker.numOfAnimations(); i++) {
1019
-						Animation anim = f.worker.getAnimationList().get(i);
1020
-						System.out.println("\tAnimation " + anim.getOrder() + ": " + anim.getName());
879
+					for (int i = 0; i < f.worker.size(); i++) {
880
+						Animation anim = f.worker.getAnimation(i);
881
+						System.out.println("\tAnimation: " + anim.getName());
1021 882
 					}
1022 883
 				}
1023 884
 
1024 885
 				if (s.equals("s") || s.equals("scan")) {
1025
-					String[] sPorts = f.worker.getSerialPorts();
886
+					String[] sPorts = HelperUtility.getPorts();
1026 887
 					f.jComboBox1.removeAllItems();
1027 888
 					for (int i = 0; i < sPorts.length; i++) {
1028 889
 						f.jComboBox1.addItem(sPorts[i]);

+ 23
- 1
CubeControl/HelperUtility.java View File

@@ -31,6 +31,7 @@
31 31
 import java.io.*;
32 32
 import java.nio.channels.*;
33 33
 import java.nio.*;
34
+import java.util.StringTokenizer;
34 35
 
35 36
 public class HelperUtility {
36 37
 
@@ -106,11 +107,32 @@ public class HelperUtility {
106 107
 	}
107 108
 
108 109
 	/**
110
+	 * Get the names of all available serial ports.
111
+	 * 
112
+	 * @return Array of port names. First entry is "No serial ports!" if no
113
+	 *         others
114
+	 */
115
+	public static String[] getPorts() {
116
+		String[] ports = { "No serial ports!" };
117
+		String portLines = getPortsOS();
118
+		if (portLines == null) {
119
+			return ports;
120
+		}
121
+		StringTokenizer sT = new StringTokenizer(portLines, "\n");
122
+		int size = sT.countTokens();
123
+		ports = new String[size];
124
+		for (int i = 0; i < size; i++) {
125
+			ports[i] = sT.nextToken();
126
+		}
127
+		return ports;
128
+	}
129
+
130
+	/**
109 131
 	 * Get all the existing serial port names
110 132
 	 * 
111 133
 	 * @return List of port names. \n between entries
112 134
 	 */
113
-	public static String getPorts() {
135
+	private static String getPortsOS() {
114 136
 		String os = System.getProperty("os.name").toLowerCase();
115 137
 		try {
116 138
 			if (os.indexOf("windows") > -1) {

+ 11
- 9
CubeControl/SerialHelper.java View File

@@ -78,7 +78,7 @@ public class SerialHelper {
78 78
 	 * @return A cubeWorker populated with the new data or null.
79 79
 	 */
80 80
 	public cubeWorker getAnimationsFromCube() {
81
-		List<Animation> animations = new ArrayList<Animation>();
81
+		Animation[] animations;
82 82
 		int animationCount, frameCount;
83 83
 		short[] data, tmp = new short[1];
84 84
 
@@ -108,6 +108,8 @@ public class SerialHelper {
108 108
 			return null;
109 109
 		}
110 110
 
111
+		animations = new Animation[animationCount];
112
+
111 113
 		// Get animations
112 114
 		for (int a = 0; a < animationCount; a++) {
113 115
 			Animation currentAnim = new Animation();
@@ -159,11 +161,11 @@ public class SerialHelper {
159 161
 				}
160 162
 
161 163
 				// Add frame to animation
162
-				currentAnim.add(f, currentFrame);
164
+				currentAnim.setFrame(currentFrame, f);
163 165
 			}
164 166
 
165 167
 			// Add animation to animations list
166
-			animations.add(a, currentAnim);
168
+			animations[a] = currentAnim;
167 169
 		}
168 170
 
169 171
 		return new cubeWorker(animations, frame);
@@ -190,7 +192,7 @@ public class SerialHelper {
190 192
 		}
191 193
 
192 194
 		// Send animation count
193
-		tmp[0] = (short)worker.numOfAnimations();
195
+		tmp[0] = (short)worker.size();
194 196
 		if (!writeData(tmp)) {
195 197
 			printErrorMessage("Timeout numOfAnimations");
196 198
 			return -1;
@@ -202,9 +204,9 @@ public class SerialHelper {
202 204
 		}
203 205
 
204 206
 		// Send animations
205
-		for (int a = 0; a < worker.numOfAnimations(); a++) {
207
+		for (int a = 0; a < worker.size(); a++) {
206 208
 			// Send frame count
207
-			tmp[0] = (short)worker.numOfFrames(a);
209
+			tmp[0] = (short)worker.getAnimation(a).size();
208 210
 			if (!writeData(tmp)) {
209 211
 				printErrorMessage("Timeout numOfFrames");
210 212
 				return -1;
@@ -216,9 +218,9 @@ public class SerialHelper {
216 218
 			}
217 219
 
218 220
 			// Send frames
219
-			for (int f = 0; f < worker.numOfFrames(a); f++) {
221
+			for (int f = 0; f < worker.getAnimation(a).size(); f++) {
220 222
 				// Frame duration
221
-				tmp[0] = worker.getFrameTime(a, f);
223
+				tmp[0] = worker.getAnimation(a).getFrame(f).getTime();
222 224
 				if (!writeData(tmp)) {
223 225
 					printErrorMessage("Timeout Frame duration");
224 226
 					return -1;
@@ -230,7 +232,7 @@ public class SerialHelper {
230 232
 				}
231 233
 
232 234
 				// Frame data
233
-				if (!writeData(worker.getFrame(a, f))) {
235
+				if (!writeData(worker.getAnimation(a).getFrame(f).getData())) {
234 236
 					printErrorMessage("Timeout Frame");
235 237
 					return -1;
236 238
 				}

+ 73
- 308
CubeControl/cubeWorker.java View File

@@ -43,41 +43,21 @@ import java.util.Collections;
43 43
 
44 44
 public class cubeWorker {
45 45
 
46
-	// --------------------
47
-	// Definitions
48
-	// --------------------
49
-
50
-	final int UP = 0;
51
-	final int DOWN = 1;
52
-
53
-	// --------------------
54
-	// Fields
55
-	// --------------------
56
-
57
-	private List<Animation> animations = new ArrayList<Animation>();
58 46
 	private final int framesRemaining = 2016; // (128 * 1024) / 65 = 2016,...
59 47
 	private boolean changedState = false;
60 48
 	private Frame parentFrame;
61
-
62
-	// --------------------
49
+	private Animation[] animations = new Animation[1];
63 50
 
64 51
 	/**
65 52
 	 * Creates a worker with one animation, containing an empty frame.
66 53
 	 */
67 54
 	public cubeWorker(Frame parent) {
68
-		animations.add(new Animation());
69
-		animations.get(0).setName("Animation 1");
70
-		animations.get(0).add(0);
71
-		animations.get(0).get(0).setName("Frame 1");
55
+		animations[0] = new Animation();
56
+		animations[0].setName("Animation 1");
72 57
 		parentFrame = parent;
73 58
 	}
74 59
 
75
-	/**
76
-	 * Creates a worker from the given animation list
77
-	 * 
78
-	 * @param anims List of animations
79
-	 */
80
-	public cubeWorker(List<Animation> anims, Frame parent) {
60
+	public cubeWorker(Animation[] anims, Frame parent) {
81 61
 		animations = anims;
82 62
 		parentFrame = parent;
83 63
 	}
@@ -88,84 +68,24 @@ public class cubeWorker {
88 68
 	 * @return number of frames.
89 69
 	 */
90 70
 	public int completeNumOfFrames() {
91
-		int count = 0;
92
-		for (int i = 0; i < numOfAnimations(); i++) {
93
-			count += numOfFrames(i);
71
+		int c = 0;
72
+		for (int i = 0; i < size(); i++) {
73
+			c += getAnimation(i).size();
94 74
 		}
95
-		return count;
75
+		return c;
96 76
 	}
97 77
 
98 78
 	// --------------------
99 79
 	// Misc. Methods
100 80
 	// --------------------
101 81
 
102
-	// Returns a number that is below the size of the animations list and not used as order
103
-	// If a order is higher or equal to the size of the list, it tries to assign a hole found to this
104
-	// Returns -1 if there is no hole
105
-	private int holeInAnimationList() {
106
-		int s = animations.size();
107
-		byte[] result = new byte[s];
108
-		int hole = -1;
109
-		int fix = -1;
110
-		for (int i = 0; i < s; i++) {
111
-			result[i] = 0;
112
-		}
113
-		for (int i = 0; i < s; i++) {
114
-			int order = animations.get(i).getOrder();
115
-			if (order >= s) {
116
-				// Houston, we have a problem...
117
-				fix = i;
118
-			}
119
-			result[order] = 1;
120
-		}
121
-		for (int i = 0; i < s; i++) {
122
-			if (result[i] == 0) {
123
-				hole = i;
124
-				break;
125
-			}
126
-		}
127
-		if ((hole != -1) && (fix != 1)) {
128
-			animations.get(fix).setOrder(hole);
129
-			return holeInAnimationList();
130
-		}
131
-		return hole;
132
-	}
133
-
134
-	// return true if damaged and to be sorted
135
-	private boolean checkAnimationList() {
136
-		for (int i = 0; i < animations.size(); i++) {
137
-			if (animations.get(i).getOrder() != i) {
138
-				int h = holeInAnimationList();
139
-				if (h != -1) {
140
-					animations.get(i).setOrder(h);
141
-				}
142
-				return true;
143
-			}
144
-		}
145
-		return false;
146
-	}
147
-
148 82
 	/**
149 83
 	 * Get the number of animations in this worker.
150
-	 * Also fixes the order of the animation list, if needed.
151 84
 	 * 
152 85
 	 * @return number of animations
153 86
 	 */
154
-	public int numOfAnimations() {
155
-		while(checkAnimationList()) {
156
-			Collections.sort(animations);
157
-		}
158
-		return animations.size();
159
-	}
160
-
161
-	/**
162
-	 * Get the number of frames in an animation.
163
-	 * 
164
-	 * @param selectedAnimation the animation you want to check
165
-	 * @return number of frames in this animation
166
-	 */
167
-	public int numOfFrames(int selectedAnimation) {
168
-		return animations.get(selectedAnimation).size();
87
+	public int size() {
88
+		return animations.length;
169 89
 	}
170 90
 
171 91
 	/**
@@ -173,14 +93,10 @@ public class cubeWorker {
173 93
 	 * 
174 94
 	 * @return number of frames remaining
175 95
 	 */
176
-	public int framesRemaining() {
96
+	public int memoryRemaining() {
177 97
 		return framesRemaining - completeNumOfFrames();
178 98
 	}
179 99
 
180
-	// --------------------
181
-	// Animation Specific
182
-	// --------------------
183
-
184 100
 	/**
185 101
 	 * Add an animation. It has an initial empty frame
186 102
 	 * 
@@ -188,210 +104,65 @@ public class cubeWorker {
188 104
 	 */
189 105
 	public int addAnimation() {
190 106
 		changedState = true;
191
-		if (framesRemaining() <= 0) {
107
+		if (memoryRemaining() <= 0) {
192 108
 			return -1;
193 109
 		} else {
194
-			int s = animations.size();
195
-			animations.add(s, new Animation());
196
-			animations.get(s).setName("Animation " + animations.size());
197
-			animations.get(s).add(0, new AFrame());
198
-			animations.get(s).get(0).setName("Frame 1");
199
-			return s;
110
+			extendArray();
111
+			animations[animations.length - 1] = new Animation();
112
+			return animations.length - 1;
200 113
 		}
201 114
 	}
202 115
 
203 116
 	/**
204 117
 	 * Remove an animation.
205 118
 	 * 
206
-	 * @param selectedAnimation the animation you want to delete
207
-	 */
208
-	public void removeAnimation(int selectedAnimation) {
209
-		changedState = true;
210
-		animations.remove(selectedAnimation);
211
-	}
212
-
213
-	/**
214
-	 * Get the name of an animation
215
-	 * 
216
-	 * @return The name
217
-	 * @param selectedAnimation The animation you want to get the name from
119
+	 * @param i the animation you want to delete
218 120
 	 */
219
-	public String getAnimationName(int selectedAnimation) {
220
-		return animations.get(selectedAnimation).getName();
221
-	}
222
-
223
-	/**
224
-	 * Set the name of an animation  @param s New name
225
-	 * 
226
-	 * @param selectedAnimation Index of the animation you want to change
227
-	 */
228
-	public void setAnimationName(String s, int selectedAnimation) {
121
+	public void removeAnimation(int i) {
229 122
 		changedState = true;
230
-		animations.get(selectedAnimation).setName(s);
123
+		shiftOver(i);
124
+		shrinkArray();
231 125
 	}
232 126
 
233 127
 	/**
234
-	 * Move an animation UP or DOWN.
235
-	 * 
236
-	 * @param dir Direction. Use UP and DOWN defined in cubeWorker
237
-	 * @param selectedAnimation Animation you want to move
128
+	 * Move an animation up.
129
+	 * @param i the animation you want to move
238 130
 	 */
239
-	public void moveAnimation(int dir, int selectedAnimation) {
240
-		changedState = true;
241
-		if (dir == UP) {
242
-			// animation moved up
243
-			if (selectedAnimation > 0) {
244
-				Animation tmp = animations.get(selectedAnimation);
245
-				animations.set(selectedAnimation,
246
-						animations.get(selectedAnimation - 1));
247
-				animations.set(selectedAnimation - 1, tmp);
248
-			}
249
-		} else if (dir == DOWN) {
250
-			// animation moved down
251
-			if (selectedAnimation < (animations.size() - 1)) {
252
-				Animation tmp = animations.get(selectedAnimation);
253
-				animations.set(selectedAnimation,
254
-						animations.get(selectedAnimation + 1));
255
-				animations.set(selectedAnimation + 1, tmp);
256
-			}
131
+	public void moveAnimationUp(int i) {
132
+		if (i > 0) {
133
+			Animation tmp = animations[i];
134
+			animations[i] = animations[i - 1];
135
+			animations[i - 1] = tmp;
257 136
 		}
258 137
 	}
259 138
 
260
-	// --------------------
261
-	// Frame Specific
262
-	// --------------------
263
-
264 139
 	/**
265
-	 * Get the name of a frame.
266
-	 * 
267
-	 * @param anim Animation the frame is in
268
-	 * @param frame Index of the frame
140
+	 * Move an animation down.
141
+	 * @param i the animation you want to move
269 142
 	 */
270
-	public String getFrameName(int anim, int frame) {
271
-		return animations.get(anim).get(frame).getName();
272
-	}
273
-
274
-	/**
275
-	 * Set the name of a frame.
276
-	 * 
277
-	 * @param s New name
278
-	 * @param anim Animation Index
279
-	 * @param frame Frame Index
280
-	 */
281
-	public void setFrameName(String s, int anim, int frame) {
282
-		changedState = true;
283
-		animations.get(anim).get(frame).setName(s);
284
-	}
285
-
286
-	/**
287
-	 * Add a Frame to an animation.
288
-	 * 
289
-	 * @return Index of new Frame or -1 if not enough space
290
-	 * @param anim Animation Index
291
-	 */
292
-	public int addFrame(int anim) {
293
-		changedState = true;
294
-		if (framesRemaining() <= 0) {
295
-			return -1;
143
+	public void moveAnimationDown(int i) {
144
+		if (i < (animations.length - 1)) {
145
+			Animation tmp = animations[i];
146
+			animations[i] = animations[i + 1];
147
+			animations[i + 1] = tmp;
296 148
 		}
297
-		int s = animations.get(anim).size();
298
-		animations.get(anim).add(s);
299
-		animations.get(anim).get(s)
300
-				.setName("Frame " + animations.get(anim).size());
301
-		return s;
302
-	}
303
-
304
-	/**
305
-	 * Remove a frame.
306
-	 * 
307
-	 * @param anim Animation Index
308
-	 * @param frame Frame you want to remove
309
-	 */
310
-	public void removeFrame(int anim, int frame) {
311
-		changedState = true;
312
-		animations.get(anim).remove(frame);
313
-	}
314
-
315
-	/**
316
-	 * Get the data of a frame.
317
-	 * 
318
-	 * @param anim Animation Index  @param frame Frame Index
319
-	 * @return 64 byte array with data (8 bits per byte => 512 bits)
320
-	 */
321
-	public short[] getFrame(int anim, int frame) {
322
-		return animations.get(anim).get(frame).getData();
323 149
 	}
324 150
 
325
-	/**
326
-	 * Set the data of a frame
327
-	 * 
328
-	 * @param data 64 byte array with data
329
-	 * @param anim Animation Index
330
-	 * @param frame Frame Index
331
-	 * @see cubeWorker#getFrame(int, int) getFrame()
332
-	 */
333
-	public void setFrame(short[] data, int anim, int frame) {
334
-		changedState = true;
335
-		animations.get(anim).get(frame).setData(data);
336
-	}
337
-
338
-	/**
339
-	 * Get frame duration.
340
-	 * 
341
-	 * @param anim Animation Index
342
-	 * @param frame Frame Index
343
-	 * @return Duration. 0 means 1/24th of a second.
344
-	 */
345
-	public short getFrameTime(int anim, int frame) {
346
-		return animations.get(anim).get(frame).getTime();
151
+	public Animation getAnimation(int i) {
152
+		if (i < animations.length) {
153
+			return animations[i];
154
+		} else {
155
+			return null;
156
+		}
347 157
 	}
348 158
 
349
-	/**
350
-	 * Set the frames duration.
351
-	 * 
352
-	 * @param time New duration
353
-	 * @param anim Animation Index
354
-	 * @param frame Frame Index
355
-	 * @see cubeWorker#getFrameTime(int, int) getFrameTime()
356
-	 */
357
-	public void setFrameTime(short time, int anim, int frame) {
159
+	public void setAnimation(Animation a, int i) {
358 160
 		changedState = true;
359
-		animations.get(anim).get(frame).setTime(time);
360
-	}
361
-
362
-	/**
363
-	 * Move a frame.
364
-	 * 
365
-	 * @param dir Direction to move. Use UP and DOWN from cubeWorker
366
-	 * @param anim Animation Index
367
-	 * @param frame Frame Index
368
-	 * @see cubeWorker#moveAnimation(int, int) moveAnimation()
369
-	 */
370
-	public void moveFrame(int dir, int anim, int frame) {
371
-		changedState = true;
372
-		if (dir == UP) {
373
-			// frame moved up
374
-			if (frame > 0) {
375
-				AFrame tmp = animations.get(anim).frames.get(frame);
376
-				animations.get(anim).frames.set(frame,
377
-						animations.get(anim).frames.get(frame - 1));
378
-				animations.get(anim).frames.set(frame - 1, tmp);
379
-			}
380
-		} else if (dir == DOWN) {
381
-			// frame moved down
382
-			if (frame < (animations.get(anim).size() - 1)) {
383
-				AFrame tmp = animations.get(anim).frames.get(frame);
384
-				animations.get(anim).frames.set(frame,
385
-						animations.get(anim).frames.get(frame + 1));
386
-				animations.get(anim).frames.set(frame + 1, tmp);
387
-			}
161
+		if (i < animations.length) {
162
+			animations[i] = a;
388 163
 		}
389 164
 	}
390 165
 
391
-	// --------------------
392
-	// File Specific
393
-	// --------------------
394
-
395 166
 	/**
396 167
 	 * Loads an animation file into this worker.
397 168
 	 * 
@@ -408,8 +179,8 @@ public class cubeWorker {
408 179
 			return -1;
409 180
 		}
410 181
 		int size = 0;
411
-		for (int i = 0; i < animations.size(); i++) {
412
-			size += animations.get(i).size();
182
+		for (int i = 0; i < animations.length; i++) {
183
+			size += animations[i].size();
413 184
 		}
414 185
 		if (size > framesRemaining) {
415 186
 			return -1;
@@ -442,17 +213,13 @@ public class cubeWorker {
442 213
 		return changedState;
443 214
 	}
444 215
 
445
-	// --------------------
446
-	// Serial Port Specific
447
-	// --------------------
448
-
449 216
 	/**
450 217
 	 * Send all animations to the cube.
451 218
 	 * 
452 219
 	 * @param port Name of serial port to use
453 220
 	 * @return 0 on success, -1 on error
454 221
 	 */
455
-	public int uploadState(String port) {
222
+	public int cubeSendState(String port) {
456 223
 		try {
457 224
 			SerialHelper sh = new SerialHelper(port, parentFrame);
458 225
 			int ret = sh.sendAnimationsToCube(this);
@@ -464,12 +231,20 @@ public class cubeWorker {
464 231
 	}
465 232
 
466 233
 	/**
234
+	 * Get the array of animations in this worker.
235
+	 * @return animation array
236
+	 */
237
+	public Animation[] getAnimationArray() {
238
+		return animations;
239
+	}
240
+
241
+	/**
467 242
 	 * Get all animations from the cube, place it in this object
468 243
 	 * 
469 244
 	 * @param port Name of serial port to use
470 245
 	 * @return 0 on success, -1 on error
471 246
 	 */
472
-	public int downloadState(String port) {
247
+	public int cubeGetState(String port) {
473 248
 		try {
474 249
 			SerialHelper sh = new SerialHelper(port, parentFrame);
475 250
 			cubeWorker ret = sh.getAnimationsFromCube();
@@ -478,7 +253,7 @@ public class cubeWorker {
478 253
 				return -1;
479 254
 			} else {
480 255
 				changedState = true;
481
-				animations = ret.getAnimationList();
256
+				animations = ret.getAnimationArray();
482 257
 				return 0;
483 258
 			}
484 259
 		} catch (Exception e) {
@@ -487,20 +262,12 @@ public class cubeWorker {
487 262
 	}
488 263
 
489 264
 	/**
490
-	 * Get the list used internally to store all the animations.
491
-	 * @return The list.
492
-	 */
493
-	public List<Animation> getAnimationList() {
494
-		return animations;
495
-	}
496
-
497
-	/**
498 265
 	 * Try to speak with the cube.
499 266
 	 * 
500 267
 	 * @return TRUE if cube responds
501 268
 	 * @param port Name of serial port
502 269
 	 */
503
-	public boolean probeCubeConnected(String port) {
270
+	public boolean cubeProbeConnected(String port) {
504 271
 		try {
505 272
 			SerialHelper sh = new SerialHelper(port, parentFrame);
506 273
 			boolean response = sh.probeForCube();
@@ -511,27 +278,25 @@ public class cubeWorker {
511 278
 		}
512 279
 	}
513 280
 
514
-	/**
515
-	 * Get the names of all available serial ports.
516
-	 * 
517
-	 * @return Array of port names. First entry is "Select serial port..." if no
518
-	 *         others
519
-	 */
520
-	public String[] getSerialPorts() {
521
-		String[] ports = { "Select serial port..." };
522
-		String portLines = HelperUtility.getPorts();
523
-		if (portLines == null) {
524
-			return ports;
525
-		}
526
-		StringTokenizer sT = new StringTokenizer(portLines, "\n");
527
-		int size = sT.countTokens();
528
-		ports = new String[size];
529
-		for (int i = 0; i < size; i++) {
530
-			ports[i] = sT.nextToken();
281
+	private void extendArray() {
282
+		Animation newArray[] = new Animation[animations.length + 1];
283
+		for (int i = 0; i < animations.length; i++) {
284
+			newArray[i] = animations[i];
531 285
 		}
532
-		return ports;
286
+		animations = newArray;
533 287
 	}
534 288
 
535
-	// --------------------
289
+	private void shrinkArray() {
290
+		Animation newArray[] = new Animation[animations.length - 1];
291
+		for (int i = 0; i < newArray.length; i++) {
292
+			newArray[i] = animations[i];
293
+		}
294
+		animations = newArray;
295
+	}
536 296
 
297
+	private void shiftOver(int toForget) {
298
+		for (int i = (toForget + 1); i < animations.length; i++) {
299
+			animations[i - 1] = animations[i];
300
+		}
301
+	}
537 302
 }

+ 2
- 2
CubeControl/layerEditFrame.java View File

@@ -71,7 +71,7 @@ public class layerEditFrame extends JFrame {
71 71
 		animI = animIndex;
72 72
 		frameI = frameIndex;
73 73
 		// frame = byteToShortArray(worker.getFrame(animIndex, frameIndex));
74
-		frame = worker.getFrame(animIndex, frameIndex);
74
+		frame = worker.getAnimation(animIndex).getFrame(frameIndex).getData();
75 75
 		li = layerIndex;
76 76
 		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
77 77
 		int frameWidth = 180;
@@ -215,7 +215,7 @@ public class layerEditFrame extends JFrame {
215 215
 			reihe = 0;
216 216
 		}
217 217
 		frame = tmpFrame;
218
-		worker.setFrame(frame, animI, frameI);
218
+		worker.getAnimation(animI).getFrame(frameI).setData(frame);
219 219
 		ListSelectionEvent layerChanged = new ListSelectionEvent(
220 220
 				LedFrame.frameList, LedFrame.frameList.getSelectedIndex(),
221 221
 				LedFrame.frameList.getSelectedIndex(), false);

Loading…
Cancel
Save