Thread: [Patchanim-commit] SF.net SVN: patchanim: [29] trunk/patchanim/src/com/mebigfatguy/patchanim/ gui/J
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-01-27 01:43:20
|
Revision: 29 http://patchanim.svn.sourceforge.net/patchanim/?rev=29&view=rev Author: dbrosius Date: 2008-01-26 17:43:26 -0800 (Sat, 26 Jan 2008) Log Message: ----------- The test frame for animations Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java Added: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java (rev 0) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 01:43:26 UTC (rev 29) @@ -0,0 +1,140 @@ +package com.mebigfatguy.patchanim.gui; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import com.mebigfatguy.patchanim.PatchAnimDocument; +import com.mebigfatguy.patchanim.surface.CombinedPatch; +import com.mebigfatguy.patchanim.surface.PatchGenerator; + +public class JTestFrame extends JFrame { + + private Thread animThread = null; + private TestPanel testPanel = null; + private int tweenCount; + private int width; + private int height; + private List<CombinedPatch> patches; + private BufferedImage image; + + public JTestFrame() { + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + PatchAnimDocument document = mediator.getDocument(); + tweenCount = document.getTweenCount(); + width = document.getWidth(); + height = document.getHeight(); + patches = document.getPatches(); + + initComponents(); + initListeners(); + } + + public synchronized void beginAnimation() { + if (animThread != null) + return; + image = PatchGenerator.buildImage(null, width, height); + + animThread = new Thread(new Runnable() { + public void run() { + try { + PatchGenerator.recalcCombinedImage(patches.get(0), image); + while (!Thread.interrupted()) { + testPanel.redraw(); + int lastPatch = patches.size() - 1; + long lastRedraw = System.currentTimeMillis(); + 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); + long now = System.currentTimeMillis(); + long sleepTime = 100 - (now - lastRedraw); + if (sleepTime > 0) + Thread.sleep(sleepTime); + testPanel.redraw(); + lastRedraw = now; + } + } + } + } catch (InterruptedException ie) { + //OK + } + } + }); + animThread.start(); + + } + + public synchronized void endAnimation() { + if (animThread == null) + return; + + try { + animThread.interrupt(); + animThread.join(); + } catch (InterruptedException ie) { + //OK + } finally { + animThread = null; + } + } + + private void initComponents() { + testPanel = new TestPanel(); + setLayout(new BorderLayout(4, 4)); + add(testPanel, BorderLayout.CENTER); + pack(); + } + + private void initListeners() { + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent we) { + endAnimation(); + dispose(); + } + }); + } + + class TestPanel extends JPanel { + public TestPanel() { + Dimension d = new Dimension(width, height); + setMinimumSize(d); + setMaximumSize(d); + setPreferredSize(d); + setSize(width, height); + } + + public void redraw() throws InterruptedException { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + invalidate(); + revalidate(); + repaint(); + } + }); + } catch (InvocationTargetException ite) { + InterruptedException ie = new InterruptedException("Error rendering test"); + ie.initCause(ite); + throw ie; + } + } + + @Override + public void paintComponent(Graphics g) { + g.drawImage(image, 0, 0, width, height, 0, 0, width, height, null); + } + } +} Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-27 01:46:08
|
Revision: 32 http://patchanim.svn.sourceforge.net/patchanim/?rev=32&view=rev Author: dbrosius Date: 2008-01-26 17:46:13 -0800 (Sat, 26 Jan 2008) Log Message: ----------- add copyright Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 01:45:15 UTC (rev 31) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 01:46:13 UTC (rev 32) @@ -1,3 +1,21 @@ +/* + * patchanim - A bezier surface patch color blend gif builder + * Copyright (C) 2008 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ package com.mebigfatguy.patchanim.gui; import java.awt.BorderLayout; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-01-27 01:59:04
|
Revision: 33 http://patchanim.svn.sourceforge.net/patchanim/?rev=33&view=rev Author: dbrosius Date: 2008-01-26 17:59:07 -0800 (Sat, 26 Jan 2008) Log Message: ----------- implement Animation Repeat types, None, Cycle and Wave Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 01:46:13 UTC (rev 32) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JTestFrame.java 2008-01-27 01:59:07 UTC (rev 33) @@ -31,6 +31,7 @@ import javax.swing.JPanel; import javax.swing.SwingUtilities; +import com.mebigfatguy.patchanim.AnimationType; import com.mebigfatguy.patchanim.PatchAnimDocument; import com.mebigfatguy.patchanim.surface.CombinedPatch; import com.mebigfatguy.patchanim.surface.PatchGenerator; @@ -42,6 +43,7 @@ private int tweenCount; private int width; private int height; + private AnimationType type; private List<CombinedPatch> patches; private BufferedImage image; @@ -51,6 +53,7 @@ tweenCount = document.getTweenCount(); width = document.getWidth(); height = document.getHeight(); + type = document.getAnimationType(); patches = document.getPatches(); initComponents(); @@ -84,6 +87,26 @@ lastRedraw = now; } } + + if (type == AnimationType.None) + return; + + if (type == 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); + long now = System.currentTimeMillis(); + long sleepTime = 100 - (now - lastRedraw); + if (sleepTime > 0) + Thread.sleep(sleepTime); + testPanel.redraw(); + lastRedraw = now; + } + } + } } } catch (InterruptedException ie) { //OK This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |