1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
|
/*
*
* Copyright (C) 1999, Institute for MicroTherapy
*
* This software and supporting documentation were developed by
*
* University of Witten/Herdecke
* Department of Radiology and MicroTherapy
* Institute for MicroTherapy
* Medical computer science
*
* Universitaetsstrasse 142
* 44799 Bochum, Germany
*
* http://www.microtherapy.de/go/cs
* mailto:computer.science@microtherapy.de
*
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND THE INSTITUTE MAKES NO
* WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
* OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES
* OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY
* AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
* Author : $Author: kleber $
* Last update : $Date: 2001/06/06 10:32:30 $
* Revision : $Revision: 1.1.1.1 $
* State: $State: Exp $
*/
package viewer.presentation;
import java.util.*;
import java.awt.geom.*;
import java.awt.*;
import java.awt.image.*;
import J2Ci.*;
import viewer.paint.*;
import viewer.gui.*;
import main.*;
import javax.swing.*;
/**
* This class manages the drawing and manipulating of
* the currently active objects on the display.
*
* @author Klaus Kleber
* @since 30.04.1999
*/
public class PaintStructure
{
/**
* Contains the Point where a moving opations of a PresentationStateLayerObject
* starts.
*
* @since 30.04.1999
*/
Point2D.Float moveAnn= new Point2D.Float();
/**
* Contains the currently painted Paintobject. This
* Object is painted in the xorMode because it saves speed.
*
* @since 30.04.1999
*/
PaintObject currentPaintObject = null;
/**
* Contains the a help value . This
* Object is painted in the xorMode because it saves speed.
*
* @since 30.04.1999
*/
public PaintObject oldPaintObject = null;
/**
* Contains the xorColor for displaying the active object.
* The xorMode will be used for drawing the active object.
*
* @since 30.04.1999
*/
Color xorColor = Color.gray;
/**
* Contains the image displaying Canvas
*
* @since 30.04.1999
* @see PresentationStateGraphicsHandler
*/
JPanel imageCanvas;
/**
* Contains the current PresentationStateGraphicsHandler.
*
* @since 30.04.1999
* @see PresentationStateGraphicsHandler
*/
PresentationStateGraphicsHandler presentationStateGraphicsHandler;
/**
* Contains the currently active PresentationStateLayerObject on the
* display if exist. If a PresentationStateLayerObject is active
* you can manipulate this object in the Canvas.
*
* @since 30.04.1999
* @see PresentationStateLayerObject
*/
public PresentationStateLayerObject currentObject = null;
/**
* Contains the current transformation for drawing objects.
*
* @since 30.04.1999
*/
public AffineTransform aff;
public boolean filled = false;
public boolean imageRelative = true;
/**
* Constructs a new object.
*
* @param presentationStateGraphicsHandler Contains the current PresentationStateGraphicsHandler
* @since 30.04.1999
*/
public PaintStructure(PresentationStateGraphicsHandler presentationStateGraphicsHandler)
{
currentPaintObject =null;
oldPaintObject = null;
aff = new AffineTransform();
this.presentationStateGraphicsHandler = presentationStateGraphicsHandler;
}
/**
* Fills/unfills the currentPaintObject.
*
* @param filled Fills/unfills the currentPaintObject.
* @since 30.04.1999
*/
public void setFilled()
{
filled = !filled;
if (currentPaintObject != null) currentPaintObject.setFilled(filled);
}
/**
* Sets the currentPaintObject to image relative or display relative.
*
* @param isDisplayRelative True sets the currentPaintObject to display relative, false sets the currentPaintObject to imageRelative.
* @since 30.04.1999
*/
public void setImageRelative()
{
imageRelative = !imageRelative;
if (currentPaintObject != null) currentPaintObject.isDisplayRelative= !imageRelative;
}
/**
* Insert a new point to the currentPaintObject.
* If the status of the PaintObejct becomes STATUS_STOP,
* the PointObject will be transformed to a PresentationStateGraphicObject.
*
* @param newPoint Specifies the new point of the PaintObject.
* @since 30.04.1999
*/
public void setNewPoint(Point2D.Float newPoint, int applyTo)
{
System.out.println("setNewPoint");
if (currentPaintObject.getStatus() == PaintObject.STATUS_STOP)
{
}
//First point
if (currentPaintObject.getStatus() == PaintObject.STATUS_NULL)
{
//setNewGraphicPaintObject(currentPaintObject);
}
currentPaintObject.setNewPoint(getInverseTransformedPoint(newPoint));
if (currentPaintObject.getStatus() == PaintObject.STATUS_STOP)
{
paintInImageCanvas(currentPaintObject, presentationStateGraphicsHandler.getCurrentColor());
presentationStateGraphicsHandler.newPaintObject(currentPaintObject,aff, applyTo);
currentPaintObject = currentPaintObject.getNewPaintObject();
}
if ((oldPaintObject != null) && (oldPaintObject instanceof InterpolatedObject))
{
setWorkingShape(null);
}
oldPaintObject = null;
}
/**
* Deletes the currentPaintObject.
*
* @since 30.04.1999
*/
public void deleteCurrentPaintObject()
{
//Creating the graphics2D
Graphics2D g2 = (Graphics2D)imageCanvas.getGraphics();
if (g2!= null)
{
try
{
//Painting the new shape
g2.setXORMode(xorColor);
if (oldPaintObject != null) oldPaintObject.drawTransformedShape(g2,aff);
if (currentPaintObject != null)currentPaintObject.drawTransformedShape(g2,aff);
}
finally
{
g2.dispose();
}
}
if (currentPaintObject!= null) currentPaintObject = currentPaintObject.getNewPaintObject();
}
/**
* Paints a new Point to the currentPaintObject, removes the last Point and
* draws the currentPaintObject with the xorMode in the imageCanvas.
*
* @param newPoint Specifies the new point of the currentPaintObject.
* @since 30.04.1999
*/
public void setPaintPoint(Point2D.Float nextPoint)
{
System.out.println("setPaintPoint");
if ((currentPaintObject.getStatus() == PaintObject.STATUS_BEGIN)||
(currentPaintObject.getStatus() == PaintObject.STATUS_WORK))
{
setWorkingShape(currentPaintObject.getMovePaintObject(getInverseTransformedPoint(nextPoint)));
}
}
/**
* Draws the current state of the paintStructure in the xorMode.
*
* @since 30.04.1999
*/
public void drawState(Graphics2D g2)
{
g2.setXORMode(xorColor);
if (oldPaintObject != null) oldPaintObject.drawTransformedShape(g2,aff);
if (currentPaintObject != null) currentPaintObject.drawTransformedShape(g2,aff);
}
/**
* Resets the paintStructure.
*
* @since 30.04.1999
*/
public void reset()
{
currentObject = null;
currentPaintObject = null;
oldPaintObject = null;
}
/**
* Gets the currentPaintObject
*
* @return The currentPaintObject.
* @since 30.04.1999
*/
public PaintObject getCurrentPaintObject()
{
return currentPaintObject;
}
/**
* Sets the currentPaintObject
*
* @param The new PaintObject.
* @since 30.04.1999
*/
public void setCurrentPaintObject(PaintObject newPaintObject)
{
currentPaintObject = newPaintObject;
}
/**
* Sets a new Point for moveAnn
*
* @param The new value
* @since 30.04.1999
*/
public void setMoveAnn(Point2D.Float newPoint)
{
moveAnn = newPoint;
}
/**
* Sets the Canvas in which the you can draw.
*
* @param imageCanvas The new Canvas.
* @since 30.04.1999
*/
public void setImageCanvas(JPanel imageCanvas)
{
this.imageCanvas = imageCanvas;
}
/**
* Returns the inverse transformed point form the AffineTransformation aff.
*
* @param displayPoint The transforming point.
* @return The inverse transformed point
* @since 30.04.1999
*/
public Point2D.Float getInverseTransformedPoint(Point2D.Float displayPoint)
{
Point2D.Float dstPoint = new Point2D.Float();
try
{
aff.inverseTransform(displayPoint,dstPoint);
}
catch(NoninvertibleTransformException e)
{
System.out.println("NoninvertibleTransformException: " + e);
}
return dstPoint;
}
/**
* Moves the currentObject if this object is a PresentationStateGraphicObject.
* The moving size and the direction depends form the Point moveAnn (defined in this
* class) and the specified point.
*
* @param point The next point where the currentObject have to moved.
* @since 30.04.1999
*/
public void movePresentationStateGraphicObject(Point2D.Float point)
{
//Creating the graphics2D
Graphics2D g2 = (Graphics2D)imageCanvas.getGraphics();
if (g2!= null)
{
try
{
g2.setXORMode(xorColor);
if (this.currentObject != null)
{
//Overwrites the old currentObject
currentObject.drawMarked(g2,aff);
currentObject.moveTo(moveAnn, point);
//writes the new currentObject
currentObject.drawMarked(g2,aff);
}
}
finally
{
g2.dispose();
}
moveAnn = point;
}
}
/**
* Moves the currentObject if this object is a PresentationStateTextObject
* to the specified point. There are two types of moving: First you can move
* the bounding box of the PresentationStateTextObject. Secoundly you can move
* the anchor point of the PresentationStateTextObject. Which type of moving
* is used depends from the properties of the PresentationStateTextObject.
*
* @param point The next point where the PresentationStateTextObject have to moved.
* @since 30.04.1999
*/
public void movePresentationStateTextObject(Point2D.Float point)
{
if (currentObject instanceof PresentationStateTextObject)
{
PresentationStateTextObject clickedText =(PresentationStateTextObject)currentObject;
//Creating the graphics2D
Graphics2D g2 = (Graphics2D)imageCanvas.getGraphics();
if (g2!= null)
{
try
{
g2.setXORMode(xorColor);
//clears the old text
if ((clickedText!= null)&&(clickedText.firstDraw == true))clickedText.draw(g2,aff, false);
clickedText.firstDraw = true;
//Draws the bunding box if needed
if (clickedText.needBox)
{
clickedText.setNewBoundingBox(g2,point,aff);
}
//draws the anchor point if needed
else if (clickedText.needAnchorPoint)
{
clickedText.setNewAnchor(g2,point,aff);
//Draws the new box
}
if (clickedText!= null)clickedText.draw(g2,aff, false);
}
finally
{
g2.dispose();
}
}
}
}
/**
* Draws the specified paintObject with the specified Color in
* the Graphics2D context of the imageCanvas.
*
* @param paintObject Specifies the drawing PaintObject
* @param color Specifies the drawing Color.
* @since 30.04.1999
*/
private void paintInImageCanvas(PaintObject paintObject, Color color)
{
//Creating the graphics2D
Graphics2D g2 = (Graphics2D)imageCanvas.getGraphics();
if (g2!= null)
{
try
{
//Overpainting the last shape
g2.setPaint(color);
if (paintObject != null) paintObject.drawTransformedShape(g2,aff);
}
finally
{
g2.dispose();
}
}
}
/**
* Sets the specified status to the currentPaintObject.
*
* @param status Specifies the new status of the current PaintObject
* @since 30.04.1999
*/
public void setCurrentStatus(int status, int applyTo)
{
getCurrentPaintObject().setStatus(status);
paintInImageCanvas(currentPaintObject, presentationStateGraphicsHandler.getCurrentColor());
presentationStateGraphicsHandler.newPaintObject(currentPaintObject,aff, applyTo);
}
/**
* Deletes the currentPaintobject, overwites the geometic representation
* in the imageCanvas in the xorMode, sets the specified
* PaintObject as the new PaintObejct and draws this object in the imageCanvas
* with the xorMode.
*
* @param thePaintObject Specifies the new PaintObject
* @since 30.04.1999
*/
public void setWorkingShape(PaintObject thePaintObject)
{
//Creating the graphics2D
Graphics2D g2 = (Graphics2D)imageCanvas.getGraphics();
if (g2!= null)
{
try
{
//Overpainting the last shape
g2.setXORMode(xorColor);
if (oldPaintObject != null) oldPaintObject.drawTransformedShape(g2,aff);
//Painting the new shape
if (thePaintObject != null) thePaintObject.drawTransformedShape(g2,aff);
}
finally
{
g2.dispose();
}
}
if (thePaintObject != null)
{
oldPaintObject= thePaintObject.copy();
}
else oldPaintObject = null;
}//setAktualShape
/**
* Sets a new currentObject and draws it with the xorMode in the imageCanvas
*
* @param newCurrentObject The new currentObject.
* @param redrawOld If true drwas the old currentObject with the xorMode in the imageCanvas.
* @since 30.04.1999
*/
public void setCurrentObject(PresentationStateLayerObject newCurrentObject,boolean redrawOld)
{
//Creating the graphics2D
Graphics2D g2 = (Graphics2D)imageCanvas.getGraphics();
if (g2!= null)
{
try
{
g2.setXORMode(xorColor);
if ((this.currentObject != null) && redrawOld)currentObject.drawMarked(g2,aff);
//Painting the new shape
if (newCurrentObject != null) newCurrentObject.drawMarked(g2,aff);
currentObject = newCurrentObject;
}
finally
{
g2.dispose();
}
}
}
}
/*
* CVS Log
* $Log: PaintStructure.java,v $
* Revision 1.1.1.1 2001/06/06 10:32:30 kleber
* Init commit for DICOMscope 3.5
* Create new CVS
*
*/
|