import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.lang.*; //import Jama.Matrix; public class ViVA extends Frame implements AdjustmentListener, ActionListener, MouseListener { static char a; Cnode Cn; static int nc, nr; MSTgraph SD; gt2 GT2; Data1 Dt; Label lfactor, lnbhd, nsd; Label tspeed; int factor, nbhd, sd; TextField input1, input2, input3; private PtCanvas1 c; private Panel p, p2; Button MSTree, SusRes, Stop, Partition, DColor, PrintPartition; static PopupMenu MSTdata; Scrollbar Speed; Font fo; private double gp[][]; double data[][]; static boolean erase[]; static int mst_count=0; static int nd = 2; double st = 0.1; static MenuItem function[]; static String fn; PrintWriter pwriter; Color pcolor[]; int aa=0; int nsta[], nend[]; boolean nerase[]; public ViVA(String filename) { fn = filename; Dt = new Data1(); try{ Dt.readData(filename); } catch(IOException e){ } nc = Dt.ncols; nr = Dt.nrows; data = new double[Dt.nrows][Dt.ncols]; GT2 = new gt2(nc,nr,nd,st); // if (a=='Y') { // Standardize(Dt.x); // } GT2.raw_data = Dt.x; // Dt = null; // System.gc(); gp = new double[nr][nc]; fo = new Font("Courier",Font.BOLD, 13); setFont(fo); setLayout(new BorderLayout()); c = new PtCanvas1(); add("Center",c); p = new Panel(); add(p, BorderLayout.SOUTH); GridBagLayout gbag=new GridBagLayout(); GridBagConstraints cg=new GridBagConstraints(); p.setLayout(gbag); tspeed=new Label("Tour Speed"); Speed = new Scrollbar(); Speed.setValues((int) 10, (int) 1, (int) 1, (int) 90); Speed.setOrientation((int) Speed.HORIZONTAL); System.out.println("Orient="+Speed.getOrientation()); MSTree = new Button("Draw MST"); SusRes = new Button("Suspend/Resume"); Partition = new Button("Make Partition"); DColor = new Button("Color Partition"); PrintPartition= new Button("Print Partition"); Stop = new Button("Quit"); MSTdata = new PopupMenu(); function = new MenuItem[7]; function[0]=new MenuItem("From Points"); function[1]=new MenuItem("From Results"); for (int i=0; i<2; i++){ MSTdata.add(function[i]); function[i].addActionListener(this); } p2=new Panel(); p2.setLayout(new GridLayout(1,6)); lfactor=new Label("Input Factor"); lnbhd=new Label("Input Neighborhood Size"); nsd=new Label("Input Multiples of S.D."); p2.add(lfactor); input1 = new TextField(2); p2.add(input1); p2.add(lnbhd); input2 = new TextField(2); p2.add(input2); p2.add(nsd); input3 = new TextField(2); p2.add(input3); input1.addActionListener(this); input2.addActionListener(this); input3.addActionListener(this); Speed.addAdjustmentListener(this); MSTree.addActionListener(this); MSTree.add(MSTdata); SusRes.addActionListener(this); Partition.addActionListener(this); PrintPartition.addActionListener(this); DColor.addActionListener(this); Stop.addActionListener(this); cg.weightx=1.0; gbag.setConstraints(MSTree,cg); gbag.setConstraints(SusRes,cg); gbag.setConstraints(Partition,cg); gbag.setConstraints(DColor,cg); gbag.setConstraints(PrintPartition,cg); cg.gridwidth=GridBagConstraints.REMAINDER; gbag.setConstraints(Stop,cg); cg.gridwidth=GridBagConstraints.REMAINDER; gbag.setConstraints(p2,cg); cg.gridwidth=1; gbag.setConstraints(tspeed,cg); cg.gridwidth=GridBagConstraints.REMAINDER; cg.fill=GridBagConstraints.BOTH; gbag.setConstraints(Speed,cg); p.add(MSTree); p.add(SusRes); p.add(Partition); p.add(DColor); p.add(PrintPartition); p.add(Stop); p.add(p2); p.add(tspeed); p.add(Speed); } public void adjustmentValueChanged(AdjustmentEvent evt) { System.out.println("evt.getValue="+evt.getValue()); st = (double)evt.getValue()/100.0; } public void actionPerformed(ActionEvent evt) { if (evt.getSource() == SusRes ) c.Sus_Res(); else if (evt.getSource() == MSTree) c.MinimalSpanning_Tree(); else if (evt.getSource() == Partition){ } else if (evt.getSource() == input1){ factor=Integer.parseInt(input1.getText()); System.out.println(factor); } else if (evt.getSource() == input2) nbhd=Integer.parseInt(input2.getText()); else if (evt.getSource() == input3) sd=Integer.parseInt(input3.getText()); else if (evt.getSource() == DColor){ nsta=new int[nr+1]; nend=new int[nr+1]; nerase=new boolean[nr+1]; for (int i=0;i=1; i--){ nsta[i]=nsta[i-1]; nend[i]=nend[i-1]; nerase[i]=nerase[i-1]; } // Cn = new Cnode(); Cn.node = new int[nr+1]; Cn.ComputeNode(nend,nr); int max; max=Cn.node[1]; for (int i=2; i<=nr; i++) if (Cn.node[i] >= max) max=Cn.node[i]; Cn.ComputeNode1(nend,nr,max); Cn.Label(nend,nr,nerase,max); aa=1; pcolor = new Color[nr]; for (int i=0; i< nr; i++){ switch ((int) Cn.label[i+1]){ case 1: pcolor[i]=Color.red; break; case 2: pcolor[i]=Color.yellow; break; case 3: pcolor[i]=Color.green; break; case 4: pcolor[i]=Color.magenta; break; case 5: pcolor[i]=Color.orange; break; case 6: pcolor[i]=Color.pink; break; case 7: pcolor[i]=Color.white; break; case 8: pcolor[i]=Color.blue; break; case 9: pcolor[i]=Color.blue.brighter(); break; default: pcolor[i]= Color.cyan; break; } } } else if (evt.getSource() == PrintPartition){ String fn_class = ViVA.fn.concat(".class"); try{ FileOutputStream fl=new FileOutputStream(fn_class); DataOutputStream out=new DataOutputStream(fl); pwriter = new PrintWriter(out,true); } catch(IOException e){System.exit(1);} for (int i=1; i 0) { try{ GT2.run_tour(st);} catch(SVDCException e) { } for (int i=0; i nr) { gBuf.setColor(Color.black); gBuf.fillRect(0,0,500,500);} } public void scalepoints(double p[][]) { d = this.getSize(); GraphWth = d.width * 8/10; GraphHgt = d.height * 8/10; Plotsz = Math.min(GraphWth, GraphHgt); xOrigin = (d.width-GraphWth)/2; yOrigin = (d.height-GraphHgt)/2; xCenter = xOrigin+GraphWth/2; yCenter = yOrigin+GraphHgt/2; double rangex = 2; double rangey = 2; for (int i=0; i 1){ for (int i=0; i 1){ for (int i=0; i 1) { g.drawLine((int)p[s][0]+xcent,(int)p[s][1]+ycent, (int)p[e][0]+xcent,(int)p[e][1]+ycent); g.drawString(Integer.toString(s+1),(int)p[s][0]+xcent, (int)p[s][1]+ycent); g.drawString(Integer.toString(e+1),(int)p[e][0]+xcent, (int)p[e][1]+ycent); } else { g.drawLine((int)p[s][0]+xcent,0+ycent,(int)p[e][0]+xcent,0+ycent); g.drawString(Integer.toString(s+1),(int)p[s][0]+xcent, 0+ycent); g.drawString(Integer.toString(e+1),(int)p[e][0]+xcent, 0+ycent); } } } }