head 1.1; access; symbols; locks; strict; comment @# @; 1.1 date 97.11.09.01.23.12; author kowallik; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @// angle vs time plot // last changed 05/08/97 // status: needs lots of cleaning up import java.awt.*; import java.util.*; import java.lang.*; class T_Graph extends Panel { // angle vs time data - static because also used by fourier static Vector t= new Vector(); boolean reshaped = false; FontMetrics fm; main parent; Image offscreen; // image for plot Image down_off; // image for x-ticklabels Image labelx_off; Image labely_off; Image left_off; double maxt,mint; // min-max for plots Panel down, small, tiny, left, labelx, labely, title; T_Graph() { setBackground(Color.lightGray); setLayout(new BorderLayout()); small=new Panel(); tiny=new Panel(); down = new Panel(); left=new Panel(); labelx=new Panel(); labely=new Panel(); add("West", labely); add("South", labelx); add("Center", small); small.setLayout(new BorderLayout(0,5)); small.add("South", down); small.add("West", left); small.add("Center", tiny); this.show(); } public void exit() { t.removeAllElements(); try { offscreen.flush(); down_off.flush(); left_off.flush(); labelx_off.flush(); labely_off.flush(); }catch(NullPointerException npe) {} } // as soon as we are done void cleanup(boolean rerun) { Graphics g; Dimension d; t.removeAllElements(); if(rerun==false) { maxt=0; mint=0; try { d = left.size(); g = left_off.getGraphics(); g.setColor(Color.lightGray); g.fillRect(0, 0, d.width, d.height); d = down.size(); g = down_off.getGraphics(); g.setColor(Color.lightGray); g.fillRect(0, 0, d.width, d.height); }catch(NullPointerException npe) {} } try { d = tiny.size(); g = offscreen.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, d.width, d.height); g.setColor(Color.black); paint(g); }catch(NullPointerException npe) {} } void draw(double y) { Graphics g; Dimension d; int j; double off=0,sc=10; if (offscreen==null) { // make sure there is enough space to label axis if(!reshaped) { d = this.size(); labely.reshape( 0, 0, 15, d.height-15); labelx.reshape(55, d.height-15, d.width-50, 15); small.reshape( 15, 0, d.width-15, d.height-15); left.reshape( 0, 0, 40, d.height-30); down.reshape( 40, d.height-30, d.width-55, 15); tiny.reshape( 40, 0, d.width-55, d.height-30); d = down.size(); down_off = this.createImage(d.width, d.height); d = left.size(); left_off = this.createImage(d.width, d.height); d = labelx.size(); labelx_off = this.createImage(d.width, d.height); d = labely.size(); labely_off = this.createImage(d.width, d.height); reshaped=true; } d=tiny.size(); offscreen=this.createImage(d.width, d.height); g = offscreen.getGraphics(); fm = g.getFontMetrics(); g.setColor(Color.white); g.fillRect(0,0,d.width, d.height); } g = offscreen.getGraphics(); g.setColor(Color.black); d = tiny.size(); // label x-axis - do this at the beginnig and whenever we filled the whole plot if((t.size()%d.width)==0) { label(); xlabel(1); } // wait to get an idea what the range for x and y is // collect data but don't plot anything if(t.size()<10) { t.addElement(new Double(y)); if(y>maxt) maxt=y; if(ymaxt) || (ymaxt) maxt=y+(y-mint)*0.05; if(yd.width) j-=d.width; if (j>2) { g.drawLine (j-1, (int)((-yo+off)*sc+d.height/2), j, (int)((-y+off)*sc+d.height/2)); g.setColor(Color.white); g.fillRect(j+1, 0, 5, d.height); } if(j<=2) { g.clearRect(0, 0, 5, d.height); } } paint(g); } public void drawcom() { Graphics g = offscreen.getGraphics(); Dimension d = tiny.size(); g.setColor(Color.white); g.fillRect(0,0,d.width, d.height); g.setColor(Color.black); int step = 1; while( (t.size()/step) > d.width) { step++; } double off= (maxt+mint)/2; double sc = d.height/(maxt-mint); for(int i=step; id.width) j-=d.width; for(i=(t.size()-j+1); iMmax) Mmax=M[j]; } d = down.size(); s = tiny.size(); f = down_off.getGraphics(); g = offscreen.getGraphics(); f.setColor(Color.lightGray); f.fillRect(0,0,d.width,d.height); f.setColor(Color.black); g.clearRect(0,0,s.width, s.height); // where to draw the labels and bars double dist = (s.width/33); double sch = 0.9*s.height/Mmax; // check if we really have 32 frequencies in case someone clicks on stop if ((el/2)>33) jmax = 33; else jmax=(el/2); for (j=0; j