/* AlgThread.java */ /* Generic algorithm running thread .. all algorithms implement specialisations of this .. overriding methods as they need */ package ciips.animation; import java.awt.*; import java.awt.event.*; 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 implements ItemListener, InputCompleteListener { 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 private static final boolean DEBUG = true; public AlgThread() { System.out.println("AlgThread cons complete"); } public void setParms( AlgAnimFrame frame, int frames ) { if(frame == null) { System.out.println("AlgThread: null frame"); } System.out.println("AlgThread - " + frames + " frames" ); this.frame = frame; this.frames = frames; d_panel = new DrawingPanel[frames]; if( DEBUG ) System.out.println("AlgThread:setParms complete"); } public void setParms( AlgAnimFrame frame, String ds[], int frames ) { setParms( frame, frames ); // dataSets = ds; } public void setParms( AlgAnimFrame frame, String df_prefix, int frames ) { this.setParms( frame, frames ); // Now locate all the data files // dataSets = getFileNames( df_prefix ); } // 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 gets 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(); } /** Find the list of file names with a given prefix and numeric extensions **/ /** public String[] getFileNames( String prefix ) { File f; String n[] = null; String names[] = new String[100]; // Arbitrary maximum int cnt = 0; URL base_name = frame.getApplet().getCodeBase(); for( cnt=0;cnt<99;cnt++ ) { String fn = prefix + cnt; try { URL dataURL = new URL( base_name, fn ); URLConnection c = dataURL.openConnection(); long x = c.getDate(); System.out.println("AlgThread:getFN - " + cnt + ": " + fn + " date " + x ); Object o = c.getContent(); if ( o == null ) break; // Assume that it we get here, we had a valid connection names[cnt] = fn; } catch (IOException e) { break; } } if ( cnt <= 0 ) { System.out.println("AlgThread:getFileNames - none found"); } else { System.out.println("AlgThread:getFileNames - " + cnt + " found"); n = new String[cnt]; for( int j=0;j