|
From: <nr...@us...> - 2011-07-27 14:46:06
|
Revision: 15727
http://dcm4che.svn.sourceforge.net/dcm4che/?rev=15727&view=rev
Author: nroduit
Date: 2011-07-27 14:45:54 +0000 (Wed, 27 Jul 2011)
Log Message:
-----------
Graphics improvement, parameters for portable version
Modified Paths:
--------------
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/GeomUtil.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/ViewTransferHandler.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicArea.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AngleToolGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/EllipseGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/FourPointsAngleToolGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/GraphicLabel.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/LineGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/OpenAngleToolGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/ParallelLineGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/PerpendicularLineGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/PolygonGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/RectangleGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/ThreePointsCircleGraphic.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-explorer/src/main/java/org/weasis/dicom/explorer/LoadLocalDicom.java
weasis/weasis_framework/trunk/weasis-distributions/etc/config/config.properties
weasis/weasis_framework/trunk/weasis-distributions/src/main/resources-portable/weasis-linux.sh
weasis/weasis_framework/trunk/weasis-distributions/src/main/resources-portable/weasis-mac.app/Contents/MacOS/weasis-mac.sh
Added Paths:
-----------
weasis/weasis_framework/trunk/weasis-launcher/src/main/java/org/weasis/launcher/messages_pt_BR.properties
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/GeomUtil.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/GeomUtil.java 2011-07-27 12:45:14 UTC (rev 15726)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/GeomUtil.java 2011-07-27 14:45:54 UTC (rev 15727)
@@ -10,45 +10,54 @@
public final class GeomUtil {
+ public static boolean isLineValid(Point2D ptA, Point2D ptB) {
+ return (ptA != null && ptB != null && !ptA.equals(ptB));
+ }
+
/**
- * @param A
- * @param B
- * @param C
- * @return
+ * @return angle between BA & BC line segment in Degree <br>
+ * 0 is returned if any argument is invalid
*/
- public static double getAngleRad(Point2D A, Point2D B, Point2D C) {
- if (A != null && B != null && C != null)
- return getAngleRad(B, C) - getAngleRad(B, A);
+ public static double getAngleRad(Point2D ptA, Point2D ptB, Point2D ptC) {
+ if (ptA != null && ptB != null && ptC != null)
+ return getAngleRad(ptB, ptC) - getAngleRad(ptB, ptA);
return 0;
}
- public static double getAngleDeg(Point2D A, Point2D B, Point2D C) {
- if (A != null && B != null && C != null)
- return Math.toDegrees(getAngleRad(A, B, C));
+ /**
+ * @return angle between BA & BC line segment in Radiant<br>
+ * 0 is returned if any argument is invalid
+ */
+ public static double getAngleDeg(Point2D ptA, Point2D ptB, Point2D ptC) {
+ if (ptA != null && ptB != null && ptC != null)
+ return Math.toDegrees(getAngleRad(ptA, ptB, ptC));
return 0;
}
/**
* Compute angle into image system basis where positive angle are defined in a ClockWise orientation<br>
- * Note : angle should be computed with "Math.atan2(B.getY() - A.getY(), B.getX() - A.getX())" in an orthonormal
- * basis system where positive angle are defined in a CounterClockWise orientation.
+ * Note : angle should be computed with "Math.atan2(ptB.getY() - ptA.getY(), ptB.getX() - ptA.getX())" in an
+ * ortho-normal basis system where positive angle is defined in a CounterClockWise orientation.
*
- * @param A
- * @param B
- * @return angle of AB line segment in radians
+ * @return angle of AB line segment in radiant<br>
+ * 0 is returned if any argument is invalid
*/
- public static double getAngleRad(Point2D A, Point2D B) {
- return Math.atan2(A.getY() - B.getY(), B.getX() - A.getX());
+ public static double getAngleRad(Point2D ptA, Point2D ptB) {
+ return (ptA != null && ptB != null) ? Math.atan2(ptA.getY() - ptB.getY(), ptB.getX() - ptA.getX()) : null;
}
- public static double getAngleDeg(Point2D A, Point2D B) {
- return Math.toDegrees(getAngleRad(A, B));
+ /**
+ * @return angle of AB line segment in radiant<br>
+ * 0 is returned if any argument is invalid
+ */
+ public static double getAngleDeg(Point2D ptA, Point2D ptB) {
+ return (ptA != null && ptB != null) ? Math.toDegrees(getAngleRad(ptA, ptB)) : null;
}
/**
* @param angle
- * in Radians
+ * in Radiant
* @return angle in the range of [ -pi ; pi ]
*/
public static double getSmallestRotationAngleRad(double angle) {
@@ -61,7 +70,7 @@
/**
* @param angle
- * in Degrees
+ * in Degree
* @return angle in the range of [ -180 ; 180 ]
*/
public static double getSmallestRotationAngleDeg(double angle) {
@@ -73,186 +82,207 @@
}
/**
- * @param A
- * @param B
- * @return
+ * @return midPoint or null if any argument is invalid
*/
- public static Point2D getMidPoint(Point2D A, Point2D B) {
- if (A != null && B != null)
- return new Point2D.Double((A.getX() + B.getX()) / 2.0, (A.getY() + B.getY()) / 2.0);
+ public static Point2D getMidPoint(Point2D ptA, Point2D ptB) {
+ if (ptA != null && ptB != null)
+ return new Point2D.Double((ptA.getX() + ptB.getX()) / 2.0, (ptA.getY() + ptB.getY()) / 2.0);
return null;
}
/**
- * @param A
+ * @param ptA
* the first point of line segment
- * @param B
+ * @param ptB
* the last point of line segment
* @param newLength
- * represents length from A to the return point C along AB line segment.<br>
- * If >AB , C point will be located on extension of AB<br>
- * If <0 , C point will be located on extension of BA <br>
- * If >0 && < AB , C point will be interior of AB<br>
- * @return New point C coordinates
+ * represents length from ptA to the return point ptC along AB line segment.<br>
+ * If >AB , ptC point will be located on extension of AB<br>
+ * If <0 , ptC point will be located on extension of BA <br>
+ * If >0 && < AB , ptC point will be interior of AB<br>
+ * @return New point ptC coordinates or null if any argument is invalid
*/
- public static Point2D getColinearPointWithLength(Point2D A, Point2D B, double newLength) {
- if (A != null && B != null)
- return getColinearPointWithRatio(A, B, newLength / A.distance(B));
+ public static Point2D getColinearPointWithLength(Point2D ptA, Point2D ptB, double newLength) {
+ if (ptA != null && ptB != null)
+ return getColinearPointWithRatio(ptA, ptB, newLength / ptA.distance(ptB));
return null;
}
/**
- * @param A
- * the first point of line segment
- * @param B
- * the last point of line segment
+ * @param ptA
+ * first point of line segment
+ * @param ptB
+ * last point of line segment
* @param k
- * represents ratio between AB and AC, C being the returned point along AB line segment.<br>
- * If >1 , C point will be located on extension of AB<br>
- * If <0 , C point will be located on extension of BA <br>
- * If >0 && <AB , C point will be interior of AB<br>
- * @return New point C coordinates
+ * represents ratio between AB and AC, ptC being the returned point along AB line segment.<br>
+ * If >1 , ptC point will be located on extension of AB<br>
+ * If <0 , ptC point will be located on extension of BA <br>
+ * If >0 && <AB , ptC point will be interior of AB<br>
+ * @return New point ptC coordinates or null if any argument is invalid
*/
- public static Point2D getColinearPointWithRatio(Point2D A, Point2D B, double k) {
- if (A != null && B != null)
- return new Point2D.Double(B.getX() * k + A.getX() * (1 - k), B.getY() * k + A.getY() * (1 - k));
+ public static Point2D getColinearPointWithRatio(Point2D ptA, Point2D ptB, double k) {
+ if (ptA != null && ptB != null)
+ return new Point2D.Double(ptB.getX() * k + ptA.getX() * (1 - k), ptB.getY() * k + ptA.getY() * (1 - k));
return null;
}
/**
- *
- * @param line1
- * @param line2
- * @return
+ * @return median line or null if any argument is invalid
*/
public static Line2D getMedianLine(Line2D line1, Line2D line2) {
if (line1 == null || line2 == null)
return null;
- Point2D A = line1.getP1(), B = line1.getP2();
- Point2D C = line2.getP1(), D = line2.getP2();
+ Point2D ptA = line1.getP1(), ptB = line1.getP2();
+ Point2D ptC = line2.getP1(), ptD = line2.getP2();
- Line2D line3 = new Line2D.Double(A, C);
- Line2D line4 = new Line2D.Double(B, D);
+ Line2D line3 = new Line2D.Double(ptA, ptC);
+ Line2D line4 = new Line2D.Double(ptB, ptD);
- Point2D M, N;
+ Point2D ptM, ptN;
if (line3.intersectsLine(line4)) {
- M = new Point2D.Double((A.getX() + D.getX()) / 2, (A.getY() + D.getY()) / 2);
- N = new Point2D.Double((B.getX() + C.getX()) / 2, (B.getY() + C.getY()) / 2);
+ ptM = new Point2D.Double((ptA.getX() + ptD.getX()) / 2, (ptA.getY() + ptD.getY()) / 2);
+ ptN = new Point2D.Double((ptB.getX() + ptC.getX()) / 2, (ptB.getY() + ptC.getY()) / 2);
} else {
- M = new Point2D.Double((A.getX() + C.getX()) / 2, (A.getY() + C.getY()) / 2);
- N = new Point2D.Double((B.getX() + D.getX()) / 2, (B.getY() + D.getY()) / 2);
+ ptM = new Point2D.Double((ptA.getX() + ptC.getX()) / 2, (ptA.getY() + ptC.getY()) / 2);
+ ptN = new Point2D.Double((ptB.getX() + ptD.getX()) / 2, (ptB.getY() + ptD.getY()) / 2);
}
- return new Line2D.Double(M, N);
+ return new Line2D.Double(ptM, ptN);
}
- public static Line2D getMedianLine(Point2D A, Point2D B, Point2D C, Point2D D) {
- return getMedianLine(new Line2D.Double(A, B), new Line2D.Double(C, D));
+ /**
+ * @return median line or null if any argument is invalid
+ */
+
+ public static Line2D getMedianLine(Point2D ptA, Point2D ptB, Point2D ptC, Point2D ptD) {
+ if (ptA == null || ptB == null || ptC == null || ptD == null)
+ return null;
+ return getMedianLine(new Line2D.Double(ptA, ptB), new Line2D.Double(ptC, ptD));
}
/**
+ * Let ptA,ptB,ptC,ptD be 2-space position vectors. .......
*
- * Let A,B,C,D be 2-space position vectors. .......
- *
- * @param A
- * @param B
- * @param C
- * @param D
* @return null if segment lines are parallel
*/
- public static Point2D getIntersectPoint(Point2D A, Point2D B, Point2D C, Point2D D) {
- Point2D P = null;
+ public static Point2D getIntersectPoint(Point2D ptA, Point2D ptB, Point2D ptC, Point2D ptD) {
+ if (ptA == null || ptB == null || ptC == null || ptD == null)
+ return null;
+ Point2D ptP = null;
+
double denominator =
- (B.getX() - A.getX()) * (D.getY() - C.getY()) - (B.getY() - A.getY()) * (D.getX() - C.getX());
+ (ptB.getX() - ptA.getX()) * (ptD.getY() - ptC.getY()) - (ptB.getY() - ptA.getY())
+ * (ptD.getX() - ptC.getX());
if (denominator != 0) {
double numerator =
- (A.getY() - C.getY()) * (D.getX() - C.getX()) - (A.getX() - C.getX()) * (D.getY() - C.getY());
+ (ptA.getY() - ptC.getY()) * (ptD.getX() - ptC.getX()) - (ptA.getX() - ptC.getX())
+ * (ptD.getY() - ptC.getY());
double r = numerator / denominator;
- P = new Point2D.Double(A.getX() + r * (B.getX() - A.getX()), A.getY() + r * (B.getY() - A.getY()));
+ ptP =
+ new Point2D.Double(ptA.getX() + r * (ptB.getX() - ptA.getX()), ptA.getY() + r
+ * (ptB.getY() - ptA.getY()));
}
- return P;
+ return ptP;
}
+ /**
+ * @return
+ */
public static Point2D getIntersectPoint(Line2D line1, Line2D line2) {
+ if (line1 == null || line2 == null)
+ return null;
return getIntersectPoint(line1.getP1(), line1.getP2(), line2.getP1(), line2.getP2());
}
- public static boolean lineParallel(Point2D A, Point2D B, Point2D C, Point2D D) {
- if (((B.getX() - A.getX()) * (D.getY() - C.getY()) - (B.getY() - A.getY()) * (D.getX() - C.getX())) == 0)
+ /**
+ * @return
+ */
+ public static boolean lineParallel(Point2D ptA, Point2D ptB, Point2D ptC, Point2D ptD) {
+ if (ptA == null || ptB == null || ptC == null || ptD == null)
+ throw new IllegalArgumentException("All the points must not be null");
+
+ if (((ptB.getX() - ptA.getX()) * (ptD.getY() - ptC.getY()) - (ptB.getY() - ptA.getY())
+ * (ptD.getX() - ptC.getX())) == 0)
return true;
return false;
}
- public static boolean lineColinear(Point2D A, Point2D B, Point2D C, Point2D D) {
- if (lineParallel(A, B, C, D))
- if (((A.getY() - C.getY()) * (D.getX() - C.getX()) - (A.getX() - C.getX()) * (D.getY() - C.getY())) == 0)
+ /**
+ * @return
+ */
+ public static boolean lineColinear(Point2D ptA, Point2D ptB, Point2D ptC, Point2D ptD) {
+ if (lineParallel(ptA, ptB, ptC, ptD))
+ if (((ptA.getY() - ptC.getY()) * (ptD.getX() - ptC.getX()) - (ptA.getX() - ptC.getX())
+ * (ptD.getY() - ptC.getY())) == 0)
return true;
-
return false;
}
/**
- *
- * @param A
- * @param B
- * @param C
* @return
*/
+ public static Point2D getPerpendicularPointToLine(Point2D ptA, Point2D ptB, Point2D ptC) {
+ if (ptA == null || ptB == null || ptA.equals(ptB) || ptC == null)
+ return null;
- public static Point2D getPerpendicularPointToLine(Point2D A, Point2D B, Point2D C) {
- double Ax = A.getX(), Ay = A.getY();
- double Bx = B.getX(), By = B.getY();
- double Cx = C.getX(), Cy = C.getY();
+ double ax = ptA.getX(), ay = ptA.getY();
+ double bx = ptB.getX(), by = ptB.getY();
+ double cx = ptC.getX(), cy = ptC.getY();
- double r = ((Ay - Cy) * (Ay - By) + (Ax - Cx) * (Ax - Bx)) / Point2D.distanceSq(Ax, Ay, Bx, By);
+ double r = ((ay - cy) * (ay - by) + (ax - cx) * (ax - bx)) / Point2D.distanceSq(ax, ay, bx, by);
- return new Point2D.Double(Ax + r * (Bx - Ax), Ay + r * (By - Ay));
+ return new Point2D.Double(ax + r * (bx - ax), ay + r * (by - ay));
}
- public static Point2D getPerpendicularPointToLine(Line2D L, Point2D C) {
- return getPerpendicularPointToLine(L.getP1(), L.getP2(), C);
+ public static Point2D getPerpendicularPointToLine(Line2D line, Point2D ptC) {
+ if (line == null || ptC == null)
+ return null;
+ return getPerpendicularPointToLine(line.getP1(), line.getP2(), ptC);
}
/**
* Find a point at a given perpendicular distance from a line
*
- * @param A
+ * @param ptA
* Start of line segment
- * @param B
+ * @param ptB
* End of line segment
- * @param P
+ * @param ptP
* Point of AB line
* @param distPC
- * Distance from line to return Point C <br>
+ * Distance from line to return Point ptC <br>
* If >0 angle between AB and PC is +90° <br>
* If <0 angle between AB and PC is -+90°
- * @return C point
+ * @return ptC point
*/
- public static Point2D getPerpendicularPointFromLine(Point2D A, Point2D B, Point2D P, double distPC) {
- double AB = A.distance(B);
- double ux = -(B.getY() - A.getY()) / AB;
- double uy = (B.getX() - A.getX()) / AB;
+ public static Point2D getPerpendicularPointFromLine(Point2D ptA, Point2D ptB, Point2D ptP, double distPC) {
+ if (ptA == null || ptB == null || ptA.equals(ptB) || ptP == null)
+ return null;
- return new Point2D.Double(P.getX() + distPC * ux, P.getY() + distPC * uy);
+ double distAB = ptA.distance(ptB);
+ double ux = -(ptB.getY() - ptA.getY()) / distAB;
+ double uy = (ptB.getX() - ptA.getX()) / distAB;
+
+ return new Point2D.Double(ptP.getX() + distPC * ux, ptP.getY() + distPC * uy);
}
- public static Point2D getPerpendicularPointFromLine(Point2D A, Point2D B, double distAP, double distPC) {
- return getPerpendicularPointFromLine(A, B, getColinearPointWithLength(A, B, distAP), distPC);
+ public static Point2D getPerpendicularPointFromLine(Point2D ptA, Point2D ptB, double distAP, double distPC) {
+ return getPerpendicularPointFromLine(ptA, ptB, getColinearPointWithLength(ptA, ptB, distAP), distPC);
}
/**
*
- * @param A
+ * @param ptA
* Start of line segment
- * @param B
+ * @param ptB
* End of line segment
* @param dist
* Distance from AB line to the parallel CD line <br>
@@ -260,15 +290,18 @@
* If <0 angle between AB and AC is -+90°
* @return
*/
- public static Line2D getParallelLine(Point2D A, Point2D B, double dist) {
- double AB = A.distanceSq(B);
- double ux = -(B.getY() - A.getY()) / AB;
- double uy = (B.getX() - A.getX()) / AB;
+ public static Line2D getParallelLine(Point2D ptA, Point2D ptB, double dist) {
+ if (ptA == null || ptB == null || ptA.equals(ptB))
+ return null;
- Point2D C = new Point2D.Double(A.getX() + dist * ux, A.getY() + dist * uy);
- Point2D D = new Point2D.Double(B.getX() + dist * ux, B.getY() + dist * uy);
+ double distAB2 = ptA.distanceSq(ptB);
+ double ux = -(ptB.getY() - ptA.getY()) / distAB2;
+ double uy = (ptB.getX() - ptA.getX()) / distAB2;
- return new Line2D.Double(C, D);
+ Point2D ptC = new Point2D.Double(ptA.getX() + dist * ux, ptA.getY() + dist * uy);
+ Point2D ptD = new Point2D.Double(ptB.getX() + dist * ux, ptB.getY() + dist * uy);
+
+ return new Line2D.Double(ptC, ptD);
}
/**
@@ -277,6 +310,9 @@
* @return
*/
public static Point2D getCircleCenter(List<Point2D> ptList) {
+ if (ptList == null)
+ return null;
+
switch (ptList.size()) {
case 3:
return getCircleCenter(ptList.get(0), ptList.get(1), ptList.get(2));
@@ -288,27 +324,34 @@
}
}
- public static Point2D getCircleCenter(Point2D a, Point2D b, Point2D c) {
- double ax = a.getX();
- double ay = a.getY();
- double bx = b.getX();
- double by = b.getY();
- double cx = c.getX();
- double cy = c.getY();
+ /**
+ * @return
+ */
+ public static Point2D getCircleCenter(Point2D ptA, Point2D ptB, Point2D ptC) {
+ if (ptA == null || ptB == null || ptC == null)
+ return null;
- double A = bx - ax;
- double B = by - ay;
- double C = cx - ax;
- double D = cy - ay;
- double E = A * (ax + bx) + B * (ay + by);
- double F = C * (ax + cx) + D * (ay + cy);
+ double ax = ptA.getX();
+ double ay = ptA.getY();
+ double bx = ptB.getX();
+ double by = ptB.getY();
+ double cx = ptC.getX();
+ double cy = ptC.getY();
- double G = 2 * (A * (cy - by) - B * (cx - bx));
- if (G == 0.0)
+ double c1 = bx - ax;
+ double c2 = by - ay;
+ double c3 = cx - ax;
+ double c4 = cy - ay;
+ double c5 = c1 * (ax + bx) + c2 * (ay + by);
+ double c6 = c3 * (ax + cx) + c4 * (ay + cy);
+
+ double denom = 2 * (c1 * (cy - by) - c2 * (cx - bx));
+
+ if (denom == 0.0)
return null; // a, b, c must be collinear
- double px = (D * E - B * F) / G;
- double py = (A * F - C * E) / G;
+ double px = (c4 * c5 - c2 * c6) / denom;
+ double py = (c1 * c6 - c3 * c5) / denom;
return new Point2D.Double(px, py);
}
@@ -324,7 +367,7 @@
public static double extractScalingFactor(AffineTransform transform) {
double scalingFactor = 1.0;
- if ((transform != null)) {
+ if (transform != null) {
double sx = transform.getScaleX();
double shx = transform.getShearX();
if (sx != 0 || shx != 0) {
@@ -346,7 +389,7 @@
public static double extractAngleRad(AffineTransform transform) {
double angleRad = 0.0;
- if ((transform != null)) {
+ if (transform != null) {
double sinTheta = transform.getShearY();
double cosTheta = transform.getScaleX();
@@ -382,7 +425,7 @@
* can be null
* @return null if either shape is null or scaling factor is zero
*/
- public static Shape getScaledShape(Shape shape, double scalingFactor, Point2D anchorPoint) {
+ public static Shape getScaledShape(final Shape shape, double scalingFactor, Point2D anchorPoint) {
if (shape == null || scalingFactor == 0)
return null;
@@ -403,41 +446,57 @@
return scaleTransform.createTransformedShape(shape);
}
- public static Rectangle2D getScaledRectangle(Rectangle2D rect, double scalingFactor) {
- if (rect == null)
- return null;
+ /**
+ * @return
+ */
+ public static Rectangle2D getScaledRectangle(final Rectangle2D rect, double scalingFactor) {
+ Rectangle2D newRect = null;
- if (scalingFactor != 1) {
+ if (rect != null && scalingFactor != 1) {
double resizedWidth = rect.getWidth() * scalingFactor;
double resizedHeight = rect.getHeight() * scalingFactor;
- rect.setRect(rect.getX(), rect.getY(), resizedWidth, resizedHeight);
+
+ newRect = (Rectangle2D) rect.clone();
+ newRect.setRect(rect.getX(), rect.getY(), resizedWidth, resizedHeight);
}
- return rect;
+ return newRect;
}
- public static Shape getCornerShape(Point2D A, Point2D O, Point2D B, double cornerSize) {
+ /**
+ * @return
+ */
+
+ public static Shape getCornerShape(Point2D ptA, Point2D ptO, Point2D ptB, double cornerSize) {
+ if (ptA == null || ptO == null || ptB == null || ptA.equals(ptO) || ptB.equals(ptO))
+ return null;
+
Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO, 2);
- Point2D I1 = GeomUtil.getColinearPointWithLength(O, A, cornerSize);
- Point2D I2 = GeomUtil.getColinearPointWithLength(O, B, cornerSize);
+ Point2D ptI1 = GeomUtil.getColinearPointWithLength(ptO, ptA, cornerSize);
+ Point2D ptI2 = GeomUtil.getColinearPointWithLength(ptO, ptB, cornerSize);
- double rotSignum = Math.signum(GeomUtil.getSmallestRotationAngleDeg(GeomUtil.getAngleDeg(B, O, A)));
- Point2D I3 = GeomUtil.getPerpendicularPointFromLine(O, A, I1, rotSignum * cornerSize);
+ double rotSignum = Math.signum(GeomUtil.getSmallestRotationAngleDeg(GeomUtil.getAngleDeg(ptB, ptO, ptA)));
+ Point2D ptI3 = GeomUtil.getPerpendicularPointFromLine(ptO, ptA, ptI1, rotSignum * cornerSize);
- path.append(new Line2D.Double(I1, I3), false);
- path.append(new Line2D.Double(I2, I3), false);
+ path.append(new Line2D.Double(ptI1, ptI3), false);
+ path.append(new Line2D.Double(ptI2, ptI3), false);
return path;
-
}
+ /**
+ * @return
+ */
public static Rectangle2D getGrowingRectangle(Rectangle2D rect, double growingSize) {
Rectangle2D growingRect = rect != null ? (Rectangle2D) rect.clone() : null;
growRectangle(growingRect, growingSize);
return growingRect;
}
+ /**
+ * @param growingSize
+ */
public static void growRectangle(Rectangle2D rect, double growingSize) {
if (rect == null)
return;
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/ViewTransferHandler.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/ViewTransferHandler.java 2011-07-27 12:45:14 UTC (rev 15726)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/ViewTransferHandler.java 2011-07-27 14:45:54 UTC (rev 15727)
@@ -83,13 +83,15 @@
TiledImage image = ImageFiler.getEmptyTiledImage(Color.BLACK, canvas.getWidth(), canvas.getHeight());
Graphics2D g = image.createGraphics();
if (g != null) {
- boolean aononymOld = canvas.getInfoLayer().getDisplayPreferences(AnnotationsLayer.ANONYM_ANNOTATIONS);
- if (!aononymOld) {
+ boolean anonymAnnotationsStatus =
+ canvas.getInfoLayer().getDisplayPreferences(AnnotationsLayer.ANONYM_ANNOTATIONS);
+ if (!anonymAnnotationsStatus) {
canvas.getInfoLayer().setDisplayPreferencesValue(AnnotationsLayer.ANONYM_ANNOTATIONS, true);
}
canvas.draw(g);
g.dispose();
- if (!aononymOld) {
+
+ if (!anonymAnnotationsStatus) {
canvas.getInfoLayer().setDisplayPreferencesValue(AnnotationsLayer.ANONYM_ANNOTATIONS, false);
}
}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java 2011-07-27 12:45:14 UTC (rev 15726)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java 2011-07-27 14:45:54 UTC (rev 15727)
@@ -11,7 +11,6 @@
package org.weasis.core.ui.graphic;
-import java.awt.AWTException;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
@@ -33,6 +32,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
+import java.util.Map;
+import java.util.TreeMap;
import javax.swing.SwingUtilities;
@@ -177,13 +178,46 @@
return handlePointList.size() == handlePointTotalNumber;
}
+ public void addHandlePoint(Point2D handlePt) {
+ handlePointList.add(handlePt);
+ }
+
public Point2D getHandlePoint(int index) {
- if (index < 0 || index >= handlePointList.size())
- return null;
- Point2D handlePoint = handlePointList.get(index);
- return (handlePoint != null) ? (Point2D) handlePointList.get(index).clone() : null;
+ Point2D handlePoint = null;
+
+ if (index >= 0 && index < handlePointList.size()) {
+ if ((handlePoint = handlePointList.get(index)) != null) {
+ handlePoint = (Point2D) handlePoint.clone();
+ }
+ }
+ return handlePoint;
}
+ public List<Point2D> getHandlePointList() {
+ List<Point2D> handlePointListcopy = new ArrayList<Point2D>(handlePointList.size());
+
+ for (Point2D handlePt : handlePointList) {
+ handlePointListcopy.add(handlePt != null ? (Point2D) handlePt.clone() : null);
+ }
+
+ return handlePointListcopy;
+
+ }
+
+ public void setHandlePoint(int index, Point2D newPoint) {
+ if (index >= 0 && index <= handlePointList.size()) {
+ if (index == handlePointList.size()) {
+ handlePointList.add(newPoint);
+ } else {
+ handlePointList.set(index, newPoint);
+ }
+ }
+ }
+
+ public int getHandlePointListSize() {
+ return handlePointList.size();
+ }
+
@Override
public String getDescription() {
return "";
@@ -199,19 +233,22 @@
DefaultView2d<?> graphPane = getDefaultView2d(event);
if (graphPane != null) {
- Point2D p = getHandlePoint(handlePtIndex);
+ Point2D handlePt = null;
- if (p != null) {
- Point mp = graphPane.getMouseCoordinatesFromImage(p.getX(), p.getY());
+ if (handlePtIndex >= 0 && handlePtIndex < handlePointList.size()) {
+ handlePt = handlePointList.get(handlePtIndex);
+ }
- if (event.getX() != mp.x || event.getY() != mp.y) {
+ if (handlePt != null) {
+ Point mousePt = graphPane.getMouseCoordinatesFromImage(handlePt.getX(), handlePt.getY());
+
+ if (event.getX() != mousePt.x || event.getY() != mousePt.y) {
try {
- event.translatePoint(mp.x - event.getX(), mp.y - event.getY());
- // event = new MouseEventDouble(event, mp.x, mp.y);
- event.setImageCoordinates(p);
- SwingUtilities.convertPointToScreen(mp, graphPane);
- new Robot().mouseMove(mp.x, mp.y);
- } catch (AWTException e1) {
+ event.translatePoint(mousePt.x - event.getX(), mousePt.y - event.getY());
+ event.setImageCoordinates(handlePt);
+ SwingUtilities.convertPointToScreen(mousePt, graphPane);
+ new Robot().mouseMove(mousePt.x, mousePt.y);
+ } catch (Exception doNothing) {
}
}
}
@@ -309,7 +346,7 @@
Rectangle2D bounds = shape.getBounds2D();
// Add pixel tolerance to ensure that the graphic is correctly repainted
- double growingSize = Math.max(handleSize * 1.5 / 2.0, lineThickness / 2.0) + 6;
+ double growingSize = Math.max(handleSize * 1.5 / 2.0, lineThickness / 2.0) + 2;
growingSize /= GeomUtil.extractScalingFactor(transform);
GeomUtil.growRectangle(bounds, growingSize);
@@ -352,22 +389,52 @@
/**
* @return selected handle point index if exist, otherwise -1
*/
- public int getHandlePointIndex(MouseEventDouble mouseevent) {
- if (mouseevent != null) {
- final Point2D mousePoint = mouseevent.getImageCoordinates();
+ public int getHandlePointIndex(MouseEventDouble mouseEvent) {
- double maxHandleDistance = handleSize * 1.5 / 2.0; // half diagonal of handle point rectangle
- maxHandleDistance /= GeomUtil.extractScalingFactor(getAffineTransform(mouseevent));
+ int nearestHandlePtIndex = -1;
+ final Point2D mousePoint = (mouseEvent != null) ? mouseEvent.getImageCoordinates() : null;
+ if (mousePoint != null && handlePointList.size() > 0) {
+ double minHandleDistance = Double.MAX_VALUE;
+ double maxHandleDistance = handleSize * 1.5 / GeomUtil.extractScalingFactor(getAffineTransform(mouseEvent));
+
for (int index = 0; index < handlePointList.size(); index++) {
Point2D handlePoint = handlePointList.get(index);
- if (mousePoint != null && handlePoint != null && mousePoint.distance(handlePoint) <= maxHandleDistance)
- return index;
+ double handleDistance = (handlePoint != null) ? mousePoint.distance(handlePoint) : Double.MAX_VALUE;
+
+ if (handleDistance <= maxHandleDistance && handleDistance < minHandleDistance) {
+ minHandleDistance = handleDistance;
+ nearestHandlePtIndex = index;
+ }
}
}
- return -1;
+ return nearestHandlePtIndex;
}
+ public List<Integer> getHandlePointIndexList(MouseEventDouble mouseEvent) {
+
+ Map<Double, Integer> indexByDistanceMap = null;
+ final Point2D mousePoint = (mouseEvent != null) ? mouseEvent.getImageCoordinates() : null;
+
+ if (mousePoint != null && handlePointList.size() > 0) {
+ double maxHandleDistance = handleSize * 1.5 / GeomUtil.extractScalingFactor(getAffineTransform(mouseEvent));
+
+ for (int index = 0; index < handlePointList.size(); index++) {
+ Point2D handlePoint = handlePointList.get(index);
+ double handleDistance = (handlePoint != null) ? mousePoint.distance(handlePoint) : Double.MAX_VALUE;
+
+ if (handleDistance <= maxHandleDistance) {
+ if (indexByDistanceMap == null) {
+ indexByDistanceMap = new TreeMap<Double, Integer>();
+ }
+ indexByDistanceMap.put(handleDistance, index);
+ }
+ }
+ }
+
+ return (indexByDistanceMap != null) ? new ArrayList<Integer>(indexByDistanceMap.values()) : null;
+ }
+
public boolean isOnGraphicLabel(MouseEventDouble mouseevent) {
if (mouseevent == null)
return false;
@@ -805,20 +872,23 @@
* @return True when not handle points equals each another. <br>
*/
public boolean isShapeValid() {
- if (isGraphicComplete()) {
- int lastPointIndex = handlePointList.size() - 1;
+ if (!isGraphicComplete())
+ return false;
- while (lastPointIndex > 0) {
- Point2D checkPoint = getHandlePoint(lastPointIndex);
- ListIterator<Point2D> listIt = handlePointList.listIterator(lastPointIndex--);
- while (listIt.hasPrevious()) {
- if (checkPoint != null && checkPoint.equals(listIt.previous()))
- return false;
- }
+ int lastPointIndex = handlePointList.size() - 1;
+
+ while (lastPointIndex > 0) {
+ Point2D checkPoint = handlePointList.get(lastPointIndex);
+
+ ListIterator<Point2D> listIt = handlePointList.listIterator(lastPointIndex--);
+
+ while (listIt.hasPrevious()) {
+ if (checkPoint != null && checkPoint.equals(listIt.previous()))
+ return false;
}
- return true;
- } else
- return false;
+ }
+ return true;
+
}
/**
@@ -826,12 +896,10 @@
*/
protected final boolean isLastPointValid() {
- Point2D lastP = getHandlePoint(handlePointList.size() - 1);
- if (lastP != null) {
- if (lastP.equals(getHandlePoint(handlePointList.size() - 2)))
- return false;
- }
- return true;
+ Point2D lastPt = handlePointList.size() > 0 ? handlePointList.get(handlePointList.size() - 1) : null;
+ Point2D previousPt = handlePointList.size() > 1 ? handlePointList.get(handlePointList.size() - 2) : null;
+
+ return lastPt == null || !lastPt.equals(previousPt);
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1017,26 +1085,10 @@
return handlePointIndex;
}
- protected abstract void updateShapeOnDrawing(MouseEventDouble mouseevent);
+ protected abstract void updateShapeOnDrawing(MouseEventDouble mouseEvent);
// /////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////
-
- public interface eHandlePoint {
- Point2D get(AbstractDragGraphic graphic);
- }
-
- static boolean isLineValid(eHandlePoint eP1, eHandlePoint eP2, AbstractDragGraphic g) {
- if (eP1 == null || eP2 == null || g == null)
- return false;
-
- Point2D p1 = eP1.get(g), p2 = eP2.get(g);
- return p1 != null && p2 != null && !p2.equals(p1);
- }
-
- // /////////////////////////////////////////////////////////////////////////////////////////////////////
- // /////////////////////////////////////////////////////////////////////////////////////////////////////
-
public class AdvancedShape implements Shape {
/**
@@ -1098,7 +1150,7 @@
if (scalingMin < 0)
throw new IllegalArgumentException();
- this.anchorPoint = anchorPoint;
+ this.anchorPoint = (Point2D) anchorPoint.clone();
this.scalingMin = scalingMin;
}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicArea.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicArea.java 2011-07-27 12:45:14 UTC (rev 15726)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicArea.java 2011-07-27 14:45:54 UTC (rev 15727)
@@ -31,10 +31,10 @@
*/
public abstract class AbstractDragGraphicArea extends AbstractDragGraphic {
- public static final Measurement ImageMean = new Measurement("Mean", false, true, true);
- public static final Measurement ImageMin = new Measurement("Min", false, true, false);
- public static final Measurement ImageMax = new Measurement("Max", false, true, false);
- public static final Measurement ImageSTD = new Measurement("StDev", false, true, false);
+ public static final Measurement IMAGE_MEAN = new Measurement("Mean", false, true, true);
+ public static final Measurement IMAGE_MIN = new Measurement("Min", false, true, false);
+ public static final Measurement IMAGE_MAX = new Measurement("Max", false, true, false);
+ public static final Measurement IMAGE_STD = new Measurement("StDev", false, true, false);
// /////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -71,10 +71,10 @@
}
public List<MeasureItem> getImageStatistics(ImageElement imageElement, boolean releaseEvent) {
- if (imageElement != null && shape != null) {
+ if (imageElement != null && isShapeValid()) {
ArrayList<MeasureItem> measVal = new ArrayList<MeasureItem>(5);
- if (ImageMin.isComputed() || ImageMax.isComputed() || ImageMean.isComputed() || ImageSTD.isComputed()) {
+ if (IMAGE_MIN.isComputed() || IMAGE_MAX.isComputed() || IMAGE_MEAN.isComputed() || IMAGE_STD.isComputed()) {
Double min = null;
Double max = null;
Double stdv = null;
@@ -143,44 +143,44 @@
}
}
String unit = imageElement.getPixelValueUnit() == null ? "" : imageElement.getPixelValueUnit(); //$NON-NLS-1$
- // if (ImageMin.isComputed() && (releaseEvent || ImageMin.isGraphicLabel())) {
- if (ImageMin.isComputed()) {
- Double val = releaseEvent || ImageMin.isQuickComputing() ? min : null;
- measVal.add(new MeasureItem(ImageMin, val, unit));
+
+ if (IMAGE_MIN.isComputed()) {
+ Double val = releaseEvent || IMAGE_MIN.isQuickComputing() ? min : null;
+ measVal.add(new MeasureItem(IMAGE_MIN, val, unit));
}
- // if (ImageMax.isComputed() && (releaseEvent || ImageMax.isGraphicLabel())) {
- if (ImageMax.isComputed()) {
- Double val = releaseEvent || ImageMax.isQuickComputing() ? max : null;
- measVal.add(new MeasureItem(ImageMax, val, unit));
+
+ if (IMAGE_MAX.isComputed()) {
+ Double val = releaseEvent || IMAGE_MAX.isQuickComputing() ? max : null;
+ measVal.add(new MeasureItem(IMAGE_MAX, val, unit));
}
- // if (ImageSTD.isComputed() && (releaseEvent || ImageSTD.isGraphicLabel())) {
- if (ImageSTD.isComputed()) {
- Double val = releaseEvent || ImageSTD.isQuickComputing() ? stdv : null;
- measVal.add(new MeasureItem(ImageSTD, val, unit));
+
+ if (IMAGE_STD.isComputed()) {
+ Double val = releaseEvent || IMAGE_STD.isQuickComputing() ? stdv : null;
+ measVal.add(new MeasureItem(IMAGE_STD, val, unit));
}
- // if (ImageMean.isComputed() && (releaseEvent || ImageMean.isGraphicLabel())) {
- if (ImageMean.isComputed()) {
- Double val = releaseEvent || ImageMean.isQuickComputing() ? mean : null;
- measVal.add(new MeasureItem(ImageMean, val, unit));
+
+ if (IMAGE_MEAN.isComputed()) {
+ Double val = releaseEvent || IMAGE_MEAN.isQuickComputing() ? mean : null;
+ measVal.add(new MeasureItem(IMAGE_MEAN, val, unit));
}
Double suv = (Double) imageElement.getTagValue(TagW.SuvFactor);
if (suv != null) {
unit = "SUV (bw)";
- if (ImageMin.isComputed()) {
+ if (IMAGE_MIN.isComputed()) {
Double val =
- releaseEvent || ImageMin.isQuickComputing() ? min == null ? null : min * suv : null;
- measVal.add(new MeasureItem(ImageMin, val, unit));
+ releaseEvent || IMAGE_MIN.isQuickComputing() ? min == null ? null : min * suv : null;
+ measVal.add(new MeasureItem(IMAGE_MIN, val, unit));
}
- if (ImageMax.isComputed()) {
+ if (IMAGE_MAX.isComputed()) {
Double val =
- releaseEvent || ImageMax.isQuickComputing() ? max == null ? null : max * suv : null;
- measVal.add(new MeasureItem(ImageMax, val, unit));
+ releaseEvent || IMAGE_MAX.isQuickComputing() ? max == null ? null : max * suv : null;
+ measVal.add(new MeasureItem(IMAGE_MAX, val, unit));
}
- if (ImageMean.isComputed()) {
+ if (IMAGE_MEAN.isComputed()) {
Double val =
- releaseEvent || ImageMean.isQuickComputing() ? mean == null ? null : mean * suv : null;
- measVal.add(new MeasureItem(ImageMean, val, unit));
+ releaseEvent || IMAGE_MEAN.isQuickComputing() ? mean == null ? null : mean * suv : null;
+ measVal.add(new MeasureItem(IMAGE_MEAN, val, unit));
}
}
}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AngleToolGraphic.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AngleToolGraphic.java 2011-07-27 12:45:14 UTC (rev 15726)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AngleToolGraphic.java 2011-07-27 14:45:54 UTC (rev 15727)
@@ -35,14 +35,14 @@
public static final Icon ICON = new ImageIcon(AngleToolGraphic.class.getResource("/icon/22x22/draw-angle.png")); //$NON-NLS-1$
- public static final Measurement Angle = new Measurement("Angle", true);
- public static final Measurement ComplementaryAngle = new Measurement("Compl. Angle", true, true, false);
+ public static final Measurement ANGLE = new Measurement("Angle", true);
+ public static final Measurement COMPLEMENTARY_ANGLE = new Measurement("Compl. Angle", true, true, false);
// /////////////////////////////////////////////////////////////////////////////////////////////////////
- Point2D A, O, B; // Let AOB be the triangle that represents the measured angle, O being the intersection point
+ Point2D ptA, ptO, ptB; // Let AOB be the triangle that represents the measured angle, O being the intersection point
boolean lineColinear; // estimate if OA & OB line segments are colinear not not
- boolean OAvalid, OBvalid; // estimate if line segments are valid or not
+ boolean lineOAvalid, lineOBvalid; // estimate if line segments are valid or not
double angleDeg; // smallest angle in Degrees in the range of [-180 ; 180] between OA & OB line segments
@@ -70,31 +70,31 @@
Shape newShape = null;
Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO, 2);
- if (OAvalid) {
- path.append(new Line2D.Double(A, O), false);
+ if (lineOAvalid) {
+ path.append(new Line2D.Double(ptA, ptO), false);
}
- if (OBvalid) {
- path.append(new Line2D.Double(O, B), false);
+ if (lineOBvalid) {
+ path.append(new Line2D.Double(ptO, ptB), false);
}
- if (OAvalid && OBvalid && !lineColinear) {
+ if (lineOAvalid && lineOBvalid && !lineColinear) {
AdvancedShape aShape = (AdvancedShape) (newShape = new AdvancedShape(2));
aShape.addShape(path);
// Let arcAngle be the partial section of the ellipse that represents the measured angle
- double startingAngle = GeomUtil.getAngleDeg(O, A);
+ double startingAngle = GeomUtil.getAngleDeg(ptO, ptA);
double radius = 32;
Rectangle2D arcAngleBounds =
- new Rectangle2D.Double(O.getX() - radius, O.getY() - radius, 2 * radius, 2 * radius);
+ new Rectangle2D.Double(ptO.getX() - radius, ptO.getY() - radius, 2 * radius, 2 * radius);
Shape arcAngle = new Arc2D.Double(arcAngleBounds, startingAngle, angleDeg, Arc2D.OPEN);
- double rMax = Math.min(O.distance(A), O.distance(B)) * 2 / 3;
+ double rMax = Math.min(ptO.distance(ptA), ptO.distance(ptB)) * 2 / 3;
double scalingMin = radius / rMax;
- aShape.addInvShape(arcAngle, O, scalingMin, true);
+ aShape.addInvShape(arcAngle, ptO, scalingMin, true);
} else if (path.getCurrentPoint() != null) {
newShape = path;
@@ -113,16 +113,16 @@
if (adapter != null) {
ArrayList<MeasureItem> measVal = new ArrayList<MeasureItem>();
- if (Angle.isComputed() || ComplementaryAngle.isComputed()) {
+ if (ANGLE.isComputed() || COMPLEMENTARY_ANGLE.isComputed()) {
double positiveAngle = Math.abs(angleDeg);
- if (Angle.isComputed() && (!drawOnLabel || Angle.isGraphicLabel())) {
- measVal.add(new MeasureItem(Angle, positiveAngle, "deg"));
+ if (ANGLE.isComputed() && (!drawOnLabel || ANGLE.isGraphicLabel())) {
+ measVal.add(new MeasureItem(ANGLE, positiveAngle, "deg"));
}
- if (ComplementaryAngle.isComputed() && (!drawOnLabel || ComplementaryAngle.isGraphicLabel())) {
- measVal.add(new MeasureItem(ComplementaryAngle, 180.0 - positiveAngle, "deg"));
+ if (COMPLEMENTARY_ANGLE.isComputed() && (!drawOnLabel || COMPLEMENTARY_ANGLE.isGraphicLabel())) {
+ measVal.add(new MeasureItem(COMPLEMENTARY_ANGLE, 180.0 - positiveAngle, "deg"));
}
}
return measVal;
@@ -134,18 +134,18 @@
@Override
public boolean isShapeValid() {
updateTool();
- return OAvalid && OBvalid;
+ return lineOAvalid && lineOBvalid;
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////
protected void init() {
- A = handlePointList.size() >= 1 ? handlePointList.get(0) : null;
- O = handlePointList.size() >= 2 ? handlePointList.get(1) : null;
- B = handlePointList.size() >= 3 ? handlePointList.get(2) : null;
+ ptA = getHandlePoint(0);
+ ptO = getHandlePoint(1);
+ ptB = getHandlePoint(2);
lineColinear = false;
- OAvalid = OBvalid = false;
+ lineOAvalid = lineOBvalid = false;
angleDeg = 0.0;
}
@@ -153,12 +153,12 @@
protected void updateTool() {
init();
- OAvalid = (A != null && O != null && !O.equals(A));
- OBvalid = (B != null && O != null && !O.equals(B));
+ lineOAvalid = (ptA != null && ptO != null && !ptO.equals(ptA));
+ lineOBvalid = (ptB != null && ptO != null && !ptO.equals(ptB));
- if (OAvalid && OBvalid) {
- angleDeg = GeomUtil.getSmallestRotationAngleDeg(GeomUtil.getAngleDeg(A, O, B));
- lineColinear = GeomUtil.lineColinear(O, A, O, B);
+ if (lineOAvalid && lineOBvalid) {
+ angleDeg = GeomUtil.getSmallestRotationAngleDeg(GeomUtil.getAngleDeg(ptA, ptO, ptB));
+ lineColinear = GeomUtil.lineColinear(ptO, ptA, ptO, ptB);
}
}
}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java 2011-07-27 12:45:14 UTC (rev 15726)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java 2011-07-27 14:45:54 UTC (rev 15727)
@@ -32,12 +32,12 @@
public static final Icon ICON = new ImageIcon(CobbAngleToolGraphic.class.getResource("/icon/22x22/draw-cobb.png")); //$NON-NLS-1$
- public static final Measurement Angle = new Measurement("Angle", true);
- public static final Measurement ComplementaryAngle = new Measurement("Compl. Angle", true, true, false);
+ public static final Measurement ANGLE = new Measurement("Angle", true);
+ public static final Measurement COMPLEMENTARY_ANGLE = new Measurement("Compl. Angle", true, true, false);
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Let O be center of perpendicular projections in Cobb's angle
- protected Point2D O;
+ protected Point2D ptO;
// ///////////////////////////////////////////////////////////////////////////////////////////////////
public CobbAngleToolGraphic(float lineThickness, Color paintColor, boolean labelVisible) {
@@ -61,47 +61,47 @@
if (handlePointIndex != -1 && handlePointList.size() >= 4) {
updateTool();
- if (ABvalid && CDvalid) {
+ if (lineABvalid && lineCDvalid) {
// Let MN be the bisector of the two line segments AB & CD, if parallel MN is the median line
Line2D lineMN;
- if (lineParallel) {
- lineMN = GeomUtil.getMedianLine(A, B, C, D);
+ if (linesParallel) {
+ lineMN = GeomUtil.getMedianLine(ptA, ptB, ptC, ptD);
} else {
AffineTransform rotate =
- AffineTransform.getRotateInstance(-Math.toRadians(angleDeg) / 2, P.getX(), P.getY());
+ AffineTransform.getRotateInstance(-Math.toRadians(angleDeg) / 2, ptP.getX(), ptP.getY());
- Point2D M = (Point2D) ABPline[0].clone();
- rotate.transform(M, M);
- lineMN = new Line2D.Double(M, P);
+ Point2D ptM = (Point2D) lineABP[0].clone();
+ rotate.transform(ptM, ptM);
+ lineMN = new Line2D.Double(ptM, ptP);
}
- if (handlePointIndex == 4 && O != null) {
- O = GeomUtil.getPerpendicularPointToLine(lineMN, O);
+ if (handlePointIndex == 4 && ptO != null) {
+ ptO = GeomUtil.getPerpendicularPointToLine(lineMN, ptO);
} else {
- if (lineParallel) {
- O = GeomUtil.getMidPoint(lineMN.getP1(), lineMN.getP1());
+ if (linesParallel) {
+ ptO = GeomUtil.getMidPoint(lineMN.getP1(), lineMN.getP1());
} else {
// Point2D H1 = GeomUtil.getColinearPointWithRatio(ABPline[0], ABPline[1], 3 / 4);
// Point2D H2 = GeomUtil.getColinearPointWithRatio(CDPline[0], CDPline[1], 3 / 4);
- Point2D H1 = GeomUtil.getMidPoint(ABPline[1], GeomUtil.getMidPoint(ABPline[0], ABPline[1]));
- Point2D H2 = GeomUtil.getMidPoint(CDPline[1], GeomUtil.getMidPoint(CDPline[0], CDPline[1]));
+ Point2D H1 = GeomUtil.getMidPoint(lineABP[1], GeomUtil.getMidPoint(lineABP[0], lineABP[1]));
+ Point2D H2 = GeomUtil.getMidPoint(lineCDP[1], GeomUtil.getMidPoint(lineCDP[0], lineCDP[1]));
Point2D O1 = GeomUtil.getPerpendicularPointToLine(lineMN, H1);
Point2D O2 = GeomUtil.getPerpendicularPointToLine(lineMN, H2);
- O = GeomUtil.getMidPoint(O1, O2);
+ ptO = GeomUtil.getMidPoint(O1, O2);
}
}
} else {
- O = null;
+ ptO = null;
}
if (handlePointList.size() < 5) {
- handlePointList.add(O);
+ handlePointList.add(ptO);
} else {
- handlePointList.set(4, O);
+ handlePointList.set(4, ptO);
}
}
@@ -115,88 +115,87 @@
Shape newShape = null;
Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO, 6);
- if (ABvalid) {
- path.append(new Line2D.Double(A, B), false);
+ if (lineABvalid) {
+ path.append(new Line2D.Double(ptA, ptB), false);
}
- if (CDvalid) {
- path.append(new Line2D.Double(C, D), false);
+ if (lineCDvalid) {
+ path.append(new Line2D.Double(ptC, ptD), false);
}
- if (ABvalid && CDvalid && O != null) {
- // TODO Fix refresh issue. Very very very bad practice to pass the class Point2D instance to different shape
- // that can be modified !!!
- Point2D O = (Point2D) this.O.clone();
+ if (lineABvalid && lineCDvalid && ptO != null) {
+
AdvancedShape aShape = (AdvancedShape) (newShape = new AdvancedShape(10));
aShape.addShape(path);
- double Ax = A.getX(), Ay = A.getY();
- double Bx = B.getX(), By = B.getY();
- double Cx = C.getX(), Cy = C.getY();
- double Dx = D.getX(), Dy = D.getY();
+ double ax = ptA.getX(), ay = ptA.getY();
+ double bx = ptB.getX(), by = ptB.getY();
+ double cx = ptC.getX(), cy = ptC.getY();
+ double dx = ptD.getX(), dy = ptD.getY();
// Let I be the perpendicular projection of O onto AB
// Let J be the perpendicular projection of O onto CD
- double distAB2 = Point2D.distanceSq(Ax, Ay, Bx, By);
- double distCD2 = Point2D.distanceSq(Cx, Cy, Dx, Dy);
+ double distAB2 = Point2D.distanceSq(ax, ay, bx, by);
+ double distCD2 = Point2D.distanceSq(cx, cy, dx, dy);
- double r1 = ((Ay - O.getY()) * (Ay - By) + (Ax - O.getX()) * (Ax - Bx)) / distAB2;
- double r2 = ((Cy - O.getY()) * (Cy - Dy) + (Cx - O.getX()) * (Cx - Dx)) / distCD2;
+ double r1 = ((ay - ptO.getY()) * (ay - by) + (ax - ptO.getX()) * (ax - bx)) / distAB2;
+ double r2 = ((cy - ptO.getY()) * (cy - dy) + (cx - ptO.getX()) * (cx - dx)) / distCD2;
- final Point2D I = new Point2D.Double(Ax + r1 * (Bx - Ax), Ay + r1 * (By - Ay));
- final Point2D J = new Point2D.Double(Cx + r2 * (Dx - Cx), Cy + r2 * (Dy - Cy));
+ final Point2D ptI = new Point2D.Double(ax + r1 * (bx - ax), ay + r1 * (by - ay));
+ final Point2D ptJ = new Point2D.Double(cx + r2 * (dx - cx), cy + r2 * (dy - cy));
if (r1 < 0 || r1 > 1) {
- aShape.addShape(new Line2D.Double(r1 > 1 ? B : A, I), getDashStroke(1.0f), true);
+ aShape.addShape(new Line2D.Double(r1 > 1 ? ptB : ptA, ptI), getDashStroke(1.0f), true);
}
if (r2 < 0 || r2 > 1) {
- aShape.addShape(new Line2D.Double(r1 > 1 ? D : C, J), getDashStroke(1.0f), true);
+ aShape.addShape(new Line2D.Double(r1 > 1 ? ptD : ptC, ptJ), getDashStroke(1.0f), true);
}
- aShape.addShape(new Line2D.Double(O, I));
- aShape.addShape(new Line2D.Double(O, J));
+ aShape.addShape(new Line2D.Double(ptO, ptI));
+ aShape.addShape(new Line2D.Double(ptO, ptJ));
// Add angle corners where I & J lies on AB & CD line segments
double cLength = 10;
- double cImax = (2.0 / 3.0) * Math.min(O.distance(I), Math.max(I.distance(A), I.distance(B)));
- aShape.addInvShape(GeomUtil.getCornerShape(GeomUtil.getMidPoint(A, B), I, O, cLength), I, cLength / cImax,
- getStroke(1.0f), true);
+ double cImax = (2.0 / 3.0) * Math.min(ptO.distance(ptI), Math.max(ptI.distance(ptA), ptI.distance(ptB)));
+ aShape.addInvShape(GeomUtil.getCornerShape(GeomUtil.getMidPoint(ptA, ptB), ptI, ptO, cLength), ptI, cLength
+ / cImax, getStroke(1.0f), true);
- double cJmax = (2.0 / 3.0) * Math.min(O.distance(J), Math.max(J.distance(C), J.distance(D)));
- aShape.addInvShape(GeomUtil.getCornerShape(GeomUtil.getMidPoint(C, D), J, O, cLength), J, cLength / cJmax,
- getStroke(1.0f), true);
+ double cJmax = (2.0 / 3.0) * Math.min(ptO.distance(ptJ), Math.max(ptJ.distance(ptC), ptJ.distance(ptD)));
+ aShape.addInvShape(GeomUtil.getCornerShape(GeomUtil.getMidPoint(ptC, ptD), ptJ, ptO, cLength), ptJ, cLengt...
[truncated message content] |