1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in 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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.scenegraph.g2d.nodes;
\r
14 import java.awt.BasicStroke;
\r
15 import java.awt.Color;
\r
16 import java.awt.Graphics2D;
\r
17 import java.awt.Shape;
\r
18 import java.awt.Stroke;
\r
19 import java.awt.geom.AffineTransform;
\r
20 import java.awt.geom.Ellipse2D;
\r
21 import java.awt.geom.Line2D;
\r
22 import java.awt.geom.Rectangle2D;
\r
24 import org.simantics.scenegraph.g2d.G2DNode;
\r
25 import org.simantics.scenegraph.utils.NodeUtil;
\r
27 public class BranchPointNode extends G2DNode {
\r
28 private static final long serialVersionUID = -5838113741617205901L;
\r
30 // public static final Shape SHAPE = new Ellipse2D.Double(-.5, -.5, 1, 1);
\r
31 // public static final Shape SHAPE2 = new Rectangle2D.Double(-.3, -.3, .6, .6);
\r
32 public static final Shape SHAPE = new Ellipse2D.Double(-.5, -.5, 1, 1);
\r
33 public static final Shape SHAPE2 = new Rectangle2D.Double(-.5, -.5, 1, 1);
\r
35 public static final Stroke STROKE = new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
\r
38 // 0 == any, 1 == horizontal, 2 == vertical
\r
41 @SyncField("degree")
\r
42 public void setDegree(int degree) {
\r
43 this.degree = degree;
\r
46 @SyncField("direction")
\r
47 public void setDirection(byte direction) {
\r
48 this.direction = direction;
\r
52 public void render(Graphics2D g) {
\r
53 AffineTransform oldTransform = g.getTransform();
\r
54 if (transform != null)
\r
55 g.transform(transform);
\r
58 renderBranchpoint(g);
\r
60 g.setTransform(oldTransform);
\r
64 private void renderBranchpoint(Graphics2D g) {
\r
65 boolean selected = NodeUtil.isSelected(this, 2);
\r
68 g.setPaint(Color.GREEN);
\r
70 g.setPaint(Color.BLACK);
\r
71 g.setStroke(STROKE);
\r
74 //g.setPaint(new Color(128,128,128,64));
\r
75 g.setPaint(Color.LIGHT_GRAY);
\r
80 g.setPaint(Color.GREEN);
\r
81 //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
\r
83 g.setPaint(Color.BLACK);
\r
84 g.setStroke(STROKE);
\r
87 g.setPaint(Color.BLACK);
\r
88 //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
\r
93 if (direction != 0) {
\r
94 g.setStroke(STROKE);
\r
95 g.setColor(degree <= 2 ? Color.BLACK : (selected ? Color.BLACK : Color.GREEN));
\r
96 if (direction == 1) {
\r
98 g.draw(new Line2D.Double(-.5, 0, .5, 0));
\r
99 } else if (direction == 2) {
\r
101 g.draw(new Line2D.Double(0, -.5, 0, .5));
\r
107 public String toString() {
\r
108 return super.toString() + " [degree=" + degree + "]";
\r
112 public Rectangle2D getBoundsInLocal() {
\r
117 return shp.getBounds2D();
\r