]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/dnd/ElementClassDragItem.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / dnd / ElementClassDragItem.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.dnd;
13
14 import java.awt.geom.Rectangle2D;
15
16 import org.simantics.g2d.element.ElementClass;
17 import org.simantics.g2d.element.handler.StaticSymbol;
18 import org.simantics.g2d.image.Image;
19 import org.simantics.scenegraph.g2d.G2DParentNode;
20 import org.simantics.utils.datastructures.hints.HintContext;
21 import org.simantics.utils.datastructures.hints.IHintContext;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public class ElementClassDragItem implements IDragItem {
27
28     private final ElementClass ec;
29     private final HintContext        ctx = new HintContext();
30
31     public ElementClassDragItem(ElementClass ec) {
32         if (ec == null)
33             throw new NullPointerException("null element class");
34         this.ec = ec;
35     }
36
37     public ElementClass getElementClass() {
38         return ec;
39     }
40
41     @Override
42     public Rectangle2D getBounds() {
43         Image i = ec.getSingleItem(StaticSymbol.class).getImage();
44         return i.getBounds();
45     }
46
47     @Override
48     public void paint(G2DParentNode parent) {
49         Image i = ec.getSingleItem(StaticSymbol.class).getImage();
50         i.init(parent);
51     }
52
53     @Override
54     public IHintContext getHintContext() {
55         return ctx;
56     }
57
58 }