]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/StaticEdgeVisuals.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / StaticEdgeVisuals.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.g2d.element.handler.impl;
13
14 import java.awt.Stroke;
15
16 import org.simantics.g2d.element.IElement;
17 import org.simantics.g2d.element.handler.EdgeVisuals;
18
19 /**
20  * Edge visuals that are the same for all edges of the class.
21  * 
22  * @author Toni Kalajainen
23  */
24 public class StaticEdgeVisuals implements EdgeVisuals {
25
26     private static final long serialVersionUID = -2263869759801224096L;
27
28     public static final StaticEdgeVisuals DEFAULT_EDGE_VISUALS =
29         new StaticEdgeVisuals(ArrowType.None, ArrowType.Stroke, ConfigurableEdgeVisuals.DEFAULT_STROKE, 3.0, 3.0);
30
31     ArrowType beginArrow, endArrow;
32     Stroke stroke;
33     StrokeType strokeType;
34     double beginArrowSize, endArrowSize;
35
36     public StaticEdgeVisuals(ArrowType beginArrow, ArrowType endArrow, Stroke stroke, double beginArrowSize, double endArrowSize)
37     {
38         this.beginArrow = beginArrow;
39         this.endArrow = endArrow;
40         this.stroke = stroke;
41         this.strokeType = StrokeType.Relative;
42         this.beginArrowSize = beginArrowSize;
43         this.endArrowSize = endArrowSize;
44     }
45
46     @Override
47     public ArrowType getArrowType(IElement e, EdgeEnd end) {
48         if (end==EdgeEnd.Begin)
49             return beginArrow;
50         if (end==EdgeEnd.End)
51             return beginArrow;
52         throw new RuntimeException();
53     }
54
55     @Override
56     public StrokeType getStrokeType(IElement e) {
57         return strokeType;
58     }
59
60     @Override
61     public Stroke getStroke(IElement e) {
62         return stroke;
63     }
64
65     @Override
66     public void setArrowType(IElement e, EdgeEnd end, ArrowType arrowType) {
67         throw new RuntimeException("Cannot modify static edge visuals");
68     }
69
70     @Override
71     public void setStroke(IElement e, Stroke s) {
72         throw new RuntimeException("Cannot modify static edge visuals");
73     }
74
75     @Override
76     public void setStrokeType(IElement e, StrokeType t) {
77         throw new RuntimeException("Cannot modify static edge visuals");
78     }
79
80     @Override
81     public double getArrowSize(IElement e, EdgeEnd end) {
82         if (end == EdgeEnd.Begin)
83             return beginArrowSize;
84         if (end==EdgeEnd.End)
85             return endArrowSize;
86         return 0;
87     }
88
89     @Override
90     public void setArrowSize(IElement e, EdgeEnd end, double size) {
91         throw new RuntimeException("Cannot modify arrow size");
92     }
93
94
95 }