Browse Source

Worked at movement...

Thomas Buck 12 years ago
parent
commit
f7e630839e
5 changed files with 54 additions and 19 deletions
  1. 1
    1
      CubeControl/AFrame.java
  2. 2
    6
      CubeControl/Animation.java
  3. 11
    5
      CubeControl/Frame.java
  4. 39
    6
      CubeControl/cubeWorker.java
  5. 1
    1
      CubeControl/makefile

+ 1
- 1
CubeControl/AFrame.java View File

@@ -83,7 +83,7 @@ public class AFrame implements Comparable<AFrame> {
83 83
 	 * @return Name of the Frame
84 84
 	 */
85 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,7 +84,7 @@ public class Animation implements Comparable<Animation> {
84 84
 	 * @return name of this animation
85 85
 	 */
86 86
 	public String getName() {
87
-		return name;
87
+		return name + " (" + order + ")";
88 88
 	}
89 89
 
90 90
 	/**
@@ -171,10 +171,6 @@ public class Animation implements Comparable<Animation> {
171 171
 		}
172 172
 	}
173 173
 
174
-	private void sortFrameList() {
175
-		Collections.sort(frames);
176
-	}
177
-
178 174
 	// return true if damaged and fixed partially
179 175
 	private boolean checkFrameList() {
180 176
 		for (int i = 0; i < frames.size(); i++) {
@@ -194,7 +190,7 @@ public class Animation implements Comparable<Animation> {
194 190
 	 */
195 191
 	public int size() {
196 192
 		while(checkFrameList()) {
197
-			sortFrameList();
193
+			Collections.sort(frames);
198 194
 		}
199 195
 		return frames.size();
200 196
 	}

+ 11
- 5
CubeControl/Frame.java View File

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

+ 39
- 6
CubeControl/cubeWorker.java View File

@@ -99,15 +99,46 @@ public class cubeWorker {
99 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 135
 	private boolean checkAnimationList() {
108 136
 		for (int i = 0; i < animations.size(); i++) {
109 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 142
 				return true;
112 143
 			}
113 144
 		}
@@ -122,7 +153,7 @@ public class cubeWorker {
122 153
 	 */
123 154
 	public int numOfAnimations() {
124 155
 		while(checkAnimationList()) {
125
-			sortAnimationList();
156
+			Collections.sort(animations);
126 157
 		}
127 158
 		return animations.size();
128 159
 	}
@@ -151,7 +182,7 @@ public class cubeWorker {
151 182
 	// --------------------
152 183
 
153 184
 	/**
154
-	 * Add an animation.
185
+	 * Add an animation. It has an initial empty frame
155 186
 	 * 
156 187
 	 * @return Index of new animation, or -1 if not enough space remaining.
157 188
 	 */
@@ -163,6 +194,8 @@ public class cubeWorker {
163 194
 			int s = animations.size();
164 195
 			animations.add(s, new Animation());
165 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 199
 			return s;
167 200
 		}
168 201
 	}

+ 1
- 1
CubeControl/makefile View File

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

Loading…
Cancel
Save