Browse Source

Fixed some frame stuff.

Auto select animations and frames, consistent order for frame and
animation buttons.
Thomas Buck 12 years ago
parent
commit
287df82da2
2 changed files with 85 additions and 65 deletions
  1. 84
    64
      CubeControl/Frame.java
  2. 1
    1
      CubeFirmware/makefile

+ 84
- 64
CubeControl/Frame.java View File

33
 import java.util.Arrays;
33
 import java.util.Arrays;
34
 
34
 
35
 public class Frame extends JFrame implements ListSelectionListener, ChangeListener{
35
 public class Frame extends JFrame implements ListSelectionListener, ChangeListener{
36
-
37
-	private static final long serialVersionUID = 23421337L;
38
-	// Anfang Variablen
39
 	private GraphicsConfiguration gConfig;
36
 	private GraphicsConfiguration gConfig;
40
 	private Canvas3D cubeCanvas;
37
 	private Canvas3D cubeCanvas;
41
 	public Led3D ledView;
38
 	public Led3D ledView;
42
-
43
-	// Anfang Attribute
44
 	private JButton editA = new JButton();
39
 	private JButton editA = new JButton();
45
 	private JButton editB = new JButton();
40
 	private JButton editB = new JButton();
46
 	private JButton editC = new JButton();
41
 	private JButton editC = new JButton();
59
 	private JButton frameRemove = new JButton();
54
 	private JButton frameRemove = new JButton();
60
 	private JButton frameRename = new JButton();
55
 	private JButton frameRename = new JButton();
61
 	private JList animList = new JList();
56
 	private JList animList = new JList();
62
-	private DefaultListModel animModel = new DefaultListModel();
57
+	private DefaultListModel animListModel = new DefaultListModel();
63
 	private JScrollPane animScrollPane = new JScrollPane(animList);
58
 	private JScrollPane animScrollPane = new JScrollPane(animList);
64
 	private JButton animUp = new JButton();
59
 	private JButton animUp = new JButton();
65
 	private JButton animDown = new JButton();
60
 	private JButton animDown = new JButton();
89
 	private JPanel serialPanel = new JPanel();
84
 	private JPanel serialPanel = new JPanel();
90
 	private JPanel settingsPanel = new JPanel();
85
 	private JPanel settingsPanel = new JPanel();
91
 	private JSlider durationSlider = new JSlider(1, 256 ,1); //min, max, value
86
 	private JSlider durationSlider = new JSlider(1, 256 ,1); //min, max, value
92
-
93
-
94
-	// Ende Attribute
95
-	
87
+	private int lastSelectedFrame = 0;
88
+	private int lastSelectedAnim = 0;
96
 	public cubeWorker worker = new cubeWorker(this);
89
 	public cubeWorker worker = new cubeWorker(this);
97
 	private boolean fileSelected = false;
90
 	private boolean fileSelected = false;
98
 	private Frame thisFrame;
91
 	private Frame thisFrame;
99
 	private static Frame recentFrame;
92
 	private static Frame recentFrame;
100
 
93
 
101
-	// Ende Variablen
102
-
103
 	private int saveExitDialog() {
94
 	private int saveExitDialog() {
104
 		String[] Optionen = { "Yes", "No" };
95
 		String[] Optionen = { "Yes", "No" };
105
 		int Auswahl = JOptionPane.showOptionDialog(this,
96
 		int Auswahl = JOptionPane.showOptionDialog(this,
174
 			ledView.setData(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getData());
165
 			ledView.setData(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getData());
175
 		}
166
 		}
176
 	}
167
 	}
168
+
169
+	private void rebuildFrameList() {
170
+		// animList selection changed, update frameList
171
+		frameListModel.clear();
172
+
173
+		// System.out.println("Selected Animation: " + animList.getSelectedIndex());
174
+		int max = worker.getAnimation(animList.getSelectedIndex()).size();
175
+	
176
+		for (int i = 0; i < max; i++) {
177
+			frameListModel.addElement(worker.getAnimation(
178
+			animList.getSelectedIndex()).getFrame(i).getName());
179
+		}
180
+		frameList.setModel(frameListModel);
181
+	}
177
 	
182
 	
178
 	/**
183
 	/**
179
 	 * ListSelectionListener that updates Anim & Frame List
184
 	 * ListSelectionListener that updates Anim & Frame List
182
 	 * @param evt List that generated the event. Has to be animList or frameList
187
 	 * @param evt List that generated the event. Has to be animList or frameList
183
 	 */
188
 	 */
184
 	public void valueChanged(ListSelectionEvent evt) {
189
 	public void valueChanged(ListSelectionEvent evt) {
185
-		if ((!evt.getValueIsAdjusting())
186
-			&& ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
187
-			// If animList or framsList is the source, we act...
188
-	
189
-			if ((evt.getSource() == animList)
190
-				&& (animList.getSelectedIndex() != -1)) {
191
-				// animList selection changed, update frameList
192
-				frameListModel.clear();
193
-	
194
-				// System.out.println("Selected Animation: " + animList.getSelectedIndex());
195
-				int max = worker.getAnimation(animList.getSelectedIndex()).size();
196
-	
197
-				for (int i = 0; i < max; i++) {
198
-				frameListModel.addElement(worker.getAnimation(
199
-					animList.getSelectedIndex()).getFrame(i).getName());
190
+		if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
191
+			// Select an animation, if not already done
192
+			if (animList.getSelectedIndex() == -1) {
193
+				if ((animListModel.getSize() > lastSelectedAnim) && (lastSelectedAnim != -1)) {
194
+					animList.setSelectedIndex(lastSelectedAnim);
195
+				} else {
196
+					animList.setSelectedIndex(0);
200
 				}
197
 				}
201
-				frameList.setModel(frameListModel);
202
 			}
198
 			}
203
-	
204
-			// If both selections are valid, update Frame duration and set 3D
205
-			// data
199
+
200
+			// Rebuild the frame list, if possible & needed
201
+			if ((evt.getSource() == animList) && (animList.getSelectedIndex() != -1)) {
202
+				rebuildFrameList();
203
+			}
204
+
205
+			// Select a frame, if not already done
206
+			if (frameList.getSelectedIndex() == -1) {
207
+				if ((frameListModel.getSize() > lastSelectedFrame) && (lastSelectedFrame != -1)) {
208
+					frameList.setSelectedIndex(lastSelectedFrame);
209
+				} else {
210
+					frameList.setSelectedIndex(0);
211
+				}
212
+				lastSelectedFrame = frameList.getSelectedIndex();
213
+			}
214
+
215
+			// If possible, set all data for selected frame
206
 			if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
216
 			if ((animList.getSelectedIndex() != -1) && (frameList.getSelectedIndex() != -1)) {
207
 				ledView.setData(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getData());
217
 				ledView.setData(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getData());
208
 				frameLengthText.setText(Integer.toString(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime()));
218
 				frameLengthText.setText(Integer.toString(worker.getAnimation(animList.getSelectedIndex()).getFrame(frameList.getSelectedIndex()).getTime()));
209
-			} else {
210
-				// clear Frame duration
211
-				frameLengthText.setText("");
219
+				durationSlider.setValue(Integer.parseInt(frameLengthText.getText()));
220
+			}
221
+
222
+			if (frameList.getSelectedIndex() != -1) {
223
+				lastSelectedAnim = animList.getSelectedIndex();
224
+			}
225
+			if (frameList.getSelectedIndex() != -1) {
226
+				lastSelectedFrame = frameList.getSelectedIndex();
227
+			}
228
+			if (lastSelectedAnim == -1) {
229
+				lastSelectedAnim = 0;
230
+			}
231
+			if (lastSelectedFrame == -1) {
232
+				lastSelectedFrame = 0;
212
 			}
233
 			}
213
 		}
234
 		}
214
 	}
235
 	}
