1   /****************************************************************************
2    **
3    ** This file is part of yFiles-2.9. 
4    ** 
5    ** yWorks proprietary/confidential. Use is subject to license terms.
6    **
7    ** Redistribution of this file or of an unauthorized byte-code version
8    ** of this file is strictly forbidden.
9    **
10   ** Copyright (c) 2000-2011 by yWorks GmbH, Vor dem Kreuzberg 28, 
11   ** 72070 Tuebingen, Germany. All rights reserved.
12   **
13   ***************************************************************************/
14  package demo.view.flowchart.painters;
15  
16  import y.view.NodeRealizer;
17  
18  import java.awt.geom.GeneralPath;
19  
20  /**
21   * This class is an implementation of {@link y.view.GenericNodeRealizer.Painter} that draws
22   * the message symbols of flowchart diagrams. There are two types of messages: user messages
23   * and network messages.
24   */
25  public class FlowchartMessagePainter extends AbstractFlowchartPainter{
26  
27    /**
28     * Boolean which is true, if the painter draws a user message and false if it draws a
29     * network message.
30     */
31    private final boolean isUserMessage;
32  
33    /**
34     * Creates a new <code>FlowchartMessagePainter</code>
35     * @param type <code>true</code> if a user message painter is created.
36     *             <code>false</code> if a network message is created.
37     */
38    public FlowchartMessagePainter(boolean type) {
39      outline = new GeneralPath();
40      isUserMessage = type;
41    }
42  
43    /**
44     * Changes the outline to the shape of the particular message node.
45     * @param context The node context
46     */
47    protected void updateOutline(NodeRealizer context) {
48      GeneralPath shapePath = (GeneralPath) getOutline();
49      shapePath.reset();
50  
51      double x = context.getX();
52      double y = context.getY();
53      double height = context.getHeight();
54      double width = context.getWidth();
55      double borderDistance = Math.min(FLOWCHART_DEFAULT_MESSAGE_INCLINATION *height, FLOWCHART_DEFAULT_MESSAGE_INCLINATION *width);
56  
57      if (isUserMessage) {
58        shapePath.moveTo((float) x, (float) y);
59        shapePath.lineTo((float) (x + width - borderDistance), (float) y);
60        shapePath.lineTo((float) (x + width), (float) (y + height*0.5));
61        shapePath.lineTo((float) (x + width - borderDistance), (float)(y + height));
62        shapePath.lineTo((float) x, (float) (y + height));
63        shapePath.closePath();
64      } else { // is network message
65        shapePath.moveTo((float) x, (float) y);
66        shapePath.lineTo((float) (x + width), (float) y);
67        shapePath.lineTo((float) (x + width), (float) (y + height));
68        shapePath.lineTo((float) x, (float) (y + height));
69        shapePath.lineTo((float) (x + borderDistance), (float) (y + height*0.5));
70        shapePath.closePath();
71      }
72    }
73  }
74