Browse Source

Merge branch 'master' of github.com:xythobuz/LED-Cube

Conflicts:
	Cube Control/frame.java
Max Nuding 12 years ago
parent
commit
9446a5345a
1 changed files with 82 additions and 53 deletions
  1. 82
    53
      Cube Control/frame.java

+ 82
- 53
Cube Control/frame.java View File

@@ -1,14 +1,3 @@
1
-import java.awt.*;
2
-import java.awt.event.*;
3
-import javax.swing.*;
4
-import javax.swing.event.*;
5
-import java.io.File;
6
-import com.sun.j3d.utils.universe.*;
7
-import com.sun.j3d.utils.geometry.*;
8
-import javax.media.j3d.*;
9
-import javax.vecmath.*;
10
-import com.sun.j3d.utils.behaviors.mouse.*;
11
-
12 1
 /*
13 2
 * frame.java
14 3
 *
@@ -33,6 +22,17 @@ import com.sun.j3d.utils.behaviors.mouse.*;
33 22
 * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
34 23
 */
35 24
 
25
+import java.awt.*;
26
+import java.awt.event.*;
27
+import javax.swing.*;
28
+import javax.swing.event.*;
29
+import java.io.File;
30
+import com.sun.j3d.utils.universe.*;
31
+import com.sun.j3d.utils.geometry.*;
32
+import javax.media.j3d.*;
33
+import javax.vecmath.*;
34
+import com.sun.j3d.utils.behaviors.mouse.*;
35
+
36 36
 class Led3D {
37 37
   private Canvas3D canvas = null;
38 38
   private SimpleUniverse universe = null;
@@ -43,12 +43,10 @@ class Led3D {
43 43
 
44 44
   private Sphere[][][] leds = new Sphere[8][8][8];
45 45
 
46
-  private static ColoringAttributes colorRed = new ColoringAttributes(1.0f, 0.0f, 0.0f, ColoringAttributes.FASTEST);
47
-  private static ColoringAttributes colorWhite = new ColoringAttributes(1.0f, 1.0f, 1.0f, ColoringAttributes.FASTEST);
48
-
46
+	private static ColoringAttributes redColor = new ColoringAttributes(new Color3f(1.0f, 0.0f, 0.0f), ColoringAttributes.FASTEST);
47
+	private static ColoringAttributes whiteColor = new ColoringAttributes(new Color3f(1.0f, 1.0f, 1.0f), ColoringAttributes.FASTEST);
49 48
   private static Material whiteMat = new Material(new Color3f(1.0f, 1.0f, 1.0f), new Color3f(1.0f, 1.0f, 1.0f), new Color3f(1.0f, 1.0f, 1.0f), new Color3f(1.0f, 1.0f, 1.0f), 42.0f);
50 49
   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), 42.0f);
51
-  private static Appearance ledAppearance = new Appearance();
52 50
 
53 51
   private Point3d eye = new Point3d(3.5, 3.5, -13.0);
54 52
   private Point3d look = new Point3d(3.5, 3.5, 0.0);
