1 4 package demo.sharededitor.models; 5 6 import demo.sharededitor.ui.ITexturable; 7 import java.awt.geom.Ellipse2D ; 8 import java.awt.geom.RectangularShape ; 9 import java.awt.Image ; 10 import java.awt.Shape ; 11 12 final class Circle 13 extends BaseObject 14 implements ITexturable 15 { 16 private Ellipse2D.Double shape; 17 18 protected Shape getShape() 19 { 20 return this.shape; 21 } 22 23 protected Shape [] getAnchors() 24 { 25 return new Shape [] { 26 new Ellipse2D.Double (x1 - 5, y2 - 5, 10, 10), 27 new Ellipse2D.Double (x2 - 5, y2 - 5, 10, 10), 28 new Ellipse2D.Double (x2 - 5, y1 - 5, 10, 10), 29 new Ellipse2D.Double (x1 - 5, y1 - 5, 10, 10) 30 }; 31 } 32 33 public synchronized void move(int dx, int dy) 34 { 35 x1 += dx; 36 y1 += dy; 37 x2 += dx; 38 y2 += dy; 39 shape.setFrameFromDiagonal(x1, y1, x2, y2); 40 this.notifyListeners(this); 41 } 42 43 public synchronized void resize(int x, int y) 44 { 45 switch (grabbedAnchor()) 46 { 47 case 0: 48 x1 = x; 49 y2 = y; 50 break; 51 case 1: 52 x2 = x; 53 y2 = y; 54 break; 55 case 2: 56 x2 = x; 57 y1 = y; 58 break; 59 case 3: 60 x1 = x; 61 y1 = y; 62 break; 63 } 64 shape.setFrameFromDiagonal(x1, y1, x2, y2); 65 this.notifyListeners(this); 66 } 67 68 public synchronized void setTexture(Image image) 69 { 70 super.setTexture(image); 71 notifyListeners(this); 72 } 73 74 public boolean isTransient() 75 { 76 RectangularShape bounds = (RectangularShape )shape.getBounds(); 77 return (bounds.getHeight() * bounds.getWidth()) < 4; 78 } 79 80 private int x1, y1, x2, y2; 81 82 public Circle() 83 { 84 x1 = y1 = x2 = y2 = 0; 85 shape = new Ellipse2D.Double (); 86 shape.setFrameFromDiagonal(x1, y1, x2, y2); 87 } 88 } 89 | Popular Tags |