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 document symbol of flowchart diagrams.
23   **/
24  public class FlowchartDocumentPainter extends AbstractFlowchartPainter {
25  
26  
27    public FlowchartDocumentPainter() {
28      super();
29      outline = new GeneralPath();
30    }
31  
32    protected void updateOutline(NodeRealizer context) {
33      GeneralPath shapePath = (GeneralPath) getOutline();
34      shapePath.reset();
35      double height = context.getHeight();
36      double width = context.getWidth();
37      double x = context.getX();
38      double y = context.getY();
39      double inflectionCoefficient;
40      GenericNodeRealizer cast_gnr = (GenericNodeRealizer) context;
41  
42  
43      if (cast_gnr.getStyleProperty(PROPERTY_RADIUS) != null) {
44        inflectionCoefficient = ((Double) cast_gnr.getStyleProperty(PROPERTY_RADIUS)).doubleValue();
45        inflectionCoefficient = Math.min(inflectionCoefficient, 0.5);
46      } else {
47        inflectionCoefficient = FLOWCHART_DEFAULT_DOCUMENT_RADIUS;
48      }
49  
50      double borderDistance = inflectionCoefficient * Math.min(width, height);
51      shapePath.moveTo((float) x, (float) y);
52      shapePath.lineTo((float) (x + width), (float) y);
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),
55          (float) (y + height - borderDistance));
56      shapePath.quadTo((float) (x + 0.25 * width), (float) (y + height + borderDistance), (float) x,
57          (float) (y + height - borderDistance));
58      shapePath.closePath();
59    }
60  }
61