@@ -68,17 +66,21 @@ class Led3D {
68 66
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
69 67
     transGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
70 68
     transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
69
+	transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
70
+	transGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
71 71
     Viewer viewer = new Viewer(canvas);
72 72
     universe = new SimpleUniverse(viewingPlatform, viewer);
73 73
     group.addChild(transGroup);
74 74
     universe.getViewingPlatform().getViewPlatformTransform().setTransform(trans3D);
75
-      universe.addBranchGraph(group); // Add group to universe
75
+    universe.addBranchGraph(group); // Add group to universe
76 76
 
77 77
     BoundingBox boundBox = new BoundingBox(new Point3d(-5.0, -5.0, -5.0), new Point3d(13.0, 13.0, 13.0));
78 78
     // roration with left mouse button
79 79
     MouseRotate behaviour = new MouseRotate(transGroup);
80 80
     BranchGroup inBetween = new BranchGroup();
81 81
     inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
82
+	inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
83
+	inBetween.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
82 84
     inBetween.addChild(behaviour);
83 85
     transGroup.addChild(inBetween);
84 86
     behaviour.setSchedulingBounds(boundBox);
@@ -87,6 +89,8 @@ class Led3D {
87 89
     MouseZoom beh2 = new MouseZoom(transGroup);
88 90
     BranchGroup brM2 = new BranchGroup();
89 91
     brM2.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
92
+	brM2.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
93
+	brM2.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
90 94
     brM2.addChild(beh2);
91 95
     inBetween.addChild(brM2);
92 96
     beh2.setSchedulingBounds(boundBox);
@@ -95,6 +99,8 @@ class Led3D {
95 99
     MouseTranslate beh3 = new MouseTranslate(transGroup);
96 100
     BranchGroup brM3 = new BranchGroup();
97 101
     brM3.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
102
+	brM3.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
103
+	brM3.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
98 104
     brM3.addChild(beh3);
99 105
     inBetween.addChild(brM3);
100 106
     beh3.setSchedulingBounds(boundBox);
@@ -104,20 +110,26 @@ class Led3D {
104 110
       for (int y = 0; y < 8; y++) {
105 111
         for (int z = 0; z < 8; z++) {
106 112
           leds[x][y][z] = new Sphere(0.05f);
113
+
107 114
           Appearance a = new Appearance();
108 115
           a.setMaterial(whiteMat);
109 116
           leds[x][y][z].setAppearance(a);
110
-          if ((x == 7) && (y == 7) && (z == 7)) {
111
-           a.setMaterial(redMat);
112
-          }
117
+		  leds[x][y][z].getShape().setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
118
+
113 119
           TransformGroup tg = new TransformGroup();
114 120
           tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
121
+		  tg.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
122
+		  tg.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
115 123
           Transform3D transform = new Transform3D();
116 124
           Vector3f vector = new Vector3f(x, y, z);
117 125
           transform.setTranslation(vector);
118 126
           tg.setTransform(transform);
119 127
           tg.addChild(leds[x][y][z]);
128
+
120 129
           BranchGroup allTheseGroupsScareMe = new BranchGroup();
130
+		  allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
131
+		  allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
132
+		  allTheseGroupsScareMe.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
121 133
           allTheseGroupsScareMe.addChild(tg);
122 134
           inBetween.addChild(allTheseGroupsScareMe);
123 135
         }
@@ -134,6 +146,27 @@ class Led3D {
134 146
     fffuuuuu.addChild(light2);
135 147
     inBetween.addChild(fffuuuuu);
136 148
   }
149
+
150
+	// 64 Element byte array
151
+	public void setData(short[] data) {
152
+		for (int y = 0; y < 8; y++) {
153
+			for (int z = 0; z < 8; z++) {
154
+				for (int x = 0; x < 8; x++) {
155
+					Appearance a = new Appearance();
156
+					if ((data[y + (z * 8)] & (1 << x)) != 0) {
157
+						// Activate led
158
+						a.setColoringAttributes(redColor);
159
+						a.setMaterial(redMat);
160
+					} else {
161
+						// Deactivate led
162
+						a.setColoringAttributes(whiteColor);
163
+						a.setMaterial(whiteMat);
164
+					}
165
+					leds[x][y][z].setAppearance(a);
166
+				}
167
+			}
168
+		}
169
+	}
137 170
 }
138 171
 
139 172
 public class frame extends JFrame implements ListSelectionListener {
@@ -206,34 +239,27 @@ public class frame extends JFrame implements ListSelectionListener {
206 239
   }
207 240
 
208 241
   public void valueChanged(ListSelectionEvent evt) {
209
-    if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
210
-     int anim = animList.getSelectedIndex();
211
-     int max;
212
-     if (anim == -1){
213
-        anim = 0;
214
-     }
215
-   if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
216
-         frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
217
-   }
218
-     if(evt.getSource() == frameList){
219
-       max = worker.numOfAnimations();
220
-     animModel.clear();
221
-     } else {
222
-       max = worker.numOfFrames(anim);
223
-       frameListModel.clear();
224
-     }
225
-
226
-   // if value changed in anim, rebuild frame, else other way round
227
-   for (int i = 0; i < max; i++) {
228
-       if(evt.getSource() == animList){
229
-      frameListModel.addElement(worker.getFrameName(anim, i));
230
-      frameList.setModel(frameListModel);
231
-       } else {
232
-      animModel.addElement(worker.getAnimationName(i));
233
-      animList.setModel(animModel);
234
-       }
235
-   }
236
-    }
242
+	if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
243
+		// If animList or framsList is the source, we act...
244
+
245
+		// If both selections are valid, update frame duration and set 3D data
246
+		if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
247
+			ledView.setData(worker.getFrame(animList.getSelectedIndex(), frameList.getSelectedIndex()));
248
+			frmLngthTxt.setText(Integer.toString(worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex())));
249
+		} else {
250
+			// clear frame duration
251
+			frmLngthTxt.setText("");
252
+		}
253
+
254
+		if ((evt.getSource() == animList) && (animList.getSelectedIndex() != -1)) {
255
+			// animList selection changed, update frameList
256
+			frameListModel.clear();
257
+			for (int i = 0; i < worker.numOfFrames(animList.getSelectedIndex()); i++) {
258
+				frameListModel.addElement(worker.getFrameName(animList.getSelectedIndex(), i));
259
+			}
260
+			frameList.setModel(frameListModel);
261
+		}
262
+	}
237 263
   }
238 264
 
239 265
   private void save() {
@@ -287,6 +313,13 @@ public class frame extends JFrame implements ListSelectionListener {
287 313
     cp.setLayout(null);
288 314
     // Anfang Komponenten
289 315
 
316
+	// ledView init
317
+	short[] dat = new short[64];
318
+	for (int i = 0; i < dat.length; i++) {
319
+		dat[i] = 0xFF;
320
+	}
321
+	ledView.setData(dat);
322
+
290 323
     //----- 3D-----
291 324
     //-------------
292 325
     cubeCanvas.setBounds(8, 8, 250, 250);
@@ -609,6 +642,7 @@ public class frame extends JFrame implements ListSelectionListener {
609 642
     frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
610 643
     // Ende Komponenten
611 644
     animList.addListSelectionListener(this);
645
+	frameList.addListSelectionListener(this);
612 646
     setResizable(false);
613 647
     setVisible(true);
614 648
   }
@@ -774,13 +808,8 @@ public class frame extends JFrame implements ListSelectionListener {
774 808
     if(worker.addAnimation() == -1){
775 809
       errorMessage("Could not add animation!");
776 810
     } else {
777
-    int n = worker.numOfAnimations() - 1;
778
-    // would have 0 anims after successfully adding one...
779
-  /*if (n < 0) {
780
-n = 0;
781
-}*/
782 811
     animModel.clear();
783
-    for (int i = 0; i < (n + 1); i++) {
812
+    for (int i = 0; i < worker.numOfAnimations(); i++) {
784 813
         animModel.add(i, worker.getAnimationName(i));
785 814
     }
786 815
     animList.setModel(animModel);

Loading…
Cancel
Save