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 the loop limit symbol of flowchart diagrams.
22   */
23  public class FlowchartLoopLimitPainter extends AbstractFlowchartPainter {
24  
25    private final boolean isLoopStart;
26  
27    public FlowchartLoopLimitPainter() {
28      this(true);
29    }
30  
31    public FlowchartLoopLimitPainter(boolean isStart){
32      this.isLoopStart = isStart;
33      outline = new GeneralPath();
34    }
35  
36    protected void updateOutline(NodeRealizer context) {
37      GeneralPath shape = (GeneralPath) getOutline();
38      shape.reset();
39      double height = context.getHeight();
40      double width = context.getWidth();
41      double x = context.getX();
42      double y = context.getY();
43      double borderDistance = Math.min(Math.min(10, width/2), height/2);
44      if (isLoopStart) {
45        shape.moveTo((float)(x + borderDistance), (float)y);
46        shape.lineTo((float)(x + width - borderDistance), (float)y);
47        shape.lineTo((float)(x+ width), (float)(y + borderDistance));
48        shape.lineTo((float)(x + width), (float)(y + height));
49        shape.lineTo((float)x, (float)(y + height));
50        shape.lineTo((float)x, (float)(y + borderDistance));
51        shape.closePath();
52      } else { //is loop end
53        shape.moveTo((float) x, (float) y);
54        shape.lineTo((float)(x + width), (float) y);
55        shape.lineTo((float)(x + width), (float)(y + height - borderDistance));
56        shape.lineTo((float)(x + width - borderDistance), (float)(y + height));
57        shape.lineTo((float)(x + borderDistance), (float)(y + height));
58        shape.lineTo((float) x, (float)(y + height -borderDistance));
59        shape.closePath();
60      }
61    }
62  
63  }
64