1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.flag;
\r
14 import java.awt.Shape;
\r
15 import java.awt.geom.Path2D;
\r
16 import java.awt.geom.Rectangle2D;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.exception.DatabaseException;
\r
21 import org.simantics.diagram.query.DiagramRequests;
\r
22 import org.simantics.g2d.elementclass.FlagClass;
\r
23 import org.simantics.g2d.elementclass.FlagClass.Mode;
\r
24 import org.simantics.g2d.elementclass.FlagClass.Type;
\r
25 import org.simantics.g2d.utils.Alignment;
\r
26 import org.simantics.structural2.modelingRules.IModelingRules;
\r
29 * @author Tuukka Lehtonen
\r
31 public class BasicFlagType extends AbstractFlagType {
\r
33 public BasicFlagType(Resource flag, IModelingRules modelingRules) {
\r
34 super(flag, modelingRules);
\r
38 public FlagInfo getInfo(ReadGraph graph) throws DatabaseException {
\r
39 Type type = getType(graph);
\r
40 Mode mode = getMode(graph);
\r
42 return FlagInfoBuilder.fill(type)
\r
43 .shape(getShape(graph, type, mode))
\r
44 .text(getText(graph))
\r
45 .textArea(getArea(graph, type, mode))
\r
46 .horizontalAlignment(Alignment.LEADING)
\r
47 .verticalAlignment(Alignment.CENTER)
\r
51 protected Rectangle2D getArea(ReadGraph graph, Type type, Mode mode) {
\r
52 return getArea(type, mode);
\r
55 public static Rectangle2D getArea(Type type, Mode mode) {
\r
56 final double width = FlagClass.DEFAULT_WIDTH;
\r
57 final double height = FlagClass.DEFAULT_HEIGHT;
\r
58 final double beakLength = FlagClass.getBeakLength(height, FlagClass.DEFAULT_BEAK_ANGLE);
\r
59 return getArea(type, mode, width, height, beakLength);
\r
62 public static Rectangle2D getArea(Type type, Mode mode, double width, double height, double beakLength) {
\r
64 double y = -height / 2;
\r
68 if (type == Type.In) {
\r
69 if (mode instanceof FlagClass.External) {
\r
70 x = -width-beakLength;
\r
71 } else if (mode == Mode.Internal) {
\r
75 } else if (type == Type.Out) {
\r
76 if (mode == Mode.Internal) {
\r
81 return new Rectangle2D.Double(x, y, w, h);
\r
84 protected Shape getShape(ReadGraph graph, Type type, Mode mode) throws DatabaseException {
\r
85 return getShape(type, mode);
\r
88 public static Shape getShape(Type type, Mode mode) {
\r
89 final double width = FlagClass.DEFAULT_WIDTH;
\r
90 final double height = FlagClass.DEFAULT_HEIGHT;
\r
91 final double beakLength = FlagClass.getBeakLength(height, FlagClass.DEFAULT_BEAK_ANGLE);
\r
92 Path2D path = new Path2D.Double();
\r
93 FlagClass.createFlagShape(path, type, mode, width, height, beakLength);
\r
97 protected String[] getText(ReadGraph graph) throws DatabaseException {
\r
98 return graph.syncRequest(DiagramRequests.getFlagText(flag));
\r