X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fflag%2FBasicFlagType.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fflag%2FBasicFlagType.java;h=747593130650b75315db50f70e5ed24bb0e20f84;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/BasicFlagType.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/BasicFlagType.java new file mode 100644 index 000000000..747593130 --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/BasicFlagType.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.flag; + +import java.awt.Shape; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.query.DiagramRequests; +import org.simantics.g2d.elementclass.FlagClass; +import org.simantics.g2d.elementclass.FlagClass.Mode; +import org.simantics.g2d.elementclass.FlagClass.Type; +import org.simantics.g2d.utils.Alignment; +import org.simantics.structural2.modelingRules.IModelingRules; + +/** + * @author Tuukka Lehtonen + */ +public class BasicFlagType extends AbstractFlagType { + + public BasicFlagType(Resource flag, IModelingRules modelingRules) { + super(flag, modelingRules); + } + + @Override + public FlagInfo getInfo(ReadGraph graph) throws DatabaseException { + Type type = getType(graph); + Mode mode = getMode(graph); + + return FlagInfoBuilder.fill(type) + .shape(getShape(graph, type, mode)) + .text(getText(graph)) + .textArea(getArea(graph, type, mode)) + .horizontalAlignment(Alignment.LEADING) + .verticalAlignment(Alignment.CENTER) + .create(); + } + + protected Rectangle2D getArea(ReadGraph graph, Type type, Mode mode) { + return getArea(type, mode); + } + + public static Rectangle2D getArea(Type type, Mode mode) { + final double width = FlagClass.DEFAULT_WIDTH; + final double height = FlagClass.DEFAULT_HEIGHT; + final double beakLength = FlagClass.getBeakLength(height, FlagClass.DEFAULT_BEAK_ANGLE); + return getArea(type, mode, width, height, beakLength); + } + + public static Rectangle2D getArea(Type type, Mode mode, double width, double height, double beakLength) { + double x = 0; + double y = -height / 2; + double w = width; + double h = height; + + if (type == Type.In) { + if (mode instanceof FlagClass.External) { + x = -width-beakLength; + } else if (mode == Mode.Internal) { + x = -beakLength; + w = beakLength; + } + } else if (type == Type.Out) { + if (mode == Mode.Internal) { + w = beakLength; + } + } + + return new Rectangle2D.Double(x, y, w, h); + } + + protected Shape getShape(ReadGraph graph, Type type, Mode mode) throws DatabaseException { + return getShape(type, mode); + } + + public static Shape getShape(Type type, Mode mode) { + final double width = FlagClass.DEFAULT_WIDTH; + final double height = FlagClass.DEFAULT_HEIGHT; + final double beakLength = FlagClass.getBeakLength(height, FlagClass.DEFAULT_BEAK_ANGLE); + Path2D path = new Path2D.Double(); + FlagClass.createFlagShape(path, type, mode, width, height, beakLength); + return path; + } + + protected String[] getText(ReadGraph graph) throws DatabaseException { + return graph.syncRequest(DiagramRequests.getFlagText(flag)); + } + +} \ No newline at end of file