X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felementclass%2FPaintableSymbolHandler.java;fp=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felementclass%2FPaintableSymbolHandler.java;h=da052041aa70b34e2feeb305c77ce787cb78b83c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=8340420c23896fe6c4162e7455b4c982487c8d1a;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/PaintableSymbolHandler.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/PaintableSymbolHandler.java index 8340420c2..da052041a 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/PaintableSymbolHandler.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/PaintableSymbolHandler.java @@ -1,89 +1,89 @@ -/******************************************************************************* - * 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; - -import java.awt.Shape; -import java.awt.geom.Rectangle2D; - -import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.InternalSize; -import org.simantics.g2d.element.handler.Pick; -import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.g2d.image.Image; -import org.simantics.g2d.utils.GeometryUtils; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.utils.datastructures.cache.IProvider; -import org.simantics.utils.datastructures.cache.StaticProvider; - -/** - * Handles pick and painting of paintable symbols - * - * @author Toni Kalajainen - */ -public class PaintableSymbolHandler implements SceneGraph, Pick, InternalSize { - - private static final long serialVersionUID = 8612101011132309291L; - - private final Rectangle2D rect; - private final Double ratio; - private final Image ps; - - private final IProvider symbolProvider; - - public PaintableSymbolHandler(Image symbol) - { - this.symbolProvider = StaticProvider.provide(symbol); - ps = symbolProvider.get(); - rect = ps.getBounds(); - ratio = rect.getWidth() / rect.getHeight(); - } - - public PaintableSymbolHandler(IProvider symbolProvider) - { - this.symbolProvider = symbolProvider; - ps = symbolProvider.get(); - rect = ps.getBounds(); - ratio = rect.getWidth() / rect.getHeight(); - } - - - @Override - public void cleanup(IElement e) { - } - - @Override - public void init(IElement e, G2DParentNode parent) { - System.out.println("PaintableSymbolHandler.paint()"); -// Graphics2D g = elementGC.getGraphics2D(); -// Image ps = ctx.getSingleItem(SymbolUtil.class).get(symbolProvider, g.getDeviceConfiguration()); -// ps.paint(elementGC); - } - - @Override - public boolean pickTest(IElement e, Shape s, PickPolicy policy) { - Shape outline = ps.getOutline(); - if (policy == PickPolicy.PICK_CONTAINED_OBJECTS) - return GeometryUtils.contains(s, outline); - if (policy == PickPolicy.PICK_INTERSECTING_OBJECTS) - return GeometryUtils.intersects(s, outline); - throw new RuntimeException("Unimplemented"); - } - - @Override - public Rectangle2D getBounds(IElement e, Rectangle2D size) { - if (size==null) size = new Rectangle2D.Double(); - size.setFrame(rect); - return size; - } - -} +/******************************************************************************* + * 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; + +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.InternalSize; +import org.simantics.g2d.element.handler.Pick; +import org.simantics.g2d.element.handler.SceneGraph; +import org.simantics.g2d.image.Image; +import org.simantics.g2d.utils.GeometryUtils; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.utils.datastructures.cache.IProvider; +import org.simantics.utils.datastructures.cache.StaticProvider; + +/** + * Handles pick and painting of paintable symbols + * + * @author Toni Kalajainen + */ +public class PaintableSymbolHandler implements SceneGraph, Pick, InternalSize { + + private static final long serialVersionUID = 8612101011132309291L; + + private final Rectangle2D rect; + private final Double ratio; + private final Image ps; + + private final IProvider symbolProvider; + + public PaintableSymbolHandler(Image symbol) + { + this.symbolProvider = StaticProvider.provide(symbol); + ps = symbolProvider.get(); + rect = ps.getBounds(); + ratio = rect.getWidth() / rect.getHeight(); + } + + public PaintableSymbolHandler(IProvider symbolProvider) + { + this.symbolProvider = symbolProvider; + ps = symbolProvider.get(); + rect = ps.getBounds(); + ratio = rect.getWidth() / rect.getHeight(); + } + + + @Override + public void cleanup(IElement e) { + } + + @Override + public void init(IElement e, G2DParentNode parent) { + System.out.println("PaintableSymbolHandler.paint()"); +// Graphics2D g = elementGC.getGraphics2D(); +// Image ps = ctx.getSingleItem(SymbolUtil.class).get(symbolProvider, g.getDeviceConfiguration()); +// ps.paint(elementGC); + } + + @Override + public boolean pickTest(IElement e, Shape s, PickPolicy policy) { + Shape outline = ps.getOutline(); + if (policy == PickPolicy.PICK_CONTAINED_OBJECTS) + return GeometryUtils.contains(s, outline); + if (policy == PickPolicy.PICK_INTERSECTING_OBJECTS) + return GeometryUtils.intersects(s, outline); + throw new RuntimeException("Unimplemented"); + } + + @Override + public Rectangle2D getBounds(IElement e, Rectangle2D size) { + if (size==null) size = new Rectangle2D.Double(); + size.setFrame(rect); + return size; + } + +}