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
 	private JButton editG = new JButton();
45
 	private JButton editG = new JButton();
46
 	private JButton editH = new JButton();
46
 	private JButton editH = new JButton();
47
 	private JButton[] editButtons = { editA, editB, editC, editD, editE, editF, editG, editH };
47
 	private JButton[] editButtons = { editA, editB, editC, editD, editE, editF, editG, editH };
48
+	private JButton toggleLegsButton = new JButton();
48
 	private DefaultListModel frameListModel = new DefaultListModel();
49
 	private DefaultListModel frameListModel = new DefaultListModel();
49
 	public JList frameList = new JList();
50
 	public JList frameList = new JList();
50
 	private JScrollPane frameListScrollPane = new JScrollPane(frameList);
51
 	private JScrollPane frameListScrollPane = new JScrollPane(frameList);
90
 	private int lastSelectedAnim = 0;
91
 	private int lastSelectedAnim = 0;
91
 	public cubeWorker worker = new cubeWorker(this);
92
 	public cubeWorker worker = new cubeWorker(this);
92
 	private boolean fileSelected = false;
93
 	private boolean fileSelected = false;
94
+	private boolean showLegs = true;
93
 	private Frame thisFrame;
95
 	private Frame thisFrame;
94
 	private static Frame recentFrame;
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
 	private int saveExitDialog() {
107
 	private int saveExitDialog() {
97
 		String[] Optionen = { "Yes", "No" };
108
 		String[] Optionen = { "Yes", "No" };
98
 		int Auswahl = JOptionPane.showOptionDialog(this,
109
 		int Auswahl = JOptionPane.showOptionDialog(this,
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
 	public Frame(String title) {
300
 	public Frame(String title) {
270
 		super(title);
301
 		super(title);
271
 		thisFrame = this;
302
 		thisFrame = this;
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
 		// Add Frame List
379
 		// Add Frame List
340
 		frameListScrollPane.setBounds(339, 379, 187, 218);
380
 		frameListScrollPane.setBounds(339, 379, 187, 218);
341
 		frameList.setModel(frameListModel);
381
 		frameList.setModel(frameListModel);
568
 		cp.add(playAnimation);
608
 		cp.add(playAnimation);
569
 		playAnimation.addActionListener(new ActionListener() {
609
 		playAnimation.addActionListener(new ActionListener() {
570
 			public void actionPerformed(ActionEvent evt){
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
 		cp.add(playAnimationFullscreen);
618
 		cp.add(playAnimationFullscreen);
595
 		playAnimationFullscreen.addActionListener(new ActionListener() {
619
 		playAnimationFullscreen.addActionListener(new ActionListener() {
596
 			public void actionPerformed(ActionEvent evt){
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
 
843
 
836
 				if (s.equals("r") || s.equals("reset"))
844
 				if (s.equals("r") || s.equals("reset"))
837
 					l.resetView();
845
 					l.resetView();
846
+
847
+				if (s.equals("l"))
848
+					f.toggleLegs();
838
 		
849
 		
839
 				if (s.equals("on") || s.equals("1")) {
850
 				if (s.equals("on") || s.equals("1")) {
840
 					short[] d = new short[64];
851
 					short[] d = new short[64];

+ 11
- 0
CubeControl/Led3D.java View File

51
 	private Matrix4d fullScreenMat = null;
51
 	private Matrix4d fullScreenMat = null;
52
 	private Frame parentFrame = null;
52
 	private Frame parentFrame = null;
53
 	private boolean inFullscreen = false;
53
 	private boolean inFullscreen = false;
54
+	private boolean showLegs = true;
54
 
55
 
55
 	private Sphere[][][] leds = new Sphere[8][8][8];
56
 	private Sphere[][][] leds = new Sphere[8][8][8];
56
 	private static ColoringAttributes redColor = new ColoringAttributes(
57
 	private static ColoringAttributes redColor = new ColoringAttributes(
65
 			new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), 64.0f);
66
 			new Color3f(1.0f, 0.0f, 0.0f), new Color3f(1.0f, 0.0f, 0.0f), 64.0f);
66
 	private Background background;
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
 	 * @param canv The Canvas3D we render our cube in
80
 	 * @param canv The Canvas3D we render our cube in
70
 	 */
81
 	 */

Loading…
Cancel
Save