|
@@ -57,6 +57,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
57
|
57
|
private JButton frameDown = new JButton();
|
58
|
58
|
private JButton frameAdd = new JButton();
|
59
|
59
|
private JButton frameRemove = new JButton();
|
|
60
|
+ private JButton frameRename = new JButton();
|
60
|
61
|
private JButton frame = new JButton();
|
61
|
62
|
private JList animList = new JList();
|
62
|
63
|
private DefaultListModel animModel = new DefaultListModel();
|
|
@@ -65,6 +66,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
65
|
66
|
private JButton animDown = new JButton();
|
66
|
67
|
private JButton animAdd = new JButton();
|
67
|
68
|
private JButton animRemove = new JButton();
|
|
69
|
+ private JButton animRename = new JButton();
|
68
|
70
|
private JTextField animPath = new JTextField();
|
69
|
71
|
private JButton load = new JButton();
|
70
|
72
|
private JButton save = new JButton();
|
|
@@ -86,47 +88,64 @@ public class frame extends JFrame implements ListSelectionListener {
|
86
|
88
|
String[] Optionen = {"Yes", "No"};
|
87
|
89
|
int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
|
88
|
90
|
if (Auswahl == JOptionPane.YES_OPTION) {
|
89
|
|
- worker.saveState(animPath.getText());
|
90
|
91
|
return 1;
|
91
|
92
|
} else {
|
92
|
93
|
return 0;
|
93
|
94
|
}
|
94
|
95
|
}
|
95
|
96
|
|
|
97
|
+ private String askString(String title, String text) {
|
|
98
|
+ return JOptionPane.showInputDialog(null, text, title, JOptionPane.QUESTION_MESSAGE);
|
|
99
|
+ }
|
|
100
|
+
|
96
|
101
|
private void errorMessage(String s) {
|
97
|
102
|
String[] Optionen = {"OK"};
|
98
|
103
|
JOptionPane.showOptionDialog(this, s, "Error!", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
|
99
|
104
|
}
|
100
|
105
|
|
101
|
106
|
public void valueChanged(ListSelectionEvent evt) {
|
102
|
|
- if ((!evt.getValueIsAdjusting()) && (evt.getSource() != animList) && (evt.getSource() != frameList)) {
|
103
|
|
- DefaultListModel model = (DefaultListModel)((JList)evt.getSource()).getModel();
|
|
107
|
+ if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
|
104
|
108
|
int anim = animList.getSelectedIndex();
|
105
|
109
|
int max;
|
106
|
|
- if(evt.getSource() == animList){
|
|
110
|
+ if (anim == -1){
|
|
111
|
+ anim = 0;
|
|
112
|
+ }
|
|
113
|
+ if(evt.getSource() == frameList){
|
107
|
114
|
max = worker.numOfAnimations();
|
108
|
|
- System.out.println(max);
|
109
|
|
-
|
|
115
|
+ animModel.clear();
|
110
|
116
|
} else {
|
111
|
|
- max = worker.numOfFrames(animList.getSelectedIndex());
|
112
|
|
-
|
|
117
|
+ max = worker.numOfFrames(anim);
|
|
118
|
+ frameListModel.clear();
|
113
|
119
|
}
|
114
|
120
|
|
115
|
|
- if (anim == -1){
|
116
|
|
- anim = 0;
|
117
|
|
- }
|
118
|
|
- model.clear();
|
119
|
|
- for (int i = 0; i < max; i++) {
|
|
121
|
+ // if value changed in anim, rebuild frame, else other way round
|
|
122
|
+ for (int i = 0; i < max; i++) {
|
120
|
123
|
if(evt.getSource() == animList){
|
121
|
|
- model.add(i, worker.getAnimationName(i));
|
|
124
|
+ frameListModel.addElement(worker.getFrameName(anim, i));
|
|
125
|
+ frameList.setModel(frameListModel);
|
122
|
126
|
} else {
|
123
|
|
- model.add(i, worker.getFrameName(anim, i));
|
|
127
|
+ animModel.addElement(worker.getAnimationName(i));
|
|
128
|
+ animList.setModel(animModel);
|
124
|
129
|
}
|
125
|
|
- }
|
126
|
|
- frameList.setModel(model);
|
|
130
|
+ }
|
127
|
131
|
}
|
128
|
132
|
}
|
129
|
133
|
|
|
134
|
+ private void save() {
|
|
135
|
+ if (fileSelected == false) {
|
|
136
|
+ JFileChooser fc = new JFileChooser();
|
|
137
|
+ int ret = fc.showSaveDialog(this);
|
|
138
|
+ if (ret == JFileChooser.APPROVE_OPTION) {
|
|
139
|
+ File file = fc.getSelectedFile();
|
|
140
|
+ fileSelected = true;
|
|
141
|
+ animPath.setText(file.getPath());
|
|
142
|
+ worker.saveState(animPath.getText());
|
|
143
|
+ }
|
|
144
|
+ } else {
|
|
145
|
+ worker.saveState(animPath.getText());
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+
|
130
|
149
|
public frame(String title) {
|
131
|
150
|
// Frame-Initialisierung
|
132
|
151
|
super(title);
|
|
@@ -143,7 +162,11 @@ public class frame extends JFrame implements ListSelectionListener {
|
143
|
162
|
addWindowListener(new WindowAdapter() {
|
144
|
163
|
public void windowClosing(WindowEvent evt) {
|
145
|
164
|
if (worker.changedStateSinceSave()) {
|
146
|
|
- saveExitDialog();
|
|
165
|
+ if (saveExitDialog() == 1) {
|
|
166
|
+ save();
|
|
167
|
+ } else {
|
|
168
|
+ return;
|
|
169
|
+ }
|
147
|
170
|
}
|
148
|
171
|
System.exit(0);
|
149
|
172
|
}
|
|
@@ -276,6 +299,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
276
|
299
|
});
|
277
|
300
|
|
278
|
301
|
frameDown.setBounds(544, 122, 107, 28);
|
|
302
|
+
|
279
|
303
|
frameDown.setText("Move down");
|
280
|
304
|
frameDown.setFont(new Font("Dialog", Font.PLAIN, 13));
|
281
|
305
|
cp.add(frameDown);
|
|
@@ -286,6 +310,28 @@ public class frame extends JFrame implements ListSelectionListener {
|
286
|
310
|
});
|
287
|
311
|
|
288
|
312
|
frameAdd.setBounds(544, 46, 107, 28);
|
|
313
|
+ frameRename.setText("Rename");
|
|
314
|
+ frameRename.setFont(new Font("Dialog", Font.PLAIN, 13));
|
|
315
|
+ cp.add(frameRename);
|
|
316
|
+ frameRename.addActionListener(new ActionListener() {
|
|
317
|
+ public void actionPerformed(ActionEvent evt) {
|
|
318
|
+ int a = animList.getSelectedIndex();
|
|
319
|
+ if (a < 0) {
|
|
320
|
+ errorMessage("Select an animation!");
|
|
321
|
+ return;
|
|
322
|
+ }
|
|
323
|
+ int f = frameList.getSelectedIndex();
|
|
324
|
+ if (f < 0) {
|
|
325
|
+ errorMessage("Select a frame!");
|
|
326
|
+ return;
|
|
327
|
+ }
|
|
328
|
+ worker.setFrameName(askString("Rename", "Rename " + frameList.getSelectedValue() + "?"), a, f);
|
|
329
|
+ frameListModel.set(f, worker.getFrameName(a, f));
|
|
330
|
+ frameList.setModel(frameListModel);
|
|
331
|
+ }
|
|
332
|
+ });
|
|
333
|
+
|
|
334
|
+
|
289
|
335
|
frameAdd.setText("Add");
|
290
|
336
|
frameAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
|
291
|
337
|
cp.add(frameAdd);
|
|
@@ -295,7 +341,11 @@ public class frame extends JFrame implements ListSelectionListener {
|
295
|
341
|
}
|
296
|
342
|
});
|
297
|
343
|
|
|
344
|
+
|
298
|
345
|
frameRemove.setBounds(544, 84, 107, 28);
|
|
346
|
+
|
|
347
|
+ frameRemove.setBounds(544, 84, 107, 33);
|
|
348
|
+
|
299
|
349
|
frameRemove.setText("Remove");
|
300
|
350
|
frameRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
|
301
|
351
|
cp.add(frameRemove);
|
|
@@ -319,6 +369,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
319
|
369
|
animList.setModel(animModel);
|
320
|
370
|
//jList2Model.addElement("");
|
321
|
371
|
cp.add(animScrollPane);
|
|
372
|
+
|
322
|
373
|
animUp.setBounds(224, 264, 99, 25);
|
323
|
374
|
animUp.setText("Move up");
|
324
|
375
|
animUp.setFont(new Font("Dialog", Font.PLAIN, 13));
|
|
@@ -329,7 +380,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
329
|
380
|
}
|
330
|
381
|
});
|
331
|
382
|
|
332
|
|
- animDown.setBounds(224, 360, 99, 25);
|
|
383
|
+ animDown.setBounds(224, 342, 99, 25);
|
333
|
384
|
animDown.setText("Move down");
|
334
|
385
|
animDown.setFont(new Font("Dialog", Font.PLAIN, 13));
|
335
|
386
|
cp.add(animDown);
|
|
@@ -339,7 +390,24 @@ public class frame extends JFrame implements ListSelectionListener {
|
339
|
390
|
}
|
340
|
391
|
});
|
341
|
392
|
|
342
|
|
- animAdd.setBounds(224, 296, 99, 25);
|
|
393
|
+ animRename.setBounds(224, 368, 99, 25);
|
|
394
|
+ animRename.setText("Rename");
|
|
395
|
+ animRename.setFont(new Font("Dialog", Font.PLAIN, 13));
|
|
396
|
+ cp.add(animRename);
|
|
397
|
+ animRename.addActionListener(new ActionListener() {
|
|
398
|
+ public void actionPerformed(ActionEvent evt) {
|
|
399
|
+ int a = animList.getSelectedIndex();
|
|
400
|
+ if (a < 0) {
|
|
401
|
+ errorMessage("Select an animation!");
|
|
402
|
+ return;
|
|
403
|
+ }
|
|
404
|
+ worker.setAnimationName(askString("Rename", "Rename " + animList.getSelectedValue() + "?"), a);
|
|
405
|
+ animModel.set(a, worker.getAnimationName(a));
|
|
406
|
+ animList.setModel(animModel);
|
|
407
|
+ }
|
|
408
|
+ });
|
|
409
|
+
|
|
410
|
+ animAdd.setBounds(224, 290, 99, 25);
|
343
|
411
|
animAdd.setText("Add");
|
344
|
412
|
animAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
|
345
|
413
|
cp.add(animAdd);
|
|
@@ -349,7 +417,7 @@ public class frame extends JFrame implements ListSelectionListener {
|
349
|
417
|
}
|
350
|
418
|
});
|
351
|
419
|
|
352
|
|
- animRemove.setBounds(224, 328, 99, 25);
|
|
420
|
+ animRemove.setBounds(224, 316, 99, 25);
|
353
|
421
|
animRemove.setText("Remove");
|
354
|
422
|
animRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
|
355
|
423
|
cp.add(animRemove);
|
|
@@ -418,12 +486,12 @@ public class frame extends JFrame implements ListSelectionListener {
|
418
|
486
|
});
|
419
|
487
|
|
420
|
488
|
jLabel4.setBounds(536, 208, 112, 20);
|
421
|
|
- jLabel4.setText("Frames remaining:");
|
|
489
|
+ jLabel4.setText("Remaining:");
|
422
|
490
|
jLabel4.setFont(new Font("Dialog", Font.PLAIN, 13));
|
423
|
491
|
cp.add(jLabel4);
|
424
|
492
|
frameRemaining.setBounds(536, 232, 113, 24);
|
425
|
493
|
frameRemaining.setEditable(false);
|
426
|
|
- frameRemaining.setText("2048");
|
|
494
|
+ frameRemaining.setText(String.valueOf(worker.framesRemaining()));
|
427
|
495
|
frameRemaining.setFont(new Font("Dialog", Font.PLAIN, 13));
|
428
|
496
|
cp.add(frameRemaining);
|
429
|
497
|
animList.setFont(new Font("Dialog", Font.PLAIN, 13));
|
|
@@ -542,13 +610,12 @@ public class frame extends JFrame implements ListSelectionListener {
|
542
|
610
|
errorMessage("Could not add animation!");
|
543
|
611
|
} else {
|
544
|
612
|
int n = worker.numOfAnimations() - 1;
|
545
|
|
- if (n < 0) {
|
|
613
|
+ // would have 0 anims after successfully adding one...
|
|
614
|
+ /*if (n < 0) {
|
546
|
615
|
n = 0;
|
547
|
|
- }
|
|
616
|
+ }*/
|
548
|
617
|
animModel.clear();
|
549
|
|
- System.out.println(n);
|
550
|
|
- //animModel.addElement(worker.getAnimationName(n));
|
551
|
|
- for (int i = 0; i < n; i++) {
|
|
618
|
+ for (int i = 0; i < (n + 1); i++) {
|
552
|
619
|
animModel.add(i, worker.getAnimationName(i));
|
553
|
620
|
}
|
554
|
621
|
animList.setModel(animModel);
|
|
@@ -572,6 +639,14 @@ public class frame extends JFrame implements ListSelectionListener {
|
572
|
639
|
}
|
573
|
640
|
animPath.setText(file.getPath());
|
574
|
641
|
worker.loadState(animPath.getText());
|
|
642
|
+ animModel.clear();
|
|
643
|
+ for (int i = 0; i < worker.numOfAnimations(); i++) {
|
|
644
|
+ animModel.addElement(worker.getAnimationName(i));
|
|
645
|
+ }
|
|
646
|
+ animList.setModel(animModel);
|
|
647
|
+
|
|
648
|
+ frameListModel.clear();
|
|
649
|
+ frameList.setModel(frameListModel);
|
575
|
650
|
}
|
576
|
651
|
}
|
577
|
652
|
|