]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/FixedSize.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / handler / impl / FixedSize.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.element.handler.impl;
13
14 import java.awt.geom.Rectangle2D;
15
16 import org.simantics.g2d.element.IElement;
17 import org.simantics.g2d.element.handler.InternalSize;
18
19 /**
20  * Handler for elements with fixed internal size (eg vector symbols). 
21  * 
22  * @author Toni Kalajainen
23  */
24 public class FixedSize implements InternalSize {
25
26     private static final long serialVersionUID = -3597595326131594492L;
27
28     public static InternalSize of(double width, double height)
29     {
30         return new FixedSize(0, 0, width, height);
31     }
32
33     public static InternalSize of(double minX, double minY, double width, double height)
34     {
35         return new FixedSize(minX, minY, width, height);
36     }
37
38     public static InternalSize of(Rectangle2D bounds)
39     {
40         return new FixedSize(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
41     }
42
43     final Double aspectRatio;
44     Rectangle2D bounds;
45
46     FixedSize(double minX, double minY, double width, double height)
47     {
48         this.aspectRatio = width / height;
49         bounds = new Rectangle2D.Double(minX, minY, width, height);
50     }
51
52     @Override
53     public Rectangle2D getBounds(IElement e, Rectangle2D s) {
54         if (s==null) s = new Rectangle2D.Double();
55         s.setFrame(bounds);             
56         return s;
57     }
58
59
60 }