Browse Source

Added open/save dialog

Thomas Buck 13 years ago
parent
commit
9074178b61
2 changed files with 57 additions and 6 deletions
  1. 55
    4
      Cube Control/frame.java
  2. 2
    2
      Cube Control/makefile

+ 55
- 4
Cube Control/frame.java View File

2
 import java.awt.event.*;
2
 import java.awt.event.*;
3
 import javax.swing.*;
3
 import javax.swing.*;
4
 import javax.swing.event.*;
4
 import javax.swing.event.*;
5
+import java.io.File;
5
 
6
 
6
 /*
7
 /*
7
  * frame.java
8
  * frame.java
58
   private JTextField animPath = new JTextField();
59
   private JTextField animPath = new JTextField();
59
   private JButton load = new JButton();
60
   private JButton load = new JButton();
60
   private JButton save = new JButton();
61
   private JButton save = new JButton();
62
+  private JButton saveAs = new JButton();
61
   private JComboBox jComboBox1 = new JComboBox();
63
   private JComboBox jComboBox1 = new JComboBox();
62
   private JButton upload = new JButton();
64
   private JButton upload = new JButton();
63
   private JButton download = new JButton();
65
   private JButton download = new JButton();
66
   // Ende Attribute
68
   // Ende Attribute
67
 
69
 
68
   private cubeWorker worker = new cubeWorker();
70
   private cubeWorker worker = new cubeWorker();
71
+  private boolean fileSelected = false;
69
   // Ende Variablen
72
   // Ende Variablen
70
 
73
 
71
   private int saveExitDialog() {
74
   private int saveExitDialog() {
295
     animPath.setText("Load/Save an animation file...");
298
     animPath.setText("Load/Save an animation file...");
296
     animPath.setFont(new Font("Dialog", Font.PLAIN, 13));
299
     animPath.setFont(new Font("Dialog", Font.PLAIN, 13));
297
     cp.add(animPath);
300
     cp.add(animPath);
298
-    load.setBounds(344, 296, 147, 25);
301
+    load.setBounds(344, 296, 100, 25);
299
     load.setText("Load");
302
     load.setText("Load");
300
     load.setFont(new Font("Dialog", Font.PLAIN, 13));
303
     load.setFont(new Font("Dialog", Font.PLAIN, 13));
301
     cp.add(load);
304
     cp.add(load);
305
       }
308
       }
306
     });
309
     });
307
 
310
 
308
-    save.setBounds(504, 296, 147, 25);
311
+    save.setBounds(454, 296, 100, 25);
309
     save.setText("Save");
312
     save.setText("Save");
310
     save.setFont(new Font("Dialog", Font.PLAIN, 13));
313
     save.setFont(new Font("Dialog", Font.PLAIN, 13));
311
     cp.add(save);
314
     cp.add(save);
315
       }
318
       }
316
     });
319
     });
317
 
320
 
321
+	saveAs.setBounds(564, 296, 90, 25);
322
+	saveAs.setText("Save As");
323
+	saveAs.setFont(new Font("Dialog", Font.PLAIN, 13));
324
+	cp.add(saveAs);
325
+	saveAs.addActionListener(new ActionListener() {
326
+		public void actionPerformed(ActionEvent evt) {
327
+			saveAs_ActionPerformed(evt);
328
+		}
329
+	});
330
+
318
     jComboBox1.setBounds(344, 328, 305, 24);
331
     jComboBox1.setBounds(344, 328, 305, 24);
319
     jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 13));
332
     jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 13));
320
     cp.add(jComboBox1);
333
     cp.add(jComboBox1);
456
   }
469
   }
457
 
470
 
458
   public void load_ActionPerformed(ActionEvent evt) {
471
   public void load_ActionPerformed(ActionEvent evt) {
459
-    worker.loadState(animPath.getText());
472
+	JFileChooser fc = new JFileChooser();
473
+	int ret = fc.showOpenDialog(this);
474
+	if (ret == JFileChooser.APPROVE_OPTION) {
475
+		File file = fc.getSelectedFile();
476
+		if (fileSelected == false) {
477
+			fileSelected = true;
478
+		}
479
+		animPath.setText(file.getPath());
480
+		worker.loadState(animPath.getText());
481
+	}
460
   }
482
   }
461
 
483
 
462
   public void save_ActionPerformed(ActionEvent evt) {
484
   public void save_ActionPerformed(ActionEvent evt) {
463
-    worker.saveState(animPath.getText());
485
+	if (fileSelected == false) {
486
+		JFileChooser fc = new JFileChooser();
487
+		int ret = fc.showSaveDialog(this);
488
+		if (ret == JFileChooser.APPROVE_OPTION) {
489
+			File file = fc.getSelectedFile();
490
+			fileSelected = true;
491
+			animPath.setText(file.getPath());
492
+			worker.saveState(animPath.getText());
493
+		}
494
+	} else {
495
+		worker.saveState(animPath.getText());
496
+	}
497
+  }
498
+
499
+  public void saveAs_ActionPerformed(ActionEvent evt) {
500
+	JFileChooser fc;
501
+	if (fileSelected == true) {
502
+		fc = new JFileChooser(new File(animPath.getText()).getParentFile());
503
+	} else {
504
+		fc = new JFileChooser();
505
+	}
506
+	int ret = fc.showSaveDialog(this);
507
+	if (ret == JFileChooser.APPROVE_OPTION) {
508
+		File file = fc.getSelectedFile();
509
+		if (fileSelected == false) {
510
+			fileSelected = true;
511
+		}
512
+		animPath.setText(file.getPath());
513
+		worker.saveState(animPath.getText());
514
+	}
464
   }
515
   }
465
 
516
 
466
 
517
 

+ 2
- 2
Cube Control/makefile View File

6
 JAVAFILES = cubeWorker.java layerEditFrame.java frame.java
6
 JAVAFILES = cubeWorker.java layerEditFrame.java frame.java
7
 
7
 
8
 ifeq ($(TARGET),win)
8
 ifeq ($(TARGET),win)
9
-CLASSES = cubeWorker.class layerEditFrame.class layerEditFrame$$1.class layerEditFrame$$2.class layerEditFrame$$3.class layerEditFrame$$4.class frame.class frame$$1.class frame$$2.class frame$$3.class frame$$4.class frame$$5.class frame$$6.class frame$$7.class frame$$8.class frame$$9.class frame$$10.class frame$$11.class frame$$12.class frame$$13.class frame$$14.class frame$$15.class frame$$16.class frame$$17.class frame$$18.class frame$$19.class frame$$20.class frame$$21.class MyListSelectionListener.class LEDoff.png LEDon.png
9
+CLASSES = cubeWorker.class layerEditFrame.class layerEditFrame$$1.class layerEditFrame$$2.class layerEditFrame$$3.class layerEditFrame$$4.class frame.class frame$$1.class frame$$2.class frame$$3.class frame$$4.class frame$$5.class frame$$6.class frame$$7.class frame$$8.class frame$$9.class frame$$10.class frame$$11.class frame$$12.class frame$$13.class frame$$14.class frame$$15.class frame$$16.class frame$$17.class frame$$18.class frame$$19.class frame$$20.class frame$$21.class frame$$22.class MyListSelectionListener.class LEDoff.png LEDon.png
10
 else
10
 else
11
-CLASSES = 'cubeWorker.class' 'layerEditFrame.class' 'layerEditFrame$$1.class' 'layerEditFrame$$2.class' 'layerEditFrame$$3.class' 'layerEditFrame$$4.class' 'frame.class' 'frame$$1.class' 'frame$$2.class' 'frame$$3.class' 'frame$$4.class' 'frame$$5.class' 'frame$$6.class' 'frame$$7.class' 'frame$$8.class' 'frame$$9.class' 'frame$$10.class' 'frame$$11.class' 'frame$$12.class' 'frame$$13.class' 'frame$$14.class' 'frame$$15.class' 'frame$$16.class' 'frame$$17.class' 'frame$$18.class' 'frame$$19.class' 'frame$$20.class' 'frame$$21.class' 'MyListSelectionListener.class' 'LEDoff.png' 'LEDon.png'
11
+CLASSES = 'cubeWorker.class' 'layerEditFrame.class' 'layerEditFrame$$1.class' 'layerEditFrame$$2.class' 'layerEditFrame$$3.class' 'layerEditFrame$$4.class' 'frame.class' 'frame$$1.class' 'frame$$2.class' 'frame$$3.class' 'frame$$4.class' 'frame$$5.class' 'frame$$6.class' 'frame$$7.class' 'frame$$8.class' 'frame$$9.class' 'frame$$10.class' 'frame$$11.class' 'frame$$12.class' 'frame$$13.class' 'frame$$14.class' 'frame$$15.class' 'frame$$16.class' 'frame$$17.class' 'frame$$18.class' 'frame$$19.class' 'frame$$20.class' 'frame$$21.class' 'frame$$22.class' 'MyListSelectionListener.class' 'LEDoff.png' 'LEDon.png'
12
 endif
12
 endif
13
 
13
 
14
 all: build clean
14
 all: build clean

Loading…
Cancel
Save