[Patchanim-commit] SF.net SVN: patchanim: [41] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-01-28 01:21:42
|
Revision: 41
http://patchanim.svn.sourceforge.net/patchanim/?rev=41&view=rev
Author: dbrosius
Date: 2008-01-27 17:21:47 -0800 (Sun, 27 Jan 2008)
Log Message:
-----------
get file io working (dirty flag still not set, tho)
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java
trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java
trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-27 23:19:28 UTC (rev 40)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/PatchAnimDocument.java 2008-01-28 01:21:47 UTC (rev 41)
@@ -47,7 +47,7 @@
tweenCount = 10;
}
- public boolean getDirty() {
+ public boolean isDirty() {
return dirty;
}
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-27 23:19:28 UTC (rev 40)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-28 01:21:47 UTC (rev 41)
@@ -109,33 +109,84 @@
}
});
+ newItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ try {
+ if (document.isDirty()) {
+ int choice = askSave();
+ if (choice == JFileChooser.CANCEL_OPTION)
+ return;
+ if (choice == JFileChooser.APPROVE_OPTION) {
+ save();
+ }
+ }
+
+ document = new PatchAnimDocument();
+ documentLocation = null;
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED);
+ }
+ }
+ });
+
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- //Ask save
- load();
+ try {
+ if (document.isDirty()) {
+ int choice = askSave();
+ if (choice == JFileChooser.CANCEL_OPTION)
+ return;
+ if (choice == JFileChooser.APPROVE_OPTION) {
+ save();
+ }
+ }
+ load();
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.LOADFAILED);
+ }
}
});
saveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- if (documentLocation == null) {
- saveAs();
- } else {
- save();
+ try {
+ if (documentLocation == null) {
+ saveAs();
+ } else {
+ save();
+ }
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED);
}
}
});
saveAsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- saveAs();
+ try {
+ saveAs();
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED);
+ }
}
});
quitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- dispose();
- System.exit(0);
+ try {
+ if (document.isDirty()) {
+ int choice = askSave();
+ if (choice == JFileChooser.CANCEL_OPTION)
+ return;
+ if (choice == JFileChooser.APPROVE_OPTION) {
+ save();
+ }
+ }
+ dispose();
+ System.exit(0);
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED);
+ }
}
});
}
@@ -174,36 +225,32 @@
}
}
- private void saveAs() {
- try {
- JFileChooser chooser = new JFileChooser();
- chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- File defLocation;
- if (documentLocation == null)
- defLocation = new File(System.getProperty("user.dir"));
- else
- defLocation = documentLocation.getParentFile();
+ private void saveAs() throws IOException {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ File defLocation;
+ if (documentLocation == null)
+ defLocation = new File(System.getProperty("user.dir"));
+ else
+ defLocation = documentLocation.getParentFile();
- chooser.setCurrentDirectory(defLocation);
- int option = chooser.showSaveDialog(JPatchAnimFrame.this);
- if (option == JFileChooser.APPROVE_OPTION) {
- String path = chooser.getSelectedFile().getPath();
- if (!path.toLowerCase().endsWith(".paf"))
- path += ".paf";
- documentLocation = new File(path);
- PatchAnimIO.saveFile(documentLocation, document);
- documentLocation = chooser.getSelectedFile();
- }
- } catch (IOException ioe) {
- JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED);
+ chooser.setCurrentDirectory(defLocation);
+ int option = chooser.showSaveDialog(JPatchAnimFrame.this);
+ if (option == JFileChooser.APPROVE_OPTION) {
+ String path = chooser.getSelectedFile().getPath();
+ if (!path.toLowerCase().endsWith(".paf"))
+ path += ".paf";
+ documentLocation = new File(path);
+ PatchAnimIO.saveFile(documentLocation, document);
+ documentLocation = chooser.getSelectedFile();
}
}
- private void save() {
- try {
- PatchAnimIO.saveFile(documentLocation, document);
- } catch (IOException ioe) {
- JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.SAVEFAILED);
- }
+ private void save() throws IOException {
+ PatchAnimIO.saveFile(documentLocation, document);
}
+
+ private int askSave() {
+ return JFileChooser.APPROVE_OPTION;
+ }
}
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-27 23:19:28 UTC (rev 40)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 01:21:47 UTC (rev 41)
@@ -47,6 +47,7 @@
public static final String ADD = "patchanim.add";
public static final String REMOVE = "patchanim.remove";
public static final String COLOR = "patchanim.color";
+ public static final String LOADFAILED = "patchanim.err.loadfailed";
public static final String SAVEFAILED = "patchanim.err.savefailed";
private static ResourceBundle rb = ResourceBundle.getBundle("com/mebigfatguy/patchanim/resources");
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-27 23:19:28 UTC (rev 40)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-28 01:21:47 UTC (rev 41)
@@ -41,3 +41,4 @@
patchanim.remove = Remove
patchanim.color = Color
patchanim.err.savefailed = Failed saving Patch Animation File
+patchanim.err.loadfailed = Failed loading Patch Animation File
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|