--- /dev/null
+/*******************************************************************************\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.scenegraph.g2d.nodes;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.Shape;\r
+import java.awt.Stroke;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Ellipse2D;\r
+import java.awt.geom.Line2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+public class BranchPointNode extends G2DNode {\r
+ private static final long serialVersionUID = -5838113741617205901L;\r
+\r
+// public static final Shape SHAPE = new Ellipse2D.Double(-.5, -.5, 1, 1);\r
+// public static final Shape SHAPE2 = new Rectangle2D.Double(-.3, -.3, .6, .6);\r
+ public static final Shape SHAPE = new Ellipse2D.Double(-.5, -.5, 1, 1);\r
+ public static final Shape SHAPE2 = new Rectangle2D.Double(-.5, -.5, 1, 1);\r
+\r
+ public static final Stroke STROKE = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);\r
+\r
+ Integer degree = 0;\r
+ // 0 == any, 1 == horizontal, 2 == vertical\r
+ Byte direction = 0;\r
+\r
+ @SyncField("degree")\r
+ public void setDegree(int degree) {\r
+ this.degree = degree;\r
+ }\r
+\r
+ @SyncField("direction")\r
+ public void setDirection(byte direction) {\r
+ this.direction = direction;\r
+ }\r
+\r
+ @Override\r
+ public void render(Graphics2D g) {\r
+ AffineTransform oldTransform = g.getTransform();\r
+ if (transform != null)\r
+ g.transform(transform);\r
+\r
+ try {\r
+ renderBranchpoint(g);\r
+ } finally {\r
+ g.setTransform(oldTransform);\r
+ }\r
+ }\r
+\r
+ private void renderBranchpoint(Graphics2D g) {\r
+ boolean selected = NodeUtil.isSelected(this, 2);\r
+ if (degree <= 2) {\r
+ if (selected) {\r
+ g.setPaint(Color.GREEN);\r
+ g.fill(SHAPE2);\r
+ g.setPaint(Color.BLACK);\r
+ g.setStroke(STROKE);\r
+ g.draw(SHAPE2);\r
+ } else {\r
+ //g.setPaint(new Color(128,128,128,64));\r
+ g.setPaint(Color.LIGHT_GRAY);\r
+ g.fill(SHAPE2);\r
+ }\r
+ } else {\r
+ if (selected) {\r
+ g.setPaint(Color.GREEN);\r
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
+ g.fill(SHAPE);\r
+ g.setPaint(Color.BLACK);\r
+ g.setStroke(STROKE);\r
+ g.draw(SHAPE);\r
+ } else {\r
+ g.setPaint(Color.BLACK);\r
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
+ g.fill(SHAPE);\r
+ }\r
+ }\r
+\r
+ if (direction != 0) {\r
+ g.setStroke(STROKE);\r
+ g.setColor(degree <= 2 ? Color.BLACK : (selected ? Color.BLACK : Color.GREEN));\r
+ if (direction == 1) {\r
+ // Horizontal\r
+ g.draw(new Line2D.Double(-.5, 0, .5, 0));\r
+ } else if (direction == 2) {\r
+ // Vertical\r
+ g.draw(new Line2D.Double(0, -.5, 0, .5));\r
+ }\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return super.toString() + " [degree=" + degree + "]";\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBoundsInLocal() {\r
+ Shape shp = SHAPE;\r
+ if (degree <= 2) {\r
+ shp = SHAPE2;\r
+ }\r
+ return shp.getBounds2D();\r
+ }\r
+}\r