package uk.ac.leeds.ccg.cluster; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import uk.ac.leeds.ccg.geotools.*; public class GamButtonHandler implements ActionListener { // Members Gamk gam; Viewer v; Frame fr; FileDialog fd; FilenameFilter ff; // Constructors public GamButtonHandler(Gamk g) { v=g.v; gam=g; // create a filedialog fr= new Frame(); fd =new FileDialog(fr,"ShapeFile to load "); ff = new FileFil(fd,".shp"); } // Methods public void actionPerformed(ActionEvent e) { // Find out which button was pressed String cmd = e.getActionCommand(); // If button pressed was quit then exit the program if(cmd.equalsIgnoreCase("quit")) { System.exit(0); } // If button pressed was load then load a file if(cmd.equalsIgnoreCase("Load")) { fd.setFilenameFilter(ff); fd.setVisible(true); // Find out which file was chosen if(fd.getFile()==null) { // If no file chosen return; // then simply return } File fs = new File(fd.getDirectory(),fd.getFile()); System.out.println("File = "+fs); //try // {ShapefileReader sr = new ShapefileReader(new URL("file://"+name.substring(0,i)));} //catch(MalformedURLException me){} try { String name = fs.getCanonicalPath(); int i = name.lastIndexOf(".shp"); ShapefileReader sr = new ShapefileReader(name.substring(0,i)); Theme t = sr.getTheme(); t.setStyle(new ShadeStyle(false,true,null,Color.black,true)); System.out.println(""+t); v.addTheme(t); } catch(FileNotFoundException e1){} catch(IOException e2) { System.err.println("File read error"); return; } } // If button pressed was calculate if(cmd.equalsIgnoreCase("Calculate")) { gam.run(); } // Handle setting parameters if(cmd.equalsIgnoreCase("min")) { float r = getPar("Minimum Radius"); gam.pars.setRadMin(r); } } public float getPar(String name) { Dialog d = new Dialog(fr); d.add(new Label(name)); TextField t = new TextField(); d.add(t); //d.setModal(true); d.setVisible(true); return new Double(t.getText()).floatValue(); } }