From 01561a68f6e2bb13cca62c7472f43c65d1c464a2 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:16:52 +0000 Subject: + rebuild bku selection git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@234 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../asit/pdfover/gui/controls/ClickableCanvas.java | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java new file mode 100644 index 00000000..2ab5c82e --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java @@ -0,0 +1,126 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class ClickableCanvas extends Canvas { + + private Image image = null; + + /** + * @param parent + * @param style + */ + public ClickableCanvas(Composite parent, int style) { + super(parent, style); + + this.addPaintListener(new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + ClickableCanvas.this.paintControl(e); + } + }); + + final Cursor hand = new Cursor(this.getDisplay(), SWT.CURSOR_HAND); + + this.addListener(SWT.Resize, new Listener() { + + @Override + public void handleEvent(Event event) { + ClickableCanvas.this.redraw(); + } + }); + + this.setCursor(hand); + + } + + /** + * Gets the image + * + * @return the image + */ + public Image getImage() { + return this.image; + } + + /** + * Sets the Image + * + * @param image + * the imgage to set + */ + public void setImage(Image image) { + this.image = image; + } + + /** + * Main painting method + * + * @param e + */ + void paintControl(PaintEvent e) { + this.paintText(e); + } + + /** + * Paint the text or image on the button + * + * @param e + */ + protected void paintText(PaintEvent e) { + Point size = this.getSize(); + int width = size.x; + + // e.gc.fillGradientRectangle(0, 1, width, height / 4, true); + + if (this.image != null) { + + //log.debug("Width: " + width + " Height: " + height); + + int w = 0; + Image tmp = null; + if(this.image.getImageData().width < width) { + tmp = new Image(getDisplay(), this.image.getImageData()); + w = (width - this.image.getImageData().width) / 2; + } else if(this.image.getImageData().width > width) { + tmp = new Image(getDisplay(), this.image.getImageData().scaledTo(width, width)); + } else { + tmp = new Image(getDisplay(), this.image.getImageData()); + } + + e.gc.drawImage(tmp, w, w); + } + + } +} -- cgit v1.2.3