head 1.1; access; symbols; locks; strict; comment @# @; 1.1 date 97.11.09.01.23.12; author kowallik; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @// the dialog where we add special configurations to the list // for the pendulum animation import java.util.*; import java.awt.*; class Add_Book extends Dialog { TextField comTF; // description TextField dampTF, extTF, phiTF, wTF; // system parameters TextField x0TF, v0TF; // initial conditions Vector Marks; List ConfList; Add_Book(Vector d_Marks, List d_List, Book_Entry cur, Frame parent) { super(parent, true); setTitle("Add Configuration"); Marks = d_Marks; ConfList = d_List; Panel mainP = new Panel(); mainP.setLayout(new GridLayout(4,1)); Panel confP = new Panel(); confP.setLayout(new FlowLayout(FlowLayout.CENTER)); Panel initP = new Panel(); initP.setLayout(new FlowLayout(FlowLayout.CENTER)); Panel textP = new Panel(); textP.setLayout(new FlowLayout(FlowLayout.CENTER)); Panel buttP = new Panel(); buttP.setLayout(new FlowLayout(FlowLayout.CENTER)); add("Center", mainP); mainP.add(confP, 0); mainP.add(initP, 1); mainP.add(textP, 2); mainP.add(buttP, 3); // now add components // buttons buttP.add(new Button("Add")); buttP.add(new Button("Clear")); buttP.add(new Button("Cancel")); // system parameters dampTF = new TextField(6); dampTF.setText((new Double(cur.damp)).toString()); extTF = new TextField(6); extTF.setText((new Double(cur.ext)).toString()); phiTF = new TextField(6); phiTF.setText((new Double(cur.phi)).toString()); wTF = new TextField(6); wTF.setText((new Double(cur.w)).toString()); confP.add(new Label("damping:")); confP.add(dampTF); confP.add(new Label("driving force:")); confP.add(extTF); confP.add(new Label("driving frequency:")); confP.add(wTF); confP.add(new Label("phase of driving force:")); confP.add(phiTF); // initial conditions x0TF = new TextField(6); x0TF.setText((new Double(cur.x)).toString()); v0TF = new TextField(6); v0TF.setText((new Double(cur.v)).toString()); initP.add(new Label("initial position:")); initP.add(x0TF); initP.add(new Label("intitial velocity:")); initP.add(v0TF); // description comTF = new TextField(50); textP.add(new Label("human readable description:")); textP.add(comTF); pack(); show(); } public boolean handleEvent(Event evt) { switch (evt.id) { case Event.ACTION_EVENT: if ("Cancel".equals(evt.arg)) { dispose(); return true; } else if ("Add".equals(evt.arg)) { Double tmp; Book_Entry newbe = new Book_Entry(); String dampst = dampTF.getText(); try { tmp = new Double(dampst); }catch (NumberFormatException nfe) { tmp = new Double(0.0); } newbe.damp = (Math.round(tmp.doubleValue()*1000)/1000.0); String extst = extTF.getText(); try { tmp = new Double(extst); }catch (NumberFormatException nfe) { tmp = new Double(0.0); } newbe.ext = (Math.round(tmp.doubleValue()*1000)/1000.0); String phist = phiTF.getText(); try { tmp = new Double(phist); }catch (NumberFormatException nfe) { tmp = new Double(0.0); } newbe.phi = (Math.round(tmp.doubleValue()*1000)/1000.0); String wst = wTF.getText(); try { tmp = new Double(wst); }catch (NumberFormatException nfe) { tmp = new Double(0.0); } newbe.w = (Math.round(tmp.doubleValue()*1000)/1000.0); String x0st = x0TF.getText(); try { tmp = new Double(x0st); }catch (NumberFormatException nfe) { tmp = new Double(0.0); } newbe.x = (Math.round(tmp.doubleValue()*1000)/1000.0); String v0st = v0TF.getText(); try { tmp = new Double(v0st); }catch (NumberFormatException nfe) { tmp = new Double(0.0); } newbe.v = (Math.round(tmp.doubleValue()*1000)/1000.0); newbe.com = comTF.getText(); if (newbe.com.equals("")) // use parameters for descrip { newbe.com=dampst+":"+extst+":"+wst+":"+phist+":"+x0st+":"+v0st; } // add to the Vector Marks.addElement(newbe); // add it to List ConfList.addItem(newbe.toString()); return true; // handle locally } else if ("Clear".equals(evt.arg)) { dampTF.setText(""); extTF.setText(""); wTF.setText(""); phiTF.setText(""); x0TF.setText(""); v0TF.setText(""); comTF.setText(""); return true; } break; case Event.WINDOW_DESTROY: dispose(); return true; default: return false; } return false; } } @