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