import java.awt.*; /*********************************************************************/ //********************************************************************* /** * Adds choices and associated text fields for Scalemap */ //********************************************************************* class ScalemapControls extends Panel { /** parent */ private Scalemap outerparent; Choice[] c; TextField[] t; /** critical a for each function */ private static double acA[]={3.5699456,3.4623171}; /** delta-a for accumulation and function choices */ private static double delaA[][]={{1.5561,0.570,0.485}, {1.6821,0.614,0.5275}}; /** universal ratio */ private static double delta=4.6692016; /** parameter of map */ double a; /** critical value of a */ double ac; /** delta a */ double dela; /** approach to critical point */ int n; /** sign giving above or below critical point */ int nsign; /** number of choice controls */ int nchoice; /** true if last ac set by choice not text field */ boolean precise; /** true if event handled */ boolean eventHandled; //********************************************************************* /** * @param target parent of type Scalemap * @param n number of controls */ //********************************************************************* ScalemapControls(Scalemap target,int n) { eventHandled=false; outerparent=target; nchoice = n; setLayout(new GridLayout(2,1)); Panel panelTop = new Panel(); Panel panelBottom = new Panel(); panelTop.setLayout(new FlowLayout(FlowLayout.LEFT)); panelBottom.setLayout(new FlowLayout(FlowLayout.LEFT)); add(panelTop); add(panelBottom); c = new Choice[nchoice]; t = new TextField[nchoice]; c[0] = new Choice(); c[0].addItem("Quadratic"); c[0].addItem("Sine"); t[0] = new TextField(String.valueOf(acA[0]),8); c[1]=new Choice (); c[1].addItem("+"); c[1].addItem("-"); c[1].select(1); // nsign=-1; // t[1] = new TextField("-",2); t[1] = new TextField(2); c[2]=new Choice(); c[2].addItem("SuperStable"); c[2].addItem("Instability"); c[2].addItem("Bandmerge"); // t[2] = new TextField(String.valueOf(delaA[0][0]),5); t[2] = new TextField(5); c[3]=new Choice (); c[3].addItem("0"); c[3].addItem("1"); c[3].addItem("2"); c[3].addItem("3"); c[3].addItem("4"); c[3].addItem("5"); c[3].addItem("6"); c[3].addItem("7"); c[3].addItem("8"); c[3].addItem("I"); c[3].select(9); // t[3] = new TextField("I",2); t[3] = new TextField(2); Label l1 = new Label("a="); Label l2 = new Label("x d ^ -"); panelTop.add(t[0]); panelTop.add(t[1]); panelTop.add(t[2]); panelTop.add(l2); panelTop.add(t[3]); panelBottom.add(c[0]); panelBottom.add(c[1]); panelBottom.add(c[2]); panelBottom.add(c[3]); precise=true; setFromChoices(); outerparent.seta(acA[0],c[0].getSelectedIndex()); } //********************************************************************* /** * Insets for layout */ //********************************************************************* public Insets insets() { return new Insets(0,0,20,0); } //********************************************************************* /** Respond to events. * Updates associated text field for choice and vice versa * Updates a and nfun in parent */ //********************************************************************* public boolean action(Event evt, Object arg) { eventHandled=false; if(evt.target instanceof Choice) { if(evt.target==c[0]) { ac=acA[c[0].getSelectedIndex()]; t[0].setText(String.valueOf(ac)); dela=delaA[c[0].getSelectedIndex()][c[2].getSelectedIndex()]; t[2].setText(String.valueOf(dela)); precise=true; } else if(evt.target==c[1]) { if(c[1].getSelectedIndex()==0) { t[1].setText("+"); nsign=1; } else { t[1].setText("-"); nsign=-1; } } else if(evt.target==c[2]){ dela=delaA[c[0].getSelectedIndex()] [c[2].getSelectedIndex()]; t[2].setText(String.valueOf(dela)); } else if(evt.target==c[3]){ t[3].setText(c[3].getSelectedItem()); } eventHandled=true; } else if(evt.target instanceof TextField) { if(evt.target==t[0]) precise = false; else if (evt.target==t[1]) { if(t[1].getText().trim().equals("+")) { nsign=1; t[1].setText("+"); c[1].select(0); } else { t[1].setText("-"); nsign=-1; c[1].select(1); } } eventHandled=true; } if(precise) ac=acA[c[0].getSelectedIndex()]; else ac=(new Double(t[0].getText())).doubleValue(); dela=(new Double(t[2].getText())).doubleValue(); try { n=Integer.parseInt(t[3].getText()); if(n < c[3].countItems()-1) { c[3].select(n); a=ac+nsign*dela*Math.pow(delta,(double)(-n)); } else { c[3].select(9); t[3].setText("I"); } } catch (NumberFormatException e) { c[3].select(9); t[3].setText("I"); a=ac; } outerparent.seta(a,c[0].getSelectedIndex()); outerparent.updateParameters(); outerparent.buttons.enableGo(); if(eventHandled) return true; else return false; } public void setFromChoices() { ac=acA[c[0].getSelectedIndex()]; t[0].setText(String.valueOf(ac)); dela=delaA[c[0].getSelectedIndex()][c[2].getSelectedIndex()]; t[2].setText(String.valueOf(dela)); precise=true; if(c[1].getSelectedIndex()==0) { t[1].setText("+"); nsign=1; } else { t[1].setText("-"); nsign=-1; } t[3].setText(c[3].getSelectedItem()); try { n=Integer.parseInt(t[3].getText()); c[3].select(n); a=ac+nsign*dela*Math.pow(delta,(double)(-n)); } catch (NumberFormatException e) { c[3].select(9); t[3].setText("I"); a=ac; } outerparent.seta(a,c[0].getSelectedIndex()); } public void setChoices(int i1, int i2, int i3, int i4) { c[0].select(i1); c[1].select(i2); c[2].select(i3); c[3].select(i4); } //********************************************************************* /** * Number of controls * @return number of controls */ //********************************************************************* public int ncontrols() { return nchoice; } } /*********************************************************************/ /*********************************************************************/