Browse Source

Toggle legs, code cleanup

Max Nuding 12 years ago
parent
commit
a3992fd301
2 changed files with 56 additions and 34 deletions
  1. 45
    34
      CubeControl/Frame.java
  2. 11
    0
      CubeControl/Led3D.java

+ 45
- 34
CubeControl/Frame.java View File

@@ -45,6 +45,7 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
45 45
 	private JButton editG = new JButton();
46 46
 	private JButton editH = new JButton();
47 47
 	private JButton[] editButtons = { editA, editB, editC, editD, editE, editF, editG, editH };
48
+	private JButton toggleLegsButton = new JButton();
48 49
 	private DefaultListModel frameListModel = new DefaultListModel();
49 50
 	public JList frameList = new JList();
50 51
 	private JScrollPane frameListScrollPane = new JScrollPane(frameList);
@@ -90,9 +91,19 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
90 91
 	private int lastSelectedAnim = 0;
91 92
 	public cubeWorker worker = new cubeWorker(this);
92 93
 	private boolean fileSelected = false;
94
+	private boolean showLegs = true;
93 95
 	private Frame thisFrame;
94 96
 	private static Frame recentFrame;
95 97
 
98
+	private void toggleLegs(){
99
+		ledView.toggleLegs();
100
+		if(showLegs) {
101
+			toggleLegsButton.setText("Beine aus");
102
+		} else {
103
+			toggleLegsButton.setText("Beine ein");
104
+		}
105
+	}
106
+
96 107
 	private int saveExitDialog() {
97 108
 		String[] Optionen = { "Yes", "No" };
98 109
 		int Auswahl = JOptionPane.showOptionDialog(this,
@@ -266,6 +277,26 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
266 277
 		}
267 278
 	}
268 279
 
280
+	private void playAnimation() {
281
+		if (animList.getSelectedIndex() == -1) {
282
+					errorMessage("Please select an animation.");
283
+				} else if (frameList.getSelectedIndex() == -1) {
284
+					errorMessage("Please select a Frame.");
285
+				} else {
286
+					for (int i = 0; i < frameList.getModel().getSize(); i++){
287
+						frameList.setSelectedIndex(i);
288
+						long time1 = (long) worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime();
289
+						long time = (long) (((time1+1) * 1000) / 24);
290
+						System.out.println("Wert: " + time1 + " Zeit: " + time);
291
+						try {
292
+							Thread.sleep(time);
293
+						} catch (Exception e) {
294
+							System.out.println(e);
295
+						}
296
+				} 
297
+		}
298
+	}
299
+
269 300
 	public Frame(String title) {
270 301
 		super(title);
271 302
 		thisFrame = this;
@@ -336,6 +367,15 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
336 367
 			});
337 368
 		}
338 369
 
370
+		toggleLegsButton.setBounds(299, 312, 102, 34);
371
+		toggleLegsButton.setText("Beine aus");
372
+		cp.add(toggleLegsButton);
373
+		toggleLegsButton.addActionListener(new ActionListener(){
374
+			public void actionPerformed(ActionEvent evt){
375
+				toggleLegs();
376
+			}
377
+		});
378
+
339 379
 		// Add Frame List
340 380
 		frameListScrollPane.setBounds(339, 379, 187, 218);
341 381
 		frameList.setModel(frameListModel);
@@ -568,23 +608,7 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
568 608
 		cp.add(playAnimation);
569 609
 		playAnimation.addActionListener(new ActionListener() {
570 610
 			public void actionPerformed(ActionEvent evt){
571
-				if (animList.getSelectedIndex() == -1) {
572
-					errorMessage("Please select an animation.");
573
-				} else if (frameList.getSelectedIndex() == -1) {
574
-					errorMessage("Please select a Frame.");
575
-				} else {
576
-					for (int i = 0; i < frameList.getModel().getSize(); i++){
577
-						frameList.setSelectedIndex(i);
578
-						long time1 = (long) worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime();
579
-						long time = (long) (((time1+1) * 1000) / 24);
580
-						System.out.println("Wert: " + time1 + " Zeit: " + time);
581
-						try {
582
-							Thread.sleep(time);
583
-						} catch (Exception e) {
584
-							System.out.println(e);
585
-						}
586
-					} 
587
-				}
611
+				playAnimation();
588 612
 			}
589 613
 		});
590 614
 	
@@ -594,23 +618,7 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
594 618
 		cp.add(playAnimationFullscreen);
595 619
 		playAnimationFullscreen.addActionListener(new ActionListener() {
596 620
 			public void actionPerformed(ActionEvent evt){
597
-				if (animList.getSelectedIndex() == -1) {
598
-					errorMessage("Please select an animation.");
599
-				} else if (frameList.getSelectedIndex() == -1) {
600
-					errorMessage("Please select a Frame.");
601
-				} else {
602
-					for (int i = 0; i < frameList.getModel().getSize(); i++){
603
-						frameList.setSelectedIndex(i);
604
-						long time1 = (long) worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime();
605
-						long time = (long) (((time1+1) * 1000) / 24);
606
-						System.out.println("Wert: " + time1 + " Zeit: " + time);
607
-						try {
608
-							Thread.sleep(time);
609
-						} catch (Exception e) {
610
-							System.out.println(e);
611
-						}
612
-					} 
613
-				}
621
+				playAnimation();
614 622
 			}
615 623
 		});
616 624
 	
@@ -835,6 +843,9 @@ public class Frame extends JFrame implements ListSelectionListener, ChangeListen
835 843
 
836 844
 				if (s.equals("r") || s.equals("reset"))
837 845
 					l.resetView();
846
+
847
+				if (s.equals("l"))
848
+					f.toggleLegs();
838 849
 		
839 850
 				if (s.equals("on") || s.equals("1")) {
840 851
 					short[] d = new short[64];

+ 11
- 0
CubeControl/Led3D.java View File

@@ -51,6 +51,7 @@ public class Led3D extends MouseAdapter {
51 51
 	private Matrix4d fullScreenMat = null;
52 52
 	private Frame parentFrame = null;
53 53
 	private boolean inFullscreen = false;
54
+	private boolean showLegs = true;
54 55
 
55 56
 	private Sphere[][][] leds = new Sphere[8][8][8];
56 57
 	private static ColoringAttributes redColor = new ColoringAttributes(
@@ -65,6 +66,16 @@ public class Led3D extends MouseAdapter {
65 66
 			new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), 64.0f);
66 67
 	private Background background;
67 68
 
69
+	
70
+	public void toggleLegs(){
71
+		if(showLegs){
72
+			group2.detach();
73
+		} else {
74
+			universe.addBranchGraph(group2);
75
+		}
76
+		showLegs = !showLegs;
77
+	}
78
+
68 79
 	/**
69 80
 	 * @param canv The Canvas3D we render our cube in
70 81
 	 */

Loading…
Cancel
Save