/** TrieAlgThread.java Authors: Unknown (CS class at UWA) **/ import java.awt.*; import java.io.*; import java.net.*; import java.util.*; import ciips.animation.*; public class TrieAlgThread extends AlgThread { Trie tree; StrList strlist; static String[] DataSets = { "Test Set 1", "Test Set 2", "Test Set 3", "Test Set 4"}; private String base_filename = "data.tr"; public boolean DEBUG = true; int offset_x = 50, offset_y=20; private AlgAnimFrame f; /** Set the number of comment panel lines needed for this algorithm **/ static { AlgAnimFrame.COMPANEL_LINES = 5; } public TrieAlgThread( AlgAnimFrame frame ) { super(); setParms( frame, DataSets, 2 ); if (DEBUG) System.out.println("TrieAlgThread: Constructing class"); f = frame; } public boolean loadData( int choice ){ DataInputStream inStream; String file_name; file_name = base_filename + choice; System.out.println ( "TrieAlgThread: loadData file - [" + file_name + "]"); try{ URL dataURL = new URL( frame.getApplet().getCodeBase(), file_name ); strlist = new StrList( dataURL ); } catch (IOException e) { System.out.println("Data File Not Found!!"); } catch (NullPointerException e){ } return (strlist != null); } public void run(){ int k = getDataPanelCount(); d_panel[k-1] = frame.getCurrentPanel(); if ( k > 1) { d_panel[k-2] = frame.getPreviousPanel(); } if (d_panel[k-1] == null) { System.out.println("TrieAlgThread: run - DrawingPanel is null"); return; } /** Create a Trie with specified dimension * and generate datasets **/ tree = new Trie( frame.getCurrentPanel().getPreferredSize() ); generateData(); // Draw the tree in Drawing Panels if (strlist != null ){ for (int i=0; i 1 ) shuffleDown(); if( DEBUG ) System.out.println( "TrieAlgThread - to tree.add()" ); // Insert into the tree tree.add( data ); AlgAnimFrame.showText( 1, "Inserting (" + data + ")" ); if( DEBUG ) System.out.println( "TrieAlgThread - to pauseSkip" ); AlgAnimFrame.pauseSkip(); } if( DEBUG ) System.out.println( "TrieAlgThread - Insert finished" ); // finish creating tree frame.finishAlg(); d_panel[k-1].repaint(); AlgAnimFrame.showText( 4, "Trie completed" ); } else { System.out.println("Data file not found\n"); } } }