]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/connection/ActionShapes.java
Merge "Search deeply for generic superclass in ReflectionUtils" into release/1.35.1
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / connection / ActionShapes.java
1 /*******************************************************************************
2  * Copyright (c) 2016 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.g2d.nodes.connection;
13
14 import java.awt.Shape;
15 import java.awt.geom.AffineTransform;
16 import java.awt.geom.PathIterator;
17 import java.awt.geom.Rectangle2D;
18 import java.io.IOException;
19 import java.io.StringReader;
20
21 import org.apache.batik.parser.AWTPathProducer;
22 import org.apache.batik.parser.ParseException;
23
24 /**
25  * @author Tuukka Lehtonen
26  * @since 1.22.2, 1.25.0
27  */
28 class ActionShapes {
29
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";
31
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";
33
34         static Shape parsePath(String path, AffineTransform xform) {
35                 try {
36                         Shape s = AWTPathProducer.createShape(new StringReader(path), PathIterator.WIND_EVEN_ODD);
37                         return xform != null ? xform.createTransformedShape(s) : s;
38                 } catch (ParseException | IOException e) {
39                         // Should not happen
40                         throw new Error(e);
41                 }
42         }
43
44         static Shape transformShape(Shape shape, double scaleX, double scaleY, double offsetX, double offsetY, double rotate) {
45                 AffineTransform tr = new AffineTransform();
46                 tr.translate(offsetX, offsetY);
47                 tr.scale(scaleX, scaleY);
48                 if (rotate != 0)
49                         tr.rotate(rotate);
50                 return tr.createTransformedShape(shape);
51         }
52
53         public static final Shape SCISSOR_SHAPE = parsePath(SCISSOR_PATH, null);
54         public static final Shape CROSS_SHAPE = parsePath(CROSS_PATH, null);
55
56         private static final Rectangle2D SCISSOR_BOUNDS = SCISSOR_SHAPE.getBounds2D();
57         private static final Rectangle2D CROSS_BOUNDS = CROSS_SHAPE.getBounds2D();
58
59         public static final double SCISSOR_WIDTH = SCISSOR_BOUNDS.getWidth();
60         public static final double SCISSOR_HEIGHT = SCISSOR_BOUNDS.getHeight();
61
62         public static final double CROSS_WIDTH = CROSS_BOUNDS.getWidth();
63         public static final double CROSS_HEIGHT = CROSS_BOUNDS.getHeight();
64
65 }