Browse Source

Worked at movement...

Thomas Buck 12 years ago
parent
commit
f7e630839e

+ 1
- 1
CubeControl/AFrame.java View File

83
 	 * @return Name of the Frame
83
 	 * @return Name of the Frame
84
 	 */
84
 	 */
85
 	public String getName() {
85
 	public String getName() {
86
-		return name;
86
+		return name + " (" + order + ")";
87
 	}
87
 	}
88
 
88
 
89
 	/**
89
 	/**

+ 2
- 6
CubeControl/Animation.java View File

84
 	 * @return name of this animation
84
 	 * @return name of this animation
85
 	 */
85
 	 */
86
 	public String getName() {
86
 	public String getName() {
87
-		return name;
87
+		return name + " (" + order + ")";
88
 	}
88
 	}
89
 
89
 
90
 	/**
90
 	/**
171
 		}
171
 		}
172
 	}
172
 	}
173
 
173
 
174
-	private void sortFrameList() {
175
-		Collections.sort(frames);
176
-	}
177
-
178
 	// return true if damaged and fixed partially
174
 	// return true if damaged and fixed partially
179
 	private boolean checkFrameList() {
175
 	private boolean checkFrameList() {
180
 		for (int i = 0; i < frames.size(); i++) {
176
 		for (int i = 0; i < frames.size(); i++) {
194
 	 */
190
 	 */
195
 	public int size() {
191
 	public int size() {
196
 		while(checkFrameList()) {
192
 		while(checkFrameList()) {
197
-			sortFrameList();
193
+			Collections.sort(frames);
198
 		}
194
 		}
199
 		return frames.size();
195
 		return frames.size();
200
 	}
196
 	}

+ 11
- 5
CubeControl/Frame.java View File

127
 				frameListModel.clear();
127
 				frameListModel.clear();
128
 				for (int i = 0; i < worker.numOfFrames(animList
128
 				for (int i = 0; i < worker.numOfFrames(animList
129
 						.getSelectedIndex()); i++) {
129
 						.getSelectedIndex()); i++) {
130
+				// Offending statement:
131
+				// worker.numOfFrames(animList.getSelectedIndex())
130
 					frameListModel.addElement(worker.getFrameName(
132
 					frameListModel.addElement(worker.getFrameName(
131
 							animList.getSelectedIndex(), i));
133
 							animList.getSelectedIndex(), i));
132
 				}
134
 				}
769
 		if (animList.getSelectedIndex() == -1) {
771
 		if (animList.getSelectedIndex() == -1) {
770
 			errorMessage("Please select an animation!");
772
 			errorMessage("Please select an animation!");
771
 		} else {
773
 		} else {
774
+			int n = worker.numOfFrames(animList.getSelectedIndex());
772
 			worker.addFrame(animList.getSelectedIndex());
775
 			worker.addFrame(animList.getSelectedIndex());
776
+			// Not reaching past this comment if frame list empty
773
 			frameRemaining.setText(Integer.toString(worker.framesRemaining()));
777
 			frameRemaining.setText(Integer.toString(worker.framesRemaining()));
774
-			int n = worker.numOfFrames(animList.getSelectedIndex()) - 1;
775
-			if (n < 0) {
776
-				n = 0;
777
-			}
778
 			frameListModel.add(n,
778
 			frameListModel.add(n,
779
 					worker.getFrameName(animList.getSelectedIndex(), n));
779
 					worker.getFrameName(animList.getSelectedIndex(), n));
780
 			frameList.setModel(frameListModel);
780
 			frameList.setModel(frameListModel);
781
 		}
781
 		}
782
-
783
 	}
782
 	}
784
 
783
 
785
 	public void frameRemove_ActionPerformed(ActionEvent evt) {
784
 	public void frameRemove_ActionPerformed(ActionEvent evt) {
1015
 					}
1014
 					}
1016
 				}
1015
 				}
1017
 
1016
 
1017
+				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());
1021
+					}
1022
+				}
1023
+
1018
 				if (s.equals("s") || s.equals("scan")) {
1024
 				if (s.equals("s") || s.equals("scan")) {
1019
 					String[] sPorts = f.worker.getSerialPorts();
1025
 					String[] sPorts = f.worker.getSerialPorts();
1020
 					f.jComboBox1.removeAllItems();
1026
 					f.jComboBox1.removeAllItems();

+ 39
- 6
CubeControl/cubeWorker.java View File

99
 	// Misc. Methods
99
 	// Misc. Methods
100
 	// --------------------
100
 	// --------------------
101
 
101
 
102
-	private void sortAnimationList() {
103
-		Collections.sort(animations);
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;
104
 	}
132
 	}
105
 
133
 
106
-	// return true if damaged and fixed partially
134
+	// return true if damaged and to be sorted
107
 	private boolean checkAnimationList() {
135
 	private boolean checkAnimationList() {
108
 		for (int i = 0; i < animations.size(); i++) {
136
 		for (int i = 0; i < animations.size(); i++) {
109
 			if (animations.get(i).getOrder() != i) {
137
 			if (animations.get(i).getOrder() != i) {
110
-				animations.get(i).setOrder(animations.size());
138
+				int h = holeInAnimationList();
139
+				if (h != -1) {
140
+					animations.get(i).setOrder(h);
141
+				}
111
 				return true;
142
 				return true;
112
 			}
143
 			}
113
 		}
144
 		}
122
 	 */
153
 	 */
123
 	public int numOfAnimations() {
154
 	public int numOfAnimations() {
124
 		while(checkAnimationList()) {
155
 		while(checkAnimationList()) {
125
-			sortAnimationList();
156
+			Collections.sort(animations);
126
 		}
157
 		}
127
 		return animations.size();
158
 		return animations.size();
128
 	}
159
 	}
151
 	// --------------------
182
 	// --------------------
152
 
183
 
153
 	/**
184
 	/**
154
-	 * Add an animation.
185
+	 * Add an animation. It has an initial empty frame
155
 	 * 
186
 	 * 
156
 	 * @return Index of new animation, or -1 if not enough space remaining.
187
 	 * @return Index of new animation, or -1 if not enough space remaining.
157
 	 */
188
 	 */
163
 			int s = animations.size();
194
 			int s = animations.size();
164
 			animations.add(s, new Animation());
195
 			animations.add(s, new Animation());
165
 			animations.get(s).setName("Animation " + animations.size());
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");
166
 			return s;
199
 			return s;
167
 		}
200
 		}
168
 	}
201
 	}

+ 1
- 1
CubeControl/makefile View File

31
 	javah -o serialInterface.h HelperUtility
31
 	javah -o serialInterface.h HelperUtility
32
 
32
 
33
 HelperUtility.class: $(JAVAFILES)
33
 HelperUtility.class: $(JAVAFILES)
34
-	javac $(JAVAFILES)
34
+	javac -g $(JAVAFILES)
35
 
35
 
36
 doc/index.html: $(JAVAFILES)
36
 doc/index.html: $(JAVAFILES)
37
 	javadoc -d doc $(JAVAFILES)
37
 	javadoc -d doc $(JAVAFILES)

Loading…
Cancel
Save