head 1.2; access; symbols; locks; strict; comment @# @; 1.2 date 97.12.01.03.58.59; author hans; state Exp; branches; next 1.1; 1.1 date 97.11.09.01.23.12; author kowallik; state Exp; branches; next ; desc @@ 1.2 log @added mini-screen option @ text @// the extra frame which contains all the controls // for the pendulum animation import java.awt.*; import java.util.*; import java.lang.*; public class Control_Win extends Frame { Scrollbar beta, d_force, d_w, d_phase, x0, y0; Choice length, delay; Button clear, go, halt, rerun; Label d_phase_c, damp_c, delay_c, ext_c, length_c, w_c, x0_c, y0_c; List ConfList(6, false); // for displaying bookmarks Vector Marks; // configurations Add_Book A_Add; // replace menu options wwith buttons JAVA BUG Button Addc, Remc, Runc; double y[]= new double[2]; static double damp, duration, ext, phi, w, x=0; static int delay_time; T_Graph time; P_Graph phase; graphic out; animation doit; boolean kill_thread = false; boolean big_screen; Control_Win(main parent) { Toolkit tk=null; Dimension screen=null; this.doit = parent.doit; this.out = parent.out; this.time = parent.time; this.phase = parent.phase; try { tk = this.getToolkit(); }catch(AWTError awte) {} if (tk != null) { screen = tk.getScreenSize(); } if(screen.height<590) { this.resize(250, 475); big_screen = false; } else { this.resize(300, 590); big_screen = true; } this.setTitle("Control Window"); setup(); } public void exit() { kill_thread = true; try { java.lang.Thread.currentThread().sleep(200); }catch(InterruptedException ie) {} if (A_Add != null) { A_Add.dispose(); A_Add = null; } } public void setup() { int i; GridBagLayout glb = new GridBagLayout(); setLayout(glb); Marks = new Vector(); // for the typical configurations ConfList = new List(); // initial conditions x0= new Scrollbar(Scrollbar.HORIZONTAL,800,1,-3141,3141); y0= new Scrollbar(Scrollbar.HORIZONTAL,916,1,-4000,4000); // system configuration d_force=new Scrollbar(Scrollbar.HORIZONTAL,520,1,0,2000); beta= new Scrollbar(Scrollbar.HORIZONTAL,200,1,0,4000); d_w= new Scrollbar(Scrollbar.HORIZONTAL,666,1,0,2000); d_phase= new Scrollbar(Scrollbar.HORIZONTAL,0,1,-3141,3141); // stuff length= new Choice(); length.addItem("25"); length.addItem("50"); length.addItem("75"); length.addItem("100"); length.select(1); delay= new Choice(); delay.addItem("5"); delay.addItem("10"); delay.addItem("15"); delay.addItem("20"); delay.addItem("25"); delay.select(1); go= new Button("Start"); halt= new Button("Stop"); rerun = new Button("Rerun"); clear= new Button("Clear"); // the scrollbars GridBagConstraints cs = new GridBagConstraints(); cs.gridwidth=11; cs.gridheight=1; cs.gridx=1; cs.gridy=1; cs.fill=GridBagConstraints.HORIZONTAL; cs.insets= new Insets(0,30,0,30); add(beta); glb.setConstraints(beta, cs); cs.gridy=3; add(d_force); glb.setConstraints(d_force, cs); cs.gridy=5; add(d_w); glb.setConstraints(d_w, cs); cs.gridy=7; add(d_phase); glb.setConstraints(d_phase, cs); cs.gridy=11; add(x0); glb.setConstraints(x0, cs); cs.gridy=13; add(y0); glb.setConstraints(y0, cs); // add captions for scrollbars cs.gridx=1; cs.gridy=0; cs.weighty=0.1; cs.insets= new Insets(0,0,0,0); damp_c=new Label("damping constant", Label.CENTER); add(damp_c); glb.setConstraints(damp_c,cs); ext_c=new Label("driving force", Label.CENTER); cs.gridy=2; add(ext_c); glb.setConstraints(ext_c,cs); w_c=new Label("driving frequency", Label.CENTER); cs.gridy=4; add(w_c); glb.setConstraints(w_c,cs); d_phase_c= new Label("phase of driving force", Label.CENTER); cs.gridy=6; add(d_phase_c); glb.setConstraints(d_phase_c,cs); x0_c=new Label("initial position", Label.CENTER); cs.gridy=10; add(x0_c); glb.setConstraints(x0_c,cs); y0_c=new Label("initial velocity", Label.CENTER); cs.gridy=12; add(y0_c); glb.setConstraints(y0_c,cs); // choice menus for timming GridBagConstraints cm = new GridBagConstraints(); cm.gridy=9; cm.gridx=5; cm.insets = new Insets(0,0,20,0); add(length); glb.setConstraints(length, cm); cm.gridx=6; add(delay); glb.setConstraints(delay, cm); // labels for choice menus cm.insets = new Insets(20,0,0,0); cm.gridx=5; cm.gridy=8; cm.weighty=0.01; length_c=new Label("duration", Label.CENTER); add(length_c); glb.setConstraints(length_c,cm); cm.gridx=6; delay_c=new Label("delay", Label.CENTER); add(delay_c); glb.setConstraints(delay_c,cm); // add buttons GridBagConstraints cb = new GridBagConstraints(); cb.gridwidth=1; cb.gridheight=1; cb.gridx=4; cb.gridy=15; cb.fill=GridBagConstraints.HORIZONTAL; cb.insets=new Insets(10,10,20,10); cb.weightx=1.0; add(go); glb.setConstraints(go,cb); cb.gridx=5; add(halt); glb.setConstraints(halt,cb); cb.gridx=6; add(clear); glb.setConstraints(clear,cb); cb.gridx=7; add(rerun); glb.setConstraints(rerun,cb); if (big_screen == true) { // the list of typical/saved configurations Book_Entry aconf = new Book_Entry(); aconf.com = "startup configuration"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.2; aconf.ext = 0.52; aconf.w = 0.666; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); aconf = new Book_Entry(); aconf.com = "a small change in frequency - two loops"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.2; aconf.ext = 0.52; aconf.w = 0.67; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); aconf = new Book_Entry(); aconf.com = "change damping - one loop and a half"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.201; aconf.ext = 0.52; aconf.w = 0.666; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); aconf = new Book_Entry(); aconf.com = "change damping again - rotate other way"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.202; aconf.ext = 0.52; aconf.w = 0.666; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); // create buttons for configurations management Addc = new Button("Add Configuration"); Remc = new Button("Remove Configuration"); Runc = new Button("Run Configuration"); GridBagConstraints cl = new GridBagConstraints(); cl.gridwidth=11; cl.gridheight=1; cl.gridx=1; cl.gridy=16; cl.fill=GridBagConstraints.HORIZONTAL; cl.weightx=1.0; Label bar = new Label("some typical configurations", Label.CENTER); add(bar); glb.setConstraints(bar,cl); cl.insets=new Insets(10,10,10,10); cl.gridheight=3; cl.gridy=17; add(ConfList); glb.setConstraints(ConfList,cl); cl.weighty=0.1; cl.gridx=1; cl.gridy=20; cl.gridheight=1; cl.insets=new Insets(0,0,0,0); add(Addc); glb.setConstraints(Addc,cl); cl.gridy=21; add(Remc); glb.setConstraints(Remc,cl); cl.gridy=22; add(Runc); glb.setConstraints(Runc,cl); } // get values from scrollbars and set variables accordingly damp=(double)beta.getValue()/1000; damp_c.setText("damping constant = "+(new Double(damp)).toString()); ext=(double)d_force.getValue()/1000; ext_c.setText("driving force = "+(new Double(ext)).toString()); w=(double)d_w.getValue()/1000; w_c.setText("driving frequency = "+(new Double(w)).toString()); y[0]=(double)x0.getValue()/1000; x0_c.setText("initial position = "+(new Double(y[0])).toString()); y[1]=(double)y0.getValue()/1000; y0_c.setText("initial velocity = "+(new Double(y[1])).toString()); phi=(double)d_phase.getValue()/1000; d_phase_c.setText("phase of driving force = "+(new Double(phi)).toString()); Double Dduration = new Double(length.getSelectedItem()); duration= Dduration.doubleValue(); Integer Ddelay = new Integer(delay.getSelectedItem()); delay_time= Ddelay.intValue(); double tmp1 = (double)x0.getValue()/1000; double tmp2 = (double)y0.getValue()/1000; out.drawint(tmp1, tmp2); show(); } public boolean handleEvent(Event evt) { switch(evt.id) { case Event.KEY_PRESS: if(evt.key==10) { try { if(!doit.isAlive()) { doit=new animation(this, x, y, phi, damp, w, ext, duration, delay_time); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, x, y, phi, damp, w, ext, duration, delay_time); doit.start(); } } break; case Event.ACTION_EVENT: if(evt.target==ConfList) { startAnimation(ConfList.getSelectedIndex()); } if ("Add Configuration".equals(evt.arg)) { Book_Entry cur = new Book_Entry(); cur.damp = (double) beta.getValue()/1000; cur.ext = (double) d_force.getValue()/1000; cur.w = (double) d_w.getValue()/1000; cur.phi = (double) d_phase.getValue()/1000; cur.x = (double) x0.getValue()/1000; cur.v = (double) y0.getValue()/1000; A_Add = new Add_Book(Marks, ConfList, cur, this); } if ("Run Configuration".equals(evt.arg)) { if (ConfList.getSelectedIndex()>=0) { startAnimation(ConfList.getSelectedIndex()); } } if ("Remove Configuration".equals(evt.arg)) { Marks.removeElementAt(ConfList.getSelectedIndex()); ConfList.delItem(ConfList.getSelectedIndex()); } if(evt.target==go) { try { if(!doit.isAlive()) { doit=new animation(this, x, y, phi, damp, w, ext, duration, delay_time); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, x, y, phi, damp, w, ext, duration, delay_time); doit.start(); } } if(evt.target==halt) { try { doit.stop(); }catch(NullPointerException n) {} } if(evt.target==clear) { try { if(!doit.isAlive()) { phase.cleanup(false); time.cleanup(false); doit.cleanup(); y[0]=(double)x0.getValue()/1000; x0_c.setText("initial position = "+(new Double(y[0])).toString()); y[1]=(double)y0.getValue()/1000; y0_c.setText("initial velocity = "+(new Double(y[1])).toString()); out.draw(y[0], y[1]); } }catch(NullPointerException n) {} } if(evt.target==rerun) { // remove old data but not scaling information phase.cleanup(true); time.cleanup(true); // set initial conditions back to scrollbar values y[0]=(double)x0.getValue()/1000; y[1]=(double)y0.getValue()/1000; // run simulation again try { if(!doit.isAlive()) { doit=new animation(this, x, y, phi, damp, w, ext, duration, delay_time); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, x, y, phi, damp, w, ext, duration, delay_time); doit.start(); } } if(evt.target==length) { Double Dduration = new Double(length.getSelectedItem()); duration= Dduration.doubleValue(); } if(evt.target==delay) { Integer Ddelay = new Integer(delay.getSelectedItem()); delay_time= Ddelay.intValue(); } break; case Event.SCROLL_ABSOLUTE: case Event.SCROLL_LINE_UP: case Event.SCROLL_LINE_DOWN: case Event.SCROLL_PAGE_UP: case Event.SCROLL_PAGE_DOWN: if(evt.target==beta) { damp=(double)beta.getValue()/1000; damp_c.setText("damping constant = "+(new Double(damp)).toString()); } if(evt.target==d_force) { ext=(double)d_force.getValue()/1000; ext_c.setText(" driving force = " + (new Double(ext)).toString()+" "); } if(evt.target==d_w) { w=(double)d_w.getValue()/1000; w_c.setText("driving frequency = "+(new Double(w)).toString()); } if(evt.target==d_phase) { phi=(double)d_phase.getValue()/1000; d_phase_c.setText("phase of driving force = "+(new Double(phi)).toString()); } if(evt.target==x0) { y[0]=(double)x0.getValue()/1000; out.draw(y[0], y[1]); x0_c.setText("initial position = "+(new Double(y[0])).toString()); } if(evt.target==y0) { y[1]=(double)y0.getValue()/1000; out.draw(y[0], y[1]); y0_c.setText("initial velocity = "+(new Double(y[1])).toString()); } break; }return false; } public void startAnimation(int Mindex) { Book_Entry be = (Book_Entry) Marks.elementAt(Mindex); beta.setValue((int) (be.damp*1000)); damp_c.setText("damping constant = "+(new Double(be.damp)).toString()); damp = be.damp; d_force.setValue((int) (be.ext*1000)); ext_c.setText("driving force = "+(new Double(be.ext)).toString()); ext = be.ext; d_w.setValue((int) (be.w*1000)); w_c.setText("driving frequency = "+(new Double(be.w)).toString()); w = be.w; x0.setValue((int) (be.x*1000)); x0_c.setText("initial position = "+(new Double(be.x)).toString()); y[0] = be.x; y0.setValue((int) (be.v*1000)); y0_c.setText("initial velocity = "+(new Double(be.v)).toString()); y[1] = be.v; d_phase.setValue((int) (be.phi*1000)); d_phase_c.setText("phase of driving force = "+(new Double(be.phi)).toString()); phi = be.phi; length.select(be.duration); Double Dduration = new Double(length.getSelectedItem()); duration= Dduration.doubleValue(); delay.select(be.delay); Integer Ddelay = new Integer(delay.getSelectedItem()); delay_time= Ddelay.intValue(); try { if(!doit.isAlive()) { doit=new animation(this, 0.0, y, be.phi, be.damp, be.w, be.ext, duration, delay_time); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, 0.0, y, be.phi, be.damp, be.w, be.ext, duration, delay_time); doit.start(); } } } @ 1.1 log @Initial revision @ text @d16 1 a16 1 List ConfList; // for displaying bookmarks d33 1 d37 3 d45 9 a53 2 this.resize(300, 600); this.setTitle("Control Window"); d55 10 d66 1 a94 5 // create buttons for configurations management Addc = new Button("Add Configuration"); Remc = new Button("Remove Configuration"); Runc = new Button("Run Configuration"); d134 1 a134 1 cs.insets= new Insets(0,50,0,50); d163 1 d248 3 a251 1 d259 4 a262 4 aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); d264 11 a274 11 aconf = new Book_Entry(); aconf.com = "a small change in frequency - two loops"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.2; aconf.ext = 0.52; aconf.w = 0.67; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); d276 11 a286 11 aconf = new Book_Entry(); aconf.com = "change damping - one loop and a half"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.201; aconf.ext = 0.52; aconf.w = 0.666; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); d288 16 a303 11 aconf = new Book_Entry(); aconf.com = "change damping again - rotate other way"; aconf.x = 0.8; aconf.v = 0.916; aconf.damp = 0.202; aconf.ext = 0.52; aconf.w = 0.666; aconf.delay = 1; aconf.duration = 3; Marks.addElement(aconf); ConfList.addItem(aconf.toString()); d322 14 a335 14 cl.weighty=0.1; cl.gridx=1; cl.gridy=20; cl.gridheight=1; cl.insets=new Insets(0,0,0,0); add(Addc); glb.setConstraints(Addc,cl); cl.gridy=21; add(Remc); glb.setConstraints(Remc,cl); cl.gridy=22; add(Runc); glb.setConstraints(Runc,cl); @