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  import y.view.GenericNodeRealizer;
18  
19  import java.awt.geom.GeneralPath;
20  
21  /**
22  * This class is an implementation of {@link y.view.GenericNodeRealizer.Painter} that draws the paper tape symbol of flowchart diagrams.
23   **/
24  public class FlowchartPaperTapePainter extends AbstractFlowchartPainter {
25  
26    public FlowchartPaperTapePainter() {
27      super();
28      outline = new GeneralPath();
29    }
30  
31    protected void updateOutline(NodeRealizer context) {
32      
33      GeneralPath shapePath = (GeneralPath) getOutline();
34      shapePath.reset();
35      
36      double x = context.getX();
37      double y = context.getY();
38      double height = context.getHeight();
39      double width = context.getWidth();
40      double capRadiusHighDependency;
41      GenericNodeRealizer cast_gnr = (GenericNodeRealizer) context;
42      if (cast_gnr.getStyleProperty(PROPERTY_RADIUS) != null) {
43        capRadiusHighDependency = ((Double) cast_gnr.getStyleProperty(PROPERTY_RADIUS)).doubleValue();
44        capRadiusHighDependency = Math.min(capRadiusHighDependency, 0.5);
45      } else {
46        capRadiusHighDependency = FLOWCHART_DEFAULT_PAPER_TAPE_RADIUS;
47      }
48      double borderDistance = capRadiusHighDependency * Math.min(width, height);
49  
50      shapePath.moveTo((float)x, (float)(y + borderDistance));
51      shapePath.quadTo((float)(x + 0.25 * width), (float)(y + 3*borderDistance), (float)(x + 0.5 * width), (float)(y +  borderDistance));
52      shapePath.quadTo((float)(x + 0.75 * width), (float)(y - borderDistance), (float)(x + width), (float)(y + borderDistance));
53      shapePath.lineTo((float)(x + width), (float)(y + height - borderDistance));
54      shapePath.quadTo((float)(x + 0.75 * width), (float)(y + height - 3 * borderDistance), (float)(x + 0.5 * width), (float)(y + height - borderDistance));
55      shapePath.quadTo((float)(x + 0.25 * width), (float)(y + height + borderDistance), (float)x, (float)(y + height - borderDistance));
56      shapePath.closePath();
57  
58    }
59  }
60