/* AlgThread.java */ /* Generic algorithm running thread .. all algorithms implement specialisations of this .. overriding methods as they need To be done: A. Provide option for 1 or 2 panels, ie before and after .. or just one B. This class should be responsible for swapping the current image to the "before" image. So that the animation can simply concern itself with maintaining the current image */ package ciips.animation; import java.awt.*; import java.io.*; import java.net.*; import java.util.*; /** Animations should extend this class and implement the run and loadData methods. */ public abstract class AlgThread extends Thread { static int max_data = 10; private String[] dataSets = { "Graph 1", "Graph 2", "Graph 3"}; static String base_data_file_name = "graph.rb"; public AlgAnimFrame frame; // Parent frame public DrawingPanel[] d_panel; static final int offset_y = 10; static final int offset_x = 50; private int frames = 1; // Number of consecutive frames to be shown //int delay = 2000; // boolean source_loaded = false; /*public Image beforeOffSc = null; Graphics beforeOffGraphics = null; Dimension beforeOffSize = null; public Image dataOffSc = null; Graphics dataOffGraphics = null; Dimension dataOffSize = null; */ public AlgThread() { System.out.println("AlgThread cons complete"); } public void setParms( AlgAnimFrame frame, String ds[], int frames ) { if(frame == null) { System.out.println("AlgThread: null frame"); } System.out.println("AlgThread - " + frames + " frames; ds[" + ds + "]"); this.frame = frame; this.frames = frames; dataSets = ds; d_panel = new DrawingPanel[frames]; System.out.println("AlgThread:setParms complete"); /* if ((frame != null) && (frame.getAlg() != null) && (frame.getAlg().dpAfter != null)) { // drawingPanel already created -> this constructor called from // clicking the run button -> use the generated data set } else { // First time .. // this constructor called from Frame constructor // We've decided not to do anything here! } */ } public String[] getDataSets() { return dataSets; } // Added in a setDelay function here public void setDelay(int delay) { frame.getCurrentPanel().setDelay(delay); } public int getDataPanelCount() { return frames; } /** Shuffle the previous panels down * Panel with index = 0 is the current panel */ public void shuffleDown( ) { if ( frames == 1 ) return; // nothing to do for( int k=1;kchoice will be a data set index in the range 0..max_data_sets-1 */ public abstract boolean loadData( int choice ); /** Generate the example data set. Reads the chosen data set from the frame's menu, and calls loadData( choice ) to load or generate the appropriate data set. */ public void generateData() { //int choice = frame.control_panel.getDataChoice(); //added // this.dpAfter = frame.getDrawingPanel(); frame.getCurrentPanel().init(); int choice = frame.getDataChoice(); if ( loadData( choice ) ) { System.out.println("Data loaded OK"); } else { System.out.println("Data loading error"); } } /** Run the animation. This is the key method that the animator provides: it starts up the animation and runs it to completion. */ public abstract void run(); public void restoreDrawingPanel() { // This needs to be here because it get called from AlgAnimFrame } //This method needs to be here for the skip button to be effective public void waitSkip() { DrawingPanel dpAfter = frame.getCurrentPanel(); if(!dpAfter.getSkip()) return; ((ImageButton)frame.getSkipItem()).setEnable(); ((ImageButton)frame.getRunItem()).setEnable(); ((ImageButton)frame.getStopItem()).setDisable(); dpAfter.setSkip(false); frame.setStep(true); frame.waitStep(); } }