//SpacePanel.java import java.awt.*; class SpacePanel extends Panel { public int xstart,ystart,xwidth,yheight; public int ixstart,iystart,ixwidth,iyheight; Einstein EIN; FontMetrics Fm; Stars s; public void init() { xstart = ixstart; ystart = iystart; xwidth = ixwidth; yheight = iyheight; s = new Stars(this); } public void thickLine (int x0, int y0, int x1, int y1,Graphics g) { g.drawLine(x0,y0,x1,y1); if (Math.abs(x1-x0) > Math.abs(y1-y0)) { g.drawLine(x0,y0-1,x1,y1-1); g.drawLine(x0,y0+1,x1,y1+1); } else { g.drawLine(x0-1,y0,x1-1,y1); g.drawLine(x0+1,y0,x1+1,y1); } } public void refocus(double newStart) { xstart = (int)newStart; } public void thickArrow (int x0, int y0, int x1, int y1,Graphics g) { double w, dw = 0.5, r = 12, dx = x1-x0, dy = y0-y1; thickLine(x0,y0,x1,y1,g); //g.fillRect(x0,y0-4,x1-x0-4,7); w = Math.atan2(dy,dx); x0 = (int)(x1-r*Math.cos(w+dw)+0.5); y0 = (int)(y1+r*Math.sin(w+dw)+0.5); thickLine(x0,y0,x1,y1,g); x0 = (int)(x1-r*Math.cos(w-dw)+0.5); y0 = (int)(y1+r*Math.sin(w-dw)+0.5); thickLine(x0,y0,x1,y1,g); } public int mapX(double x)//Maps x to screen { Rectangle r = getBounds(); int newX = (int) ((x-xstart)*(r.width/xwidth)); //console.println("X= "+x+" newX= "+newX); return newX; } public int mapBack(double newX) { Rectangle r = getBounds(); return ((int) newX/(r.width/xwidth)+xstart); } public int mapY(double y)//Maps y to screen { Rectangle r = getBounds(); int newY = (int) ((r.height/yheight)*(ystart-y)); //console.println("Y= "+y+" newY= "+newY); return newY; } public SpacePanel(int xstart,int ystart,int width,int height,Einstein EIN) { super(); this.xstart = xstart; this.ixstart = xstart; this.ystart = ystart; this.iystart = ystart; this.xwidth = width; this.ixwidth = width; this.yheight = height; this.iyheight = height; Font spaceFont = new Font("Serif",Font.PLAIN,12); setFont(spaceFont); Fm = getFontMetrics(spaceFont); this.EIN = EIN; s = new Stars(this); } public void paint(Graphics gr) { Rectangle r = getBounds(); EIN.offscr.setColor(Color.white); EIN.offscr.fillRect(0,0,r.width,r.height); EIN.offscr.setColor(Color.black); EIN.offscr.fillRoundRect(0,0,r.width,r.height,20,20); EIN.offscr.setColor(Color.white); s.draw(EIN.offscr); for (int loop=0;loop<11;loop++) { EIN.offscr.fillOval(mapX(xstart+loop*(xwidth/10))-1,mapY(0)-1,2,2); } if ((xstart < 0) && ((xstart+xwidth) > 0)) for (int loop=0;loop<11;loop++) { EIN.offscr.fillOval(mapX(0)-1,mapY(ystart - loop*(yheight/10))-1,2,2); } if (EIN.mover != null) EIN.mover.draw(EIN.frame,EIN.offscr); if (EIN.topValue != 0) { EIN.offscr.setColor(Color.blue); int arrowLength = EIN.topValue+5; thickArrow((r.width-arrowLength)/2,25,(r.width-arrowLength)/2+arrowLength,25,EIN.offscr); } gr.drawImage(EIN.image,0,0,this); } public void update(Graphics g) { if (EIN.frame == Reality.OBSERVER_FRAME) { if ((EIN.reality.theirX) > (xstart+xwidth)) { refocus(xstart+xwidth); } } paint(g); } }