00001 package delaunaypackage; 00002 import java.awt.*; 00003 /* 00004 * AlgorithmUI class. Each algorithm has a set of user interface 00005 * controls. This class provides them. 00006 */ 00007 class AlgorithmUI extends Panel { 00008 TextField nPointsTextField; 00009 // Checkbox animateCheckBox[]; 00010 Checkbox runCheckBox; 00011 // TextField pauseTextField; 00012 TriangulationAlgorithm algorithm; // Algorithm which uses this UI. 00013 00014 public AlgorithmUI(TriangulationAlgorithm algorithm, 00015 String label, int nPoints /*, int pause*/) { 00016 00017 this.algorithm = algorithm; 00018 00019 // One set of controls per algorithm. 00020 setLayout(new GridLayout(0,7)); 00021 add(new Label(label, Label.LEFT)); 00022 add(runCheckBox = new Checkbox(null, null, true)); 00023 add(nPointsTextField = new TextField(String.valueOf(nPoints), 5)); 00024 // animateCheckBox = new Checkbox[AnimateControl.nEntities]; 00025 // animateCheckBox[AnimateControl.triangles] = new Checkbox(null, null, true); 00026 // add(animateCheckBox[AnimateControl.triangles]); 00027 // animateCheckBox[AnimateControl.circles] = new Checkbox(null, null, true); 00028 // add(animateCheckBox[AnimateControl.circles]); 00029 // animateCheckBox[AnimateControl.points] = new Checkbox(null, null, true); 00030 // add(animateCheckBox[AnimateControl.points]); 00031 // pauseTextField = new TextField(String.valueOf(pause), 5); 00032 // add(pauseTextField); 00033 } 00034 00035 public void setAlgorithm(TriangulationAlgorithm algorithm) { 00036 this.algorithm = algorithm; 00037 } 00038 00039 // Gets the current value in a text field. 00040 int getValue(TextField tF) { 00041 int i; 00042 try { 00043 i = Integer.valueOf(tF.getText()).intValue(); 00044 } catch (java.lang.NumberFormatException e) { 00045 i = 0; 00046 } 00047 return i; 00048 } 00049 00050 public boolean handleEvent(Event evt) { 00051 // if (evt.id == Event.ACTION_EVENT) { 00052 // if (evt.target == runCheckBox) { 00053 // algorithm.control().setRun(((Boolean)evt.arg).booleanValue()); 00054 // return true; 00055 // } else if (evt.target == animateCheckBox[AnimateControl.triangles]) { 00056 // algorithm.control().setAnimate(AnimateControl.triangles, 00057 // ((Boolean)evt.arg).booleanValue()); 00058 // return true; 00059 // } else if (evt.target == animateCheckBox[AnimateControl.circles]) { 00060 // algorithm.control().setAnimate(AnimateControl.circles, 00061 // ((Boolean)evt.arg).booleanValue()); 00062 // return true; 00063 // } else if (evt.target == animateCheckBox[AnimateControl.points]) { 00064 // algorithm.control().setAnimate(AnimateControl.points, 00065 // ((Boolean)evt.arg).booleanValue()); 00066 // return true; 00067 // } else if (evt.target == pauseTextField) { 00068 // algorithm.control().setPause(getValue(pauseTextField)); 00069 // return true; 00070 // } else if (evt.target == nPointsTextField) { 00071 // algorithm.control().nPoints = getValue(nPointsTextField); 00072 // return true; 00073 // } 00074 // } 00075 00076 return false; 00077 } 00078 }
1.5.5