| FlowchartMessagePainter.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.painters;
29
30 import y.view.NodeRealizer;
31
32 import java.awt.Shape;
33 import java.awt.geom.GeneralPath;
34
35 /**
36 * Draws the message symbols of flowchart diagrams.
37 * There are two types of messages: user messages and network messages.
38 */
39 public class FlowchartMessagePainter extends AbstractFlowchartPainter{
40
41 /**
42 * Determines if this painter will paint a flowchart user message symbol
43 * or a flowchart network message symbol.
44 */
45 private final boolean isUserMessage;
46
47 /**
48 * Initializes a new <code>FlowchartMessagePainter</code> instance for
49 * user message or network message visualization.
50 * @param type if <code>true</code>, this painter will paint the user message
51 * symbol; otherwise it will paint the network message symbol.
52 */
53 public FlowchartMessagePainter( boolean type ) {
54 isUserMessage = type;
55 }
56
57 protected Shape newShape( NodeRealizer context ) {
58 double x = context.getX();
59 double y = context.getY();
60 double height = context.getHeight();
61 double width = context.getWidth();
62 double borderDistance = Math.min(FLOWCHART_DEFAULT_MESSAGE_INCLINATION *height, FLOWCHART_DEFAULT_MESSAGE_INCLINATION *width);
63
64 GeneralPath shapePath = new GeneralPath();
65 if (isUserMessage) {
66 shapePath.moveTo((float) x, (float) y);
67 shapePath.lineTo((float) (x + width - borderDistance), (float) y);
68 shapePath.lineTo((float) (x + width), (float) (y + height*0.5));
69 shapePath.lineTo((float) (x + width - borderDistance), (float)(y + height));
70 shapePath.lineTo((float) x, (float) (y + height));
71 shapePath.closePath();
72 } else { // is network message
73 shapePath.moveTo((float) x, (float) y);
74 shapePath.lineTo((float) (x + width), (float) y);
75 shapePath.lineTo((float) (x + width), (float) (y + height));
76 shapePath.lineTo((float) x, (float) (y + height));
77 shapePath.lineTo((float) (x + borderDistance), (float) (y + height*0.5));
78 shapePath.closePath();
79 }
80 return shapePath;
81 }
82 }
83