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,6 +2,7 @@ import java.awt.*;
2 2
 import java.awt.event.*;
3 3
 import javax.swing.*;
4 4
 import javax.swing.event.*;
5
+import java.io.File;
5 6
 
6 7
 /*
7 8
  * frame.java
@@ -58,6 +59,7 @@ public class frame extends JFrame {
58 59
   private JTextField animPath = new JTextField();
59 60
   private JButton load = new JButton();
60 61
   private JButton save = new JButton();
62
+  private JButton saveAs = new JButton();
61 63
   private JComboBox jComboBox1 = new JComboBox();
62 64
   private JButton upload = new JButton();
63 65
   private JButton download = new JButton();
@@ -66,6 +68,7 @@ public class frame extends JFrame {
66 68
   // Ende Attribute
67 69
 
68 70
   private cubeWorker worker = new cubeWorker();
71
+  private boolean fileSelected = false;
69 72
   // Ende Variablen
70 73
 
71 74
   private int saveExitDialog() {
@@ -295,7 +298,7 @@ public class frame extends JFrame {
295 298
     animPath.setText("Load/Save an animation file...");
296 299
     animPath.setFont(new Font("Dialog", Font.PLAIN, 13));
297 300
     cp.add(animPath);
298
-    load.setBounds(344, 296, 147, 25);
301
+    load.setBounds(344, 296, 100, 25);
299 302
     load.setText("Load");
300 303
     load.setFont(new Font("Dialog", Font.PLAIN, 13));
301 304
     cp.add(load);
@@ -305,7 +308,7 @@ public class frame extends JFrame {
305 308
       }
306 309
     });
307 310
 
308
-    save.setBounds(504, 296, 147, 25);
311
+    save.setBounds(454, 296, 100, 25);
309 312
     save.setText("Save");
310 313
     save.setFont(new Font("Dialog", Font.PLAIN, 13));
311 314
     cp.add(save);
@@ -315,6 +318,16 @@ public class frame extends JFrame {
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 331
     jComboBox1.setBounds(344, 328, 305, 24);
319 332
     jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 13));
320 333
     cp.add(jComboBox1);
@@ -456,11 +469,49 @@ public class frame extends JFrame {
456 469
   }
457 470
 
458 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 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,9 +6,9 @@ TARGET = unix
6 6
 JAVAFILES = cubeWorker.java layerEditFrame.java frame.java
7 7
 
8 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 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 12
 endif
13 13
 
14 14
 all: build clean

Loading…
Cancel
Save