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=8340420c23896fe6c4162e7455b4c982487c8d1a;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;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 new file mode 100644 index 000000000..8340420c2 --- /dev/null +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/PaintableSymbolHandler.java @@ -0,0 +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; + } + +}