[Pixelle-commit] SF.net SVN: pixelle: [129] trunk/pixelle/src/com/mebigfatguy/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-06-30 03:14:32
|
Revision: 129
http://pixelle.svn.sourceforge.net/pixelle/?rev=129&view=rev
Author: dbrosius
Date: 2008-06-29 20:14:41 -0700 (Sun, 29 Jun 2008)
Log Message:
-----------
implement save, and saveas
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java
trunk/pixelle/src/com/mebigfatguy/pixelle/actions/OpenFileAction.java
trunk/pixelle/src/com/mebigfatguy/pixelle/actions/SaveFileAsAction.java
trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java 2008-06-30 02:43:23 UTC (rev 128)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java 2008-06-30 03:14:41 UTC (rev 129)
@@ -73,6 +73,7 @@
public static final String CLIP_COLOR = "label.clip_color";
public static final String ROLL_COLOR = "label.roll_color";
public static final String WAVE_COLOR = "label.wave_color";
+ public static final String SAVE_OVERWRITE = "label.save_overwrite";
private static ResourceBundle rb = ResourceBundle.getBundle("com/mebigfatguy/pixelle/resources/pixelle");
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/actions/OpenFileAction.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/actions/OpenFileAction.java 2008-06-30 02:43:23 UTC (rev 128)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/actions/OpenFileAction.java 2008-06-30 03:14:41 UTC (rev 129)
@@ -22,6 +22,7 @@
import java.io.File;
import java.util.Locale;
+import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
@@ -50,7 +51,12 @@
return true;
String path = f.getPath().toLowerCase(Locale.getDefault());
- return (path.endsWith(".gif") || path.endsWith(".jpg") || path.endsWith(".png") || path.endsWith(".bmp"));
+ String[] formats = ImageIO.getReaderFormatNames();
+ for (String format : formats) {
+ if (path.endsWith(format.toLowerCase(Locale.getDefault())))
+ return true;
+ }
+ return false;
}
@Override
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/actions/SaveFileAsAction.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/actions/SaveFileAsAction.java 2008-06-30 02:43:23 UTC (rev 128)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/actions/SaveFileAsAction.java 2008-06-30 03:14:41 UTC (rev 129)
@@ -19,8 +19,16 @@
package com.mebigfatguy.pixelle.actions;
import java.awt.event.ActionEvent;
+import java.io.File;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Locale;
+import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+import javax.swing.filechooser.FileFilter;
import com.mebigfatguy.pixelle.PixelleBundle;
import com.mebigfatguy.pixelle.PixelleFrame;
@@ -37,6 +45,48 @@
}
public void actionPerformed(ActionEvent e) {
-
+ JFileChooser fc = new JFileChooser();
+ fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ fc.setFileFilter(new FileFilter() {
+ @Override
+ public boolean accept(File f) {
+ if (f.isDirectory())
+ return true;
+
+ String path = f.getPath().toLowerCase(Locale.getDefault());
+ String[] formats = ImageIO.getReaderFormatNames();
+ for (String format : formats) {
+ if (path.endsWith(format.toLowerCase(Locale.getDefault())))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Graphic Files";
+ }
+ });
+
+ if (JFileChooser.APPROVE_OPTION == fc.showSaveDialog(frame)) {
+ try {
+ File f = fc.getSelectedFile();
+ if (!f.exists() || askSaveFile(f)) {
+ String ext = f.getPath();
+ ext = ext.substring(ext.lastIndexOf('.')+1);
+ ImageIO.write(frame.getImage().getSaveImage(), ext, f);
+ }
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(frame, ioe.getMessage());
+ ioe.printStackTrace();
+ }
+ }
}
+
+ private boolean askSaveFile(File f) {
+ String title = MessageFormat.format(PixelleBundle.getString(PixelleBundle.TITLE), f.getName());
+ String message = MessageFormat.format(PixelleBundle.getString(PixelleBundle.SAVE_OVERWRITE), f.getPath());
+ int choice = JOptionPane.showConfirmDialog(frame, message, title, JOptionPane.YES_NO_OPTION);
+ return choice == JOptionPane.OK_OPTION;
+ }
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties 2008-06-30 02:43:23 UTC (rev 128)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties 2008-06-30 03:14:41 UTC (rev 129)
@@ -72,3 +72,5 @@
label.roll_color = Color Rolling
label.wave_color = Color Waving
+label.save_overwrite = The file "{0}" already exists, do you want to overwrite it?
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|