import java.awt.*; import java.math.*; import java.lang.*; /*--------------- NDisp --------------------*/ public class NDisp extends Frame { public NDisp(Object m,String title) { owner=m; if (title==null) setTitle("Neuron Activity"); else setTitle(title); canvas= new Canvas(); canvas.setBackground(Color.white); add("Center",canvas); Panel p=new Panel(); p.add(new Button("Close")); p.add(new Button("Draw")); add("South",p); } public NDisp() { this(null,null); } public boolean mouseDown(Event evt, int x, int y) { Point p=canvas.getLocation(); x=x-p.x; y=y-p.y; //System.out.println("Down: step 0"); if (!Lastdrawn) return true; x-=Lastx0; y-=Lasty0; //System.out.println("Down: step 1"); if (x<0 || y<0) return true; //System.out.println("Down: step 2"); int col= x / (Lastwi+1); int row= y / (Lastwi+1); //System.out.println("hit row,col:"+row+","+col); if (col>=Lastncol) return true; //System.out.println("Down: step 3"); if (row>=Lastnrow) return true; //System.out.println("Down: step 4"); if (row*Lastncol+col>=Lastsize) return true; //System.out.println("Down: step 5"); FARS.cellNotify(owner,row*Lastncol+col); //System.out.println("Down: step 6"); return true; } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY) System.exit(0); return super.handleEvent(evt); } public boolean action(Event evt, Object arg) { if (arg.equals("Draw")) { demo();} if (arg.equals("Close")) { System.exit(0); } else return super.action(evt,arg); return true; } public Canvas getCanvas() { return canvas;} public Graphics getGraphics() { return g; } public void clearCanvas() { Graphics g=canvas.getGraphics(); Dimension d=canvas.size(); g.clearRect(0,0,d.width,d.height); } /* IMPR: pull out the unnecc. geom. computation in an other method. Compute them when necc. i.e resize occurs */ public void drawArray(double[] a,double min,double max,long[] col,int size,int ncol) { int MARGIN; double mag; int wi,he,x,y,column,x0,y0,nrow; int R,G,B; long v; Color c; Graphics g=canvas.getGraphics(); Dimension d=canvas.size(); MARGIN = d.width / 50; if ((d.height / 50) ((d.height/2-MARGIN-nrow)/nrow)) wi=(d.height/2-MARGIN-nrow)/nrow; //wi-=1; wi=wi*2+1; column=0; x0=(d.width-(wi+1)*ncol)/2; y0=(d.height-(wi+1)*nrow)/2; //x0=MARGIN; y0=MARGIN; x=x0; y=y0; Lastncol=ncol; Lastnrow=nrow; Lastx0 =x0; Lasty0 =y0; Lastwi =wi; Lastsize=size; Lastdrawn=true; for (int i=0;i>16); v=v%(1<<16); G=(int)(v>>8) ; v=v%(1<<8); B=(int)v; //System.out.println(R+" "+G+" "+B); c=new Color(R,G,B); //drawBar(g,x,y,wi,he,c); drawSArea(g,x,y,wi,he,c); x+=wi+1; column++; if (column>=ncol) {column=0; y+=wi+1; x=x0;} } } public void drawSArea0(Graphics g,int x,int y,int size,int val,Color col) { if (val<0) { val=0; System.err.println("NDisp: underflow (-) value truncated to 0");} if (val>size) { val=size; System.err.println("NDisp: overflow (>maxvalue) value truncated to maxvalue"); } g.clearRect(x+1,y+1,size-2,size-2); g.setColor(col); int cx=(x+x+size-1)/2; int cy=(y+y+size-1)/2; int r =val/2; g.fillRect(cx-r,cy-r,2*r+1,2*r+1); g.drawRect(x,y,size-1,size-1); g.setColor(Color.red); g.drawLine(cx,cy,cx,cy); } public void drawSArea(Graphics g,int x,int y,int size,int val,Color col) { if (val<0) { val=0; System.err.println("NDisp: underflow (-) value truncated to 0");} if (val>size) { val=size; System.err.println("NDisp: overflow (>maxvalue) value truncated to maxvalue"); } //g.clearRect(x+1,y+1,size-2,size-2); g.setColor(col); g.fillRect(x,y,size,size); int cx=(x+x+size-1)/2; int cy=(y+y+size-1)/2; int r =val/2; g.draw3DRect(cx-r,cy-r,2*r+1-1,2*r+1-1,true); //g.drawRect(x,y,size-1,size-1); //g.setColor(Color.red); //g.drawLine(cx,cy,cx,cy); } public void drawBar(Graphics g,int x,int y,int wi,int he,Color col) { if (he<0) { y+=he-1; he=-he;} g.setColor(col); g.fillRect(x,y,wi,he); g.setColor(Color.black); g.drawRect(x,y,wi,he); } public void demo() { int SZ=50; double[] act=new double[SZ]; long[] col=new long[SZ]; for (int i=0;i