import java.awt.*; class ExCanvas extends Panel { BorderLayout l = null; Dimension min_size = new Dimension(100, 100); Dimension pref_size = new Dimension(100, 100); Graphics g2; Image image=null, org=null, pnt=null, pnt_hi=null, buffy=null; int org_width=0, org_height=0, pnt_width=0, pnt_height=0; int org_x=0, org_y=0; Scrollbar vertical; Scrollbar horizontal; boolean origin_select=true; boolean point_select=false; boolean inside = false; int last_x = 0, last_y = 0; Triplet points = null; model3D creator = null; public ExCanvas(Image picture, Image origin, Image point, Image highlight, model3D c) { creator = c; l = new BorderLayout(); setLayout(l); image = picture; buffy = c.createImage(picture.getWidth(this), picture.getHeight(this)); g2 = buffy.getGraphics(); org = origin; org_width = org.getWidth(this); org_height = org.getHeight(this); pnt = point; pnt_width = pnt.getWidth(this); pnt_height = pnt.getHeight(this); pnt_hi = highlight; min_size = new Dimension(Math.min(min_size.width, picture.getWidth(this)), Math.min(min_size.height, picture.getHeight(this))); pref_size = new Dimension(picture.getWidth(this)+15, picture.getHeight(this)+15); vertical = new Scrollbar(Scrollbar.VERTICAL); vertical.setValues(0, 1, 0, 0); horizontal = new Scrollbar(Scrollbar.HORIZONTAL); horizontal.setValues(0, 1, 0, 0); add("East", vertical); add("South", horizontal); layout(); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { simple_paint(g2); g.drawImage(buffy, 0, 0, this); } public void simple_paint(Graphics g) { if (image!=null) { g.drawImage(image, 0, 0, this); } if (!origin_select) { if (org!=null) { g.drawImage(org, org_x, org_y, this); } } if (pnt!=null) { Triplet tmp = points; while (tmp!=null) { Point p = (Point) tmp.first; g.drawImage(pnt, p.x, p.y, this); tmp = (Triplet) tmp.second; } } if (inside) { if (origin_select) { if (org!=null) { g.drawImage(org, last_x, last_y, this); } } else { if (pnt_hi!=null) { g.drawImage(pnt_hi, last_x, last_y, this); } } } vertical.paint(g); horizontal.paint(g); } public Dimension preferredSize() { return pref_size; } public Dimension minimumSize() { return min_size; } public void layout() { Dimension d = size(); vertical.reshape(d.width-15 ,0 , 15, d.height-15); horizontal.reshape(0, d.height-15, d.width-15, 15); } public boolean mouseEnter(Event e, int mx, int my) { if (origin_select) { last_x = mx-org_width; last_y = my-org_height; } else { last_x = mx-pnt_width; last_y = my-pnt_height; } inside = true; repaint(); return true; } public boolean mouseMove(Event e, int mx, int my) { if (origin_select) { last_x = mx-org_width; last_y = my-org_height; } else { last_x = mx-pnt_width; last_y = my-pnt_height; } repaint(); return true; } public void getPoints() { point_select=true; } public boolean mouseDown(Event e, int mx, int my) { if (origin_select) { org_x = mx-org_width; org_y = my-org_height; origin_select=false; creator.deliver_point(this, mx, my); } else if (point_select) { points = new Triplet(new Point(mx-pnt_width,my-pnt_height),points,null); point_select=false; creator.deliver_point(this, mx, my); } repaint(); return true; } public boolean mouseExit(Event e, int mx, int my) { inside = false; repaint(); return true; } }