| FlowchartElements.java |
1 /****************************************************************************
2 * This demo file is part of yFiles for Java 2.14.
3 * Copyright (c) 2000-2017 by yWorks GmbH, Vor dem Kreuzberg 28,
4 * 72070 Tuebingen, Germany. All rights reserved.
5 *
6 * yFiles demo files exhibit yFiles for Java functionalities. Any redistribution
7 * of demo files in source code or binary form, with or without
8 * modification, is not permitted.
9 *
10 * Owners of a valid software license for a yFiles for Java version that this
11 * demo is shipped with are allowed to use the demo source code as basis
12 * for their own yFiles for Java powered applications. Use of such programs is
13 * governed by the rights and conditions as set out in the yFiles for Java
14 * license agreement.
15 *
16 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 ***************************************************************************/
28 package demo.view.flowchart.layout;
29
30 import y.base.DataProvider;
31 import y.base.Edge;
32 import y.base.Graph;
33 import y.base.GraphInterface;
34 import y.base.Node;
35
36 /**
37 * Provides type constants and corresponding <code>isXYZType()</code> methods for Flowchart symbols. These constants and
38 * methods are used by {@link FlowchartLayouter} and its associated classes to identify specific nodes and handle them
39 * appropriately.
40 *
41 * @noinspection ImplicitNumericConversion
42 */
43 public class FlowchartElements {
44 /**
45 * Type constant for an invalid type.
46 */
47 public static final byte TYPE_INVALID = 0;
48 /**
49 * Type constant for an event type.
50 */
51 public static final byte NODE_TYPE_EVENT = 1;
52 /**
53 * Type constant for a start event type.
54 */
55 public static final byte NODE_TYPE_START_EVENT = 7;
56 /**
57 * Type constant for a end event type.
58 */
59 public static final byte NODE_TYPE_END_EVENT = 9;
60 /**
61 * Type constant for a decision type.
62 */
63 public static final byte NODE_TYPE_DECISION = 2;
64 /**
65 * Type constant for a process type.
66 */
67 public static final byte NODE_TYPE_PROCESS = 3;
68 /**
69 * Type constant for a group type.
70 */
71 public static final byte NODE_TYPE_GROUP = 8;
72 /**
73 * Type constant for a annotation type.
74 */
75 public static final byte NODE_TYPE_ANNOTATION = 10;
76 /**
77 * Type constant for a pool type.
78 */
79 public static final byte NODE_TYPE_POOL = 12;
80 /**
81 * Type constant for a data type.
82 */
83 public static final byte NODE_TYPE_DATA = 11;
84
85 /**
86 * Type constant for a connection type (sequence flow).
87 */
88 public static final byte EDGE_TYPE_SEQUENCE_FLOW = 4;
89
90 /**
91 * Type constant for a connection type (message flow).
92 */
93 public static final byte EDGE_TYPE_MESSAGE_FLOW = 5;
94
95 /**
96 * Type constant for a connection type (association).
97 */
98 public static final byte EDGE_TYPE_ASSOCIATION = 6;
99
100 /**
101 * Returns true for activity nodes. For Flowcharts, this are Process, Data, and Group. For BPMN, this are Task and
102 * Sub-Process.
103 */
104 static boolean isActivity(final Graph graph, final Node node) {
105 final byte type = getType(graph, node);
106 return (type == NODE_TYPE_PROCESS) || (type == NODE_TYPE_DATA) || (type == NODE_TYPE_GROUP);
107 }
108
109 /**
110 * Returns true for group nodes. For BPMN, this is Sub-Process.
111 */
112 static boolean isGroup(final Graph graph, final Node node) {
113 return getType(graph, node) == NODE_TYPE_GROUP;
114 }
115
116 /**
117 * Returns true for annotation nodes.
118 */
119 static boolean isAnnotation(final Graph graph, final Node node) {
120 return getType(graph, node) == NODE_TYPE_ANNOTATION;
121 }
122
123 /**
124 * Returns true for event nodes. For Flowchart, this are start and terminator, delay, display, manual operation and
125 * preparation. For BPMN, this are start, end and other events.
126 */
127 static boolean isEvent(final Graph graph, final Node node) {
128 final byte type = getType(graph, node);
129 return (type == NODE_TYPE_START_EVENT) || (type == NODE_TYPE_EVENT) || (type == NODE_TYPE_END_EVENT);
130 }
131
132 /**
133 * Returns true for start event nodes.
134 */
135 static boolean isStartEvent(final Graph graph, final Node node) {
136 return getType(graph, node) == NODE_TYPE_START_EVENT;
137 }
138
139 /**
140 * Returns true for end event nodes.
141 */
142 static boolean isEndEvent(final Graph graph, final Node node) {
143 return getType(graph, node) == NODE_TYPE_END_EVENT;
144 }
145
146 /**
147 * Returns true for decision nodes. For BPMN, this are all Gateways.
148 */
149 static boolean isDecision(final Graph graph, final Node node) {
150 return getType(graph, node) == NODE_TYPE_DECISION;
151 }
152
153 static boolean isUndefined(final Graph graph, final Edge edge) {
154 return getType(graph, edge) == TYPE_INVALID;
155 }
156
157 static boolean isRegularEdge(final Graph graph, final Edge edge) {
158 return getType(graph, edge) == EDGE_TYPE_SEQUENCE_FLOW;
159 }
160
161 static boolean isMessageFlow(final Graph graph, final Edge edge) {
162 return getType(graph, edge) == EDGE_TYPE_MESSAGE_FLOW;
163 }
164
165 static byte getType(final GraphInterface graph, final Edge dataHolder) {
166 final DataProvider dataProvider = graph.getDataProvider(FlowchartLayouter.EDGE_TYPE_DPKEY);
167 return dataProvider == null ? TYPE_INVALID : (byte) dataProvider.getInt(dataHolder);
168 }
169
170 static byte getType(final GraphInterface graph, final Node dataHolder) {
171 final DataProvider dataProvider = graph.getDataProvider(FlowchartLayouter.NODE_TYPE_DPKEY);
172 return dataProvider == null ? TYPE_INVALID : (byte) dataProvider.getInt(dataHolder);
173 }
174
175 private FlowchartElements() {
176 }
177 }
178