Browse Source

Source now pretty

Thomas Buck 12 years ago
parent
commit
a0e7721d22

+ 6
- 0
CubeControl/.classpath View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry excluding="libSerial/" kind="src" path=""/>
4
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
+	<classpathentry kind="output" path=""/>
6
+</classpath>

+ 17
- 0
CubeControl/.project View File

@@ -0,0 +1,17 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>CubeControl</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+	</buildSpec>
14
+	<natures>
15
+		<nature>org.eclipse.jdt.core.javanature</nature>
16
+	</natures>
17
+</projectDescription>

+ 64
- 56
CubeControl/AFrame.java View File

@@ -20,11 +20,12 @@
20 20
  * You should have received a copy of the GNU General Public License
21 21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22 22
  */
23
-
24 23
 import java.util.Arrays;
25 24
 
26 25
 /**
27
- * The representation of a single frame. Contains the data of all 512 LEDs in a given time.
26
+ * The representation of a single frame. Contains the data of all 512 LEDs in a
27
+ * given time.
28
+ * 
28 29
  * @author Thomas Buck
29 30
  * @author Max Nuding
30 31
  * @author Felix Bäder
@@ -32,65 +33,72 @@ import java.util.Arrays;
32 33
  */
33 34
 
34 35
 public class AFrame {
35
-  private short[] data = new short[64];
36
-  private short duration = 1;
37
-  private String name = "Frame";
36
+	private short[] data = new short[64];
37
+	private short duration = 1;
38
+	private String name = "Frame";
38 39
 
39
-  /**
40
-   * Gets the Name of this Frame
41
-   * @return Name of the Frame
42
-   */
43
-  public String getName() {
44
-    return name;
45
-  }
40
+	/**
41
+	 * Gets the Name of this Frame
42
+	 * 
43
+	 * @return Name of the Frame
44
+	 */
45
+	public String getName() {
46
+		return name;
47
+	}
46 48
 
47
-  /**
48
-   * Sets the Name of this Frame
49
-   * @param s New Name
50
-   */
51
-  public void setName(String s) {
52
-    name = s;
53
-  }
49
+	/**
50
+	 * Sets the Name of this Frame
51
+	 * 
52
+	 * @param s New Name
53
+	 */
54
+	public void setName(String s) {
55
+		name = s;
56
+	}
54 57
 
55
-  /**
56
-   * Sets the Data of this Frame
57
-   * @param d 64 bytes that contain data (8 bit per byte, so 8 LEDs)
58
-   */
59
-  public void setData(short[] d) {
60
-    data = d;
61
-  }
58
+	/**
59
+	 * Sets the Data of this Frame
60
+	 * 
61
+	 * @param d 64 bytes that contain data (8 bit per byte, so 8 LEDs)
62
+	 */
63
+	public void setData(short[] d) {
64
+		data = d;
65
+	}
62 66
 
63
-  /**
64
-   * Gets tha Data of this Frame
65
-   * @return 64 bytes that contain data (8 bits / LEDs per byte)
66
-   */
67
-  public short[] getData() {
68
-    return data;
69
-  }
67
+	/**
68
+	 * Gets tha Data of this Frame
69
+	 * 
70
+	 * @return 64 bytes that contain data (8 bits / LEDs per byte)
71
+	 */
72
+	public short[] getData() {
73
+		return data;
74
+	}
70 75
 
71
-  /**
72
-   * Sets the Duration of this Frame
73
-   * @param t Duration of frame in (( t * (1/24) ) + (1/24)) seconds
74
-   */
75
-  public void setTime(short t) {
76
-    duration = t;
77
-  }
76
+	/**
77
+	 * Sets the Duration of this Frame
78
+	 * 
79
+	 * @param t Duration of frame in (( t * (1/24) ) + (1/24)) seconds
80
+	 */
81
+	public void setTime(short t) {
82
+		duration = t;
83
+	}
78 84
 
79
-  /**
80
-   * Gets the Duration of this Frame
81
-   * @return Duration of frame.
82
-   * @see AFrame#setTime(short) setTime()
83
-   */
84
-  public short getTime() {
85
-    return duration;
86
-  }
85
+	/**
86
+	 * Gets the Duration of this Frame
87
+	 * 
88
+	 * @return Duration of frame.
89
+	 * @see AFrame#setTime(short) setTime()
90
+	 */
91
+	public short getTime() {
92
+		return duration;
93
+	}
87 94
 
88
-  /**
89
-   * Gets the Data of the Layer you want
90
-   * @param i Number of Layer you want
91
-   * @return 8 byte array with data of selected layer
92
-   */
93
-  public short[] getLayer(int i) {
94
-    return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
95
-  }
95
+	/**
96
+	 * Gets the Data of the Layer you want
97
+	 * 
98
+	 * @param i Number of Layer you want
99
+	 * @return 8 byte array with data of selected layer
100
+	 */
101
+	public short[] getLayer(int i) {
102
+		return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
103
+	}
96 104
 }

+ 98
- 89
CubeControl/Animation.java View File

@@ -20,12 +20,12 @@
20 20
  * You should have received a copy of the GNU General Public License
21 21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22 22
  */
23
-
24 23
 import java.util.ArrayList;
25 24
 import java.util.List;
26 25
 
27 26
 /**
28 27
  * A collection of frames that represent an entire animation.
28
+ * 
29 29
  * @author Thomas Buck
30 30
  * @author Max Nuding
31 31
  * @author Felix Bäder
@@ -33,100 +33,109 @@ import java.util.List;
33 33
  */
34 34
 
35 35
 public class Animation {
36
-  List<AFrame> frames = new ArrayList<AFrame>();
37
-  private int lastFrameIndex = 0;
38
-  private String name = "Animation";
36
+	List<AFrame> frames = new ArrayList<AFrame>();
37
+	private int lastFrameIndex = 0;
38
+	private String name = "Animation";
39 39
 
40
-  /**
41
-   * Gets the name of this animation
42
-   * @return name of this animation
43
-   */
44
-  public String getName() {
45
-    return name;
46
-  }
40
+	/**
41
+	 * Gets the name of this animation
42
+	 * 
43
+	 * @return name of this animation
44
+	 */
45
+	public String getName() {
46
+		return name;
47
+	}
47 48
 
48
-  /**
49
-   * Sets the name of this animation
50
-   * @param s new name
51
-   */
52
-  public void setName(String s) {
53
-    name = s;
54
-  }
49
+	/**
50
+	 * Sets the name of this animation
51
+	 * 
52
+	 * @param s
53
+	 *            new name
54
+	 */
55
+	public void setName(String s) {
56
+		name = s;
57
+	}
55 58
 
56
-  /**
57
-   * Gets the specified frame in this animation
58
-   * @param i Index of frame you want
59
-   * @return The selected frame
60
-   */
61
-  public AFrame get(int i) {
62
-    try {
63
-      return frames.get(i);
64
-    } catch (IndexOutOfBoundsException e) {
65
-      System.out.println(e.toString());
66
-      return null;
67
-    }
68
-  }
59
+	/**
60
+	 * Gets the specified frame in this animation
61
+	 * 
62
+	 * @param i Index of frame you want
63
+	 * @return The selected frame
64
+	 */
65
+	public AFrame get(int i) {
66
+		try {
67
+			return frames.get(i);
68
+		} catch (IndexOutOfBoundsException e) {
69
+			System.out.println(e.toString());
70
+			return null;
71
+		}
72
+	}
69 73
 
70
-  /**
71
-   * Sets the selected Frame
72
-   * @param f the frame you want to place in this animation
73
-   * @param i Index of the frame you want to override
74
-   */
75
-  public void set(AFrame f, int i) {
76
-    if (lastFrameIndex <= i) {
77
-      try {
78
-        frames.set(i, f);
79
-      } catch (IndexOutOfBoundsException e) {
80
-        System.out.println(e.toString());
81
-      }
82
-    }
83
-  }
74
+	/**
75
+	 * Sets the selected Frame
76
+	 * 
77
+	 * @param f the frame you want to place in this animation
78
+	 * @param i Index of the frame you want to override
79
+	 */
80
+	public void set(AFrame f, int i) {
81
+		if (lastFrameIndex <= i) {
82
+			try {
83
+				frames.set(i, f);
84
+			} catch (IndexOutOfBoundsException e) {
85
+				System.out.println(e.toString());
86
+			}
87
+		}
88
+	}
84 89
 
85
-  /**
86
-   * Removes a frame. Subsequent frames shift to the left.
87
-   * @param i Index of frame you want to remove
88
-   */
89
-  public void remove(int i) {
90
-    try {
91
-      frames.remove(i);
92
-    } catch (IndexOutOfBoundsException e) {
93
-      System.out.println(e.toString());
94
-    }
95
-  }
90
+	/**
91
+	 * Removes a frame. Subsequent frames shift to the left.
92
+	 * 
93
+	 * @param i Index of frame you want to remove
94
+	 */
95
+	public void remove(int i) {
96
+		try {
97
+			frames.remove(i);
98
+		} catch (IndexOutOfBoundsException e) {
99
+			System.out.println(e.toString());
100
+		}
101
+	}
96 102
 
97
-  /**
98
-   * Add a new (empty) frame at the specified position
99
-   * @param i Index you want to place the new frame in
100
-   * @see Animation#size size()
101
-   */
102
-  public void add(int i) {
103
-    try {
104
-      frames.add(i, new AFrame());
105
-      lastFrameIndex++;
106
-    } catch (IndexOutOfBoundsException e)  {
107
-      System.out.println(e.toString());
108
-    }
109
-  }
103
+	/**
104
+	 * Add a new (empty) frame at the specified position
105
+	 * 
106
+	 * @param i Index you want to place the new frame in
107
+	 * @see Animation#size size()
108
+	 */
109
+	public void add(int i) {
110
+		try {
111
+			frames.add(i, new AFrame());
112
+			lastFrameIndex++;
113
+		} catch (IndexOutOfBoundsException e) {
114
+			System.out.println(e.toString());
115
+		}
116
+	}
110 117
 
111
-  /**
112
-   * Add a specified frame at the specified position
113
-   * @param i Index for new frame
114
-   * @param f data for new frame
115
-   */
116
-  public void add(int i, AFrame f) {
117
-    try {
118
-      frames.add(i, f);
119
-      lastFrameIndex++;
120
-    } catch (IndexOutOfBoundsException e)  {
121
-      System.out.println(e.toString());
122
-    }
123
-  }
118
+	/**
119
+	 * Add a specified frame at the specified position
120
+	 * 
121
+	 * @param i Index for new frame
122
+	 * @param f data for new frame
123
+	 */
124
+	public void add(int i, AFrame f) {
125
+		try {
126
+			frames.add(i, f);
127
+			lastFrameIndex++;
128
+		} catch (IndexOutOfBoundsException e) {
129
+			System.out.println(e.toString());
130
+		}
131
+	}
124 132
 
125
-  /**
126
-   * Return size of this animation, in number of frames
127
-   * @return number of frames
128
-   */
129
-  public int size() {
130
-    return frames.size();
131
-  }
133
+	/**
134
+	 * Return size of this animation, in number of frames
135
+	 * 
136
+	 * @return number of frames
137
+	 */
138
+	public int size() {
139
+		return frames.size();
140
+	}
132 141
 }