215
 
236
 
216
 	public void stateChanged(ChangeEvent e){
237
 	public void stateChanged(ChangeEvent e){
217
-			frameLengthText.setText(durationSlider.getValue() + "");
218
-		
238
+		frameLengthText.setText(durationSlider.getValue() + "");
219
 	}
239
 	}
220
 	
240
 	
221
 	private void save() {
241
 	private void save() {
258
 
278
 
259
 		// Build Animation List
279
 		// Build Animation List
260
 		for (int i = 0; i < worker.size(); i++) {
280
 		for (int i = 0; i < worker.size(); i++) {
261
-			animModel.addElement(worker.getAnimation(i).getName());
281
+			animListModel.addElement(worker.getAnimation(i).getName());
262
 		}
282
 		}
263
 
283
 
264
 		// Ask user to save before closing the window
284
 		// Ask user to save before closing the window
323
 		cp.add(frameListScrollPane);
343
 		cp.add(frameListScrollPane);
324
 		// Add Animation List
344
 		// Add Animation List
325
 		animScrollPane.setBounds(18, 378, 187, 219);
345
 		animScrollPane.setBounds(18, 378, 187, 219);
326
-		animList.setModel(animModel);
346
+		animList.setModel(animListModel);
327
 		cp.add(animScrollPane);
347
 		cp.add(animScrollPane);
328
 
348
 
329
 		// Add Move Frame Up Button
349
 		// Add Move Frame Up Button
432
 		animUp.addActionListener(new ActionListener() {
452
 		animUp.addActionListener(new ActionListener() {
433
 			public void actionPerformed(ActionEvent evt) {
453
 			public void actionPerformed(ActionEvent evt) {
434
 				int i = animList.getSelectedIndex();
454
 				int i = animList.getSelectedIndex();
435
-				if ((i > 0) && (animModel.getSize() >= 2)) {
436
-					Object tmp = animModel.get(i);
437
-					animModel.set(i, animModel.get(i - 1));
438
-					animModel.set(i - 1, tmp);
455
+				if ((i > 0) && (animListModel.getSize() >= 2)) {
456
+					Object tmp = animListModel.get(i);
457
+					animListModel.set(i, animListModel.get(i - 1));
458
+					animListModel.set(i - 1, tmp);
439
 					animList.setSelectedIndex(i - 1);
459
 					animList.setSelectedIndex(i - 1);
440
 					worker.moveAnimationUp(i);
460
 					worker.moveAnimationUp(i);
441
 				}
461
 				}
443
 		});
463
 		});
444
 
464
 
445
 		// Add Move Animation Down Button
465
 		// Add Move Animation Down Button
446
-		animDown.setBounds(211, 423, 110, 39);
466
+		animDown.setBounds(211, 558, 110, 39);
447
 		animDown.setText("Move down");
467
 		animDown.setText("Move down");
448
 		animDown.setFont(font);
468
 		animDown.setFont(font);
449
 		cp.add(animDown);
469
 		cp.add(animDown);
450
 		animDown.addActionListener(new ActionListener() {
470
 		animDown.addActionListener(new ActionListener() {
451
 			public void actionPerformed(ActionEvent evt) {
471
 			public void actionPerformed(ActionEvent evt) {
452
 				int i = animList.getSelectedIndex();
472
 				int i = animList.getSelectedIndex();
453
-				if ((i >= 0) && (animModel.getSize() >= 2) && (i < (animModel.getSize() - 1))) {
454
-					Object tmp = animModel.get(i);
455
-					animModel.set(i, animModel.get(i + 1));
456
-					animModel.set(i + 1, tmp);
473
+				if ((i >= 0) && (animListModel.getSize() >= 2) && (i < (animListModel.getSize() - 1))) {
474
+					Object tmp = animListModel.get(i);
475
+					animListModel.set(i, animListModel.get(i + 1));
476
+					animListModel.set(i + 1, tmp);
457
 					animList.setSelectedIndex(i + 1);
477
 					animList.setSelectedIndex(i + 1);
458
 					worker.moveAnimationDown(i);
478
 					worker.moveAnimationDown(i);
459
 				}
479
 				}
461
 		});
481
 		});
462
 
482
 
463
 		// Add Rename Animation Button
483
 		// Add Rename Animation Button
464
-		animRename.setBounds(211, 468, 110, 39);
484
+		animRename.setBounds(211, 513, 110, 39);
465
 		animRename.setText("Rename");
485
 		animRename.setText("Rename");
466
 		animRename.setFont(font);
486
 		animRename.setFont(font);
467
 		cp.add(animRename);
487
 		cp.add(animRename);
473
 					return;
493
 					return;
474
 				}
494
 				}
475
 				worker.getAnimation(a).setName(askString("Rename", "Rename " + animList.getSelectedValue() + "?"));
495
 				worker.getAnimation(a).setName(askString("Rename", "Rename " + animList.getSelectedValue() + "?"));
476
-				animModel.set(a, worker.getAnimation(a).getName());
477
-				animList.setModel(animModel);
496
+				animListModel.set(a, worker.getAnimation(a).getName());
497
+				animList.setModel(animListModel);
478
 			}
498
 			}
479
 		});
