[Patchanim-commit] SF.net SVN: patchanim: [53] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-01-29 05:54:57
|
Revision: 53
http://patchanim.svn.sourceforge.net/patchanim/?rev=53&view=rev
Author: dbrosius
Date: 2008-01-28 21:55:02 -0800 (Mon, 28 Jan 2008)
Log Message:
-----------
add export to list of jpgs or pngs
Modified Paths:
--------------
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/gui/JPatchAnimFrame.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-28 07:50:54 UTC (rev 52)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchAnimFrame.java 2008-01-29 05:55:02 UTC (rev 53)
@@ -24,10 +24,14 @@
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
+import java.text.NumberFormat;
+import java.util.List;
import java.util.ResourceBundle;
+import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
@@ -36,9 +40,14 @@
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
+import com.mebigfatguy.patchanim.AnimationType;
+import com.mebigfatguy.patchanim.ExportType;
+import com.mebigfatguy.patchanim.OutOfBoundsColor;
import com.mebigfatguy.patchanim.PatchAnimDocument;
import com.mebigfatguy.patchanim.io.PatchAnimIO;
import com.mebigfatguy.patchanim.main.PatchAnimBundle;
+import com.mebigfatguy.patchanim.surface.CombinedPatch;
+import com.mebigfatguy.patchanim.surface.PatchGenerator;
public class JPatchAnimFrame extends JFrame {
@@ -46,9 +55,11 @@
private JMenuItem newItem;
private JMenuItem openItem;
- private JMenuItem closeItem;
private JMenuItem saveItem;
private JMenuItem saveAsItem;
+ private JMenu exportMenu;
+ private JMenuItem exportJpgsItem;
+ private JMenuItem exportPngsItem;
private JMenuItem quitItem;
private PatchAnimDocument document;
private File documentLocation;
@@ -91,6 +102,13 @@
saveAsItem = new JMenuItem(rb.getString(PatchAnimBundle.SAVEAS));
fileMenu.add(saveAsItem);
fileMenu.addSeparator();
+ exportMenu = new JMenu(rb.getString(PatchAnimBundle.EXPORT));
+ exportJpgsItem = new JMenuItem(rb.getString(PatchAnimBundle.JPGSERIES));
+ exportPngsItem = new JMenuItem(rb.getString(PatchAnimBundle.PNGSERIES));
+ exportMenu.add(exportJpgsItem);
+ exportMenu.add(exportPngsItem);
+ fileMenu.add(exportMenu);
+ fileMenu.addSeparator();
quitItem = new JMenuItem(rb.getString(PatchAnimBundle.QUIT));
fileMenu.add(quitItem);
@@ -183,6 +201,26 @@
}
});
+ exportJpgsItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ try {
+ exportFiles(ExportType.JPegs);
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED);
+ }
+ }
+ });
+
+ exportPngsItem.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ try {
+ exportFiles(ExportType.Pngs);
+ } catch (IOException ioe) {
+ JOptionPane.showMessageDialog(JPatchAnimFrame.this, PatchAnimBundle.EXPORTFAILED);
+ }
+ }
+ });
+
quitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
@@ -286,4 +324,67 @@
ResourceBundle rb = PatchAnimBundle.getBundle();
return JOptionPane.showConfirmDialog(JPatchAnimFrame.this, rb.getString(PatchAnimBundle.ASKSAVE), rb.getString(PatchAnimBundle.TITLE), JOptionPane.YES_NO_CANCEL_OPTION);
}
+
+ private void exportFiles(ExportType type) 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)
+ return;
+
+ File dir = chooser.getSelectedFile();
+ dir.mkdir();
+ String baseName = dir.getName();
+
+ BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight());
+
+ List<CombinedPatch> patches = document.getPatches();
+ int lastPatch = patches.size() - 1;
+ int tweenCount = document.getTweenCount();
+ OutOfBoundsColor oob = document.getOutOfBoundsColor();
+ int imageIndex = 1;
+ AnimationType atype = document.getAnimationType();
+
+ for(int p = 0; p < lastPatch; p++) {
+ CombinedPatch startPatch = patches.get(p);
+ CombinedPatch endPatch = patches.get(p+1);
+ for (int t = 0; t < tweenCount; t++) {
+ CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)tweenCount);
+ PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
+ writeSingleFile(image, imageIndex++, dir, baseName, type);
+ }
+ }
+
+ if (atype == AnimationType.None)
+ return;
+
+ if (atype == AnimationType.Wave) {
+ for (int p = lastPatch; p > 0; p--) {
+ CombinedPatch startPatch = patches.get(p-1);
+ CombinedPatch endPatch = patches.get(p);
+ for (int t = tweenCount - 1; t >= 0; t--) {
+ CombinedPatch tweenPatch = CombinedPatch.tween(startPatch, endPatch, (double)t / (double)tweenCount);
+ PatchGenerator.recalcCombinedImage(tweenPatch, image, oob);
+ writeSingleFile(image, imageIndex++, dir, baseName, type);
+ }
+ }
+ }
+ }
+
+ private void writeSingleFile(BufferedImage image, int index, File dir, String baseName, ExportType type) throws IOException {
+ NumberFormat nf = NumberFormat.getIntegerInstance();
+ nf.setMinimumIntegerDigits(6);
+ String name = baseName + "_" + nf.format(index) + "." + type.getExtension();
+
+ File imageFile = new File(dir, name);
+ ImageIO.write(image, type.getExtension(), imageFile);
+ }
}
+
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-28 07:50:54 UTC (rev 52)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/main/PatchAnimBundle.java 2008-01-29 05:55:02 UTC (rev 53)
@@ -29,6 +29,9 @@
public static final String OPEN = "patchanim.open";
public static final String SAVE = "patchanim.save";
public static final String SAVEAS = "patchanim.saveas";
+ public static final String EXPORT = "patchanim.export";
+ public static final String JPGSERIES = "patchanim.jpgs";
+ public static final String PNGSERIES = "patchanim.pngs";
public static final String QUIT = "patchanim.quit";
public static final String CONTROLS = "patchanim.control";
public static final String WIDTH = "patchanim.width";
@@ -53,6 +56,7 @@
public static final String ASKSAVE = "patchanim.asksave";
public static final String LOADFAILED = "patchanim.err.loadfailed";
public static final String SAVEFAILED = "patchanim.err.savefailed";
+ public static final String EXPORTFAILED = "patchanim.err.exportfailed";
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-28 07:50:54 UTC (rev 52)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/resources.properties 2008-01-29 05:55:02 UTC (rev 53)
@@ -22,6 +22,9 @@
patchanim.open = Open...
patchanim.save = Save
patchanim.saveas = Save As...
+patchanim.export = Export As...
+patchanim.jpgs = a series of JPGs
+patchanim.pngs = a series of PNGs
patchanim.quit = Quit
patchanim.control = Controls
patchanim.width = Width
@@ -46,3 +49,4 @@
patchanim.asksave = Do you want to save your changes?
patchanim.err.savefailed = Failed saving Patch Animation File
patchanim.err.loadfailed = Failed loading Patch Animation File
+patchanim.err.exportfailed = Failed exporting PatchAnimations
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|