]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/ActionShapes.java
Merge "InputStream returns -1 on EOF instead of throwing IOException"
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / connection / ActionShapes.java
1 /*******************************************************************************\r
2  * Copyright (c) 2016 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.g2d.nodes.connection;\r
13 \r
14 import java.awt.Shape;\r
15 import java.awt.geom.AffineTransform;\r
16 import java.awt.geom.PathIterator;\r
17 import java.awt.geom.Rectangle2D;\r
18 import java.io.IOException;\r
19 import java.io.StringReader;\r
20 \r
21 import org.apache.batik.parser.AWTPathProducer;\r
22 import org.apache.batik.parser.ParseException;\r
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  * @since 1.22.2, 1.25.0\r
27  */\r
28 class ActionShapes {\r
29 \r
30         private static final String SCISSOR_PATH = "M 1.0204323,-0.337727 C 0.92746851,-0.449273 0.76034565,-0.444851 0.6356318,-0.396443 l -0.78340687,0.296247 c -0.22844697,-0.124111 -0.45371804,-0.08771 -0.45389716,-0.148477 -1.3989e-4,-0.0475 0.0435015,-0.03722 0.0366086,-0.160853 -0.006619,-0.118717 -0.1308295,-0.206188 -0.24796642,-0.198065 -0.11720479,-3.56e-4 -0.23843025,0.08983 -0.23910595,0.213676 -0.00836,0.124786 0.096897,0.240343 0.221027,0.248145 0.14544563,0.02121 0.40264226,-0.06761 0.5240569,0.148471 -0.0894972,0.166266 -0.24914468,0.167198 -0.39351418,0.159315 -0.11985922,-0.0065 -0.26369532,0.02823 -0.32050912,0.146186 -0.0549,0.113051 -2.567e-4,0.27357 0.12665686,0.307747 0.12812523,0.04659 0.30371326,-0.01328 0.33371488,-0.160538 0.0231253,-0.113504 -0.0573489,-0.166568 -0.0266378,-0.207838 0.0231733,-0.03113 0.17097889,-0.01358 0.4338543,-0.13258 l 0.85013888,0.296862 c 0.10739722,0.02964 0.23851917,0.02826 0.33326488,-0.07755 L 0.14842838,0.004094 1.0204312,-0.337731 Z m -1.7489069,-0.176336 c 0.12383244,0.06866 0.11428878,0.255942 -0.0140755,0.292584 -0.11605716,0.0408 -0.2648432,-0.0717 -0.2281757,-0.197724 0.021388,-0.103377 0.15747907,-0.141864 0.24225133,-0.09486 z m 0.007633,0.765633 c 0.12914301,0.04727 0.1078809,0.265594 -0.0232155,0.295316 -0.0869168,0.03046 -0.2114303,-0.01258 -0.2205326,-0.115113 -0.017329,-0.124578 0.12880443,-0.237615 0.24374818,-0.180208 z";\r
31 \r
32         private static final String CROSS_PATH = "M 0.82205219,-1.16919 0.00195748,-0.3491 -0.81813723,-1.16919 -1.1707871,-0.81654 -0.35069244,0.00355 -1.1707871,0.82364 -0.81813723,1.17629 0.00195748,0.3562 0.82205219,1.17629 1.1747021,0.82364 0.35460739,0.00355 l 0,0 0.82009471,-0.82009 z";\r
33 \r
34         static Shape parsePath(String path, AffineTransform xform) {\r
35                 try {\r
36                         Shape s = AWTPathProducer.createShape(new StringReader(path), PathIterator.WIND_EVEN_ODD);\r
37                         return xform != null ? xform.createTransformedShape(s) : s;\r
38                 } catch (ParseException | IOException e) {\r
39                         // Should not happen\r
40                         throw new Error(e);\r
41                 }\r
42         }\r
43 \r
44         static Shape transformShape(Shape shape, double scaleX, double scaleY, double offsetX, double offsetY, double rotate) {\r
45                 AffineTransform tr = new AffineTransform();\r
46                 tr.translate(offsetX, offsetY);\r
47                 tr.scale(scaleX, scaleY);\r
48                 if (rotate != 0)\r
49                         tr.rotate(rotate);\r
50                 return tr.createTransformedShape(shape);\r
51         }\r
52 \r
53         public static final Shape SCISSOR_SHAPE = parsePath(SCISSOR_PATH, null);\r
54         public static final Shape CROSS_SHAPE = parsePath(CROSS_PATH, null);\r
55 \r
56         private static final Rectangle2D SCISSOR_BOUNDS = SCISSOR_SHAPE.getBounds2D();\r
57         private static final Rectangle2D CROSS_BOUNDS = CROSS_SHAPE.getBounds2D();\r
58 \r
59         public static final double SCISSOR_WIDTH = SCISSOR_BOUNDS.getWidth();\r
60         public static final double SCISSOR_HEIGHT = SCISSOR_BOUNDS.getHeight();\r
61 \r
62         public static final double CROSS_WIDTH = CROSS_BOUNDS.getWidth();\r
63         public static final double CROSS_HEIGHT = CROSS_BOUNDS.getHeight();\r
64 \r
65 }\r