From cfc65077a2ff494401e76d28ef90fcbd22c0a418 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:57:13 +0000 Subject: Added custom border to MainBar buttons Added Hand cursor for MainBar buttons git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@54 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../java/at/asit/pdfover/gui/controls/MainBarButton.java | 12 +++++++++++- .../at/asit/pdfover/gui/controls/MainBarEndButton.java | 14 +++----------- .../at/asit/pdfover/gui/controls/MainBarMiddleButton.java | 14 +++----------- .../asit/pdfover/gui/controls/MainBarRectangleButton.java | 14 ++++---------- .../at/asit/pdfover/gui/controls/MainBarStartButton.java | 13 +++---------- 5 files changed, 24 insertions(+), 43 deletions(-) (limited to 'pdf-over-gui/src') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java index 631ee3e8..509780fb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java @@ -17,9 +17,14 @@ package at.asit.pdfover.gui.controls; // Imports import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseMoveListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Region; @@ -48,6 +53,8 @@ public abstract class MainBarButton extends Canvas { } }); + final Cursor hand = new Cursor(this.getDisplay(), SWT.CURSOR_HAND); + this.addListener(SWT.Resize, new Listener() { @Override @@ -58,6 +65,8 @@ public abstract class MainBarButton extends Canvas { } }); + this.setCursor(hand); + this.inactiveBackground = new Color(getDisplay(), 0x4B, 0x95, 0x00); this.activeBackground = new Color(getDisplay(), 0x98, 0xF2, 0x3D); @@ -171,7 +180,8 @@ public abstract class MainBarButton extends Canvas { e.gc.drawText(this.getText(), textx, texty); } else { int imgx = (width - height) / 2; - Image tmp = new Image(getDisplay(), this.image.getImageData().scaledTo(height, height)); + Image tmp = new Image(getDisplay(), this.image.getImageData() + .scaledTo(height, height)); e.gc.drawImage(tmp, imgx, 0); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java index b80b9645..2542d805 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java @@ -48,7 +48,7 @@ public class MainBarEndButton extends MainBarButton { * at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt * .events.PaintEvent) */ - /*@Override + @Override protected void paintButton(PaintEvent e) { Point size = this.getSize(); int height = size.y - 2; @@ -56,22 +56,14 @@ public class MainBarEndButton extends MainBarButton { int split = 10; int width = size.x; - int textlen = 0; - - if(this.getText() != null) { - textlen = this.getText().length(); - } - e.gc.drawLine(0, 0, width, 0); e.gc.drawLine(width, 0, width+split, (height) / 2); e.gc.drawLine(width, height, 0, height); e.gc.drawLine(0, height, 0+split, (height) / 2); e.gc.drawLine(0+split, (height) / 2, 0, 0); - int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; - int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; - e.gc.drawText(this.getText(), textx, texty); - }*/ + super.paintButton(e); + } /* * (non-Javadoc) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java index 5b9b580f..5512a74e 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java @@ -44,7 +44,7 @@ public class MainBarMiddleButton extends MainBarButton { /* (non-Javadoc) * @see at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt.events.PaintEvent) */ - /*@Override + @Override protected void paintButton(PaintEvent e) { Point size = this.getSize(); @@ -60,16 +60,8 @@ public class MainBarMiddleButton extends MainBarButton { e.gc.drawLine(0, height, 0+split, (height) / 2); e.gc.drawLine(0+split, (height) / 2, 0, 0); - int textlen = 0; - - if(getText() != null) { - textlen = this.getText().length(); - } - - int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; - int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; - e.gc.drawText(this.getText(), textx, texty); - }*/ + super.paintButton(e); + } /* (non-Javadoc) * @see at.asit.pdfover.gui.controls.MainBarButton#getCustomRegion() diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java index edac29e5..17971982 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java @@ -46,27 +46,21 @@ public class MainBarRectangleButton extends MainBarButton { /* (non-Javadoc) * @see at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt.events.PaintEvent) */ - /*@Override + @Override protected void paintButton(PaintEvent e) { Point size = this.getSize(); int height = size.y - 2; int width = size.x; - - int textlen = 0; - if(getText() != null) { - textlen = getText().length(); - } e.gc.drawLine(0, 0, width, 0); e.gc.drawLine(width, 0, width, height); e.gc.drawLine(width, height, 0, height); e.gc.drawLine(0, height, 0, 0); - int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; - int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; - e.gc.drawText(getText(), textx, texty); - }*/ + + super.paintButton(e); + } /* (non-Javadoc) * @see at.asit.pdfover.gui.controls.MainBarButton#getCustomRegion() diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java index 2577ce40..d43c86de 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java @@ -44,7 +44,6 @@ public class MainBarStartButton extends MainBarButton { /* (non-Javadoc) * @see at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt.events.PaintEvent) */ - /* @Override protected void paintButton(PaintEvent e) { Point size = this.getSize(); @@ -53,21 +52,15 @@ public class MainBarStartButton extends MainBarButton { int split = 10; int width = size.x - split; - - int textlen = 0; - if(getText() != null) { - textlen = getText().length(); - } e.gc.drawLine(0, 0, width, 0); e.gc.drawLine(width, 0, width + split, (height) / 2); e.gc.drawLine(width + split, (height) / 2, width, height); e.gc.drawLine(width, height, 0, height); e.gc.drawLine(0, height, 0, 0); - int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; - int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; - e.gc.drawText(getText(), textx, texty); - }*/ + + super.paintButton(e); + } /* (non-Javadoc) * @see at.asit.pdfover.gui.controls.MainBarButton#getRegion() -- cgit v1.2.3