head 1.1; access; symbols; locks; strict; comment @# @; 1.1 date 97.12.01.03.59.30; author hans; state Exp; branches; next ; desc @animation of chaotic behavior the extra frame with all the controls @ 1.1 log @Initial revision @ 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; // the Scrollbars in the other window Scrollbar x1, v1, x2, v2; Label l_x1, l_v1, l_x2, l_v2; Choice length, delay; Button clear, go, halt, rerun; Label d_phase_c, damp_c, delay_c, ext_c, length_c, w_c; List ConfList; // for displaying bookmarks Vector Marks; // configurations Add_Book A_Add; // replace menu options with buttons JAVA BUG Button Addc, Remc, Runc; double y1[]= new double[2]; double y2[]= new double[2]; static double damp, duration, ext, phi, w, x=0; static int delay_time; P_Graph phase1, phase2; graphic out1, out2; animation doit; boolean kill_thread = false; boolean big_screen; Control_Win(main parent) { Toolkit tk=null; Dimension screen=null; this.out1 = parent.out1; this.out2 = parent.out2; this.phase1 = parent.phase1; this.phase2 = parent.phase2; x1=parent.x0_1; v1=parent.v0_1; x2=parent.x0_2; v2=parent.v0_2; l_x1=parent.l_x0_1; l_v1=parent.l_v0_1; l_x2=parent.l_x0_2; l_v2=parent.l_v0_2; 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(6, false); // 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.addItem("150"); length.addItem("200"); 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); // 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); // 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(10,0,0,0); cm.gridx=5; cm.gridy=8; cm.weighty=0.1; 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=10; cb.fill=GridBagConstraints.HORIZONTAL; cb.insets=new Insets(0,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); // the list of typical/saved configurations // not included on tiny screens if(big_screen == true) { Book_Entry aconf = new Book_Entry(); aconf.com = "startup configuration"; aconf.x1 = 0.8; aconf.v1 = 0.917; aconf.x2 = 0.8; aconf.v2 = 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 = "changing initial velocity of first pendulum"; aconf.x1 = 0.8; aconf.v1 = 0.915; aconf.x2 = 0.8; aconf.v2 = 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 = "same velocities - different positions"; aconf.x1 = 0.8; aconf.v1 = 0.916; aconf.x2 = 0.799; aconf.v2 = 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 = "simple pendulum very close to separatrix"; aconf.x1 = 0.0; aconf.v1 = 1.9; aconf.x2 = 0.0; aconf.v2 = 1.993; aconf.damp = 0.0; aconf.ext = 0.0; aconf.w = 0.0; 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=11; cl.fill=GridBagConstraints.HORIZONTAL; Label bar = new Label("some typical configurations", Label.CENTER); add(bar); glb.setConstraints(bar,cl); cl.insets=new Insets(2,10,2,10); cl.gridheight=4; cl.gridy=12; // cl.weighty=2.0; add(ConfList); glb.setConstraints(ConfList,cl); cl.weighty=0.1; cl.gridx=1; cl.gridy=16; cl.gridheight=1; cl.insets=new Insets(0,0,0,0); add(Addc); glb.setConstraints(Addc,cl); cl.gridy=17; add(Remc); glb.setConstraints(Remc,cl); cl.gridy=18; 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()); y1[0]=(double)x1.getValue()/1000; l_x1.setText("position = "+(new Double(y1[0])).toString()); y1[1]=(double)v1.getValue()/1000; l_v1.setText("velocity = "+(new Double(y1[1])).toString()); y2[0]=(double)x2.getValue()/1000; l_x2.setText("position = "+(new Double(y2[0])).toString()); y2[1]=(double)v2.getValue()/1000; l_v2.setText("velocity = "+(new Double(y2[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(); 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, y1, y2, phi, damp, w, ext, duration, delay_time, out1, out2, phase1, phase2); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, y1, y2, phi, damp, w, ext, duration, delay_time, out1, out2, phase1, phase2); 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.x1 = (double) x1.getValue()/1000; cur.v1 = (double) v1.getValue()/1000; cur.x2 = (double) x2.getValue()/1000; cur.v2 = (double) v2.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, y1, y2, phi, damp, w, ext, duration, delay_time, out1, out2, phase1, phase2); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, y1, y2, phi, damp, w, ext, duration, delay_time, out1, out2, phase1, phase2); doit.start(); } } if(evt.target==halt) { try { doit.stop(); }catch(NullPointerException n) {} } if(evt.target==clear) { try { if(!doit.isAlive()) { phase1.cleanup(false); phase2.cleanup(false); doit.cleanup(); y1[0]=(double)x1.getValue()/1000; l_x1.setText("position = "+(new Double(y1[0])).toString()); y1[1]=(double)v1.getValue()/1000; l_v1.setText("velocity = "+(new Double(y1[1])).toString()); y2[0]=(double)x2.getValue()/1000; l_x2.setText("position = "+(new Double(y2[0])).toString()); y2[1]=(double)v2.getValue()/1000; l_v2.setText("velocity = "+(new Double(y2[1])).toString()); out1.draw(y1[0], y1[1]); out2.draw(y2[0], y2[1]); } }catch(NullPointerException n) {} } if(evt.target==rerun) { // remove old data but not scaling information phase1.cleanup(true); phase2.cleanup(true); // set initial conditions back to scrollbar values y1[0]=(double)x1.getValue()/1000; y1[1]=(double)v1.getValue()/1000; y2[0]=(double)x2.getValue()/1000; y2[1]=(double)v2.getValue()/1000; // run simulation again try { if(!doit.isAlive()) { doit=new animation(this, y1, y2, phi, damp, w, ext, duration, delay_time, out1, out2, phase1, phase2); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, y1, y2, phi, damp, w, ext, duration, delay_time, out1, out2, phase1, phase2); 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()); } 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; x1.setValue((int) (be.x1*1000)); l_x1.setText("position = "+(new Double(be.x1)).toString()); y1[0] = be.x1; v1.setValue((int) (be.v1*1000)); l_v1.setText("velocity = "+(new Double(be.v1)).toString()); y1[1] = be.v1; x2.setValue((int) (be.x2*1000)); l_x2.setText("position = "+(new Double(be.x2)).toString()); y2[0] = be.x2; v2.setValue((int) (be.v2*1000)); l_v2.setText("velocity = "+(new Double(be.v2)).toString()); y2[1] = be.v2; 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, y1, y2, be.phi, be.damp, be.w, be.ext, duration, delay_time, out1, out2, phase1, phase2); doit.start(); } }catch(NullPointerException n) { doit=new animation(this, y1, y2, be.phi, be.damp, be.w, be.ext, duration, delay_time, out1, out2, phase1, phase2); doit.start(); } } } @