package sunw.demo.hotspots; import java.awt.*; import java.util.*; public class ShapeMgr extends Canvas { Vector _vec; HotSpotMgr _hsm; HotSpot _hs; RectangleShape r; LineShape l; OvalShape o; Graphics g = getGraphics(); private int shapeT = 1; private String shapeName = "Line"; private String shapeColor = "black"; private String focusColor = "black"; private String shapeThickness = "1"; public ShapeMgr() { _vec = new Vector(); _hsm = new HotSpotMgr(); setBackground(Color.darkGray); resize(300,300); } public void setShapeName(String _shapeName) { shapeName = _shapeName; if (shapeName.equals("Line")) { l = new LineShape(10,10,100,100); manage(l); } else if (shapeName.equals("Rectangle")) { r = new RectangleShape(10,10,100,100); manage(r); } else if (shapeName.equals("Oval")) { o = new OvalShape(10,10,100,100); manage(o); } else { } } public String getShapeName() { return shapeName; } public void setShapeColor(String _shapeColor) { shapeColor = _shapeColor; repaint(); } public String getShapeColor() { return shapeColor; } public void setFocusColor(String _focusColor) { focusColor = _focusColor; repaint(); } public String getFocusColor() { return focusColor; } public void setShapeThickness(String _shapeThickness) { shapeThickness = _shapeThickness; shapeT = Integer.valueOf(shapeThickness).intValue(); repaint(); } public String getShapeThickness() { return shapeThickness; } public void manage(Shape s){ _vec.addElement(s); Vector vecShapes = s.getHotSpots(); for (int i = 0; i < vecShapes.size(); i++) { _hsm.manage((HotSpot)vecShapes.elementAt(i)); } repaint(); } public boolean mouseDrag(Event e, int x, int y) { if (_hs != null) { _hs.setCoordinates(new Coordinates(x, y)); _hs.notifyObservers(); repaint(); } return true; } public boolean mouseDown(Event e, int x, int y) { _hs = _hsm.isAt(new Coordinates(x, y)); return true; } public boolean mouseUp(Event e, int x, int y) { _hs = null; return true; } public void paint(Graphics g) { for (int i = 0; i < _vec.size(); i++) { Shape s = (Shape)_vec.elementAt(i); if (focusColor.equals("magenta")) { g.setColor(Color.magenta); } else if (focusColor.equals("green")) { g.setColor(Color.green); } else if (focusColor.equals("gray")) { g.setColor(Color.gray); } else if (focusColor.equals("cyan")) { g.setColor(Color.cyan); } else if (focusColor.equals("orange")) { g.setColor(Color.orange); } else if (focusColor.equals("blue")) { g.setColor(Color.blue); } else if (focusColor.equals("yellow")) { g.setColor(Color.yellow); } else if (focusColor.equals("red")) { g.setColor(Color.red); } else if (focusColor.equals("black")) { g.setColor(Color.black); } else{ } // g.setColor(Color.lightGray); Vector vecShapes = s.getHotSpots(); for (int j = 0; j < vecShapes.size(); j++) { HotSpot hs = (HotSpot)vecShapes.elementAt(j); hs.paint(g); } if (shapeColor.equals("magenta")) { g.setColor(Color.magenta); } else if (shapeColor.equals("green")) { g.setColor(Color.green); } else if (shapeColor.equals("gray")) { g.setColor(Color.gray); } else if (shapeColor.equals("cyan")) { g.setColor(Color.cyan); } else if (shapeColor.equals("orange")) { g.setColor(Color.orange); } else if (shapeColor.equals("blue")) { g.setColor(Color.blue); } else if (shapeColor.equals("yellow")) { g.setColor(Color.yellow); } else if (shapeColor.equals("red")) { g.setColor(Color.red); } else if (shapeColor.equals("black")) { g.setColor(Color.black); } else{ } // g.setColor(Color.black); s.paint(g); } } }