+ 176
- 175
CubeControl/AnimationUtility.java View File

@@ -20,7 +20,6 @@
20 20
  * You should have received a copy of the GNU General Public License
21 21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22 22
  */
23
-
24 23
 import java.io.FileWriter;
25 24
 import java.io.File;
26 25
 import java.util.Scanner;
@@ -30,6 +29,7 @@ import java.util.List;
30 29
 
31 30
 /**
32 31
  * A helper class that loads animations from a file or saves them to one.
32
+ * 
33 33
  * @author Thomas Buck
34 34
  * @author Max Nuding
35 35
  * @author Felix Bäder
@@ -37,178 +37,179 @@ import java.util.List;
37 37
  */
38 38
 
39 39
 public class AnimationUtility {
40
-  private static String lastError = null;
41
-
42
-  /**
43
-   * Read a file, return ArrayList with all animations in the file.
44
-   * @param path Path of file
45
-   * @return Populated ArrayList
46
-   * @throws Excpetion When something goes wrong with the Scanner...
47
-   */
48
-  public static List<Animation> readFile(String path) throws Exception {
49
-    Scanner sc = new Scanner(new File(path));
50
-  List<Animation> animations = new ArrayList<Animation>();
51
-  do {
52
-  Animation tmp = readAnimation(sc);
53
-  if (tmp == null) {
54
-    return animations;
55
-  }
56
-  if (sc.hasNextLine()) {
57
-    sc.nextLine();
58
-  }
59
-    animations.add(tmp);
60
-  } while (sc.hasNextLine());
61
-
62
-  return animations;
63
-  }
64
-
65
-  /**
66
-   * Write a file with all Animations of an ArrayList
67
-   * @param path Path to write to
68
-   * @param animations ArrayList with all animations to be saved
69
-   * @see AnimationUtility#getLastError() getLastError()
70
-   */
71
-  public static void writeFile(String path, List<Animation> animations) {
72
-    File f = new File(path);
73
-    if (f.exists()) {
74
-      try {
75
-        f.delete();
76
-      } catch (Exception e) {
77
-        lastError = e.toString();
78
-        return;
79
-      }
80
-    }
81
-    FileWriter output = null;
82
-    try {
83
-      output = new FileWriter(f);
84
-      for (int i = 0; i < animations.size(); i++) {
85
-        writeAnimation(animations.get(i), output, (i == (animations.size() - 1)));
86
-      }
87
-    } catch (Exception e) {
88
-      lastError = e.toString();
89
-      return;
90
-    } finally {
91
-      if (output != null) {
92
-        try {
93
-          output.close();
94
-        } catch (Exception e) {
95
-          lastError = e.toString();
96
-        }
97
-      }
98
-    }
99
-
100
-  }
101
-
102
-  /**
103
-   * Get the last error that occured while writing
104
-   * @return Text of the exception that occured
105
-   * @see AnimationUtility#writeFile(String, ArrayList) writeFile()
106
-   */
107
-  public static String getLastError() {
108
-    String tmp = lastError;
109
-    lastError = null;
110
-    return tmp;
111
-  }
112
-
113
-  private static Animation readAnimation(Scanner sc) {
114
-  Animation anim = new Animation();
115
-  AFrame f = null;
116
-  int index = 0;
117
-  String tmpSize = sc.nextLine().replaceAll("\\n", "");
118
-  if (tmpSize.equals("")) {
119
-    return null;
120
-  }
121
-  Integer tmpSizeAgain = new Integer(tmpSize);
122
-  int size = tmpSizeAgain.intValue();
123
-  anim.setName(sc.nextLine());
124
-  while (size > 0) {
125
-    f = readFrame(sc, index);
126
-    anim.add(index, f);
127
-    index++;
128
-    size--;
129
-  }
130
-  return anim;
131
-  }
132
-
133
-  private static AFrame readFrame(Scanner sc, int index) {
134
-    AFrame frame = new AFrame();
135
-    frame.setName(sc.nextLine());
136
-    short[] d = {};
137
-    for (int i = 0; i < 8; i++) {
138
-      short[] data = hexConvert(sc.nextLine());
139
-      d = concat(d, data);
140
-    }
141
-  
142
-    frame.setData(d);
143
-    d = hexConvert(sc.nextLine());
144
-    frame.setTime(d[0]);
145
-    return frame;
146
-  }
147
-  
148
-  /*private static short[] invert(short[] a){
149
-    short[] tmp = new short[a.length];
150
-    int j = 0;
151
-    for(int i = a.length-1; i >= 0; i--){
152
-      tmp[j] = a[i];
153
-      j++;
154
-    }
155
-    return tmp;
156
-  }*/
157
-
158
-  private static short[] concat(short[] a, short[] b) {
159
-  short[] c = new short[a.length + b.length];
160
-  System.arraycopy(a, 0, c, 0, a.length);
161
-  System.arraycopy(b, 0, c, a.length, b.length);
162
-  return c;
163
-  }
164
-
165
-  private static short[] hexConvert(String hex) {
166
-    hex = hex.replaceAll("\\n", "");
167
-
168
-      short[] tmp = new short[hex.length()/2];
169
-      for (int i = 0; i < hex.length(); i=i+2){
170
-        char[] tmpString = new char[2];
171
-        tmpString[0] = hex.charAt(i);
172
-        tmpString[1] = hex.charAt(i+1);
173
-        String tmpS = String.copyValueOf(tmpString);
174
-        if(i == 0){
175
-          tmp[0] = Short.parseShort(tmpS, 16);
176
-        } else {
177
-          tmp[i/2] = Short.parseShort(tmpS, 16);
178
-        }
179
-
180
-      }
181
-      return tmp;
182
-
183
-
184
-  }
185
-
186
-  private static void writeAnimation(Animation anim, FileWriter f, boolean last) throws IOException {
187
-    f.write(anim.size() + "\n");
188
-  f.write(anim.getName() + "\n");
189
-    for (int i = 0; i < anim.size(); i++) {
190
-      writeFrame(anim.get(i), f);
191
-    }
192
-    if (!last) {
193
-    f.write("\n");
194
-  }
195
-  }
196
-
197
-  private static void writeFrame(AFrame fr, FileWriter f) throws IOException {
198
-    f.write(fr.getName() + "\n");
199
-  for (int i = 0; i < 8; i++) {
200
-      writeLayer(fr.getLayer(i), f);
201
-    }
202
-    f.write(Integer.toString( (fr.getTime() & 0xff) + 0x100, 16).substring(1) + "\n");
203
-  }
204
-
205
-  private static void writeLayer(short[] l, FileWriter f) throws IOException {
206
-    String hex = "";
207
-    for (int i = 0; i < l.length; i++) {
208
-      hex += Integer.toString( (l[i] & 0xff) + 0x100, 16).substring(1);
209
-    }
210
-    hex += "\n";
211
-
212
-    f.write(hex);
213
-  }
40
+	private static String lastError = null;
41
+
42
+	/**
43
+	 * Read a file, return ArrayList with all animations in the file.
44
+	 * 
45
+	 * @param path Path of file
46
+	 * @return Populated ArrayList
47
+	 * @throws Excpetion When something goes wrong with the Scanner...
48
+	 */
49
+	public static List<Animation> readFile(String path) throws Exception {
50
+		Scanner sc = new Scanner(new File(path));
51
+		List<Animation> animations = new ArrayList<Animation>();
52
+		do {
53
+			Animation tmp = readAnimation(sc);
54
+			if (tmp == null) {
55
+				return animations;
56
+			}
57
+			if (sc.hasNextLine()) {
58
+				sc.nextLine();
59
+			}
60
+			animations.add(tmp);
61
+		} while (sc.hasNextLine());
62
+
63
+		return animations;
64
+	}
65
+
66
+	/**
67
+	 * Write a file with all Animations of an ArrayList
68
+	 * 
69
+	 * @param path Path to write to
70
+	 * @param animations ArrayList with all animations to be saved
71
+	 * @see AnimationUtility#getLastError() getLastError()
72
+	 */
73
+	public static void writeFile(String path, List<Animation> animations) {
74
+		File f = new File(path);
75
+		if (f.exists()) {
76
+			try {
77
+				f.delete();
78
+			} catch (Exception e) {
79
+				lastError = e.toString();
80
+				return;
81
+			}
82
+		}
83
+		FileWriter output = null;
84
+		try {
85
+			output = new FileWriter(f);
86
+			for (int i = 0; i < animations.size(); i++) {
87
+				writeAnimation(animations.get(i), output,
88
+						(i == (animations.size() - 1)));
89
+			}
90
+		} catch (Exception e) {
91
+			lastError = e.toString();
92
+			return;
93
+		} finally {
94
+			if (output != null) {
95
+				try {
96
+					output.close();
97
+				} catch (Exception e) {
98
+					lastError = e.toString();
99
+				}
100
+			}
101
+		}
102
+
103
+	}
104
+
105
+	/**
106
+	 * Get the last error that occured while writing
107
+	 * 
108
+	 * @return Text of the exception that occured
109
+	 * @see AnimationUtility#writeFile(String, ArrayList) writeFile()
110
+	 */
111
+	public static String getLastError() {
112
+		String tmp = lastError;
113
+		lastError = null;
114
+		return tmp;
115
+	}
116
+
117
+	private static Animation readAnimation(Scanner sc) {
118
+		Animation anim = new Animation();
119
+		AFrame f = null;
120
+		int index = 0;
121
+		String tmpSize = sc.nextLine().replaceAll("\\n", "");
122
+		if (tmpSize.equals("")) {
123
+			return null;
124
+		}
125
+		Integer tmpSizeAgain = new Integer(tmpSize);
126
+		int size = tmpSizeAgain.intValue();
127
+		anim.setName(sc.nextLine());
128
+		while (size > 0) {
129
+			f = readFrame(sc, index);
130
+			anim.add(index, f);
131
+			index++;
132
+			size--;
133
+		}
134
+		return anim;
135
+	}
136
+
137
+	private static AFrame readFrame(Scanner sc, int index) {
138
+		AFrame frame = new AFrame();
139
+		frame.setName(sc.nextLine());
140
+		short[] d = {};
141
+		for (int i = 0; i < 8; i++) {
142
+			short[] data = hexConvert(sc.nextLine());
143
+			d = concat(d, data);
144
+		}
145
+
146
+		frame.setData(d);
147
+		d = hexConvert(sc.nextLine());
148
+		frame.setTime(d[0]);
149
+		return frame;
150
+	}
151
+
152
+	/*
153
+	 * private static short[] invert(short[] a){ short[] tmp = new
154
+	 * short[a.length]; int j = 0; for(int i = a.length-1; i >= 0; i--){ tmp[j]
155
+	 * = a[i]; j++; } return tmp; }
156
+	 */
157
+
158
+	private static short[] concat(short[] a, short[] b) {
159
+		short[] c = new short[a.length + b.length];
160
+		System.arraycopy(a, 0, c, 0, a.length);
161
+		System.arraycopy(b, 0, c, a.length, b.length);
162
+		return c;
163
+	}
164
+
165
+	private static short[] hexConvert(String hex) {
166
+		hex = hex.replaceAll("\\n", "");
167
+
168
+		short[] tmp = new short[hex.length() / 2];
169
+		for (int i = 0; i < hex.length(); i = i + 2) {
170
+			char[] tmpString = new char[2];
171
+			tmpString[0] = hex.charAt(i);
172
+			tmpString[1] = hex.charAt(i + 1);
173
+			String tmpS = String.copyValueOf(tmpString);
174
+			if (i == 0) {
175
+				tmp[0] = Short.parseShort(tmpS, 16);
176
+			} else {
177
+				tmp[i / 2] = Short.parseShort(tmpS, 16);
178
+			}
179
+
180
+		}
181
+		return tmp;
182
+
183
+	}
184
+
185
+	private static void writeAnimation(Animation anim, FileWriter f,
186
+			boolean last) throws IOException {
187
+		f.write(anim.size() + "\n");
188
+		f.write(anim.getName() + "\n");
189
+		for (int i = 0; i < anim.size(); i++) {
190
+			writeFrame(anim.get(i), f);
191
+		}
192
+		if (!last) {
193
+			f.write("\n");
194
+		}
195
+	}
196
+
197
+	private static void writeFrame(AFrame fr, FileWriter f) throws IOException {
198
+		f.write(fr.getName() + "\n");
199
+		for (int i = 0; i < 8; i++) {
200
+			writeLayer(fr.getLayer(i), f);
201
+		}
202
+		f.write(Integer.toString((fr.getTime() & 0xff) + 0x100, 16)
203
+				.substring(1) + "\n");
204
+	}
205
+
206
+	private static void writeLayer(short[] l, FileWriter f) throws IOException {
207
+		String hex = "";
208
+		for (int i = 0; i < l.length; i++) {
209
+			hex += Integer.toString((l[i] & 0xff) + 0x100, 16).substring(1);
210
+		}
211
+		hex += "\n";
212
+
213
+		f.write(hex);
214
+	}
214 215
 }

