import java.awt.*; import java.applet.*; import java.util.*; import java.awt.event.*; import java.io.*; /* for Java Applet public class K_Visible extends Applet implements java.awt.event.ActionListener,java.awt.event.ItemListener,java.awt.event.AdjustmentListener, java.awt.event.TextListener{ */ public class K_Visible extends Frame implements java.awt.event.ActionListener,java.awt.event.ItemListener,java.awt.event.AdjustmentListener, java.awt.event.TextListener{ int w = 900; int h = 800; Color blanchedalmond = new Color((float)(1.000000), (float)(0.921569),(float)(0.803922)); Color teal = new Color((float)(0.000000),(float)(0.501961), (float)(0.501961)); Button normalon,curvature,tangentV,envelop,evolute,osculate, offset,oneosculate,skeleton1,caustic,orthotomic,normalor, skeleton2,laplace,cdriven1,cdriven2,voronoid,contourmap, onenormal,oneoffset; Button clear,center,rescale; boolean framesw=false; /* for application file I/O */ Menu file; Menu save; MenuItem loadp,savep,savei; MenuItem quit; MenuBar mfield; /* for simulator */ Checkbox skeleton1circle,skeleton1normal,skeleton1center,skeleton1movin; Checkbox tracekminimalap; Checkbox tracekminimacd1; Checkbox tracekminimacd2; Checkbox tracekminimacmap; TextField maxitcd1,maxitcd2,maxitlap,maxitcon; TextField disnumcd1,disnumcd2,disnumlap,disnumcon; TextField sparam,constparam1,constparam2,LEparam,distparam; Label constlabel1,constlabel2; Vector Rating; Button samplinginit; Label labbfield,labbfield2; Panel bfield; /* for Java Applet K_VisibleFrame windowv;*/ /* for Application */ K_Visible windowv; Scrollbar scrX,scrY,bparam; Checkbox move,scale,pick; CheckboxGroup cursortype; Checkbox bsccolorcb,oneosccolorcb,osccolorcb,orcolorcb, evocolorcb,offcolorcb,efncolorcb,cacolorcb, norcolorcb,onencolorcb,oneoffcolorcb; AppletMenu system; AppletMenu2 curves,evolution,basic,skeleton; Button closew,addmorep; Checkbox drawcontrolp,curvev,samplingvis,sampling; GridBagLayout gridbagl; GridBagConstraints gridbagc; B_SplineClosed bscc; SplineManager drawClosedCurve=null; /* for Java Applet public void init(){ */ /* for Application */ public K_Visible(){ gridbagl = new GridBagLayout(); gridbagc = new GridBagConstraints(); /* Control Methods */ cursortype = new CheckboxGroup(); move = new Checkbox("Move",cursortype,false); pick = new Checkbox("Pick",cursortype,true); scale = new Checkbox("Zoom",cursortype,false); center = new Button("Center"); rescale = new Button("Init Zoom"); rescale.setFont(new Font("TimesRoman", Font.ITALIC,10)); move.setFont(new Font("TimesRoman", Font.ITALIC,12)); center.setFont(new Font("TimesRoman", Font.ITALIC,10)); scale.setFont(new Font("TimesRoman", Font.ITALIC,12)); pick.setFont(new Font("TimesRoman", Font.ITALIC,12)); scrX = new Scrollbar(Scrollbar.HORIZONTAL,0,50,-600,600); scrY = new Scrollbar(Scrollbar.VERTICAL,0,50,-400,400); bparam = new Scrollbar(Scrollbar.HORIZONTAL,160,20,8,260); bparam.setUnitIncrement(1); bparam.setBlockIncrement(1); scrX.setUnitIncrement(10); scrX.setBlockIncrement(20); scrY.setUnitIncrement(10); scrY.setBlockIncrement(20); rescale.addActionListener(this); center.addActionListener(this); scrX.addAdjustmentListener(this); scrY.addAdjustmentListener(this); bparam.addAdjustmentListener(this); pick.addItemListener(this); scale.addItemListener(this); move.addItemListener(this); bfield = new Panel(); makeMenuBar(); bfield.add(center); bfield.add(rescale); bfield.add(pick); bfield.add(move); bfield.add(scale); bscc = new B_SplineClosed(800,400); drawClosedCurve = new SplineManager(800,400,bscc); drawClosedCurve.setScrollbar(scrX,scrY); mfield = makeIOMenuBar(); setLayout(gridbagl); /* for application */ this.setMenuBar(mfield); /* */ gridbagc.weightx =1; gridbagc.weighty =1; gridbagc.gridwidth = GridBagConstraints.REMAINDER; gridbagl.setConstraints(bfield,gridbagc); this.add(bfield); gridbagc.ipadx = 800; gridbagc.ipady = 0; gridbagc.gridy = GridBagConstraints.RELATIVE; gridbagl.setConstraints(scrX,gridbagc); this.add(scrX); gridbagc.ipadx = 800; gridbagc.ipady = 400; gridbagc.weightx= 15; gridbagc.gridwidth = GridBagConstraints.RELATIVE; gridbagc.gridy = GridBagConstraints.RELATIVE; gridbagl.setConstraints(drawClosedCurve,gridbagc); this.add(drawClosedCurve); gridbagc.gridx = GridBagConstraints.RELATIVE; gridbagc.ipadx = 0; gridbagc.ipady = 400; gridbagc.weightx=0; gridbagc.gridwidth = GridBagConstraints.REMAINDER; gridbagl.setConstraints(scrY,gridbagc); this.add(scrY); System.out.println("Visualization Curvature"); System.out.println("by the 2D closed 5-degree B-Spline Curve"); this.setForeground(teal); this.setBackground(blanchedalmond); } public static void main(String args[]) { K_Visible cardboard = new K_Visible(); cardboard.setSize(900,600); cardboard.setTitle("Curve Simulator"); cardboard.setVisible(true); } public MenuBar makeIOMenuBar(){ MenuBar returnout; returnout = new MenuBar(); quit = new MenuItem("exit program"); file = new Menu("file"); file.setFont(new Font("TimesRoman", Font.PLAIN, 20)); savei = new MenuItem("save image"); savei.setFont(new Font("TimesRoman", Font.PLAIN, 20)); savei.addActionListener(this); quit.addActionListener(this); loadp = new MenuItem("load"); loadp.setFont(new Font("TimesRoman", Font.PLAIN, 20)); savep = new MenuItem("save"); savep.setFont(new Font("TimesRoman", Font.PLAIN, 20)); loadp.addActionListener(this); savep.addActionListener(this); file.add(quit); file.add(savep); file.add(savei); file.add(loadp); returnout.add(file); return returnout; } public TextField makeTextF(String str,int dn){ TextField tmp = new TextField(str,dn); //tmp.setFont(new Font("TimesRoman", Font.PLAIN, 18)); tmp.setForeground(teal); tmp.setBackground(blanchedalmond); tmp.addTextListener(this); return tmp; } public Button makeButton(String str){ Button tmp = new Button(str); tmp.setFont(new Font("TimesRoman", Font.PLAIN, 18)); tmp.addActionListener(this); tmp.setForeground(teal); tmp.setBackground(blanchedalmond); return tmp; } public Checkbox makeCheckbox(String str){ Checkbox tmp = new Checkbox(str,false); tmp.setFont(new Font("TimesRoman", Font.PLAIN, 18)); tmp.addItemListener(this); tmp.setForeground(teal); tmp.setBackground(blanchedalmond); return tmp; } public void makeMenuBar(){ bfield.setForeground(teal); bfield.setBackground(blanchedalmond); /* root menus */ system = new AppletMenu("System",5,1); basic = new AppletMenu2("Basic Properties"); curves = new AppletMenu2("Curves"); evolution = new AppletMenu2("Evolutions"); skeleton = new AppletMenu2("Skeleton"); /* Rating */ Rating = new Vector(16); for(int i=0;i<16;i++) Rating.addElement(makeCheckbox(" ")); ((Checkbox)Rating.elementAt(14)).setState(true); ((Checkbox)Rating.elementAt(15)).setState(true); /* System */ clear = makeButton("Clear Memory"); closew = makeButton("Open New Window"); addmorep = makeButton("Split Control Points"); /* */ sampling = makeCheckbox("Rate for only skeleton"); samplinginit = makeButton("Initialize Rate"); sampling.setState(true); system.Badd(clear); system.Badd(addmorep); system.Badd(closew); system.Badd(samplinginit); system.Badd(bparam); //system.Badd(sampling); system.finishadd(); bfield.add(system); /* Basic Properties */ Panel dummyprootbasic = new Panel(); Panel dummypchildbasic1 = new Panel(); Panel dummypchildbasic2 = new Panel(); dummypchildbasic1.setLayout(new GridLayout(6,1)); dummypchildbasic2.setLayout(new GridLayout(6,1)); drawcontrolp = makeCheckbox("Control Points"); drawcontrolp.setState(true); samplingvis = makeCheckbox("Sampling"); samplingvis.setState(true); curvev = makeCheckbox("B-Spline"); curvev.setState(true); normalon = makeButton("Normals"); curvature = makeButton("Curvature Normals"); tangentV = makeButton("Tangents"); dummypchildbasic1.add(drawcontrolp); dummypchildbasic1.add(curvev); dummypchildbasic1.add(samplingvis); dummypchildbasic1.add(normalon); dummypchildbasic1.add(curvature); dummypchildbasic1.add(tangentV); dummypchildbasic2.add(new Label(" ")); dummypchildbasic2.add(new Label(" ")); dummypchildbasic2.add(new Label("Rating")); for(int i=0;i<3;i++) dummypchildbasic2.add(((Checkbox)Rating.elementAt(i))); dummyprootbasic.add(dummypchildbasic1); dummyprootbasic.add(dummypchildbasic2); basic.Badd(dummyprootbasic); basic.finishadd(); bfield.add(basic); Panel dummyproot = new Panel(); Panel dummypchild1 = new Panel(); Panel dummypchild2 = new Panel(); Panel dummypchild3 = new Panel(); dummypchild1.setLayout(new GridLayout(11,1)); dummypchild2.setLayout(new GridLayout(11,1)); dummypchild3.setLayout(new GridLayout(11,1)); Label mess1 = new Label("Methods"); Label mess2 = new Label("Coloring"); Label mess3 = new Label("Rating"); mess1.setFont(new Font("TimesRoman", Font.PLAIN, 18)); bsccolorcb = makeCheckbox("Inital Curve Color"); curves.Badd(bsccolorcb); oneosculate = makeButton("Moving Osculating Circle"); oneosccolorcb = makeCheckbox(" "); osculate = makeButton("Osculating Circles"); osccolorcb = makeCheckbox(" "); offset = makeButton("Offset Curves"); offcolorcb = makeCheckbox(" "); oneoffset = makeButton("Moving Offset Curve"); oneoffcolorcb = makeCheckbox(" "); envelop = makeButton("Family of Normals"); efncolorcb = makeCheckbox(" "); onenormal = makeButton("Moving Normal"); onencolorcb = makeCheckbox(" "); evolute = makeButton("Evolute"); evocolorcb = makeCheckbox(" "); orthotomic = makeButton("Orthotomic Curve"); orcolorcb = makeCheckbox(" "); normalor = makeButton("Family of Orthotomic Normals"); norcolorcb = makeCheckbox(" "); caustic = makeButton("Caustics"); cacolorcb = makeCheckbox(" "); dummypchild1.add(mess1); dummypchild1.add(osculate); dummypchild1.add(oneosculate); dummypchild1.add(offset); dummypchild1.add(oneoffset); dummypchild1.add(envelop); dummypchild1.add(onenormal); dummypchild1.add(evolute); dummypchild1.add(orthotomic); dummypchild1.add(normalor); dummypchild1.add(caustic); dummypchild2.add(mess2); dummypchild2.add(osccolorcb); dummypchild2.add(oneosccolorcb); dummypchild2.add(offcolorcb); dummypchild2.add(oneoffcolorcb); dummypchild2.add(efncolorcb); dummypchild2.add(onencolorcb); dummypchild2.add(evocolorcb); dummypchild2.add(orcolorcb); dummypchild2.add(norcolorcb); dummypchild2.add(cacolorcb); dummypchild3.add(mess3); for(int i=3;i<13;i++) dummypchild3.add(((Checkbox)Rating.elementAt(i))); dummyproot.add(dummypchild1); dummyproot.add(dummypchild2); dummyproot.add(dummypchild3); curves.Badd(dummyproot); curves.finishadd(); bfield.add(curves); /* Evolutions */ Panel dummyproot2 = new Panel(); Panel dummypchilde1 = new Panel(); Panel dummypchilde2 = new Panel(); Panel dummypchilde3 = new Panel(); Panel dummypchilde4 = new Panel(); dummypchilde1.setLayout(new GridLayout(6,1)); dummypchilde2.setLayout(new GridLayout(6,1)); dummypchilde3.setLayout(new GridLayout(6,1)); dummypchilde4.setLayout(new GridLayout(6,1)); Label messe1 = new Label("Flows"); Label messe2 = new Label("k-min"); Label messe3 = new Label("Iteration"); Label messe4 = new Label("Display"); messe1.setFont(new Font("TimesRoman", Font.PLAIN, 18)); messe3.setFont(new Font("TimesRoman", Font.PLAIN, 18)); messe4.setFont(new Font("TimesRoman", Font.PLAIN, 18)); /* Curvature Driven F = k */ cdriven1 = makeButton("Curvature Driven F = k"); tracekminimacd1 = makeCheckbox(" "); /* Curvature Driven F = c + d*k */ cdriven2 = makeButton("Curvature Driven F = c + d*k"); tracekminimacd2 = makeCheckbox(" "); constparam1 = makeTextF("-2.0",4); constlabel1 = new Label("c = "); constlabel1.setFont(new Font("TimesRoman", Font.PLAIN, 18)); constparam2 = makeTextF("0.5",4); constlabel2 = new Label("d (<> 0) = "); constlabel2.setFont(new Font("TimesRoman", Font.PLAIN, 18)); /* Laplacian Flow */ laplace = makeButton("Laplacian Flow"); tracekminimalap = makeCheckbox(" "); LEparam = makeTextF("0.5",4); /* Distance Function Flow */ distparam = makeTextF("0.02",4); contourmap = makeButton("Distance Function Flow"); tracekminimacmap = makeCheckbox(" "); /* Panel mychi12 = new Panel(); Label dchi12 = new Label(" dist() = const = "); dchi12.setFont(new Font("TimesRoman", Font.PLAIN, 18)); mychi12.add(dchi12); mychi12.add(distparam); */ dummypchilde1.add(messe1); dummypchilde1.add(cdriven1); dummypchilde1.add(cdriven2); Panel mychi1 = new Panel(); mychi1.add(constlabel1); mychi1.add(constparam1); mychi1.add(constlabel2); mychi1.add(constparam2); dummypchilde1.add(mychi1); dummypchilde1.add(laplace); dummypchilde1.add(contourmap); //dummypchilde1.add(mychi12); dummypchilde2.add(messe2); dummypchilde2.add(tracekminimacd1); dummypchilde2.add(tracekminimacd2); Label dchi1 = new Label(" "); dchi1.setFont(new Font("TimesRoman", Font.PLAIN, 18)); Panel mychi2 = new Panel(); mychi2.add(dchi1); dummypchilde2.add(mychi2); dummypchilde2.add(tracekminimalap); dummypchilde2.add(tracekminimacmap); /* Label dchi21 = new Label(" "); dchi21.setFont(new Font("TimesRoman", Font.PLAIN, 18)); Panel mychi22 = new Panel(); mychi22.add(dchi21); dummypchilde2.add(mychi22); */ maxitcd1 = makeTextF("1000",4); maxitcd2 = makeTextF("1000",4); maxitlap = makeTextF("500",4); maxitcon = makeTextF("50",4); disnumcd1 = makeTextF("100",4); disnumcd2 = makeTextF("50",4); disnumlap = makeTextF("50",4); disnumcon = makeTextF("4",4); dummypchilde3.add(messe3); dummypchilde3.add(maxitcd1); dummypchilde3.add(maxitcd2); Label dchi2 = new Label(" "); dchi2.setFont(new Font("TimesRoman", Font.PLAIN, 18)); Panel mychi3 = new Panel(); mychi3.add(dchi2); dummypchilde3.add(mychi3); dummypchilde3.add(maxitlap); dummypchilde3.add(maxitcon); /* Label dchi32 = new Label(" "); dchi2.setFont(new Font("TimesRoman", Font.PLAIN, 18)); Panel mychi33 = new Panel(); mychi33.add(dchi32); dummypchilde3.add(mychi33); */ dummypchilde4.add(messe4); dummypchilde4.add(disnumcd1); dummypchilde4.add(disnumcd2); Label dchi3 = new Label(" "); dchi3.setFont(new Font("TimesRoman", Font.PLAIN, 18)); Panel mychi4 = new Panel(); mychi4.add(dchi3); dummypchilde4.add(mychi4); dummypchilde4.add(disnumlap); dummypchilde4.add(disnumcon); /* Label dchi43 = new Label(" "); dchi43.setFont(new Font("TimesRoman", Font.PLAIN, 18)); Panel mychi44 = new Panel(); mychi44.add(dchi43); dummypchilde4.add(mychi44); */ dummyproot2.add(dummypchilde1); dummyproot2.add(dummypchilde2); dummyproot2.add(dummypchilde3); dummyproot2.add(dummypchilde4); evolution.Badd(dummyproot2); evolution.finishadd(); bfield.add(evolution); /* Skeletons */ Panel dummyprootske = new Panel(); Panel dummypchildske1 = new Panel(); Panel dummypchildske2 = new Panel(); dummypchildske1.setLayout(new GridLayout(8,1)); dummypchildske2.setLayout(new GridLayout(8,1)); Label messske1 = new Label("Medial Axis"); messske1.setFont(new Font("TimesRoman", Font.PLAIN, 18)); /* Skeleton via bi-tangent circles */ skeleton1 = makeButton("Skeleton via bitangent circles"); skeleton1movin = makeCheckbox("moving bitangent circle"); skeleton1circle = makeCheckbox("bitangent circle"); skeleton1normal = makeCheckbox("normal to skeleton"); skeleton1center = makeCheckbox("center of bitangent"); dummypchildske1.add(messske1); dummypchildske1.add(skeleton1); dummypchildske1.add(skeleton1movin); dummypchildske1.add(skeleton1circle); dummypchildske1.add(skeleton1normal); dummypchildske1.add(skeleton1center); skeleton2 = makeButton("Skeleton via Voronoi diagram"); voronoid = makeButton("Voronoi diagram"); dummypchildske1.add(skeleton2); dummypchildske1.add(voronoid); dummypchildske2.add(new Label("Rating")); dummypchildske2.add(((Checkbox)Rating.elementAt(13))); for(int i=0;i<4;i++) dummypchildske2.add(new Label(" ")); dummypchildske2.add(((Checkbox)Rating.elementAt(14))); dummypchildske2.add(((Checkbox)Rating.elementAt(15))); dummyprootske.add(dummypchildske1); dummyprootske.add(dummypchildske2); skeleton.Badd(dummyprootske); skeleton.finishadd(); bfield.add(skeleton); } public void adjustmentValueChanged(AdjustmentEvent e) { if(e.getSource() == scrX || e.getSource() == scrY){ drawClosedCurve.moveCenter(scrX.getValue(),scrY.getValue()); }else if(e.getSource() == bparam){ drawClosedCurve.changeParam(bparam.getValue()); } } public int getIntTF(TextField dtf){ double dummyd=1.0; try{ dummyd = (Double.valueOf(dtf.getText().trim())).doubleValue(); }catch(java.lang.NumberFormatException e){ Toolkit tkForBeep = getToolkit(); tkForBeep.beep(); System.out.println("Erorr ! This is not a number."); System.out.println("Please input again."); } return ((int)(dummyd)); } public double getDoubleTF(TextField dtf){ double dummyd=1.0; try{ dummyd = (Double.valueOf(dtf.getText().trim())).doubleValue(); }catch(java.lang.NumberFormatException e){ Toolkit tkForBeep = getToolkit(); tkForBeep.beep(); System.out.println("Erorr ! This is not a number."); System.out.println("Please input again."); } return (dummyd); } public boolean checkEP(int di1,int di2){ if(di1<0 || di2< 0){ Toolkit tkForBeep = getToolkit(); tkForBeep.beep(); System.out.println("Erorr ! Parameter does not correct range."); System.out.println("Please input again."); return false; } return true; } public void textValueChanged(TextEvent e){ setEvolutionParameter(); } public void setEvolutionParameter(){ int di11,di12,di21,di22,di31,di32,di41,di42; double dicontC=-2.0; double dicontD=0.5; double dLEpcilon = 0.5; double ddist = 0.02; di11 = getIntTF(maxitcd1); di12 = getIntTF(disnumcd1); di21 = getIntTF(maxitcd2); di22 = getIntTF(disnumcd2); di31 = getIntTF(maxitlap); di32 = getIntTF(disnumlap); di41 = getIntTF(maxitcon); di42 = getIntTF(disnumcon); dicontC = getDoubleTF(constparam1); dicontD = getDoubleTF(constparam2); ddist = getDoubleTF(distparam); dLEpcilon = 0.5; if(checkEP(di11,di12) && checkEP(di21,di22) && checkEP(di31,di32) && checkEP(di41,di42)){ if(drawClosedCurve!=null){ drawClosedCurve.setEvolutionP(di11,di12,di21,di22,di31, di32,di41,di42,dicontC,dicontD, dLEpcilon,ddist); } } } public void itemStateChanged(ItemEvent evt){ Object dummyobj = evt.getSource(); if(dummyobj==pick ||dummyobj==move ||dummyobj==scale ){ if(cursortype.getSelectedCheckbox()==pick){ drawClosedCurve.FreePick(); }else if(cursortype.getSelectedCheckbox()==move){ drawClosedCurve.FreeMove(); }else if(cursortype.getSelectedCheckbox()==scale){ drawClosedCurve.FreeScale(); } return; } boolean firstcheck=false; for(int i=0;i<16;i++){ if(dummyobj == ((Checkbox)Rating.elementAt(i))){ firstcheck = true; } } if(firstcheck){ this.setratingstates(); return; } this.setcolorstates(); } private void setratingstates(){ drawClosedCurve.setRating(Rating); } private void setcolorstates(){ drawClosedCurve.ColorSelect(bsccolorcb.getState(),evocolorcb.getState(), osccolorcb.getState(),offcolorcb.getState(), efncolorcb.getState(),oneosccolorcb.getState(), cacolorcb.getState(), orcolorcb.getState(),norcolorcb.getState(), onencolorcb.getState(), oneoffcolorcb.getState(), drawcontrolp.getState(), curvev.getState(),sampling.getState(), samplingvis.getState() ); drawClosedCurve.newboxcbSelect(skeleton1circle.getState(), skeleton1normal.getState(), skeleton1center.getState(), tracekminimalap.getState(), tracekminimacd1.getState(), tracekminimacd2.getState(), tracekminimacmap.getState(), skeleton1movin.getState()); } private void virtualclear(){ bsccolorcb.setState(false); osccolorcb.setState(false); evocolorcb.setState(false); offcolorcb.setState(false); efncolorcb.setState(false); cacolorcb.setState(false); orcolorcb.setState(false); oneosccolorcb.setState(false); oneoffcolorcb.setState(false); onencolorcb.setState(false); norcolorcb.setState(false); cursortype.setSelectedCheckbox(pick); skeleton1movin.setState(false); skeleton1circle.setState(false); skeleton1normal.setState(false); skeleton1center.setState(false); tracekminimalap.setState(false); tracekminimacd1.setState(false); tracekminimacd2.setState(false); tracekminimacmap.setState(false); contourmap.setForeground(teal); cdriven1.setForeground(teal); cdriven2.setForeground(teal); laplace.setForeground(teal); skeleton1.setForeground(teal); skeleton2.setForeground(teal); voronoid.setForeground(teal); normalor.setForeground(teal); curvature.setForeground(teal); tangentV.setForeground(teal); envelop.setForeground(teal); evolute.setForeground(teal); osculate.setForeground(teal); offset.setForeground(teal); oneosculate.setForeground(teal); onenormal.setForeground(teal); oneoffset.setForeground(teal); drawcontrolp.setState(true); curvev.setState(true); sampling.setState(true); for(int i=0;i<14;i++) ((Checkbox)Rating.elementAt(i)).setState(false); ((Checkbox)Rating.elementAt(14)).setState(true); ((Checkbox)Rating.elementAt(15)).setState(true); samplingvis.setState(true); caustic.setForeground(teal); orthotomic.setForeground(teal); normalon.setForeground(teal); scrX.setValue(0); scrY.setValue(0); bparam.setValue(160); maxitcd1.setText("1000"); maxitcd2.setText("1000"); maxitlap.setText("500"); maxitcon.setText("50"); disnumcd1.setText("100"); disnumcd2.setText("50"); disnumlap.setText("50"); disnumcon.setText("4"); constparam1.setText("-2.0"); constparam2.setText("0.5"); this.setEvolutionParameter(); drawClosedCurve.setScrollbar(scrX,scrY); drawClosedCurve.changeParam(160); } public void actionPerformed(ActionEvent evt) { System.out.println(evt.getSource()); /* for Java Application */ if(evt.getSource() == quit) { checkquit check = new checkquit(this); check.show(); }else if(evt.getSource() ==savei){ FileDialog saveFileDialog; String destinationFileName; GIFEncoder encode; OutputStream output; saveFileDialog = new FileDialog(this,"Save File",FileDialog.SAVE); saveFileDialog.pack(); saveFileDialog.show(); System.out.println("Please wait..."); Image dummyimage; if (saveFileDialog.getFile() != null) { destinationFileName = saveFileDialog.getDirectory() + saveFileDialog.getFile(); try{ dummyimage = drawClosedCurve.getImage(); encode = new GIFEncoder(dummyimage); output = new BufferedOutputStream(new FileOutputStream (destinationFileName)); encode.Write(output); output.close(); drawClosedCurve.mydg.dispose(); }catch(IOException e){ System.out.println("Error ! IOException in NLSMSimulator.java"); }catch (AWTException e) {System.out.println("Error ! AWTException in NLSMSimulator.java");} } System.out.println("Save finish !"); }else if((evt.getSource() == savep)&&(bscc.numberofpoint!=0)){ FileDialog saveFileDialog; String destinationFileName; saveFileDialog = new FileDialog(this,"Save File",FileDialog.SAVE); saveFileDialog.setFont(new Font("TimesRoman", Font.BOLD, 18)); saveFileDialog.pack(); saveFileDialog.show(); int ds; if (saveFileDialog.getFile() != null) { destinationFileName = saveFileDialog.getDirectory() + saveFileDialog.getFile(); try{ FileOutputStream output = new FileOutputStream(destinationFileName); PrintWriter pwp = new PrintWriter(output); Knot now = drawClosedCurve.mycurve.Head; while(now.next != drawClosedCurve.mycurve.Tail){ now = now.next; pwp.print(now.x); pwp.print(' '); pwp.println(now.y); } pwp.close(); output.close(); } catch (IOException e) { System.out.println("IOException"); } } }else if(evt.getSource() == loadp) { //virtualclear(); //bscc = new B_SplineClosed(800,400); //drawClosedCurve.clearimage(bscc); FileDialog loadFileDialog; String destinationFileName; loadFileDialog = new FileDialog(this,"Load File",FileDialog.LOAD); loadFileDialog.setFont(new Font("TimesRoman", Font.BOLD, 18)); loadFileDialog.pack(); loadFileDialog.show(); int ds; if (loadFileDialog.getFile() != null) { destinationFileName = loadFileDialog.getDirectory() + loadFileDialog.getFile(); try{ FileInputStream input = new FileInputStream (destinationFileName); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(input)); StringTokenizer st; int dj; Knot now = drawClosedCurve.mycurve.Head; while((now.next)!=drawClosedCurve.mycurve.Tail){ now = (now.next); st = new StringTokenizer(lnr.readLine()); double dx = (Double.valueOf(st.nextToken())).doubleValue(); double dy = (Double.valueOf(st.nextToken())).doubleValue(); System.out.println("x = "+dx+" y = "+dy); now.x = dx; now.y = dy; } drawClosedCurve.mycurve.setInitControlPs(); lnr.close(); input.close(); }catch (IOException e){ System.out.println("IOException"); } } drawClosedCurve.repaint(); }else if(evt.getSource() == clear){ this.virtualclear(); System.out.println("in clear"); bscc = new B_SplineClosed(800,400); drawClosedCurve.clearimage(bscc); addmorep.setForeground(teal); addmorep.setLabel("Split Control Points"); }else if(evt.getSource() == samplinginit){ bparam.setValue(160); drawClosedCurve.changeParam(bparam.getValue()); }else if(evt.getSource() == addmorep){ if(!bscc.split){ bscc.SplitCP(); drawClosedCurve.SplitCP(); addmorep.setForeground(Color.red); addmorep.setLabel("Collapse Points"); }else{ bscc.CollapseCP(); drawClosedCurve.CollapseCP(); addmorep.setForeground(teal); addmorep.setLabel("Split Control Points"); } }else if(evt.getSource() == closew){ if(!framesw){ closew.setLabel("Close Frame Window"); closew.setForeground(Color.red); /* for Java Applet windowv = new K_VisibleFrame(); */ /* for Application */ windowv = new K_Visible(); windowv.pack(); windowv.show(); windowv.setVisible(true); framesw = true; }else{ closew.setLabel("Open New Window"); closew.setForeground(teal); windowv.setVisible(false); windowv.basic.bfield.dispose(); windowv.evolution.bfield.dispose(); windowv.skeleton.bfield.dispose(); windowv.curves.bfield.dispose(); windowv.system.bfield.dispose(); windowv.dispose(); framesw=false; } }else if(evt.getSource() == center){ scrX.setValue(0); scrY.setValue(0); drawClosedCurve.CenterMove(); }else if(evt.getSource() == rescale){ drawClosedCurve.Rescale(); }else if(evt.getSource() == normalor){ drawClosedCurve.normalorVisible(); if(drawClosedCurve.norsw==1){ normalor.setForeground(Color.red); }else{ normalor.setForeground(teal); } }else if(evt.getSource() == contourmap){ drawClosedCurve.contourmapVisible(); if(drawClosedCurve.contourmap){ contourmap.setForeground(Color.red); }else{ contourmap.setForeground(teal); } }else if(evt.getSource() == cdriven1){ drawClosedCurve.cdriven1Visible(); if(drawClosedCurve.cdriven1){ cdriven1.setForeground(Color.red); }else{ cdriven1.setForeground(teal); } }else if(evt.getSource() == cdriven2){ drawClosedCurve.cdriven2Visible(); if(drawClosedCurve.cdriven2){ cdriven2.setForeground(Color.red); }else{ cdriven2.setForeground(teal); } }else if(evt.getSource() == laplace){ drawClosedCurve.laplaceVisible(); if(drawClosedCurve.laplace){ laplace.setForeground(Color.red); }else{ laplace.setForeground(teal); } }else if(evt.getSource() == skeleton1){ drawClosedCurve.skeleton1Visible(); if(drawClosedCurve.skeleton1){ skeleton1.setForeground(Color.red); }else{ skeleton1.setForeground(teal); } }else if(evt.getSource() == skeleton2){ drawClosedCurve.skeleton2Visible(); if(drawClosedCurve.skeleton2){ skeleton2.setForeground(Color.red); }else{ skeleton2.setForeground(teal); } }else if(evt.getSource() == voronoid){ drawClosedCurve.voronoidVisible(); if(drawClosedCurve.voronoid){ voronoid.setForeground(Color.red); }else{ voronoid.setForeground(teal); } }else if(evt.getSource() == caustic){ drawClosedCurve.causticVisible(); if(drawClosedCurve.casw==1){ caustic.setForeground(Color.red); }else{ caustic.setForeground(teal); } }else if(evt.getSource() == orthotomic){ drawClosedCurve.orthotomicVisible(); if(drawClosedCurve.orsw==1){ orthotomic.setForeground(Color.red); }else{ orthotomic.setForeground(teal); } }else if(evt.getSource() == envelop){ drawClosedCurve.familyNVisible(); if(drawClosedCurve.fnsw==1){ envelop.setForeground(Color.red); }else{ envelop.setForeground(teal); } }else if(evt.getSource() == offset){ drawClosedCurve.offsetVisible(); if(drawClosedCurve.ofsw==1){ offset.setForeground(Color.red); }else{ offset.setForeground(teal); } }else if(evt.getSource() == oneosculate){ drawClosedCurve.oneosculatingVisible(); if(drawClosedCurve.oneosw==1){ oneosculate.setForeground(Color.red); }else{ oneosculate.setForeground(teal); } }else if(evt.getSource() == onenormal){ drawClosedCurve.onenormalVisible(); if(drawClosedCurve.onensw){ onenormal.setForeground(Color.red); }else{ onenormal.setForeground(teal); } }else if(evt.getSource() == oneoffset){ drawClosedCurve.oneoffVisible(); if(drawClosedCurve.oneoffsw){ oneoffset.setForeground(Color.red); }else{ oneoffset.setForeground(teal); } }else if(evt.getSource() == osculate){ drawClosedCurve.osculatingVisible(); if(drawClosedCurve.osw==1){ osculate.setForeground(Color.red); }else{ osculate.setForeground(teal); } }else if(evt.getSource() == evolute){ drawClosedCurve.evoluteVisible(); if(drawClosedCurve.esw==1){ evolute.setForeground(Color.red); }else{ evolute.setForeground(teal); } }else if(evt.getSource() == normalon){ drawClosedCurve.normalVisible(); if(drawClosedCurve.nsw==1){ normalon.setForeground(Color.red); }else{ normalon.setForeground(teal); } }else if(evt.getSource() == curvature){ drawClosedCurve.curvatureVisible(); if(drawClosedCurve.csw==1){ curvature.setForeground(Color.red); }else{ curvature.setForeground(teal); } }else if(evt.getSource() == tangentV){ drawClosedCurve.tangentVisible(); if(drawClosedCurve.tsw==1){ tangentV.setForeground(Color.red); }else{ tangentV.setForeground(teal); } } } private Knot Next(Knot now) { return (now.next); } private Knot Back(Knot now) { return (now.back); } private void Append(Knot now,Knot t) { Knot dummy = t.back; now.next = t; t.back = now; now.back = dummy; dummy.next =now; } }