X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felementclass%2Fcanvas%2FElementViewport.java;h=508c608df32cd23cbf4f4b70b1ee04efb9529903;hb=refs%2Fchanges%2F38%2F238%2F2;hp=84163afad3a14ad3449122466bcc61e580c2db39;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/canvas/ElementViewport.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/canvas/ElementViewport.java index 84163afad..508c608df 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/canvas/ElementViewport.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/canvas/ElementViewport.java @@ -1,64 +1,64 @@ -/******************************************************************************* - * 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.g2d.elementclass.canvas; - -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; - -import org.simantics.g2d.element.ElementUtils; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.scenegraph.utils.GeometryUtils; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; -import org.simantics.utils.page.MarginUtils; -import org.simantics.utils.page.MarginUtils.Margins; - -/** - * Lock viewport (KEY_VIEWPORT) of DiagramPainter to an element. - * - * e.setHint(DiagramHints.KEY_DIAGRAM, ElementUtils.getDiagram(focusE)); Note! - * Add this handler _before_ diagram painter in element class - * - * Keys: ElementViewport.KEY_ELEMENT - * - * @See {@link DiagramPainter} - * @author Toni Kalajainen - */ -public class ElementViewport implements SceneGraph { - - public static final Key KEY_ELEMENT = new KeyOf(IElement.class); - - private static final long serialVersionUID = -849879952227051310L; - - public static final ElementViewport INSTANCE = new ElementViewport(); - - private final Margins margins = MarginUtils.MARGINS5; - - @Override - public void cleanup(IElement e) { - } - - @Override - public void init(IElement e, G2DParentNode parent) { - // Initializes viewport before DiagramPainter initializes the - // scenegraph. - IElement focusE = e.getHint(KEY_ELEMENT); - Rectangle2D focusBounds = ElementUtils.getElementBounds(focusE); - Rectangle2D bounds = ElementUtils.getElementBounds(e); - - AffineTransform at = GeometryUtils.fitArea(bounds, focusBounds, margins); - e.setHint(DiagramPainter.KEY_VIEWPORT, at); - } - -} +/******************************************************************************* + * 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.g2d.elementclass.canvas; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.utils.GeometryUtils; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; +import org.simantics.utils.page.MarginUtils; +import org.simantics.utils.page.MarginUtils.Margins; + +/** + * Lock viewport (KEY_VIEWPORT) of DiagramPainter to an element. + * + * e.setHint(DiagramHints.KEY_DIAGRAM, ElementUtils.getDiagram(focusE)); Note! + * Add this handler _before_ diagram painter in element class + * + * Keys: ElementViewport.KEY_ELEMENT + * + * @See {@link DiagramPainter} + * @author Toni Kalajainen + */ +public class ElementViewport implements SceneGraph { + + public static final Key KEY_ELEMENT = new KeyOf(IElement.class); + + private static final long serialVersionUID = -849879952227051310L; + + public static final ElementViewport INSTANCE = new ElementViewport(); + + private final Margins margins = MarginUtils.MARGINS5; + + @Override + public void cleanup(IElement e) { + } + + @Override + public void init(IElement e, G2DParentNode parent) { + // Initializes viewport before DiagramPainter initializes the + // scenegraph. + IElement focusE = e.getHint(KEY_ELEMENT); + Rectangle2D focusBounds = ElementUtils.getElementBounds(focusE); + Rectangle2D bounds = ElementUtils.getElementBounds(e); + + AffineTransform at = GeometryUtils.fitArea(bounds, focusBounds, margins); + e.setHint(DiagramPainter.KEY_VIEWPORT, at); + } + +}