4 import java.awt.image.*;
8 import java.awt.event.KeyEvent;
13 public int x1, y1, x2, y2;
14 private int x1R, y1R, x2R, y2R;
15 private static int lineWidth = 1;
19 public Line(
int ox1,
int oy1,
int ox2,
int oy2) {
22 x1=x+x1R; y1=y+y1R; x2=x+x2R; y2=y+y2R;
38 this(ox1, oy1, ox2, oy2);
42 protected void grow(
int xend,
int yend) {
43 if (xend<0) xend=0;
if (yend<0) yend=0;
44 if (xend>xMax) xend=xMax;
if (yend>yMax) yend=yMax;
45 int xstart=x+x1R, ystart=y+y1R;
47 int dx = Math.abs(xend-xstart);
48 int dy = Math.abs(yend-ystart);
54 x=Math.min(x+x1R,xend); y=Math.min(y+y1R,yend);
55 x1R=xstart-x; y1R=ystart-y;
56 x2R=xend-x; y2R=yend-y;
57 width=Math.abs(x2R-x1R); height=Math.abs(y2R-y1R);
58 if (width<1) width=1;
if (height<1) height=1;
61 imp.
draw(clipX, clipY, clipWidth, clipHeight);
63 oldWidth=width; oldHeight=height;
66 protected void moveHandle(
int ox,
int oy) {
67 x1=x+x1R; y1=y+y1R; x2=x+x2R; y2=y+y2R;
68 switch (activeHandle) {
69 case 0: x1=ox; y1=oy;
break;
70 case 1: x2=ox; y2=oy;
break;
72 int dx = ox-(x1+(x2-x1)/2);
73 int dy = oy-(y1+(y2-y1)/2);
74 x1+=dx; y1+=dy; x2+=dx; y2+=dy;
78 int dx = Math.abs(x1-x2);
79 int dy = Math.abs(y1-y2);
80 if (activeHandle==0) {
81 if (dx>=dy) y1= y2;
else x1 = x2;
82 }
else if (activeHandle==1) {
83 if (dx>=dy) y2= y1;
else x2 = x1;
86 x=Math.min(x1,x2); y=Math.min(y1,y2);
89 width=Math.abs(x2R-x1R); height=Math.abs(y2R-y1R);
91 imp.
draw(clipX, clipY, clipWidth, clipHeight);
98 protected void mouseDownInHandle(
int handle,
int sx,
int sy) {
99 state = MOVING_HANDLE;
100 activeHandle = handle;
101 ic.
setCursor(
new Cursor(Cursor.CROSSHAIR_CURSOR));
106 g.setColor(ROIColor);
107 x1=x+x1R; y1=y+y1R; x2=x+x2R; y2=y+y2R;
112 int sx3 = sx1 + (sx2-sx1)/2;
113 int sy3 = sy1 + (sy2-sy1)/2;
114 g.drawLine(sx1, sy1, sx2, sy2);
115 if (state!=CONSTRUCTING) {
116 int size2 = HANDLE_SIZE/2;
117 if (ic!=null) mag = ic.getMagnification();
118 drawHandle(g, sx1-size2, sy1-size2);
119 drawHandle(g, sx2-size2, sy2-size2);
120 drawHandle(g, sx3-size2, sy3-size2);
123 if (updateFullWindow)
124 {updateFullWindow =
false; imp.
draw();}
136 return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
142 double[] line = ip.
getLine(x1, y1, x2, y2);
146 public void drawPixels() {
150 if (
Line.getWidth()>1)
151 updateFullWindow =
true;
154 public boolean contains(
int x,
int y) {
161 int size = HANDLE_SIZE+5;
162 int halfSize = size/2;
163 int sx1 = ic.
screenX(x+x1R) - halfSize;
164 int sy1 = ic.
screenY(y+y1R) - halfSize;
165 int sx2 = ic.
screenX(x+x2R) - halfSize;
166 int sy2 = ic.
screenY(y+y2R) - halfSize;
167 int sx3 = sx1 + (sx2-sx1)/2-1;
168 int sy3 = sy1 + (sy2-sy1)/2-1;
169 if (sx>=sx1&&sx<=sx1+size&&sy>=sy1&&sy<=sy1+size)
return 0;
170 if (sx>=sx2&&sx<=sx2+size&&sy>=sy2&&sy<=sy2+size)
return 1;
171 if (sx>=sx3&&sx<=sx3+size+2&&sy>=sy3&&sy<=sy3+size+2)
return 2;
175 public static int getWidth() {
179 public static void setWidth(
int w) {
188 case KeyEvent.VK_UP: y2R--;
break;
189 case KeyEvent.VK_DOWN: y2R++;
break;
190 case KeyEvent.VK_LEFT: x2R--;
break;
191 case KeyEvent.VK_RIGHT: x2R++;
break;