aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2013-06-26 10:42:10 (EDT)
committerDirk Fauth2013-06-26 10:42:10 (EDT)
commit0c1127c96a45f85ba7561b9b68228be94d3e7da9 (patch)
treea55b3f8a65d5ed66b4c27dca1cf7eac0ad52f558
parent5f4b3343b380a9973d32f3f45eb22b614ad1e6ef (diff)
downloadorg.eclipse.nebula-0c1127c96a45f85ba7561b9b68228be94d3e7da9.zip
org.eclipse.nebula-0c1127c96a45f85ba7561b9b68228be94d3e7da9.tar.gz
org.eclipse.nebula-0c1127c96a45f85ba7561b9b68228be94d3e7da9.tar.bz2
Added support to connect the zoom behaviour of different Gantt charts
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java5
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/CompoundZoomHandler.java60
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java27
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java7
-rw-r--r--widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IZoomHandler.java35
5 files changed, 124 insertions, 10 deletions
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java
index 4365c0c..da501ec 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/AbstractSettings.java
@@ -506,6 +506,11 @@ public abstract class AbstractSettings implements ISettings {
public boolean scrollChartVerticallyOnMouseWheel() {
return true;
}
+
+ public int getMinZoomLevel() {
+ return ISettings.MIN_ZOOM_LEVEL;
+ }
+
public Calendar getPeriodStart() {
return null;
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/CompoundZoomHandler.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/CompoundZoomHandler.java
new file mode 100644
index 0000000..727edc5
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/CompoundZoomHandler.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth and others.
+ * 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Point;
+
+public class CompoundZoomHandler implements IZoomHandler {
+
+ private List<IZoomHandler> handler = new ArrayList<IZoomHandler>();
+
+ public void addHandler(IZoomHandler handler) {
+ this.handler.add(handler);
+ }
+
+ public void removeHandler(IViewPortHandler handler) {
+ this.handler.remove(handler);
+ }
+
+ public void zoomIn() {
+ for (IZoomHandler vph : this.handler) {
+ vph.zoomIn();
+ }
+ }
+
+ public void zoomIn(boolean fromMouseWheel, Point mouseLoc) {
+ for (IZoomHandler vph : this.handler) {
+ vph.zoomIn(fromMouseWheel, mouseLoc);
+ }
+ }
+
+ public void zoomOut() {
+ for (IZoomHandler vph : this.handler) {
+ vph.zoomOut();
+ }
+ }
+
+ public void zoomOut(boolean fromMouseWheel, Point mouseLoc) {
+ for (IZoomHandler vph : this.handler) {
+ vph.zoomOut(fromMouseWheel, mouseLoc);
+ }
+ }
+
+ public void resetZoom() {
+ for (IZoomHandler vph : this.handler) {
+ vph.resetZoom();
+ }
+ }
+
+}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
index 46f951b..8c3650c 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/GanttComposite.java
@@ -72,7 +72,7 @@ import org.eclipse.swt.widgets.Tracker;
// -- FEATURES
// TODO: allow zoom-out for D-day charts (we need to flip it from ISettings.D_DAY to a bool as we should draw d-day headers in each respective zoom-level head instead)
// TODO: millisecond view
-public final class GanttComposite extends Canvas implements MouseListener, MouseMoveListener, MouseTrackListener, KeyListener {
+public final class GanttComposite extends Canvas implements MouseListener, MouseMoveListener, MouseTrackListener, KeyListener, IZoomHandler {
public static int _osType = Constants.OS_OTHER;
@@ -328,6 +328,8 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
private final Calendar[] holidays;
+ private IZoomHandler zoomHandler;
+
static {
final String osProperty = System.getProperty("os.name");
if (osProperty != null) {
@@ -440,6 +442,7 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
});
this.holidays = holidays;
+ this.zoomHandler = this;
}
// midnight "thread" (we need to redraw the screen once at Midnight as the date line will otherwise be incorrect)
@@ -491,9 +494,9 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
_showZoomHelper = _settings.showZoomLevelBox();
if (event.count > 0) {
- zoomIn(true, new Point(event.x, event.y));
+ zoomHandler.zoomIn(true, new Point(event.x, event.y));
} else {
- zoomOut(true, new Point(event.x, event.y));
+ zoomHandler.zoomOut(true, new Point(event.x, event.y));
}
} else {
// note to self: on SWT 3.5+ it seems we just force it, older versions may need to turn this off
@@ -1471,17 +1474,17 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
zoomIn.addListener(SWT.Selection, new Listener() {
public void handleEvent(final Event event) {
- zoomIn();
+ zoomHandler.zoomIn();
}
});
zoomOut.addListener(SWT.Selection, new Listener() {
public void handleEvent(final Event event) {
- zoomOut();
+ zoomHandler.zoomOut();
}
});
zoomReset.addListener(SWT.Selection, new Listener() {
public void handleEvent(final Event event) {
- resetZoom();
+ zoomHandler.resetZoom();
}
});
@@ -8284,7 +8287,7 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
zoomIn(false, null);
}
- private void zoomIn(boolean fromMouseWheel, Point mouseLoc) {
+ public void zoomIn(boolean fromMouseWheel, Point mouseLoc) {
checkWidget();
if (!_settings.enableZooming()) return;
/*
@@ -8292,8 +8295,8 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
return;*/
_zoomLevel--;
- if (_zoomLevel < ISettings.MIN_ZOOM_LEVEL) {
- _zoomLevel = ISettings.MIN_ZOOM_LEVEL;
+ if (_zoomLevel < _settings.getMinZoomLevel()) {
+ _zoomLevel = _settings.getMinZoomLevel();
return;
}
@@ -8322,7 +8325,7 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
zoomOut(false, null);
}
- private void zoomOut(boolean fromMouseWheel, Point mouseLoc) {
+ public void zoomOut(boolean fromMouseWheel, Point mouseLoc) {
checkWidget();
if (!_settings.enableZooming()) return;
@@ -8554,4 +8557,8 @@ public final class GanttComposite extends Canvas implements MouseListener, Mouse
ISettings getSettings() {
return _settings;
}
+
+ public void setZoomHandler(IZoomHandler zoomHandler) {
+ this.zoomHandler = zoomHandler;
+ }
}
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java
index 973c33b..0f05e14 100644
--- a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/ISettings.java
@@ -1077,6 +1077,13 @@ public interface ISettings {
*/
public boolean scrollChartVerticallyOnMouseWheel();
+ /**
+ * Returns the minimum zoom level.
+ * Default should return {@link ISettings#MIN_ZOOM_LEVEL}
+ * @return
+ */
+ public int getMinZoomLevel();
+
public Calendar getPeriodStart();
public Calendar getPeriodEnd();
diff --git a/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IZoomHandler.java b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IZoomHandler.java
new file mode 100644
index 0000000..ee95a8b
--- /dev/null
+++ b/widgets/ganttchart/org.eclipse.nebula.widgets.ganttchart/src/org/eclipse/nebula/widgets/ganttchart/IZoomHandler.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Dirk Fauth and others.
+ * 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:
+ * Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.nebula.widgets.ganttchart;
+
+import org.eclipse.swt.graphics.Point;
+
+public interface IZoomHandler {
+
+ /**
+ * Zooms in. If zooming is disabled, does nothing.
+ */
+ public void zoomIn();
+
+ public void zoomIn(boolean fromMouseWheel, Point mouseLoc);
+
+ /**
+ * Zooms out. If zooming is disabled, does nothing.
+ */
+ public void zoomOut();
+
+ public void zoomOut(boolean fromMouseWheel, Point mouseLoc);
+
+ /**
+ * Resets the zoom level to that set in the settings.
+ */
+ public void resetZoom();
+}