+ 919
- 853
CubeControl/Frame.java
File diff suppressed because it is too large
View File


+ 16
- 7
CubeControl/HelperUtility.java View File

@@ -28,7 +28,6 @@
28 28
  * @author Felix Bäder
29 29
  * @version 1.0
30 30
  */
31
-
32 31
 import java.io.*;
33 32
 import java.nio.channels.*;
34 33
 import java.nio.*;
@@ -65,7 +64,8 @@ public class HelperUtility {
65 64
 			// have to use a stream
66 65
 			InputStream in = HelperUtility.class.getResourceAsStream(name);
67 66
 			// System.out.println("Input Stream: " + in);
68
-			File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + path + name);
67
+			File fileOut = new File(System.getProperty("java.io.tmpdir") + "/"
68
+					+ path + name);
69 69
 			OutputStream out = new FileOutputStream(fileOut);
70 70
 			ReadableByteChannel inChannel = Channels.newChannel(in);
71 71
 			WritableByteChannel outChannel = Channels.newChannel(out);
@@ -80,7 +80,8 @@ public class HelperUtility {
80 80
 	}
81 81
 
82 82
 	// http://thomaswabner.wordpress.com/2007/10/09/fast-stream-copy-using-javanio-channels/
83
-	public static void fastChannelCopy(ReadableByteChannel src, WritableByteChannel dest) throws IOException {
83
+	public static void fastChannelCopy(ReadableByteChannel src,
84
+			WritableByteChannel dest) throws IOException {
84 85
 		ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
85 86
 		while (src.read(buffer) != -1) {
86 87
 			// prepare the buffer to be drained
@@ -101,6 +102,7 @@ public class HelperUtility {
101 102
 
102 103
 	/**
103 104
 	 * Get all the existing serial port names
105
+	 * 
104 106
 	 * @return List of port names. \n between entries
105 107
 	 */
106 108
 	public static String getPorts() {
@@ -121,8 +123,10 @@ public class HelperUtility {
121 123
 
122 124
 	/**
123 125
 	 * Open Connection to a port
126
+	 * 
124 127
 	 * @return TRUE if successful
125
-	 * @param name Port to open
128
+	 * @param name
129
+	 *            Port to open
126 130
 	 */
127 131
 	public static native boolean openPort(String name);
128 132
 
@@ -133,15 +137,20 @@ public class HelperUtility {
133 137
 
134 138
 	/**
135 139
 	 * Read data from Cube
136
-	 * @param length Amount of data to read
140
+	 * 
141
+	 * @param length
142
+	 *            Amount of data to read
137 143
 	 * @return Data read
138 144
 	 */
139 145
 	public static native short[] readData(int length);
140 146
 
141 147
 	/**
142 148
 	 * Write data to Cube
143
-	 * @param data Data to write
144
-	 * @param length Length of data
149
+	 * 
150
+	 * @param data
151
+	 *            Data to write
152
+	 * @param length
153
+	 *            Length of data
145 154
 	 */
146 155
 	public static native void writeData(short[] data, int length);
147 156
 }

+ 132
- 117
CubeControl/Led3D.java View File

@@ -1,37 +1,36 @@
1 1
 /*
2
-* Led3D.java
3
-*
4
-*
5
-* Copyright 2011 Thomas Buck <xythobuz@me.com>
6
-* Copyright 2011 Max Nuding <max.nuding@gmail.com>
7
-* Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
8
-*
9
-* This file is part of LED-Cube.
10
-*
11
-* LED-Cube is free software: you can redistribute it and/or modify
12
-* it under the terms of the GNU General Public License as published by
13
-* the Free Software Foundation, either version 3 of the License, or
14
-* (at your option) any later version.
15
-*
16
-* LED-Cube is distributed in the hope that it will be useful,
17
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
-* GNU General Public License for more details.
20
-*
21
-* You should have received a copy of the GNU General Public License
22
-* along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
23
-*/
24
-
2
+ * Led3D.java
3
+ *
4
+ *
5
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
6
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
7
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
8
+ *
9
+ * This file is part of LED-Cube.
10
+ *
11
+ * LED-Cube is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation, either version 3 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * LED-Cube is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
23
+ */
25 24
 import com.sun.j3d.utils.universe.*;
26 25
 import com.sun.j3d.utils.geometry.*;
27 26
 import javax.media.j3d.*;
28 27
 import javax.vecmath.*;
29 28
 import com.sun.j3d.utils.behaviors.mouse.*;
30
-import java.awt.Color;
31 29
 import com.sun.j3d.utils.image.TextureLoader;
32 30
 
33 31
 /**
34 32
  * This class is responsible for displaying the 3D View of our Cube.
33
+ * 
35 34
  * @author Thomas Buck
36 35
  * @author Max Nuding
37 36
  * @author Felix Bäder
@@ -43,97 +42,108 @@ public class Led3D {
43 42
 	private SimpleUniverse universe = null;
44 43
 	private BranchGroup group = null;
45 44
 	private Transform3D trans3D = null;
46
-	private BranchGroup inBetween = null;
47 45
 	private TransformGroup transGroup = null;
48 46
 
49 47
 	private Sphere[][][] leds = new Sphere[8][8][8];
50
-	private static ColoringAttributes redColor = new ColoringAttributes(new Color3f(1.0f, 0.0f, 0.0f), ColoringAttributes.FASTEST);
51
-	private static ColoringAttributes whiteColor = new ColoringAttributes(new Color3f(0.2f, 0.2f, 0.2f), ColoringAttributes.FASTEST);
52
-	private static Material whiteMat = new Material(new Color3f(0.2f, 0.2f, 0.2f), new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.2f, 0.2f, 0.2f), new Color3f(0.2f, 0.2f, 0.2f), 64.0f);
53
-	private static Material redMat = new Material(new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), 64.0f);
54
-
55
-  /**
56
-   * @param canv The Canvas3D we render our cube in
57
-   */
58
-  public Led3D(Canvas3D canv) {
59
-
60
-    canvas = canv;
61
-    group = new BranchGroup();
62
-    // Position viewer, so we are looking at object
63
-    trans3D = new Transform3D();
64
-	Matrix4d mat = new Matrix4d();
65
-	mat.setRow(0, 0.744, 0.0237, -0.66756, -0.34);
66
-	mat.setRow(1, 0.136, -0.9837, 0.117, 3.24);
67
-	mat.setRow(2, -0.6536, -0.1785, -0.735, -8.32);
68
-	mat.setRow(3, 0.0, 0.0, 0.0, 1.0);
69
-	trans3D.set(mat);
70
-
71
-	transGroup = new TransformGroup(trans3D);
72
-	transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
73
-	transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
74
-    ViewingPlatform viewingPlatform = new ViewingPlatform();
75
-    Viewer viewer = new Viewer(canvas);
76
-    universe = new SimpleUniverse(viewingPlatform, viewer);
77
-
78
-    BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
79
-    // roration with left mouse button
80
-    MouseRotate behaviour = new MouseRotate(transGroup);
81
-	behaviour.setSchedulingBounds(boundBox);
82
-    transGroup.addChild(behaviour);
83
-
84
-    // zoom with middle mouse button
85
-    MouseZoom beh2 = new MouseZoom(transGroup);
86
-	beh2.setSchedulingBounds(boundBox);
87
-	transGroup.addChild(beh2);
88
-
89
-    // move with right mouse button
90
-    MouseTranslate beh3 = new MouseTranslate(transGroup);
91
-    beh3.setSchedulingBounds(boundBox);
92
-	transGroup.addChild(beh3);
93
-
94
-	group.addChild(createBackground());
95
-
96
-    // Add all our led sphares to the universe
97
-    for (int x = 0; x < 8; x++) {
98
-      for (int y = 0; y < 8; y++) {
99
-        for (int z = 0; z < 8; z++) {
100
-          Appearance a = new Appearance();
101
-          a.setMaterial(whiteMat);
102
-		  a.setColoringAttributes(whiteColor);
103
-		  
104
-		  leds[x][y][z] = new Sphere(0.08f, Sphere.ENABLE_APPEARANCE_MODIFY, a);
105
-
106
-          TransformGroup tg = new TransformGroup();
107
-          Transform3D transform = new Transform3D();
108
-          Vector3f vector = new Vector3f(x, y, z);
109
-          transform.setTranslation(vector);
110
-          tg.setTransform(transform);
111
-          tg.addChild(leds[x][y][z]);
112
-          transGroup.addChild(tg);
113
-
114
-		  drawLedFeetVertical((double)x, y + 0.5, (double)z, 0.9f, 0.01f);
115
-		  if (x < 7)
116
-			  drawLedFeetHorizontal(x + 0.5, (double)y, (double)z, 0.9f, 0.01f, 0);
117
-        }
118
-      }
119
-	  // 8 times, use x as y
120
-	  drawLedFeetHorizontal(0.5, (double)x, 3.5, 7.0f, 0.02f, 90);
121
-	  drawLedFeetHorizontal(6.5, (double)x, 3.5, 7.0f, 0.02f, 90);
122
-	  drawLedFeetHorizontal(3.5, (double)x, 3.5, 7.0f, 0.02f, 90);
123
-    }
124
-
125
-    // Add an ambient light
126
-    Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
127
-    AmbientLight light2 = new AmbientLight(light2Color);
128
-    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
129
-    light2.setInfluencingBounds(bounds);
130
-    light2.setEnable(true);
131
-    transGroup.addChild(light2);
132
-	group.addChild(transGroup);
133
-	universe.addBranchGraph(group); // Add group to universe
134
-  }
135
-
136
-	private void drawLedFeetVertical(double x, double y, double z, float length, float rad) {
48
+	private static ColoringAttributes redColor = new ColoringAttributes(
49
+			new Color3f(1.0f, 0.0f, 0.0f), ColoringAttributes.FASTEST);
50
+	private static ColoringAttributes whiteColor = new ColoringAttributes(
51
+			new Color3f(0.2f, 0.2f, 0.2f), ColoringAttributes.FASTEST);
52
+	private static Material whiteMat = new Material(new Color3f(0.2f, 0.2f,
53
+			0.2f), new Color3f(0.0f, 0.0f, 0.0f),
54
+			new Color3f(0.2f, 0.2f, 0.2f), new Color3f(0.2f, 0.2f, 0.2f), 64.0f);
55
+	private static Material redMat = new Material(
56
+			new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f),
57
+			new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), 64.0f);
58
+
59
+	/**
60
+	 * @param canv The Canvas3D we render our cube in
61
+	 */
62
+	public Led3D(Canvas3D canv) {
63
+
64
+		canvas = canv;
65
+		group = new BranchGroup();
66
+		// Position viewer, so we are looking at object
67
+		trans3D = new Transform3D();
68
+		Matrix4d mat = new Matrix4d();
69
+		mat.setRow(0, 0.744, 0.0237, -0.66756, -0.34);
70
+		mat.setRow(1, 0.136, -0.9837, 0.117, 3.24);
71
+		mat.setRow(2, -0.6536, -0.1785, -0.735, -8.32);
72
+		mat.setRow(3, 0.0, 0.0, 0.0, 1.0);
73
+		trans3D.set(mat);
74
+
75
+		transGroup = new TransformGroup(trans3D);
76
+		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
77
+		transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
78
+		ViewingPlatform viewingPlatform = new ViewingPlatform();
79
+		Viewer viewer = new Viewer(canvas);
80
+		universe = new SimpleUniverse(viewingPlatform, viewer);
81
+
82
+		BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0),
83
+				new Point3d(13.0, 13.0, 13.0));
84
+		// roration with left mouse button
85
+		MouseRotate behaviour = new MouseRotate(transGroup);
86
+		behaviour.setSchedulingBounds(boundBox);
87
+		transGroup.addChild(behaviour);
88
+
89
+		// zoom with middle mouse button
90
+		MouseZoom beh2 = new MouseZoom(transGroup);
91
+		beh2.setSchedulingBounds(boundBox);
92
+		transGroup.addChild(beh2);
93
+
94
+		// move with right mouse button
95
+		MouseTranslate beh3 = new MouseTranslate(transGroup);
96
+		beh3.setSchedulingBounds(boundBox);
97
+		transGroup.addChild(beh3);
98
+
99
+		group.addChild(createBackground());
100
+
101
+		// Add all our led sphares to the universe
102
+		for (int x = 0; x < 8; x++) {
103
+			for (int y = 0; y < 8; y++) {
104
+				for (int z = 0; z < 8; z++) {
105
+					Appearance a = new Appearance();
106
+					a.setMaterial(whiteMat);
107
+					a.setColoringAttributes(whiteColor);
108
+
109
+					leds[x][y][z] = new Sphere(0.08f,
110
+							Sphere.ENABLE_APPEARANCE_MODIFY, a);
111
+
112
+					TransformGroup tg = new TransformGroup();
113
+					Transform3D transform = new Transform3D();
114
+					Vector3f vector = new Vector3f(x, y, z);
115
+					transform.setTranslation(vector);
116
+					tg.setTransform(transform);
117
+					tg.addChild(leds[x][y][z]);
118
+					transGroup.addChild(tg);
119
+
120
+					drawLedFeetVertical((double) x, y + 0.5, (double) z, 0.9f,
121
+							0.01f);
122
+					if (x < 7)
123
+						drawLedFeetHorizontal(x + 0.5, (double) y, (double) z,
124
+								0.9f, 0.01f, 0);
125
+				}
126
+			}
127
+			// 8 times, use x as y
128
+			drawLedFeetHorizontal(0.5, (double) x, 3.5, 7.0f, 0.02f, 90);
129
+			drawLedFeetHorizontal(6.5, (double) x, 3.5, 7.0f, 0.02f, 90);
130
+			drawLedFeetHorizontal(3.5, (double) x, 3.5, 7.0f, 0.02f, 90);
131
+		}
132
+
133
+		// Add an ambient light
134
+		Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
135
+		AmbientLight light2 = new AmbientLight(light2Color);
136
+		BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
137
+				100.0);
138
+		light2.setInfluencingBounds(bounds);
139
+		light2.setEnable(true);
140
+		transGroup.addChild(light2);
141
+		group.addChild(transGroup);
142
+		universe.addBranchGraph(group); // Add group to universe
143
+	}
144
+
145
+	private void drawLedFeetVertical(double x, double y, double z,
146
+			float length, float rad) {
137 147
 		// draw Feet going down
138 148
 		Appearance feetApp = new Appearance();
139 149
 		feetApp.setMaterial(whiteMat);
@@ -150,7 +160,8 @@ public class Led3D {
150 160
 		transGroup.addChild(tg);
151 161
 	}
152 162
 
153
-	private void drawLedFeetHorizontal(double x, double y, double z, float length, float rad, int deg) {
163
+	private void drawLedFeetHorizontal(double x, double y, double z,
164
+			float length, float rad, int deg) {
154 165
 		// draw Feet going down
155 166
 		Appearance feetApp = new Appearance();
156 167
 		feetApp.setMaterial(whiteMat);
@@ -184,9 +195,10 @@ public class Led3D {
184 195
 	}
185 196
 
186 197
 	/**
187
-	 * Prints the translation matrix that is changed by moving/rotating the 3D Cube with your mouse.
198
+	 * Prints the translation matrix that is changed by moving/rotating the 3D
199
+	 * Cube with your mouse.
188 200
 	 */
189
-  	public void printTranslationData() {
201
+	public void printTranslationData() {
190 202
 		Matrix4d mat = new Matrix4d();
191 203
 		Transform3D t = new Transform3D();
192 204
 		transGroup.getTransform(t);
@@ -197,6 +209,7 @@ public class Led3D {
197 209
 
198 210
 	/**
199 211
 	 * Sets the data that is displayed by the LEDs
212
+	 * 
200 213
 	 * @param data 64 byte array with the data (8 bits/LEDs per byte)
201 214
 	 */
202 215
 	public void setData(short[] data) {
@@ -221,9 +234,11 @@ public class Led3D {
221 234
 
222 235
 	// create nice background
223 236
 	private Background createBackground() {
224
-		ImageComponent2D image = new TextureLoader(getClass().getResource("bg.png"), null).getImage();
237
+		ImageComponent2D image = new TextureLoader(getClass().getResource(
238
+				"bg.png"), null).getImage();
225 239
 		Background bg = new Background(image);
226
-		bg.setApplicationBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
240
+		bg.setApplicationBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
241
+				100.0));
227 242
 		return bg;
228 243
 	}
229 244
 }

+ 263
- 234
CubeControl/cubeWorker.java View File

@@ -27,11 +27,13 @@
27 27
  */
28 28
 import java.util.ArrayList;
29 29
 import java.util.List;
30
-import java.util.Collections;
31 30
 import java.util.StringTokenizer;
32 31
 
33 32
 /**
34
- * This class holds all Data of the Application. Additionally it performs the transmission of animation data to/from the cube and saves/loads animations in/from a file.
33
+ * This class holds all Data of the Application. Additionally it performs the
34
+ * transmission of animation data to/from the cube and saves/loads animations
35
+ * in/from a file.
36
+ * 
35 37
  * @author Thomas Buck
36 38
  * @author Felix Bäder
37 39
  * @author Max Nuding
@@ -40,343 +42,368 @@ import java.util.StringTokenizer;
40 42
 
41 43
 public class cubeWorker {
42 44
 
43
-// --------------------
44
-// Definitions
45
-// --------------------
46
-
47
-  final int UP = 0;
48
-  final int DOWN = 1;
49
-
50
-// --------------------
51
-// Fields
52
-// --------------------
53
-
54
-  private List<Animation> animations = new ArrayList<Animation>();
55
-  private int framesRemaining = 2016; // (128 * 1024) / 65 = 2016,...
56
-  private boolean changedState = false;
57
-
58
-// --------------------
59
-
60
-  /**
61
-   * Creates a worker with one animation, containing an empty frame.
62
-   */
63
-  cubeWorker() {
64
-  animations.add(new Animation());
65
-  animations.get(0).setName("Animation 1");
66
-  animations.get(0).add(0);
67
-  animations.get(0).get(0).setName("Frame 1");
68
-  framesRemaining--;
69
-  }
70
-  
71
-  /**
72
-   * Creates a worker from the given animation list
73
-   * @param anims List of animations
74
-   */
75
-  cubeWorker(List<Animation> anims) {
76
-    animations = anims;
77
-  }
78
-
79
-// --------------------
80
-// Misc. Methods
81
-// --------------------
45
+	// --------------------
46
+	// Definitions
47
+	// --------------------
48
+
49
+	final int UP = 0;
50
+	final int DOWN = 1;
51
+
52
+	// --------------------
53
+	// Fields
54
+	// --------------------
55
+
56
+	private List<Animation> animations = new ArrayList<Animation>();
57
+	private int framesRemaining = 2016; // (128 * 1024) / 65 = 2016,...
58
+	private boolean changedState = false;
59
+
60
+	// --------------------
61
+
62
+	/**
63
+	 * Creates a worker with one animation, containing an empty frame.
64
+	 */
65
+	cubeWorker() {
66
+		animations.add(new Animation());
67
+		animations.get(0).setName("Animation 1");
68
+		animations.get(0).add(0);
69
+		animations.get(0).get(0).setName("Frame 1");
70
+		framesRemaining--;
71
+	}
72
+
73
+	/**
74
+	 * Creates a worker from the given animation list
75
+	 * 
76
+	 * @param anims List of animations
77
+	 */
78
+	cubeWorker(List<Animation> anims) {
79
+		animations = anims;
80
+	}
81
+
82
+	// --------------------
83
+	// Misc. Methods
84
+	// --------------------
82 85
 
83 86
 	/**
84 87
 	 * Get the number of animations in this worker.
88
+	 * 
85 89
 	 * @return number of animations
86 90
 	 */
87
-    public int numOfAnimations() {
88
-           return animations.size();
89
-    }
91
+	public int numOfAnimations() {
92
+		return animations.size();
93
+	}
90 94
 
91 95
 	/**
92 96
 	 * Get the number of frames in an animation.
97
+	 * 
93 98
 	 * @param selectedAnimation the animation you want to check
94 99
 	 * @return number of frames in this animation
95 100
 	 */
96
-    public int numOfFrames(int selectedAnimation) {
97
-           return animations.get(selectedAnimation).size();
98
-    }
101
+	public int numOfFrames(int selectedAnimation) {
102
+		return animations.get(selectedAnimation).size();
103
+	}
99 104
 
100
-    /**
105
+	/**
101 106
 	 * Get the number of frames you can add until the Cubes memory is full.
107
+	 * 
102 108
 	 * @return number of frames remaining
103 109
 	 */
104
-    public int framesRemaining() {
105
-           return framesRemaining;
106
-    }
107
-
110
+	public int framesRemaining() {
111
+		return framesRemaining;
112
+	}
108 113
 
109
-// --------------------
110
-// Animation Specific
111
-// --------------------
114
+	// --------------------
115
+	// Animation Specific
116
+	// --------------------
112 117
 
113 118
 	/**
114 119
 	 * Add an animation.
120
+	 * 
115 121
 	 * @return Index of new animation, or -1 if not enough space remaining.
116 122
 	 */
117
-    public int addAnimation() {
118
-    	changedState = true;
119
-    	if (framesRemaining <= 0) {
120
-          return -1;
121
-    	} else {
122
-    	  int s = animations.size();
123
-    	  animations.add(s, new Animation());
124
-    	  animations.get(s).setName("Animation " + animations.size());
125
-    	  return s;
126
-    	}
127
-    }
123
+	public int addAnimation() {
124
+		changedState = true;
125
+		if (framesRemaining <= 0) {
126
+			return -1;
127
+		} else {
128
+			int s = animations.size();
129
+			animations.add(s, new Animation());
130
+			animations.get(s).setName("Animation " + animations.size());
131
+			return s;
132
+		}
133
+	}
128 134
 
129 135
 	/**
130 136
 	 * Remove an animation.
137
+	 * 
131 138
 	 * @param selectedAnimation the animation you want to delete
132 139
 	 */
133
-    public void removeAnimation(int selectedAnimation) {
134
-    changedState = true;
135
-    animations.remove(selectedAnimation);
136
-    }
140
+	public void removeAnimation(int selectedAnimation) {
141
+		changedState = true;
142
+		animations.remove(selectedAnimation);
143
+	}
137 144
 
138 145
 	/**
139 146
 	 * Get the name of an animation
147
+	 * 
140 148
 	 * @return The name
141 149
 	 * @param selectedAnimation The animation you want to get the name from
142 150
 	 */
143
-  public String getAnimationName(int selectedAnimation) {
144
-      return animations.get(selectedAnimation).getName();
145
-    }
151
+	public String getAnimationName(int selectedAnimation) {
152
+		return animations.get(selectedAnimation).getName();
153
+	}
146 154
 
147 155
 	/**
148
-	 * Set the name of an animation
149
-	 * @param s New name
156
+	 * Set the name of an animation  @param s New name
157
+	 * 
150 158
 	 * @param selectedAnimation Index of the animation you want to change
151 159
 	 */
152
-  public void setAnimationName(String s, int selectedAnimation) {
153
-      changedState = true;
154
-    animations.get(selectedAnimation).setName(s);
155
-    }
160
+	public void setAnimationName(String s, int selectedAnimation) {
161
+		changedState = true;
162
+		animations.get(selectedAnimation).setName(s);
163
+	}
156 164
 
157 165
 	/**
158 166
 	 * Move an animation UP or DOWN.
167
+	 * 
159 168
 	 * @param dir Direction. Use UP and DOWN defined in cubeWorker
160 169
 	 * @param selectedAnimation Animation you want to move
161 170
 	 */
162
-  public void moveAnimation(int dir, int selectedAnimation) {
163
-  changedState = true;
164
-    if (dir == UP){
165
-        //animation moved up
166
-      if (selectedAnimation > 0) {
167
-        Animation tmp = animations.get(selectedAnimation);
168
-		animations.set(selectedAnimation, animations.get(selectedAnimation - 1));
169
-		animations.set(selectedAnimation - 1, tmp);
170
-    }
171
-    } else if (dir == DOWN){
172
-      //animation moved down
173
-    if (selectedAnimation < (animations.size() - 1)) {
174
-        Animation tmp = animations.get(selectedAnimation);
175
-		animations.set(selectedAnimation, animations.get(selectedAnimation + 1));
176
-		animations.set(selectedAnimation + 1, tmp);
177
-  }
178
-    }
179
-  }
180
-
181
-// --------------------
182
-// Frame Specific
183
-// --------------------
171
+	public void moveAnimation(int dir, int selectedAnimation) {
172
+		changedState = true;
173
+		if (dir == UP) {
174
+			// animation moved up
175
+			if (selectedAnimation > 0) {
176
+				Animation tmp = animations.get(selectedAnimation);
177
+				animations.set(selectedAnimation,
178
+						animations.get(selectedAnimation - 1));
179
+				animations.set(selectedAnimation - 1, tmp);
180
+			}
181
+		} else if (dir == DOWN) {
182
+			// animation moved down
183
+			if (selectedAnimation < (animations.size() - 1)) {
184
+				Animation tmp = animations.get(selectedAnimation);
185
+				animations.set(selectedAnimation,
186
+						animations.get(selectedAnimation + 1));
187
+				animations.set(selectedAnimation + 1, tmp);
188
+			}
189
+		}
190
+	}
191
+
192
+	// --------------------
193
+	// Frame Specific
194
+	// --------------------
184 195
 
185 196
 	/**
186 197
 	 * Get the name of a frame.
198
+	 * 
187 199
 	 * @param anim Animation the frame is in
188 200
 	 * @param frame Index of the frame
189 201
 	 */
190
-  public String getFrameName(int anim, int frame) {
191
-      return animations.get(anim).get(frame).getName();
192
-    }
202
+	public String getFrameName(int anim, int frame) {
203
+		return animations.get(anim).get(frame).getName();
204
+	}
193 205
 
194 206
 	/**
195 207
 	 * Set the name of a frame.
208
+	 * 
196 209
 	 * @param s New name
197 210
 	 * @param anim Animation Index
198 211
 	 * @param frame Frame Index
199 212
 	 */
200
-    public void setFrameName(String s, int anim, int frame) {
201
-    changedState = true;
202
-    animations.get(anim).get(frame).setName(s);
203
-    }
213
+	public void setFrameName(String s, int anim, int frame) {
214
+		changedState = true;
215
+		animations.get(anim).get(frame).setName(s);
216
+	}
204 217
 
205 218
 	/**
206 219
 	 * Add a Frame to an animation.
220
+	 * 
207 221
 	 * @return Index of new Frame or -1 if not enough space
208 222
 	 * @param anim Animation Index
209 223
 	 */
210
-    public int addFrame(int anim) {
211
-    changedState = true;
212
-    if (framesRemaining <= 0) {
213
-      return -1;
214
-    }
215
-    framesRemaining--;
216
-    int s = animations.get(anim).size();
217
-    animations.get(anim).add(s);
218
-  animations.get(anim).get(s).setName("Frame " + animations.get(anim).size());
219
-    return s;
220
-    }
221
-
222
-    /**
224
+	public int addFrame(int anim) {
225
+		changedState = true;
226
+		if (framesRemaining <= 0) {
227
+			return -1;
228
+		}
229
+		framesRemaining--;
230
+		int s = animations.get(anim).size();
231
+		animations.get(anim).add(s);
232
+		animations.get(anim).get(s)
233
+				.setName("Frame " + animations.get(anim).size());
234
+		return s;
235
+	}
236
+
237
+	/**
223 238
 	 * Remove a frame.
239
+	 * 
224 240
 	 * @param anim Animation Index
225 241
 	 * @param frame Frame you want to remove
226 242
 	 */
227
-    public void removeFrame(int anim, int frame) {
228
-    changedState = true;
229
-    animations.get(anim).remove(frame);
230
-    }
243
+	public void removeFrame(int anim, int frame) {
244
+		changedState = true;
245
+		animations.get(anim).remove(frame);
246
+	}
231 247
 
232 248
 	/**
233 249
 	 * Get the data of a frame.
234
-	 * @param anim Animation Index
235
-	 * @param frame Frame Index
250
+	 * 
251
+	 * @param anim Animation Index  @param frame Frame Index
236 252
 	 * @return 64 byte array with data (8 bits per byte => 512 bits)
237 253
 	 */
238
-    public short[] getFrame(int anim, int frame) {
239
-    return animations.get(anim).get(frame).getData();
240
-  }
254
+	public short[] getFrame(int anim, int frame) {
255
+		return animations.get(anim).get(frame).getData();
256
+	}
241 257
 
242 258
 	/**
243 259
 	 * Set the data of a frame
260
+	 * 
244 261
 	 * @param data 64 byte array with data
245 262
 	 * @param anim Animation Index
246 263
 	 * @param frame Frame Index
247 264
 	 * @see cubeWorker#getFrame(int, int) getFrame()
248 265
 	 */
249
-    public void setFrame(short[] data, int anim, int frame) {
250
-    changedState = true;
251
-    animations.get(anim).get(frame).setData(data);
252
-    }
253
-
254
-  /**
255
-   * Get frame duration.
256
-   * @param anim Animation Index
257
-   * @param frame Frame Index
258
-   * @return Duration. 0 means 1/24th of a second.
259
-   */
260
-  public short getFrameTime(int anim, int frame) {
261
-    return animations.get(anim).get(frame).getTime();
262
-  }
263
-
264
-  /**
265
-   * Set the frames duration.
266
-   * @param time New duration
267
-   * @param anim Animation Index
268
-   * @param frame Frame Index
269
-   * @see cubeWorker#getFrameTime(int, int) getFrameTime()
270
-   */
271
-  public void setFrameTime(short time, int anim, int frame) {
272
-    changedState = true;
273
-    animations.get(anim).get(frame).setTime(time);
274
-  }
275
-
276
-  /**
277
-   * Move a frame.
278
-   * @param dir Direction to move. Use UP and DOWN from cubeWorker
279
-   * @param anim Animation Index
280
-   * @param frame Frame Index
281
-   * @see cubeWorker#moveAnimation(int, int) moveAnimation()
282
-   */
283
-  public void moveFrame(int dir, int anim, int frame){
284
-  changedState = true;
285
-    if (dir == UP){
286
-        // frame moved up
287
-        if (frame > 0) {
288
-          AFrame tmp = animations.get(anim).frames.get(frame);
289
-		  animations.get(anim).frames.set(frame, animations.get(anim).frames.get(frame - 1));
290
-		  animations.get(anim).frames.set(frame - 1, tmp);
291
-      }
292
-    } else if (dir == DOWN){
293
-      // frame moved down
294
-    if (frame < (animations.get(anim).size() - 1)) {
295
-      AFrame tmp = animations.get(anim).frames.get(frame);
296
-		  animations.get(anim).frames.set(frame, animations.get(anim).frames.get(frame + 1));
297
-		  animations.get(anim).frames.set(frame + 1, tmp);
298
-    }
299
-    }
300
-  }
301
-
302
-// --------------------
303
-// File Specific
304
-// --------------------
266
+	public void setFrame(short[] data, int anim, int frame) {
267
+		changedState = true;
268
+		animations.get(anim).get(frame).setData(data);
269
+	}
270
+
271
+	/**
272
+	 * Get frame duration.
273
+	 * 
274
+	 * @param anim Animation Index
275
+	 * @param frame Frame Index
276
+	 * @return Duration. 0 means 1/24th of a second.
277
+	 */
278
+	public short getFrameTime(int anim, int frame) {
279
+		return animations.get(anim).get(frame).getTime();
280
+	}
281
+
282
+	/**
283
+	 * Set the frames duration.
284
+	 * 
285
+	 * @param time New duration
286
+	 * @param anim Animation Index
287
+	 * @param frame Frame Index
288
+	 * @see cubeWorker#getFrameTime(int, int) getFrameTime()
289
+	 */
290
+	public void setFrameTime(short time, int anim, int frame) {
291
+		changedState = true;
292
+		animations.get(anim).get(frame).setTime(time);
293
+	}
294
+
295
+	/**
296
+	 * Move a frame.
297
+	 * 
298
+	 * @param dir Direction to move. Use UP and DOWN from cubeWorker
299
+	 * @param anim Animation Index
300
+	 * @param frame Frame Index
301
+	 * @see cubeWorker#moveAnimation(int, int) moveAnimation()
302
+	 */
303
+	public void moveFrame(int dir, int anim, int frame) {
304
+		changedState = true;
305
+		if (dir == UP) {
306
+			// frame moved up
307
+			if (frame > 0) {
308
+				AFrame tmp = animations.get(anim).frames.get(frame);
309
+				animations.get(anim).frames.set(frame,
310
+						animations.get(anim).frames.get(frame - 1));
311
+				animations.get(anim).frames.set(frame - 1, tmp);
312
+			}
313
+		} else if (dir == DOWN) {
314
+			// frame moved down
315
+			if (frame < (animations.get(anim).size() - 1)) {
316
+				AFrame tmp = animations.get(anim).frames.get(frame);
317
+				animations.get(anim).frames.set(frame,
318
+						animations.get(anim).frames.get(frame + 1));
319
+				animations.get(anim).frames.set(frame + 1, tmp);
320
+			}
321
+		}
322
+	}
323
+
324
+	// --------------------
325
+	// File Specific
326
+	// --------------------
305 327
 
306 328
 	/**
307 329
 	 * Loads an animation file into this worker.
330
+	 * 
308 331
 	 * @param path Path of file to load
309 332
 	 * @return 0 on success, -1 on error.
310 333
 	 */
311
-    public int loadState(String path) {
312
-      changedState = false;
313
-    try {
314
-      animations = AnimationUtility.readFile(path);
315
-    } catch (Exception e) {
316
-    System.out.println("Did not load!");
317
-      e.printStackTrace(System.out);
318
-      return -1;
319
-    }
320
-    int size = 0;
321
-    for (int i = 0; i < animations.size(); i++) {
322
-      size += animations.get(i).size();
323
-    }
324
-    framesRemaining = 2016 - size;
325
-    if (size > 2016) {
326
-      return -1;
327
-    }
328
-        return 0;
329
-    }
334
+	public int loadState(String path) {
335
+		changedState = false;
336
+		try {
337
+			animations = AnimationUtility.readFile(path);
338
+		} catch (Exception e) {
339
+			System.out.println("Did not load!");
340
+			e.printStackTrace(System.out);
341
+			return -1;
342
+		}
343
+		int size = 0;
344
+		for (int i = 0; i < animations.size(); i++) {
345
+			size += animations.get(i).size();
346
+		}
347
+		framesRemaining = 2016 - size;
348
+		if (size > 2016) {
349
+			return -1;
350
+		}
351
+		return 0;
352
+	}
330 353
 
331 354
 	/**
332 355
 	 * Save the state of this object into a file.
356
+	 * 
333 357
 	 * @param path Path to save file in
334 358
 	 * @return 0 on success, -1 on error
335 359
 	 */
336
-    public int saveState(String path) {
337
-           changedState = false;
338
-       AnimationUtility.writeFile(path, animations);
339
-       if (AnimationUtility.getLastError() != null) {
340
-         System.out.println(AnimationUtility.getLastError());
341
-         return -1;
342
-      }
343
-           return 0;
344
-    }
360
+	public int saveState(String path) {
361
+		changedState = false;
362
+		AnimationUtility.writeFile(path, animations);
363
+		if (AnimationUtility.getLastError() != null) {
364
+			System.out.println(AnimationUtility.getLastError());
365
+			return -1;
366
+		}
367
+		return 0;
368
+	}
345 369
 
346 370
 	/**
347 371
 	 * Check if something changed after loading/saving.
372
+	 * 
348 373
 	 * @return TRUE if something changed, FALSE otherwise
349 374
 	 */
350
-    public boolean changedStateSinceSave() {
351
-           return changedState;
352
-    }
375
+	public boolean changedStateSinceSave() {
376
+		return changedState;
377
+	}
353 378
 
354
-// --------------------
355
-// Serial Port Specific
356
-// --------------------
379
+	// --------------------
380
+	// Serial Port Specific
381
+	// --------------------
357 382
 
358
-    /**
383
+	/**
359 384
 	 * Send all animations to the cube.
385
+	 * 
360 386
 	 * @param port Name of serial port to use
361 387
 	 * @return 0 on success, -1 on error
362 388
 	 */
363
-    public int uploadState(String port) {
389
+	public int uploadState(String port) {
364 390
 
365
-           return -1;
366
-    }
391
+		return -1;
392
+	}
367 393
 
368 394
 	/**
369 395
 	 * Get all animations from the cube, place it in this object
370
-	 * @param port Name of serial port to use
371
-	 * @return 0 on success, -1 on error
396
+	 * 
397
+	 * @param port Name of serial port to use  @return 0 on success, -1 on error
372 398
 	 */
373
-    public int downloadState(String port) {
399
+	public int downloadState(String port) {
374 400
 
375
-           return -1;
376
-    }
401
+		return -1;
402
+	}
377 403
 
378 404
 	/**
379 405
 	 * Try to speak with the cube.
406
+	 * 
380 407
 	 * @return TRUE if cube responds
381 408
 	 * @param port Name of serial port
382 409
 	 */
@@ -386,10 +413,12 @@ public class cubeWorker {
386 413
 
387 414
 	/**
388 415
 	 * Get the names of all available serial ports.
389
-	 * @return Array of port names. First entry is "Select serial port..." if no others
416
+	 * 
417
+	 * @return Array of port names. First entry is "Select serial port..." if no
418
+	 *         others
390 419
 	 */
391
-    public String[] getSerialPorts() {
392
-		String[] ports = {"Select serial port..."};
420
+	public String[] getSerialPorts() {
421
+		String[] ports = { "Select serial port..." };
393 422
 		String portLines = HelperUtility.getPorts();
394 423
 		if (portLines == null) {
395 424
 			return ports;
@@ -401,8 +430,8 @@ public class cubeWorker {
401 430
 			ports[i] = sT.nextToken();
402 431
 		}
403 432
 		return ports;
404
-    }
433
+	}
405 434
 
406
-// --------------------
435
+	// --------------------
407 436
 
408 437
 }

+ 205
- 202
CubeControl/layerEditFrame.java View File

@@ -1,27 +1,26 @@
1 1
 /*
2
-* layerEditFrame.java
3
-*
4
-*
5
-* Copyright 2011 Thomas Buck <xythobuz@me.com>
6
-* Copyright 2011 Max Nuding <max.nuding@gmail.com>
7
-* Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
8
-*
9
-* This file is part of LED-Cube.
10
-*
11
-* LED-Cube is free software: you can redistribute it and/or modify
12
-* it under the terms of the GNU General Public License as published by
13
-* the Free Software Foundation, either version 3 of the License, or
14
-* (at your option) any later version.
15
-*
16
-* LED-Cube is distributed in the hope that it will be useful,
17
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
-* GNU General Public License for more details.
20
-*
21
-* You should have received a copy of the GNU General Public License
22
-* along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
23
-*/
24
-
2
+ * layerEditFrame.java
3
+ *
4
+ *
5
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
6
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
7
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
8
+ *
9
+ * This file is part of LED-Cube.
10
+ *
11
+ * LED-Cube is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation, either version 3 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * LED-Cube is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
23
+ */
25 24
 import java.awt.*;
26 25
 import java.awt.event.*;
27 26
 import javax.swing.*;
@@ -29,6 +28,7 @@ import javax.swing.event.*;
29 28
 
30 29
 /**
31 30
  * Shows a windows that allows the user to toggle the state of 64 LEDs.
31
+ * 
32 32
  * @author Max Nuding
33 33
  * @author Thomas Buck
34 34
  * @author Felix Bäder
@@ -36,201 +36,204 @@ import javax.swing.event.*;
36 36
  */
37 37
 
38 38
 public class layerEditFrame extends JFrame {
39
-  // Anfang Attribute
40
-
41
-  private JPanel panelLED1 = new JPanel(null, true);
42
-  JButton[][] ledPanels = new JButton[8][8];
43
-  ImageIcon on = new ImageIcon(getClass().getResource("LEDon.png"));
44
-  ImageIcon off = new ImageIcon(getClass().getResource("LEDoff.png"));
45
-  byte[][] ledStatus = new byte[8][8];
46
-  boolean changedStateSinceSave = false;
47
-  short[] frame;
48
-  int li;
49
-  boolean finish = false;
50
-  cubeWorker worker = null;
51
-  int animI;
52
-  int frameI;
53
-  Frame LedFrame;
54
-
55
-  // Ende Attribute
56
-  /**
57
-   * Create a new layer editor.
58
-   * @param animIndex Current animation
59
-   * @param frameIndex Current frame
60
-   * @param layerIndex Layer to edit
61
-   * @param work the cubeWorker containing the data
62
-   * @param LEDframe Used to call valueChanged, to trigger 3D View update
63
-   */
64
-  public layerEditFrame(int animIndex, int frameIndex, int layerIndex, cubeWorker work, Frame LEDframe) {
65
-    // Frame-Initialisierung
66
-    super("Layer Edit");
67
-    worker = work;
68
-    LedFrame = LEDframe;
69
-    animI = animIndex;
70
-    frameI = frameIndex;
71
-    //frame =  byteToShortArray(worker.getFrame(animIndex, frameIndex));
72
-    frame = worker.getFrame(animIndex, frameIndex);
73
-    li = layerIndex;
74
-    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
75
-    int frameWidth = 180;
76
-    int frameHeight = 230;
77
-    setSize(frameWidth, frameHeight);
78
-    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
79
-    int x = (d.width - getSize().width) / 2;
80
-    int y = (d.height - getSize().height) / 2;
81
-    setLocation(x, y);
82
-    setResizable(false);
83
-    Container cp = getContentPane();
84
-    cp.setLayout(null);
85
-
86
-    for(int i = 0; i < 8; i++){
87
-      for(int j = 0; j < 8; j++){
88
-         final int finalI = i;
89
-         final int finalJ = j;
90
-         ledPanels[i][j] = new JButton(on);
91
-         ledPanels[i][j].setBounds((i*20)+5, (j*20)+5, 15, 15);
92
-         ledPanels[i][j].addActionListener(new ActionListener() {
93
-           public void actionPerformed(ActionEvent evt) {
94
-             btnClicked(finalI, finalJ);
95
-           }
96
-         });
97
-         ledPanels[i][j].setVisible(true);
98
-         cp.add(ledPanels[i][j]);
99
-      }
100
-    }
101
-    loadData();
102
-    JButton saveBtn = new JButton("Save");
103
-    JButton cancelBtn = new JButton("Cancel");
104
-
105
-    saveBtn.setBounds(5, 170, 70, 25);
106
-    saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
107
-    cp.add(saveBtn);
108
-    cancelBtn.setBounds(80, 170, 80, 25);
109
-    cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
110
-    cp.add(cancelBtn);
111
-    setVisible(true);
112
-
113
-
114
-
115
-    saveBtn.addActionListener(new ActionListener() {
116
-      public void actionPerformed(ActionEvent evt) {
117
-        save();
118
-      }
119
-    });
120
-
121
-    cancelBtn.addActionListener(new ActionListener() {
122
-      public void actionPerformed(ActionEvent evt) {
123
-        cancel();
124
-      }
125
-    });
126
-
127
-
128
-    addWindowListener(new WindowAdapter() {
129
-      public void windowClosing(WindowEvent evt) {
130
-             if(changedStateSinceSave){
131
-                saveExitDialog();
132
-             }
133
-             dispose();
134
-      }
135
-    });
136
-  }
137
-    // Anfang Komponenten
138
-
139
-    // Ende Komponenten
140
-  private void loadData(){
141
-
142
-    for(int i = 0; i < 8; i++){
143
-      int div = frame[(8*(li+1)+i)-8];
144
-      int[] rest = new int[8];
145
-      int ctr = 0;
146
-      while(div != 0){
147
-        rest[ctr] = div%2;
148
-        div = div/2;
149
-        ctr++;
150
-      }
151
-
152
-      for(int j = 0; j < 8; j++){
153
-        if(rest[j] == 0){
154
-         ledPanels[j][i].setIcon(off);
155
-        } else {
156
-         ledPanels[j][i].setIcon(on);
157
-        }
158
-        ledStatus[j][i] = (byte) rest[j];
159
-      }
160
-
161
-    }
162
-
163
-  }
39
+	// Anfang Attribute
40
+
41
+	private static final long serialVersionUID = 13374223L;
42
+	JButton[][] ledPanels = new JButton[8][8];
43
+	ImageIcon on = new ImageIcon(getClass().getResource("LEDon.png"));
44
+	ImageIcon off = new ImageIcon(getClass().getResource("LEDoff.png"));
45
+	byte[][] ledStatus = new byte[8][8];
46
+	boolean changedStateSinceSave = false;
47
+	short[] frame;
48
+	int li;
49
+	boolean finish = false;
50
+	cubeWorker worker = null;
51
+	int animI;
52
+	int frameI;
53
+	Frame LedFrame;
54
+
55
+	// Ende Attribute
56
+	/**
57
+	 * Create a new layer editor.
58
+	 * 
59
+	 * @param animIndex Current animation
60
+	 * @param frameIndex Current frame
61
+	 * @param layerIndex Layer to edit
62
+	 * @param work the cubeWorker containing the data
63
+	 * @param LEDframe Used to call valueChanged, to trigger 3D View update
64
+	 */
65
+	public layerEditFrame(int animIndex, int frameIndex, int layerIndex,
66
+			cubeWorker work, Frame LEDframe) {
67
+		// Frame-Initialisierung
68
+		super("Layer Edit");
69
+		worker = work;
70
+		LedFrame = LEDframe;
71
+		animI = animIndex;
72
+		frameI = frameIndex;
73
+		// frame = byteToShortArray(worker.getFrame(animIndex, frameIndex));
74
+		frame = worker.getFrame(animIndex, frameIndex);
75
+		li = layerIndex;
76
+		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
77
+		int frameWidth = 180;
78
+		int frameHeight = 230;
79
+		setSize(frameWidth, frameHeight);
80
+		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
81
+		int x = (d.width - getSize().width) / 2;
82
+		int y = (d.height - getSize().height) / 2;
83
+		setLocation(x, y);
84
+		setResizable(false);
85
+		Container cp = getContentPane();
86
+		cp.setLayout(null);
87
+
88
+		for (int i = 0; i < 8; i++) {
89
+			for (int j = 0; j < 8; j++) {
90
+				final int finalI = i;
91
+				final int finalJ = j;
92
+				ledPanels[i][j] = new JButton(on);
93
+				ledPanels[i][j].setBounds((i * 20) + 5, (j * 20) + 5, 15, 15);
94
+				ledPanels[i][j].addActionListener(new ActionListener() {
95
+					public void actionPerformed(ActionEvent evt) {
96
+						btnClicked(finalI, finalJ);
97
+					}
98
+				});
99
+				ledPanels[i][j].setVisible(true);
100
+				cp.add(ledPanels[i][j]);
101
+			}
102
+		}
103
+		loadData();
104
+		JButton saveBtn = new JButton("Save");
105
+		JButton cancelBtn = new JButton("Cancel");
106
+
107
+		saveBtn.setBounds(5, 170, 70, 25);
108
+		saveBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
109
+		cp.add(saveBtn);
110
+		cancelBtn.setBounds(80, 170, 80, 25);
111
+		cancelBtn.setFont(new Font("Dialog", Font.PLAIN, 13));
112
+		cp.add(cancelBtn);
113
+		setVisible(true);
114
+
115
+		saveBtn.addActionListener(new ActionListener() {
116
+			public void actionPerformed(ActionEvent evt) {
117
+				save();
118
+			}
119
+		});
120
+
121
+		cancelBtn.addActionListener(new ActionListener() {
122
+			public void actionPerformed(ActionEvent evt) {
123
+				cancel();
124
+			}
125
+		});
126
+
127
+		addWindowListener(new WindowAdapter() {
128
+			public void windowClosing(WindowEvent evt) {
129
+				if (changedStateSinceSave) {
130
+					saveExitDialog();
131
+				}
132
+				dispose();
133
+			}
134
+		});
135
+	}
136
+
137
+	// Anfang Komponenten
138
+
139
+	// Ende Komponenten
140
+	private void loadData() {
141
+
142
+		for (int i = 0; i < 8; i++) {
143
+			int div = frame[(8 * (li + 1) + i) - 8];
144
+			int[] rest = new int[8];
145
+			int ctr = 0;
146
+			while (div != 0) {
147
+				rest[ctr] = div % 2;
148
+				div = div / 2;
149
+				ctr++;
150
+			}
151
+
152
+			for (int j = 0; j < 8; j++) {
153
+				if (rest[j] == 0) {
154
+					ledPanels[j][i].setIcon(off);
155
+				} else {
156
+					ledPanels[j][i].setIcon(on);
157
+				}
158
+				ledStatus[j][i] = (byte) rest[j];
159
+			}
160
+
161
+		}
162
+
163
+	}
164 164
 
165 165
 	/**
166 166
 	 * Get the edited data back. NOTE: The worker is updated automagically!
167
+	 * 
167 168
 	 * @return Now changed 64 byte array.
168 169
 	 */
169
-   public short[] getFinalFrame(){
170
-      if (finish == false) {
171
-        return null;
172
-      }
173
-      return frame;
174
-   }
170
+	public short[] getFinalFrame() {
171
+		if (finish == false) {
172
+			return null;
173
+		}
174
+		return frame;
175
+	}
175 176
 
176 177
 	/**
177 178
 	 * Gets called when the user clicks on a Toggle Button.
179
+	 * 
178 180
 	 * @param i X-Coordinate of Button
179 181
 	 * @param j Y-Coordinate of Button
180 182
 	 */
181
-  public void btnClicked(int i, int j){
182
-    changedStateSinceSave = true;
183
-    if (ledPanels[i][j].getIcon() == on){
184
-      ledPanels[i][j].setIcon(off);
185
-       ledStatus[i][j] = 0;
186
-    } else {
187
-      ledPanels[i][j].setIcon(on);
188
-       ledStatus[i][j] = 1;
189
-    }
190
-
191
-  }
183
+	public void btnClicked(int i, int j) {
184
+		changedStateSinceSave = true;
185
+		if (ledPanels[i][j].getIcon() == on) {
186
+			ledPanels[i][j].setIcon(off);
187
+			ledStatus[i][j] = 0;
188
+		} else {
189
+			ledPanels[i][j].setIcon(on);
190
+			ledStatus[i][j] = 1;
191
+		}
192
+
193
+	}
192 194
 
193 195
 	/**
194 196
 	 * Action of Cancel Button. Removes this window...
195 197
 	 */
196
-  public void cancel(){
197
-    dispose();
198
-  }
198
+	public void cancel() {
199
+		dispose();
200
+	}
199 201
 
200 202
 	/**
201
-	 * Gets called when clicking the save button. Puts data back into Worker and fires ListSelectionEvent in Worker, so that the 3D View is updated.
203
+	 * Gets called when clicking the save button. Puts data back into Worker and
204
+	 * fires ListSelectionEvent in Worker, so that the 3D View is updated.
202 205
 	 */
203
-  public void save(){
204
-    int ctr = 0;
205
-    short[] tmpFrame = frame;
206
-    changedStateSinceSave = false;
207
-    short reihe = 0;
208
-    for(int j = 0; j < 8; j++){
209
-      for(int i = 0; i < 8; i++){
210
-        reihe += ((short) Math.pow(2, i)) * ledStatus[i][j];
211
-        ctr++;
212
-      }
213
-      tmpFrame[(8*(li+1)+j)-8] = reihe;
214
-      reihe = 0;
215
-    }
216
-      frame = tmpFrame;
217
-      worker.setFrame(frame, animI, frameI);
218
-      ListSelectionEvent layerChanged = new ListSelectionEvent(LedFrame.frameList, LedFrame.frameList.getSelectedIndex(), LedFrame.frameList.getSelectedIndex(), false);
219
-      LedFrame.valueChanged(layerChanged);
220
-      dispose();
221
-  }
222
-
223
-
224
-
225
-  private int saveExitDialog() {
226
-    String[] Optionen = {"Yes", "No"};
227
-    int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
228
-    if (Auswahl == JOptionPane.YES_OPTION) {
229
-       save();
230
-       return 1;
231
-    } else {
232
-       return 0;
233
-    }
234
-  }
206
+	public void save() {
207
+		short[] tmpFrame = frame;
208
+		changedStateSinceSave = false;
209
+		short reihe = 0;
210
+		for (int j = 0; j < 8; j++) {
211
+			for (int i = 0; i < 8; i++) {
212
+				reihe += ((short) Math.pow(2, i)) * ledStatus[i][j];
213
+			}
214
+			tmpFrame[(8 * (li + 1) + j) - 8] = reihe;
215
+			reihe = 0;
216
+		}
217
+		frame = tmpFrame;
218
+		worker.setFrame(frame, animI, frameI);
219
+		ListSelectionEvent layerChanged = new ListSelectionEvent(
220
+				LedFrame.frameList, LedFrame.frameList.getSelectedIndex(),
221
+				LedFrame.frameList.getSelectedIndex(), false);
222
+		LedFrame.valueChanged(layerChanged);
223
+		dispose();
224
+	}
225
+
226
+	private int saveExitDialog() {
227
+		String[] Optionen = { "Yes", "No" };
228
+		int Auswahl = JOptionPane.showOptionDialog(this,
229
+				"Do you want to save your changes?", "Save?",
230
+				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
231
+				Optionen, Optionen[0]);
232
+		if (Auswahl == JOptionPane.YES_OPTION) {
233
+			save();
234
+			return 1;
235
+		} else {
236
+			return 0;
237
+		}
238
+	}
235 239
 }
236
-

+ 78
- 0
CubeControl/libSerial/.project View File

@@ -0,0 +1,78 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>libSerial</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10
+			<triggers>clean,full,incremental,</triggers>
11
+			<arguments>
12
+				<dictionary>
13
+					<key>?name?</key>
14
+					<value></value>
15
+				</dictionary>
16
+				<dictionary>
17
+					<key>org.eclipse.cdt.make.core.append_environment</key>
18
+					<value>true</value>
19
+				</dictionary>
20
+				<dictionary>
21
+					<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
22
+					<value>all</value>
23
+				</dictionary>
24
+				<dictionary>
25
+					<key>org.eclipse.cdt.make.core.buildArguments</key>
26
+					<value></value>
27
+				</dictionary>
28
+				<dictionary>
29
+					<key>org.eclipse.cdt.make.core.buildCommand</key>
30
+					<value>make</value>
31
+				</dictionary>
32
+				<dictionary>
33
+					<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
34
+					<value>clean</value>
35
+				</dictionary>
36
+				<dictionary>
37
+					<key>org.eclipse.cdt.make.core.contents</key>
38
+					<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
39
+				</dictionary>
40
+				<dictionary>
41
+					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
42
+					<value>false</value>
43
+				</dictionary>
44
+				<dictionary>
45
+					<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
46
+					<value>true</value>
47
+				</dictionary>
48
+				<dictionary>
49
+					<key>org.eclipse.cdt.make.core.enableFullBuild</key>
50
+					<value>true</value>
51
+				</dictionary>
52
+				<dictionary>
53
+					<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
54
+					<value>all</value>
55
+				</dictionary>
56
+				<dictionary>
57
+					<key>org.eclipse.cdt.make.core.stopOnError</key>
58
+					<value>true</value>
59
+				</dictionary>
60
+				<dictionary>
61
+					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
62
+					<value>true</value>
63
+				</dictionary>
64
+			</arguments>
65
+		</buildCommand>
66
+		<buildCommand>
67
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
68
+			<triggers>full,incremental,</triggers>
69
+			<arguments>
70
+			</arguments>
71
+		</buildCommand>
72
+	</buildSpec>
73
+	<natures>
74
+		<nature>org.eclipse.cdt.core.cnature</nature>
75
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
76
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
77
+	</natures>
78
+</projectDescription>

+ 50
- 0
CubeControl/libSerial/makefile View File

@@ -0,0 +1,50 @@
1
+CC = gcc
2
+# Path to jni.h
3
+ifdef SystemRoot
4
+HEADERPATH = C:/Program\ Files/Java/jdk1.6.0_29/include
5
+RM = del
6
+PLATFORM = Win
7
+else
8
+HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
9
+RM = rm -f
10
+PLATFORM = Mac
11
+endif
12
+
13
+# --------------------------------------
14
+
15
+all: libSerial
16
+
17
+doc: doc/index.html
18
+
19
+serialInterface.h: HelperUtility.class
20
+	javah -o serialInterface.h HelperUtility
21
+
22
+HelperUtility.class: ../HelperUtility.java
23
+	javac ../HelperUtility.java
24
+	cp ../HelperUtility.class HelperUtility.class
25
+
26
+# SystemRoot is only defined in Windows
27
+ifdef SystemRoot
28
+libSerial: Serial.dll
29
+else
30
+libSerial: libSerial.jnilib
31
+endif
32
+
33
+libSerial.jnilib: serialHelper.c unixSerial.c serialInterface.h
34
+	$(CC) -x c -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o
35
+	$(CC) -dynamiclib -o libSerial.jnilib serialHelper.o
36
+
37
+Serial.dll: serialHelper.c winSerial.c serialInterface.h
38
+	$(CC) -x c -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper
39
+	$(CC) -shared -o Serial.dll serialHelper.o
40
+
41
+# Delete intermediate files
42
+clean:
43
+	$(RM) *.class
44
+	$(RM) *.h
45
+	$(RM) *.o
46
+ifdef SystemRoot
47
+	$(RM) *.dll
48
+else
49
+	$(RM) *.jnilib
50
+endif

CubeControl/serialHelper.c → CubeControl/libSerial/serialHelper.c View File

@@ -26,9 +26,9 @@
26 26
 #include "serialInterface.h"
27 27
 
28 28
 #ifdef winHelper
29
-#include "helper/winSerial.c"
29
+#include "winSerial.c"
30 30
 #else
31
-#include "helper/unixSerial.c"
31
+#include "unixSerial.c"
32 32
 #endif
33 33
 
34 34
 JNIEXPORT jstring JNICALL Java_HelperUtility_getThePorts(JNIEnv *env, jclass class, jstring s) {

CubeControl/helper/unixSerial.c → CubeControl/libSerial/unixSerial.c View File


CubeControl/helper/winSerial.c → CubeControl/libSerial/winSerial.c View File


+ 15
- 13
CubeControl/makefile View File

@@ -1,15 +1,16 @@
1 1
 # Name of your C-Compiler
2 2
 CC = gcc
3
+INJAR = *.class LEDoff.png LEDon.png splash.png bg.png
3 4
 # Path to jni.h
4 5
 ifdef SystemRoot
5 6
 HEADERPATH = C:/Program\ Files/Java/jdk1.6.0_29/include
6 7
 RM = del
7
-INJAR = *.class *.png Serial.dll
8
+INJAR += Serial.dll
8 9
 PLATFORM = Win
9 10
 else
10 11
 HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
11 12
 RM = rm -f
12
-INJAR = *.class *.png libSerial.jnilib
13
+INJAR += libSerial.jnilib
13 14
 PLATFORM = Mac
14 15
 endif
15 16
 
@@ -19,7 +20,7 @@ JAVAFILES = HelperUtility.java AnimationUtility.java Animation.java AFrame.java
19 20
 
20 21
 # --------------------------------------
21 22
 
22
-all: libSerial CubeControl.jar clean
23
+all: CubeControl.jar clean
23 24
 
24 25
 doc: doc/index.html
25 26
 
@@ -32,28 +33,29 @@ serialInterface.h: HelperUtility.class
32 33
 HelperUtility.class: $(JAVAFILES)
33 34
 	javac $(JAVAFILES)
34 35
 
35
-libSerial.jnilib: serialHelper.c helper/unixSerial.c serialInterface.h
36
-	$(CC) -x c -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o
37
-	$(CC) -dynamiclib -o libSerial.jnilib serialHelper.o
38
-
39
-Serial.dll: serialHelper.c helper/winSerial.c serialInterface.h
40
-	$(CC) -x c -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper
41
-	$(CC) -shared -o Serial.dll serialHelper.o
42
-
43 36
 doc/index.html: $(JAVAFILES)
44 37
 	javadoc -d doc $(JAVAFILES)
45 38
 
46
-# SystemRoot is only defined in Windows
47 39
 ifdef SystemRoot
48 40
 libSerial: Serial.dll
49 41
 else
50 42
 libSerial: libSerial.jnilib
51 43
 endif
52 44
 
45
+Serial.dll: libSerial/serialHelper.c libSerial/winSerial.c
46
+	make -C libSerial
47
+	mv libSerial/Serial.dll Serial.dll
48
+	make -C libSerial clean
49
+
50
+libSerial.jnilib: libSerial/serialHelper.c libSerial/unixSerial.c
51
+	make -C libSerial
52
+	mv libSerial/libSerial.jnilib libSerial.jnilib
53
+	make -C libSerial clean
54
+
53 55
 # Delete intermediate files
54 56
 clean:
55 57
 	$(RM) *.class
56
-	$(RM) *.h
58
+	$(RM) *.
57 59
 	$(RM) *.o
58 60
 ifdef SystemRoot
59 61
 	$(RM) *.dll

Loading…
Cancel
Save