summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:16:52 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:16:52 +0000
commit01561a68f6e2bb13cca62c7472f43c65d1c464a2 (patch)
treee66afea3723e790a6c13e2cfe5ab45201492f949 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java
parent5201ddc04f09989b0be856bf005b7ddc19312c81 (diff)
downloadpdf-over-01561a68f6e2bb13cca62c7472f43c65d1c464a2.tar.gz
pdf-over-01561a68f6e2bb13cca62c7472f43c65d1c464a2.tar.bz2
pdf-over-01561a68f6e2bb13cca62c7472f43c65d1c464a2.zip
+ rebuild bku selection
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@234 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ClickableCanvas.java126
1 files changed, 126 insertions, 0 deletions
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);
+ }
+
+ }
+}