[Arakhnę-Dev] [405] * Add utility functions on zoomable contexts.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 405
Author:   galland
Date:     2013-04-04 09:15:27 +0200 (Thu, 04 Apr 2013)
Log Message:
-----------
* Add utility functions on zoomable contexts.

Removed Paths:
-------------
    trunk/ui/ui-awt/src/main/java/org/arakhne/afc/ui/awt/ZoomableContextUtil.java

Deleted: trunk/ui/ui-awt/src/main/java/org/arakhne/afc/ui/awt/ZoomableContextUtil.java
===================================================================
--- trunk/ui/ui-awt/src/main/java/org/arakhne/afc/ui/awt/ZoomableContextUtil.java	2013-04-04 07:10:14 UTC (rev 404)
+++ trunk/ui/ui-awt/src/main/java/org/arakhne/afc/ui/awt/ZoomableContextUtil.java	2013-04-04 07:15:27 UTC (rev 405)
@@ -1,804 +0,0 @@
-/* $Id$
- * 
- * This is a part of NetEditor project from Arakhne.org:
- * package org.arakhne.neteditor.zoompanel.
- * 
- * Copyright (C) 2002  Stéphane GALLAND, Mahdi Hannoun
- * Copyright (C) 2004-2012  Stéphane GALLAND
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * This program is free software; you can redistribute it and/or modify
- */
-package org.arakhne.afc.ui.awt;
-
-import java.awt.Font;
-import java.awt.Polygon;
-import java.awt.Shape;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Arc2D;
-import java.awt.geom.Area;
-import java.awt.geom.CubicCurve2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import java.awt.geom.Path2D;
-import java.awt.geom.PathIterator;
-import java.awt.geom.QuadCurve2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RoundRectangle2D;
-
-/** Utilities for ZoomableContext.
- *
- * @author $Author: galland$
- * @version $FullVersion$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- */
-public class ZoomableContextUtil {
-
-	/** Translates the specified rectangle
-	 *  into the screen space.
-	 *
-	 * @param r is the rectangle in the logical space when input and the
-	 * same rectangle in screen space when output.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flipX indicates if the X screen axis is inverted.
-	 * @param flipY indicates if the Y screen axis is inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translationX is the translation X in the context.
-	 * @param translationY is the translation Y in the context.
-	 * @param zoom is the current zooming factor of the view.
-	 */
-	public static void logical2pixel_r(Rectangle2D r, boolean canZoom,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (canZoom)
-			logical2pixel_r(r, flipX, flipY, documentScreenRectangle, translationX, translationY, zoom);
-	}
-	
-	private static void logical2pixel_r(Rectangle2D r,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		assert(r!=null);
-		float x = (float)((flipX) ? r.getMaxX() : r.getMinX());
-		float y = (float)((flipY) ? r.getMaxY() : r.getMinY());
-		float px = logical2pixel_x(x, flipX, documentScreenRectangle, translationX, zoom);
-		float py = logical2pixel_y(y, flipY, documentScreenRectangle, translationY, zoom);
-		float pw = logical2pixel_size((float)r.getWidth(), zoom);
-		float ph = logical2pixel_size((float)r.getHeight(), zoom);
-		r.setRect(px, py, pw, ph);
-	}
-
-	/** Translates the specified rectangle
-	 *  into the logical space.
-	 *
-	 * @param r is the rectangle in the screen space when input and the
-	 * same rectangle in logical space when output.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flipX indicates if the X screen axis is inverted.
-	 * @param flipY indicates if the Y screen axis is inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translationX is the translation X in the context.
-	 * @param translationY is the translation Y in the context.
-	 * @param zoom is the current zooming factor of the view.
-	 */
-	public static void pixel2logical_r(Rectangle2D r, boolean canZoom,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (canZoom)
-			pixel2logical_r(r, flipX, flipY, documentScreenRectangle, translationX, translationY, zoom);
-	}
-	
-	private static void pixel2logical_r(Rectangle2D r,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		assert(r!=null);
-		float x = (float)((flipX) ? r.getMaxX() : r.getMinX());
-		float y = (float)((flipY) ? r.getMaxY() : r.getMinY());
-		float lx = pixel2logical_x(x, flipX, documentScreenRectangle, translationX, zoom);
-		float ly = pixel2logical_y(y, flipY, documentScreenRectangle, translationY, zoom);
-		float lw = pixel2logical_size((float)r.getWidth(), zoom);
-		float lh = pixel2logical_size((float)r.getHeight(), zoom);
-		r.setRect(lx, ly, lw, lh);
-	}
-
-	private static void create(
-			PathIterator pathIterator,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom,
-			Path2D output) {
-		float[] coords = new float[8];
-		while (!pathIterator.isDone()) {
-			switch(pathIterator.currentSegment(coords)) {
-			case PathIterator.SEG_MOVETO:
-				output.moveTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_LINETO:
-				output.lineTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_CUBICTO:
-				output.curveTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x(coords[2], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[3], flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x(coords[4], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[5], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_QUADTO:
-				output.quadTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x(coords[2], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[3], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_CLOSE:
-				output.closePath();
-				break;
-			default:
-				throw new IllegalArgumentException();
-			}
-			pathIterator.next();
-		}
-	}
-
-	private static void create2(
-			Shape s,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom,
-			Path2D output) {
-		PathIterator it = s.getPathIterator(new AffineTransform());
-		float[] coords = new float[8];
-		while (!it.isDone()) {
-			switch(it.currentSegment(coords)) {
-			case PathIterator.SEG_MOVETO:
-				output.moveTo(
-						pixel2logical_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[1], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_LINETO:
-				output.lineTo(
-						pixel2logical_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[1], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_CUBICTO:
-				output.curveTo(
-						pixel2logical_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[1], flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x(coords[2], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[3], flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x(coords[4], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[5], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_QUADTO:
-				output.quadTo(
-						pixel2logical_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[1], flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x(coords[2], flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(coords[3], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_CLOSE:
-				output.closePath();
-				break;
-			default:
-				throw new IllegalArgumentException();
-			}
-			it.next();
-		}
-	}
-
-	/** Translates the specified shape
-	 *  into the screen space.
-	 *
-	 * @param <T> is the type of shape to convert.
-	 * @param s is the shape in the logical space.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flipX indicates if the X screen axis is inverted.
-	 * @param flipY indicates if the Y screen axis is inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translationX is the translation X in the context.
-	 * @param translationY is the translation Y in the context.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a shape into the screen space.
-	 */
-	public static <T extends Shape> T logical2pixel(
-			T s, boolean canZoom,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (canZoom)
-			return logical2pixel(s, flipX, flipY, documentScreenRectangle, translationX, translationY, zoom);
-		return s;
-	}
-
-	@SuppressWarnings("unchecked")
-	private static <T extends Shape> T logical2pixel(
-			T s,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (s==null) return null;
-		SupportedShape type = SupportedShape.getTypeOf(s.getClass());
-		try {
-			switch(type) {
-			case RECTANGLE2D:
-			{
-				Rectangle2D r = (Rectangle2D)s;
-				float x = (float)((flipX) ? r.getMaxX() : r.getMinX());
-				float y = (float)((flipY) ? r.getMaxY() : r.getMinY());
-				return (T)new Rectangle2D.Double(
-						logical2pixel_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_size((float)r.getWidth(), zoom),
-						logical2pixel_size((float)r.getHeight(), zoom));
-			}
-			case ROUND_RECTANGLE:
-			{
-				RoundRectangle2D r = (RoundRectangle2D)s;
-				float x = (float)((flipX) ? r.getMaxX() : r.getMinX());
-				float y = (float)((flipY) ? r.getMaxY() : r.getMinY());
-				return (T)new RoundRectangle2D.Double(
-						logical2pixel_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_size((float)r.getWidth(), zoom),
-						logical2pixel_size((float)r.getHeight(), zoom),
-						logical2pixel_size((float)r.getArcWidth(), zoom),
-						logical2pixel_size((float)r.getArcHeight(), zoom));
-			}
-			case ELLIPSE:
-			{
-				Ellipse2D e = (Ellipse2D)s;
-				float x = (float)((flipX) ? e.getMaxX() : e.getMinX());
-				float y = (float)((flipY) ? e.getMaxY() : e.getMinY());
-				return (T)new Ellipse2D.Double(
-						logical2pixel_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_size((float)e.getWidth(), zoom),
-						logical2pixel_size((float)e.getHeight(), zoom));
-			}
-			case LINE:
-			{
-				Line2D l = (Line2D)s;
-				return (T)new Line2D.Double(
-						logical2pixel_x((float)l.getX1(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)l.getY1(), flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x((float)l.getX2(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)l.getY2(), flipY, documentScreenRectangle, translationY, zoom));
-			}
-			case ARC:
-			{
-				Arc2D a = (Arc2D)s;
-				float x = (float)((flipX) ? a.getMaxX() : a.getMinX());
-				float y = (float)((flipY) ? a.getMaxY() : a.getMinY());
-				return (T)new Arc2D.Double(
-						logical2pixel_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_size((float)a.getWidth(), zoom),
-						logical2pixel_size((float)a.getHeight(), zoom),
-						a.getAngleStart(),
-						a.getAngleExtent(),
-						a.getArcType());
-			}
-			case POLYGON:
-			{
-				Polygon p = (Polygon)s ;
-				float x, y;
-				GeneralPath p2 = new GeneralPath() ;
-				for( int i=0; i < p.npoints; ++i ) {
-					x = logical2pixel_x(p.xpoints[i], flipX, documentScreenRectangle, translationX, zoom);
-					y = logical2pixel_y(p.ypoints[i], flipY, documentScreenRectangle, translationY, zoom);
-					if (i==0)
-						p2.moveTo(x, y);
-					else
-						p2.lineTo(x, y);
-				}
-				p2.closePath();
-				return (T)p2 ;
-			}
-			case CUBIC_CURVE:
-			{
-				CubicCurve2D c = (CubicCurve2D)s ;
-				return (T)new CubicCurve2D.Double(
-						logical2pixel_x((float)c.getX1(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getY1(), flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x((float)c.getCtrlX1(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getCtrlY1(), flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x((float)c.getCtrlX2(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getCtrlY2(), flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x((float)c.getX2(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getY2(), flipY, documentScreenRectangle, translationY, zoom));
-			}
-			case QUAD_CURVE:
-			{
-				QuadCurve2D c = (QuadCurve2D)s ;
-				return (T)new QuadCurve2D.Double(
-						logical2pixel_x((float)c.getX1(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getY1(), flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x((float)c.getCtrlX(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getCtrlY(), flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x((float)c.getX2(), flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y((float)c.getY2(), flipY, documentScreenRectangle, translationY, zoom));
-			}
-			case PATH:
-			{
-				Path2D p = (Path2D)s;
-				Path2D p2 = new GeneralPath(p.getWindingRule());
-				create(
-						p.getPathIterator(null), flipX, flipY, documentScreenRectangle,
-						translationX, translationY, zoom, p2);
-				return (T)p2;
-			}
-			case AREA:
-			{
-				Area a = (Area)s ;
-				GeneralPath p2 = new GeneralPath();
-				create(
-						a.getPathIterator(null),
-						flipX, flipY, documentScreenRectangle,
-						translationX, translationY, zoom, p2);
-				return (T)new Area(p2);
-			}
-			case VIRTUALIZABLE_SHAPE:
-			{
-				VirtualizableShape vs = (VirtualizableShape)s;
-				return (T)vs.toScreen(flipX, flipY, documentScreenRectangle, translationX, translationY, zoom);
-			}
-			default:
-				throw new IllegalArgumentException();
-			}
-		}
-		catch(ClassCastException _) {
-			//
-		}
-
-		throw new UnsupportedShapeException(type);
-	}
-
-	/** Translates the specified shape
-	 *  into the logical space.
-	 *
-	 * @param <T> is the type of shape to convert.
-	 * @param s is the shape in the screen space.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flipX indicates if the X screen axis is inverted.
-	 * @param flipY indicates if the Y screen axis is inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translationX is the translation X in the context.
-	 * @param translationY is the translation Y in the context.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a shape into the logical space.
-	 */
-	public static <T extends Shape> T pixel2logical(
-			T s, boolean canZoom,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (canZoom)
-			return pixel2logical(s, flipX, flipY, documentScreenRectangle, translationX, translationY, zoom);
-		return s;
-	}
-	
-	@SuppressWarnings("unchecked")
-	private static <T extends Shape> T pixel2logical(
-			T s,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (s==null) return null;
-		SupportedShape type = SupportedShape.getTypeOf(s.getClass());
-		try {
-			switch(type) {
-			case RECTANGLE2D:
-			{
-				Rectangle2D r = (Rectangle2D)s;
-				float x = (float)((flipX) ? r.getMaxX() : r.getMinX());
-				float y = (float)((flipY) ? r.getMaxY() : r.getMinY());
-				return (T)new Rectangle2D.Double(
-						pixel2logical_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_size((float)r.getWidth(), zoom),
-						pixel2logical_size((float)r.getHeight(), zoom));
-			}
-			case ROUND_RECTANGLE:
-			{
-				RoundRectangle2D r = (RoundRectangle2D)s;
-				float x = (float) ((flipX) ? r.getMaxX() : r.getMinX());
-				float y = (float) ((flipY) ? r.getMaxY() : r.getMinY());
-				return (T)new RoundRectangle2D.Double(
-						pixel2logical_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_size((float)r.getWidth(), zoom),
-						pixel2logical_size((float)r.getHeight(), zoom),
-						pixel2logical_size((float)r.getArcWidth(), zoom),
-						pixel2logical_size((float)r.getArcHeight(), zoom));
-			}
-			case ELLIPSE:
-			{
-				Ellipse2D e = (Ellipse2D)s;
-				float x = (float) ((flipX) ? e.getMaxX() : e.getMinX());
-				float y = (float) ((flipY) ? e.getMaxY() : e.getMinY());
-				return (T)new Ellipse2D.Double(
-						pixel2logical_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_size((float)e.getWidth(), zoom),
-						pixel2logical_size((float)e.getHeight(), zoom));
-			}
-			case LINE:
-			{
-				Line2D l = (Line2D)s;
-				return (T)new Line2D.Double(
-						pixel2logical_x((float)l.getX1(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)l.getY1(), flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x((float)l.getX2(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)l.getY2(), flipY, documentScreenRectangle, translationY, zoom));
-			}
-			case ARC:
-			{
-				Arc2D a = (Arc2D)s;
-				float x = (float) ((flipX) ? a.getMaxX() : a.getMinX());
-				float y = (float) ((flipY) ? a.getMaxY() : a.getMinY());
-				return (T)new Arc2D.Double(
-						pixel2logical_x(x, flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y(y, flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_size((float)a.getWidth(), zoom),
-						pixel2logical_size((float)a.getHeight(), zoom),
-						a.getAngleStart(),
-						a.getAngleExtent(),
-						a.getArcType());
-			}
-			case POLYGON:
-			{
-				Polygon p = (Polygon)s ;
-				GeneralPath p2 = new GeneralPath() ;
-				float x, y;
-				for( int i=0; i < p.npoints; ++i ) {
-					x = pixel2logical_x(p.xpoints[i], flipX, documentScreenRectangle, translationX, zoom);
-					y = pixel2logical_y(p.ypoints[i], flipY, documentScreenRectangle, translationY, zoom);
-					if (i==0) p2.moveTo(x, y);
-					else p2.lineTo(x, y);
-				}
-				p2.closePath();
-				return (T)p2 ;
-			}
-			case CUBIC_CURVE:
-			{
-				CubicCurve2D c = (CubicCurve2D)s ;
-				return (T)new CubicCurve2D.Double(
-						pixel2logical_x((float)c.getX1(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getY1(), flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x((float)c.getCtrlX1(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getCtrlY1(), flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x((float)c.getCtrlX2(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getCtrlY2(), flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x((float)c.getX2(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getY2(), flipY, documentScreenRectangle, translationY, zoom));
-			}
-			case QUAD_CURVE:
-			{
-				QuadCurve2D c = (QuadCurve2D)s ;
-				return (T)new QuadCurve2D.Double(
-						pixel2logical_x((float)c.getX1(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getY1(), flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x((float)c.getCtrlX(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getCtrlY(), flipY, documentScreenRectangle, translationY, zoom),
-						pixel2logical_x((float)c.getX2(), flipX, documentScreenRectangle, translationX, zoom),
-						pixel2logical_y((float)c.getY2(), flipY, documentScreenRectangle, translationY, zoom));
-			}
-			case PATH:
-			{
-				Path2D p = (Path2D)s;
-				Path2D p2 = new GeneralPath(p.getWindingRule());
-				create2(
-						p, flipX, flipY, documentScreenRectangle,
-						translationX, translationY, zoom, p2);
-				return (T)p2;
-			}
-			case AREA:
-			{
-				Area a = (Area)s ;
-				GeneralPath p2 = new GeneralPath();
-				create2(
-						a, flipX, flipY, documentScreenRectangle,
-						translationX, translationY, zoom, p2);
-				return (T)new Area(p2);
-			}
-			case VIRTUALIZABLE_SHAPE:
-			{
-				VirtualizableShape vs = (VirtualizableShape)s;
-				return (T)vs.fromScreen(flipX, flipY, documentScreenRectangle, translationX, translationY, zoom);
-			}
-			default:
-				throw new IllegalArgumentException();
-			}
-		}
-		catch(ClassCastException _) {
-			//
-		}
-
-		throw new UnsupportedShapeException(type);
-	}
-
-	/** Translates the specified workspace location
-	 *  into the screen location.
-	 *
-	 * @param l is the coordinate along the workspace space X-axis.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flip indicates if the X axis should be inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translation is the current translation of the view.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a location along the screen space X-axis.
-	 */
-	public static float logical2pixel_x(float l, boolean canZoom, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		if (canZoom)
-			return logical2pixel_x(l, flip, documentScreenRectangle, translation, zoom);
-		return l;
-	}		
-	
-	private static float logical2pixel_x(float l, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		float p = (l+translation) * zoom;
-		if (flip) {
-			p = (float) ((documentScreenRectangle.getX() + documentScreenRectangle.getWidth()) - (p - documentScreenRectangle.getX()));
-		}
-		return p;
-	}
-
-	/** Translates the specified workspace location
-	 *  into the screen location.
-	 *
-	 * @param l is the coordinate along the workspace space Y-axis.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flip indicates if the Y axis should be inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translation is the current translation of the view.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a location along the screen space Y-axis.
-	 */
-	public static float logical2pixel_y(float l, boolean canZoom, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		if (canZoom)
-			return logical2pixel_y(l, flip, documentScreenRectangle, translation, zoom);
-		return l;
-	}
-	
-	private static float logical2pixel_y(float l, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		float p = (l+translation) * zoom;
-		if (flip) {
-			p = (float) ((documentScreenRectangle.getY() + documentScreenRectangle.getHeight()) - (p - documentScreenRectangle.getY()));
-		}
-		return p;
-	}
-
-	/** Translates the specified screen location
-	 *  into the logical location.
-	 *
-	 * @param p is the location along the screen space X-axis.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flip indicates if the X axis should be inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translation is the current translation of the view.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a location along the logical space X-axis.
-	 */
-	public static float pixel2logical_x(float p, boolean canZoom, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		if (canZoom)
-			return pixel2logical_x(p, flip, documentScreenRectangle, translation, zoom);
-		return p;
-	}
-
-	private static float pixel2logical_x(float p, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		float fp;
-		if (flip) {
-			fp = (float) ((documentScreenRectangle.getX() + documentScreenRectangle.getWidth()) - (p - documentScreenRectangle.getX()));
-		}
-		else {
-			fp = p;
-		}
-		return (fp / zoom) - translation;
-	}
-
-	/** Translates the specified screen location
-	 *  into the logical location.
-	 *
-	 * @param p is the location along the screen space Y-axis.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flip indicates if the Y axis should be inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translation is the current translation of the view.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a location along the logical space Y-axis.
-	 */
-	public static float pixel2logical_y(float p, boolean canZoom, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		if (canZoom)
-			return pixel2logical_y(p, flip, documentScreenRectangle, translation, zoom);
-		return p;
-	}
-	
-	private static float pixel2logical_y(float p, boolean flip,
-			Rectangle2D documentScreenRectangle, float translation, float zoom) {
-		float fp;
-		if (flip) {
-			fp = (float) ((documentScreenRectangle.getY() + documentScreenRectangle.getHeight()) - (p - documentScreenRectangle.getY()));
-		}
-		else {
-			fp = p;
-		}
-		return (fp / zoom) - translation;
-	}
-
-	/** Translates the specified workspace length
-	 *  into the screen length.
-	 *
-	 * @param l is the length in the workspace space.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a length into the screen space.
-	 */
-	public static float logical2pixel_size(float l, boolean canZoom, float zoom) {
-		if (canZoom)
-			return logical2pixel_size(l, zoom);
-		return l;
-	}
-
-	private static float logical2pixel_size(float l, float zoom) {
-		float s = l * zoom;
-		if ((l!=0)&&(s==0)) s = 1f;
-		return s;
-	}
-
-	/** Translates the specified screen length
-	 *  into the logical length.
-	 *
-	 * @param l is the length in the screen space.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a length into the logical space.
-	 */
-	public static float pixel2logical_size(float l, boolean canZoom, float zoom) {
-		if (canZoom)
-			return pixel2logical_size(l, zoom);
-		return l;
-	}
-
-	private static float pixel2logical_size(float l, float zoom) {
-		return l / zoom;
-	}
-	
-	/** Translate the specified font from a logical length to a screen length.
-	 * 
-	 * @param font is the font with a size in the logical coordinate system.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return the font with a size suitable for the screen coordinate system.
-	 */
-	public static Font logical2pixel(Font font, boolean canZoom, float zoom) {
-		if (canZoom) {
-			float nSize = logical2pixel_size(font.getSize2D(), zoom);
-			return font.deriveFont(nSize);
-		}
-		return font;
-	}
-
-	/** Translate the specified font from a screen length to a logical length.
-	 * 
-	 * @param font is the font with a size in the screen coordinate system.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return the font with a size suitable for the logical coordinate system.
-	 */
-	public static Font pixel2logical(Font font, boolean canZoom, float zoom) {
-		/*Map<TextAttribute,Object> attrs = (Map<TextAttribute,Object>)font.getAttributes();
-		attrs.put(TextAttribute.SIZE, pixel2logical_size(font.getSize2D()));
-		*/
-		if (canZoom) {
-			float nSize = pixel2logical_size(font.getSize2D(), zoom);
-			return font.deriveFont(nSize);
-		}
-		return font;
-	}
-
-	/** Translates the specified path
-	 *  into the screen space.
-	 *
-	 * @param path is the path in the logical space.
-	 * @param canZoom indicates if the zooming should be applied.
-	 * @param flipX indicates if the X screen axis is inverted.
-	 * @param flipY indicates if the Y screen axis is inverted.
-	 * @param documentScreenRectangle is the area covered by the document in screen space.
-	 * @param translationX is the translation X in the context.
-	 * @param translationY is the translation Y in the context.
-	 * @param zoom is the current zooming factor of the view.
-	 * @return a shape into the screen space.
-	 */
-	public static Path2D logical2pixel(
-			PathIterator path, boolean canZoom,
-			boolean flipX, boolean flipY,
-			Rectangle2D documentScreenRectangle,
-			float translationX, float translationY,
-			float zoom) {
-		if (canZoom) {
-			Path2D p2 = new GeneralPath(path.getWindingRule());
-			create(
-					path, flipX, flipY, documentScreenRectangle,
-					translationX, translationY, zoom, p2);
-			return p2;
-		}
-		GeneralPath pathObj = new GeneralPath();
-		float[] coords = new float[8];
-		while (!path.isDone()) {
-			switch(path.currentSegment(coords)) {
-			case PathIterator.SEG_MOVETO:
-				pathObj.moveTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_LINETO:
-				pathObj.lineTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_CUBICTO:
-				pathObj.curveTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x(coords[2], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[3], flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x(coords[4], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[5], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_QUADTO:
-				pathObj.quadTo(
-						logical2pixel_x(coords[0], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[1], flipY, documentScreenRectangle, translationY, zoom),
-						logical2pixel_x(coords[2], flipX, documentScreenRectangle, translationX, zoom),
-						logical2pixel_y(coords[3], flipY, documentScreenRectangle, translationY, zoom));
-				break;
-			case PathIterator.SEG_CLOSE:
-				pathObj.closePath();
-				break;
-			default:
-				throw new IllegalArgumentException();
-			}
-			path.next();
-		}
-		return pathObj;
-	}
-}
\ No newline at end of file


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/