aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHallvard Traetteberg2012-05-10 03:46:10 (EDT)
committerHallvard Traetteberg2012-06-02 09:35:05 (EDT)
commit79fce915d534ebd23bfe55424a600b797333f6ed (patch)
tree41d5f7c20274be7789c18c95855294fc0d8d628c
parent355a48eacc1dd01a2dd547171d7247a463a67a2e (diff)
downloadorg.eclipse.nebula-79fce915d534ebd23bfe55424a600b797333f6ed.zip
org.eclipse.nebula-79fce915d534ebd23bfe55424a600b797333f6ed.tar.gz
org.eclipse.nebula-79fce915d534ebd23bfe55424a600b797333f6ed.tar.bz2
Restructure label and pinpoint provider and support tool tips.
-rw-r--r--widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/IToolTipProvider.java15
-rw-r--r--widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/LabelImageProvider.java134
-rw-r--r--widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/PinPointProvider.java61
3 files changed, 149 insertions, 61 deletions
diff --git a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/IToolTipProvider.java b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/IToolTipProvider.java
new file mode 100644
index 0000000..b7f8c29
--- /dev/null
+++ b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/IToolTipProvider.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Hallvard Trūtteberg.
+ * 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:
+ * Hallvard Trūtteberg - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.jface.geomap;
+
+public interface IToolTipProvider {
+ public Object getToolTip(Object element);
+}
diff --git a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/LabelImageProvider.java b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/LabelImageProvider.java
new file mode 100644
index 0000000..060289d
--- /dev/null
+++ b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/LabelImageProvider.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Hallvard Trūtteberg.
+ * 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:
+ * Hallvard Trūtteberg - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.nebula.jface.geomap;
+
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * A default implementation of a LabelProvider that uses a GoogleIconDescriptor to create a bubble image with the text returned by getText.
+ * @author hal
+ *
+ */
+public class LabelImageProvider extends LabelProvider implements IPinPointProvider, IToolTipProvider {
+
+ private ImageRegistry imageRegistry;
+
+ private boolean hasShadow;
+
+ private RGB textColor = new RGB(0, 0, 0);
+ private RGB fillColor = new RGB(255, 250, 200);
+
+ private String iconStyle = GoogleIconDescriptor.icon_bubble_text_small;
+ private String frameStyle = GoogleIconDescriptor.frame_style_bb;
+
+ protected ImageRegistry getImageRegistry() {
+ if (imageRegistry == null) {
+ imageRegistry = createImageRegistry();
+ }
+ return imageRegistry;
+ }
+
+ protected ImageRegistry createImageRegistry() {
+ return new ImageRegistry();
+ }
+
+ @Override
+ public void dispose() {
+ if (imageRegistry != null) {
+ imageRegistry.dispose();
+ imageRegistry = null;
+ }
+ super.dispose();
+ }
+
+ public boolean hasShadow() {
+ return hasShadow;
+ }
+
+ public void setHasShadow(boolean hasShadow) {
+ this.hasShadow = hasShadow;
+ }
+
+ public RGB getTextColor() {
+ return textColor;
+ }
+
+ public void setTextColor(RGB textColor) {
+ this.textColor = textColor;
+ }
+
+ public RGB getFillColor() {
+ return fillColor;
+ }
+
+ public void setFillColor(RGB fillColor) {
+ this.fillColor = fillColor;
+ }
+
+ public String getIconStyle() {
+ return iconStyle;
+ }
+
+ public void setIconStyle(String iconStyle) {
+ this.iconStyle = iconStyle;
+ }
+
+ public String getFrameStyle() {
+ return frameStyle;
+ }
+
+ public void setFrameStyle(String frameStyle) {
+ this.frameStyle = frameStyle;
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ String text = getText(element);
+ if (text == null) {
+ return null;
+ }
+ Image image = getImageRegistry().get(text);
+ if (image == null) {
+ GoogleIconDescriptor.Options options = new GoogleIconDescriptor.Options(getIconStyle(), null, getFrameStyle(), hasShadow(), text, getFillColor(), getTextColor());
+ GoogleIconDescriptor descriptor = new GoogleIconDescriptor(options);
+ imageRegistry.put(text, descriptor);
+ image = getImageRegistry().get(text);
+ }
+ return image;
+ }
+
+ public Point getPinPoint(Object element) {
+ // must correspond to frameStyle
+ return getPinPoint(element, 0.0f, 1.0f);
+ }
+
+ /**
+ * Helper method for computing the point based on the size of the image.
+ * The float arguments alignX and alignY are multiplied with the width and height of the image, respectively.
+ * @param element the element to provide the point for
+ * @param alignX a float that is multiplied with the width of the image, to give the x coordinate of the point
+ * @param alignY a float that is multiplied with the height of the image, to give the y coordinate of the point
+ * @return
+ */
+ protected Point getPinPoint(Object element, float alignX, float alignY) {
+ Rectangle bounds = getImage(element).getBounds();
+ return new Point((int) (bounds.width * alignX), (int) (bounds.height * alignY));
+ }
+
+ public Object getToolTip(Object element) {
+ return getText(element);
+ }
+}
diff --git a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/PinPointProvider.java b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/PinPointProvider.java
deleted file mode 100644
index f361b64..0000000
--- a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/PinPointProvider.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Hallvard Trūtteberg.
- * 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:
- * Hallvard Trūtteberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.nebula.jface.geomap;
-
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-
-/**
- * A default implementation of a LabelProvider that also implements IPinPointProvider.
- * @author hal
- *
- */
-public class PinPointProvider extends LabelProvider implements IPinPointProvider {
-
- private final Point defaultPinPoint;
-
- /**
- * A PinPointProvider that returns the corresponding pin point.
- * @param x the x coordinate of the point
- * @param y the y coordinate of the point
- */
- public PinPointProvider(int x, int y) {
- defaultPinPoint = new Point(0, 0);
- }
-
- /**
- * A PinPointProvider that returns 0, 0 for the pin point.
- */
- public PinPointProvider() {
- this(0, 0);
- }
-
- /**
- * The default implementation just returns the value of the defaultPinPoint field.
- */
- public Point getPinPoint(Object element) {
- return defaultPinPoint;
- }
-
- /**
- * Helper method for computing the point based on the size of the image.
- * The float arguments alignX and alignY are multiplied with the width and height of the image, respectively.
- * @param element the element to provide the point for
- * @param alignX a float that is multiplied with the width of the image, to give the x coordinate of the point
- * @param alignY a float that is multiplied with the height of the image, to give the y coordinate of the point
- * @return
- */
- protected Point getPinPoint(Object element, float alignX, float alignY) {
- Rectangle bounds = getImage(element).getBounds();
- return new Point((int) (bounds.width * alignX), (int) (bounds.height * alignY));
- }
-}