499
 		});
480
 
500
 
481
 		// Add button for adding animations
501
 		// Add button for adding animations
482
-		animAdd.setBounds(211, 513, 110, 39);
502
+		animAdd.setBounds(211, 423, 110, 39);
483
 		animAdd.setText("Add");
503
 		animAdd.setText("Add");
484
 		animAdd.setFont(font);
504
 		animAdd.setFont(font);
485
 		cp.add(animAdd);
505
 		cp.add(animAdd);
488
 				if (worker.addAnimation() == -1) {
508
 				if (worker.addAnimation() == -1) {
489
 					errorMessage("Could not add animation!");
509
 					errorMessage("Could not add animation!");
490
 				} else {
510
 				} else {
491
-					animModel.clear();
511
+					animListModel.clear();
492
 					for (int i = 0; i < worker.size(); i++) {
512
 					for (int i = 0; i < worker.size(); i++) {
493
-						animModel.add(i, worker.getAnimation(i).getName());
513
+						animListModel.add(i, worker.getAnimation(i).getName());
494
 					}
514
 					}
495
-					animList.setModel(animModel);
515
+					animList.setModel(animListModel);
496
 				}
516
 				}
497
 			}
517
 			}
498
 		});
518
 		});
499
 
519
 
500
 		// Add Animation remove button
