mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-01-05 11:29:43 +00:00
Extracted AnimationWorker from DataPanel
This commit is contained in:
parent
9d706d62ef
commit
95538f5282
62
src/com/bytezone/diskbrowser/gui/AnimationWorker.java
Normal file
62
src/com/bytezone/diskbrowser/gui/AnimationWorker.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package com.bytezone.diskbrowser.gui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.SwingWorker;
|
||||||
|
|
||||||
|
import com.bytezone.diskbrowser.applefile.SHRPictureFile2;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
|
public class AnimationWorker extends SwingWorker<Void, Integer>
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
volatile boolean running;
|
||||||
|
SHRPictureFile2 image;
|
||||||
|
DataPanel owner;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
public AnimationWorker (DataPanel owner, SHRPictureFile2 image)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
assert image.isAnimation ();
|
||||||
|
this.image = image;
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
public void cancel ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground () throws Exception
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
running = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
Thread.sleep (image.getDelay ());
|
||||||
|
publish (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace ();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@Override
|
||||||
|
protected void process (List<Integer> chunks)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
image.nextFrame ();
|
||||||
|
owner.update ();
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,6 @@ import javax.swing.JTabbedPane;
|
|||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingWorker;
|
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ public class DataPanel extends JTabbedPane
|
|||||||
boolean assemblerTextValid;
|
boolean assemblerTextValid;
|
||||||
DataSource currentDataSource;
|
DataSource currentDataSource;
|
||||||
|
|
||||||
private Worker animation;
|
private AnimationWorker animation;
|
||||||
|
|
||||||
final MenuHandler menuHandler;
|
final MenuHandler menuHandler;
|
||||||
|
|
||||||
@ -381,7 +380,7 @@ public class DataPanel extends JTabbedPane
|
|||||||
{
|
{
|
||||||
if (animation != null)
|
if (animation != null)
|
||||||
animation.cancel ();
|
animation.cancel ();
|
||||||
animation = new Worker ((SHRPictureFile2) dataSource);
|
animation = new AnimationWorker (this, (SHRPictureFile2) dataSource);
|
||||||
animation.execute ();
|
animation.execute ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,49 +514,4 @@ public class DataPanel extends JTabbedPane
|
|||||||
if (currentDataSource instanceof BasicTextFile)
|
if (currentDataSource instanceof BasicTextFile)
|
||||||
setDataSource (currentDataSource);
|
setDataSource (currentDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
class Worker extends SwingWorker<Void, Integer>
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
volatile boolean running;
|
|
||||||
SHRPictureFile2 image;
|
|
||||||
|
|
||||||
public Worker (SHRPictureFile2 image)
|
|
||||||
{
|
|
||||||
assert image.isAnimation ();
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancel ()
|
|
||||||
{
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground () throws Exception
|
|
||||||
{
|
|
||||||
running = true;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (running)
|
|
||||||
{
|
|
||||||
Thread.sleep (image.getDelay ());
|
|
||||||
publish (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace ();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void process (List<Integer> chunks)
|
|
||||||
{
|
|
||||||
image.nextFrame ();
|
|
||||||
update ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user