Revision 228 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrame.java
FFrame.java | ||
---|---|---|
29 | 29 |
import java.awt.Rectangle; |
30 | 30 |
import java.awt.event.MouseEvent; |
31 | 31 |
import java.awt.geom.AffineTransform; |
32 |
import java.awt.geom.Area; |
|
33 |
import java.awt.geom.NoninvertibleTransformException; |
|
32 | 34 |
import java.awt.geom.Point2D; |
33 | 35 |
import java.awt.geom.Rectangle2D; |
34 | 36 |
import java.awt.image.BufferedImage; |
... | ... | |
851 | 853 |
public void setDocument(Document document) { |
852 | 854 |
this.document = document; |
853 | 855 |
} |
856 |
|
|
857 |
/** |
|
858 |
* Gets the visible rectangle of the frame, taking rotation into |
|
859 |
* consideration. The result of this method is the rectangular area |
|
860 |
* of the unrotated frame that will be visible when the frame gets |
|
861 |
* rotated. |
|
862 |
* |
|
863 |
* @param visibleLayoutDocRect |
|
864 |
* The visible area of the layout document |
|
865 |
* @param frame |
|
866 |
* The bounding box of this frame |
|
867 |
* @return |
|
868 |
* the rectangular area of the unrotated frame that will be |
|
869 |
* visible when the frame gets rotated, measured in screen coordinates |
|
870 |
*/ |
|
871 |
protected Rectangle2D getVisibleRect(Rectangle2D visibleLayoutDocRect, Rectangle2D frame) { |
|
872 |
if (getRotation()>0) { |
|
873 |
Area area = new Area(frame); |
|
874 |
AffineTransform at = new AffineTransform(); |
|
875 |
at.rotate(Math.toRadians(getRotation()), frame.getCenterX(), frame.getCenterY()); |
|
876 |
Area rotatedArea = area.createTransformedArea(at); |
|
877 |
Area visibleArea = new Area(visibleLayoutDocRect); |
|
878 |
// this is the visible rectangle of the rotated fframeview in layout coordinates |
|
879 |
visibleArea.intersect(rotatedArea); |
|
880 |
if (visibleArea.isEmpty()) { |
|
881 |
return null; |
|
882 |
} |
|
883 |
// now we need to calculate the corresponding visible area of the fframeview before rotating, |
|
884 |
// in order to know which area of the non-rotated fframeview must be drawn |
|
885 |
try { |
|
886 |
Area nonRotatedVisibleArea = visibleArea.createTransformedArea(at.createInverse()); |
|
887 |
Rectangle2D nonRotatedVisibleBounds = nonRotatedVisibleArea.getBounds2D(); |
|
888 |
return nonRotatedVisibleBounds; |
|
889 |
} catch (NoninvertibleTransformException e) { |
|
890 |
LoggerFactory.getLogger(FFrame.class).error(e.getMessage(), e); |
|
891 |
return null; |
|
892 |
} |
|
893 |
} |
|
894 |
else { |
|
895 |
Rectangle2D.Double visibleArea = new Rectangle2D.Double(); |
|
896 |
Rectangle2D.intersect(visibleLayoutDocRect, frame, visibleArea); |
|
897 |
if (visibleArea.isEmpty()) { |
|
898 |
return null; |
|
899 |
} |
|
900 |
return visibleArea; |
|
901 |
} |
|
902 |
} |
|
903 |
|
|
854 | 904 |
} |
Also available in: Unified diff