]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/FixedSize.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / FixedSize.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/FixedSize.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/FixedSize.java
new file mode 100644 (file)
index 0000000..e33357e
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.element.handler.impl;\r
+\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+\r
+/**\r
+ * Handler for elements with fixed internal size (eg vector symbols). \r
+ * \r
+ * @author Toni Kalajainen\r
+ */\r
+public class FixedSize implements InternalSize {\r
+\r
+    private static final long serialVersionUID = -3597595326131594492L;\r
+\r
+    public static InternalSize of(double width, double height)\r
+    {\r
+        return new FixedSize(0, 0, width, height);\r
+    }\r
+\r
+    public static InternalSize of(double minX, double minY, double width, double height)\r
+    {\r
+        return new FixedSize(minX, minY, width, height);\r
+    }\r
+\r
+    public static InternalSize of(Rectangle2D bounds)\r
+    {\r
+        return new FixedSize(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());\r
+    }\r
+\r
+    final Double aspectRatio;\r
+    Rectangle2D bounds;\r
+\r
+    FixedSize(double minX, double minY, double width, double height)\r
+    {\r
+        this.aspectRatio = width / height;\r
+        bounds = new Rectangle2D.Double(minX, minY, width, height);\r
+    }\r
+\r
+    @Override\r
+    public Rectangle2D getBounds(IElement e, Rectangle2D s) {\r
+        if (s==null) s = new Rectangle2D.Double();\r
+        s.setFrame(bounds);            \r
+        return s;\r
+    }\r
+\r
+\r
+}\r