]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/ExampleConnectionStyle.java
Round corners between non-axis-aligned connection lines properly
[simantics/platform.git] / bundles / org.simantics.diagram.connection / src / org / simantics / diagram / connection / rendering / ExampleConnectionStyle.java
1 /*******************************************************************************
2  * Copyright (c) 2011 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  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.connection.rendering;
13
14 import java.awt.BasicStroke;
15 import java.awt.Color;
16 import java.awt.Graphics2D;
17 import java.awt.geom.Ellipse2D;
18 import java.awt.geom.Line2D;
19 import java.awt.geom.Path2D;
20 import java.io.Serializable;
21
22 public class ExampleConnectionStyle implements ConnectionStyle, Serializable {
23
24     private static final long serialVersionUID = -5799681720482456895L;
25
26     public final static BasicStroke SOLID = 
27             new BasicStroke(1f); 
28     
29     public final static BasicStroke BOLD = 
30             new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); 
31     
32         @Override
33         public void drawLine(Graphics2D g, double x1, double y1, double x2,
34                         double y2, boolean isTransient) {
35                 g.setColor(Color.BLACK);
36                 if(isTransient)
37                         g.draw(new Line2D.Double(x1, y1, x2, y2));
38                 else {
39                         g.setStroke(BOLD);
40                         g.draw(new Line2D.Double(x1, y1, x2, y2));
41                         g.setStroke(SOLID);
42                 }
43         }
44
45         @Override
46         public void drawPath(Graphics2D g, Path2D path, boolean isTransient) {
47             g.setColor(Color.BLACK);
48             if(isTransient)
49                 g.draw(path);
50             else {
51                 g.setStroke(BOLD);
52                 g.draw(path);
53                 g.setStroke(SOLID);
54             }
55         }
56
57         @Override
58         public void drawBranchPoint(Graphics2D g, double x, double y) {
59                 g.setColor(Color.BLACK);
60                 g.fill(new Ellipse2D.Double(x-3, y-3, 6, 6));           
61         }
62
63         @Override
64         public void drawDegeneratedLine(Graphics2D g, double x, double y,
65                         boolean isHorizontal, boolean isTransient) {
66                 double d = getDegeneratedLineLength()*0.5;
67                 if(isHorizontal)
68                         g.draw(new Line2D.Double(x-d, y, x+d, y));
69                 else
70                         g.draw(new Line2D.Double(x, y-d, x, y+d));
71         }
72
73         @Override
74         public double getDegeneratedLineLength() {
75                 return 8.0;
76         }
77
78 }