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