| /******************************************************************************* |
| * Copyright (c) 2010-2011, Istvan Rath and Zoltan Ujhelyi |
| * 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: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.visualisation.common.labelproviders.internal; |
| |
| import org.eclipse.draw2d.Graphics; |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.draw2d.Shape; |
| import org.eclipse.draw2d.geometry.Dimension; |
| import org.eclipse.draw2d.geometry.Rectangle; |
| import org.eclipse.swt.graphics.Image; |
| |
| /** |
| * Figure class centering an Image and a Label below it. |
| * @author Istvan Rath |
| * |
| */ |
| public class ImageCenteringFigure extends ShapeCenteringFigure |
| { |
| |
| private Image im; |
| |
| public ImageCenteringFigure(boolean needBorder, Image image,String labelText,IFigure tooltip) |
| { |
| super(needBorder,labelText,tooltip); |
| im = image; |
| } |
| |
| public ImageCenteringFigure(Image image,String labelText,IFigure tooltip) |
| { |
| super(false,labelText,tooltip); |
| im = image; |
| } |
| |
| /* |
| @Override |
| protected void createAnchors() |
| { |
| iIncomingAnchor = new ChopboxAnchor(iShapeFigure); |
| iOutgoingAnchor = new ChopboxAnchor(iShapeFigure); |
| } |
| */ |
| /** |
| * Override in subclasses if not original image file size is desired. |
| * @return |
| */ |
| protected Dimension getShapeDimension() |
| { |
| if (im!=null) |
| { |
| org.eclipse.swt.graphics.Rectangle bounds = im.getBounds(); |
| return new Dimension(bounds.width, bounds.height); |
| } |
| return new Dimension(50,50); |
| } |
| |
| public class ImageShape extends Shape |
| { |
| @Override |
| protected void fillShape(Graphics graphics) |
| { |
| Rectangle ca = ImageShape.this.getClientArea(); |
| org.eclipse.swt.graphics.Rectangle bounds = im.getBounds(); |
| graphics.drawImage(im, |
| 0,0, |
| bounds.width, bounds.height, |
| ca.x, ca.y, |
| ca.width, ca.height |
| ); |
| } |
| @Override |
| protected void outlineShape(Graphics graphics) { |
| // outline is empty |
| } |
| } |
| |
| @Override |
| protected void createShapeFigure() |
| { |
| iShapeFigure = new ImageShape(); |
| iShapeFigure.setOpaque(false); |
| iShapeFigure.setBackgroundColor(ColorFactory.getColor(239,235,231)); |
| iShapeFigure.setForegroundColor(ColorFactory.getColor(70,70,70)); |
| iShapeFigure.setSize(getShapeDimension()); |
| } |
| |
| |
| |
| |
| } |