520
 		// Add Animation remove button
501
-		animRemove.setBounds(211, 558, 110, 39);
521
+		animRemove.setBounds(211, 468, 110, 39);
502
 		animRemove.setText("Remove");
522
 		animRemove.setText("Remove");
503
 		animRemove.setFont(font);
523
 		animRemove.setFont(font);
504
 		cp.add(animRemove);
524
 		cp.add(animRemove);
508
 					errorMessage("Select an animation.");
528
 					errorMessage("Select an animation.");
509
 				} else {
529
 				} else {
510
 					worker.removeAnimation(animList.getSelectedIndex());
530
 					worker.removeAnimation(animList.getSelectedIndex());
511
-					animModel.removeElementAt(animList.getSelectedIndex());
512
-					animList.setModel(animModel);
531
+					animListModel.removeElementAt(animList.getSelectedIndex());
532
+					animList.setModel(animListModel);
513
 				}
533
 				}
514
 			}
534
 			}
515
 		});
535
 		});
602
 		});
622
 		});
603
 	
623
 	
604
 		frameDuration.setBounds(462, 129, 55, 20);
624
 		frameDuration.setBounds(462, 129, 55, 20);
605
-		frameDuration.setText("OK");
625
+		frameDuration.setText("Save");
606
 		frameDuration.setFont(font);
626
 		frameDuration.setFont(font);
607
 		cp.add(frameDuration);
627
 		cp.add(frameDuration);
608
 		frameDuration.addActionListener(new ActionListener() {
628
 		frameDuration.addActionListener(new ActionListener() {
628
 				}
648
 				}
629
 			}
649
 			}
630
 		});
650
 		});
631
-
632
-		
633
 	
651
 	
634
 		animPath.setBounds(417, 281, 228, 20);
652
 		animPath.setBounds(417, 281, 228, 20);
635
 		animPath.setEditable(false);
653
 		animPath.setEditable(false);
652
 					}
670
 					}
653
 					animPath.setText(file.getPath());
671
 					animPath.setText(file.getPath());
654
 					worker.loadState(animPath.getText());
672
 					worker.loadState(animPath.getText());
655
-					animModel.clear();
673
+					animListModel.clear();
656
 					for (int i = 0; i < worker.size(); i++) {
674
 					for (int i = 0; i < worker.size(); i++) {
657
-						animModel.addElement(worker.getAnimation(i).getName());
675
+						animListModel.addElement(worker.getAnimation(i).getName());
658
 					}
676
 					}
659
-					animList.setModel(animModel);
677
+					animList.setModel(animListModel);
660
 					frameListModel.clear();
678
 					frameListModel.clear();
661
 					frameList.setModel(frameListModel);
679
 					frameList.setModel(frameListModel);
662
 				}
680
 				}
743
 		frameLengthLabel.setFont(font);
761
 		frameLengthLabel.setFont(font);
744
 		cp.add(frameLengthLabel);
762
 		cp.add(frameLengthLabel);
745
 	
763
 	
746
-		frameLengthText.setBounds(419, 129, 36, 20);
764
+		frameLengthText.setBounds(419, 129, 40, 20);
747
 		frameLengthText.setFont(font);
765
 		frameLengthText.setFont(font);
748
 		cp.add(frameLengthText);
766
 		cp.add(frameLengthText);
749
 
767
 
794
 		frameList.addListSelectionListener(this);
812
 		frameList.addListSelectionListener(this);
795
 		setResizable(false);
813
 		setResizable(false);
796
 		setVisible(true);
814
 		setVisible(true);
815
+
816
+		valueChanged(new ListSelectionEvent(animList, 0, 0, false));
797
 	}
817
 	}
798
 	
818
 	
799
 	public Led3D get3D() {
819
 	public Led3D get3D() {

+ 1
- 1
CubeFirmware/makefile View File

261
 
261
 
262
 
262
 
263
 # Default target.
263
 # Default target.
264
-all: begin gccversion sizebefore build sizeafter finished end clean_list
264
+all: begin gccversion sizebefore build sizeafter finished end
265
 
265
 
266
 build: elf hex eep lss sym
266
 build: elf hex eep lss sym
267
 
267
 

Loading…
Cancel
Save