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