diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2012-11-08 11:34:05 +0100 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2012-11-08 11:34:12 +0100 |
commit | 0069178bbfcf6a39599422e6821c6b9c1e2a91d6 (patch) | |
tree | aa214c5894c911bc582b23a71227e9edbc13331c /trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java | |
parent | 9730dd493ab3820f052d8303cafbcc5fa2dfce12 (diff) | |
download | pdf-over-0069178bbfcf6a39599422e6821c6b9c1e2a91d6.tar.gz pdf-over-0069178bbfcf6a39599422e6821c6b9c1e2a91d6.tar.bz2 pdf-over-0069178bbfcf6a39599422e6821c6b9c1e2a91d6.zip |
+ rebuild bku selection
Diffstat (limited to 'trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java')
-rw-r--r-- | trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java new file mode 100644 index 00000000..2ab5c82e --- /dev/null +++ b/trunk/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); + } + + } +} |