From 7876b8a44bf4ea8b2d49646b366a30dfdbbf2643 Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Thu, 14 May 2020 14:35:24 +0300 Subject: [PATCH] #28 Adapt Chronograph for Passage Operator Rework "swt.stage" package Signed-off-by: Alexander Fedorov --- ...hStageImpl.java => ChronographCanvas.java} | 50 +++--------- .../internal/swt/stage/ChronographStage.java | 80 ------------------- .../internal/swt/stage/StageMouse.java | 6 +- .../internal/swt/stage/StagePaint.java | 4 +- .../internal/swt/stage/StageResize.java | 6 +- .../{StageMouseWheel.java => StageWheel.java} | 6 +- .../chronograph/viewer/ChronographViewer.java | 7 +- 7 files changed, 23 insertions(+), 136 deletions(-) rename bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/{ChronographStageImpl.java => ChronographCanvas.java} (94%) delete mode 100644 bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStage.java rename bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/{StageMouseWheel.java => StageWheel.java} (88%) diff --git a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStageImpl.java b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographCanvas.java similarity index 94% rename from bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStageImpl.java rename to bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographCanvas.java index d6036da..801ed83 100644 --- a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStageImpl.java +++ b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographCanvas.java @@ -42,14 +42,13 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; 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.eclipse.swt.widgets.ScrollBar; -public final class ChronographStageImpl extends Canvas implements ChronographStage { +public final class ChronographCanvas extends Canvas { private final AreaRectangle areaRectangle; @@ -80,11 +79,11 @@ public final class ChronographStageImpl extends Canvas implements ChronographSta private static ChronographManagerRenderers INSTANCE = ChronographManagerRenderers.getInstance(); - public ChronographStageImpl(Composite parent, ContainerProvider provider) { + public ChronographCanvas(Composite parent, ContainerProvider provider) { this(parent, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL, provider); } - public ChronographStageImpl(Composite parent, int style, ContainerProvider provider) { + public ChronographCanvas(Composite parent, int style, ContainerProvider provider) { super(parent, style); this.areaRectangle = new AreaRectangle(); this.dataProvider = provider; @@ -136,20 +135,16 @@ public void handleEvent(final Event event) { } private void initListeners() { - StageMouse msListener = new StageMouse<>(this); - StageMouseWheel msWheelListener = new StageMouseWheel<>(this); - StageResize resizeListener = new StageResize<>(this); addPaintListener(new StagePaint(this)); - addMouseListener(msListener); - addMouseMoveListener(msListener); - addMouseTrackListener(msListener); - addListener(SWT.MouseWheel, msWheelListener); - addListener(SWT.Resize, resizeListener); + StageMouse mouse = new StageMouse(this); + addMouseListener(mouse); + addMouseMoveListener(mouse); + addMouseTrackListener(mouse); + addListener(SWT.MouseWheel, new StageWheel(this)); + addListener(SWT.Resize, new StageResize(this)); } - @Override public void verticalScroll(Event event) { - if (event != null && event.detail == 0) { return; } @@ -173,7 +168,6 @@ protected void horizontalScroll(Event event) { redraw(); } - @Override public void updateScrollers() { if (bricks == null || bricks.isEmpty()) { return; @@ -183,7 +177,6 @@ public void updateScrollers() { scrollBarHorizontal.setSelection(pXhint); } - @Override public void handleResize() { Rectangle rect = getBounds(); Rectangle client = getClientArea(); @@ -308,7 +301,6 @@ public Rectangle getBounds() { return new Rectangle(0, 0, super.getBounds().width, pY); } - @Override public Rectangle getMainBounds() { return boundsGlobal; } @@ -340,7 +332,6 @@ private void calculateSectionBounds(Area area, Collection
sections, int } } - @Override public void calculateObjectBounds() { Rectangle clientArea = super.getClientArea(); visiableArea = new AreaImpl(clientArea.x, clientArea.y, clientArea.width, clientArea.height); @@ -428,7 +419,6 @@ private void drawSelectedObjects(final GC gc, Area area, final Collection getDrawingObjects() { return registry.getBricks(); } @@ -483,7 +471,6 @@ private void updateStageScale() { } } - @Override public void scaleUp() { checkWidget(); stageScale--; @@ -493,7 +480,6 @@ public void scaleUp() { navigateToUnit(pXhint); } - @Override public void scaleDown() { checkWidget(); stageScale++; @@ -507,12 +493,10 @@ public void redraw() { super.redraw(); } - @Override public int getPositionByX() { return pX; } - @Override public void setPositionByX(int x) { this.pX = x; } @@ -522,22 +506,10 @@ public Rectangle getClientArea() { return super.getClientArea(); } - @Override public void getHint() { pXhint = pX / (pxlHint * stageScale); } - @Override - public void setLayoutData(GridData gridData) { - super.setLayoutData(gridData); - - } - - @Override - public void setInput(List objects) { - } - - @Override public Area getBrickArea(Brick brick) { return getDrawingArea(brick); } @@ -550,7 +522,6 @@ public void removeSelected(Brick brick) { bricksSelected.remove(brick); } - @Override public void addRemoveSelected(Brick brick) { List markedBriks = new ArrayList(); for (Brick selectedBrick : bricksSelected) { @@ -567,7 +538,6 @@ public void addRemoveSelected(Brick brick) { } } - @Override public void setProvider(ContainerProvider provider) { this.dataProvider = provider; this.labelProvider = provider.getLabelProvider(); @@ -577,7 +547,6 @@ public void setProvider(ContainerProvider provider) { this.redraw(); } - @Override public void setZoomLevelDown() { this.zoom++; this.calculateObjectBounds(); @@ -585,7 +554,6 @@ public void setZoomLevelDown() { } - @Override public void setZoomLevelUp() { this.zoom--; if (this.zoom < 1) { diff --git a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStage.java b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStage.java deleted file mode 100644 index 3e31b51..0000000 --- a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/ChronographStage.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 ArSysOp - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Sergei Kovalchuk - - * initial API and implementation - *******************************************************************************/ -package org.eclipse.chronograph.internal.swt.stage; - -import java.util.List; - -import org.eclipse.chronograph.internal.api.Area; -import org.eclipse.chronograph.internal.api.Brick; -import org.eclipse.chronograph.internal.api.providers.ContainerProvider; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Drawable; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Event; - -/** - * - * Interface dedicated to specify main stage - * - */ -public interface ChronographStage extends Drawable { - - public void setInput(List objects); - - public List getDrawingObjects(); - - public void setCursor(Cursor cursor); - - public void setPositionByX(int x); - - public int getPositionByX(); - - public void setLayoutData(GridData data); - - public Rectangle getClientArea(); - - public Rectangle getMainBounds(); - - public int getScale(); - - public void redraw(); - - public void updateScrollers(); - - public void verticalScroll(Event event); - - public void scaleUp(); - - public void scaleDown(); - - public void getHint(); - - public void handleResize(); - - public void calculateObjectBounds(); - - public void navigateToUnit(int unit); - - public Area getBrickArea(Brick to); - - public void addRemoveSelected(Brick brick); - - public void setProvider(ContainerProvider provider); - - public void setZoomLevelDown(); - - public void setZoomLevelUp(); - -} diff --git a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouse.java b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouse.java index cb034bc..e2e1e00 100644 --- a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouse.java +++ b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouse.java @@ -32,9 +32,9 @@ * * @param */ -final class StageMouse implements MouseListener, MouseMoveListener, MouseTrackListener { +final class StageMouse implements MouseListener, MouseMoveListener, MouseTrackListener { - private T stage; + private ChronographCanvas stage; private static final Cursor CURSOR_NONE = new Cursor(Display.getDefault(), SWT.NONE); private static final Cursor CURSOR_HAND = new Cursor(Display.getDefault(), SWT.CURSOR_HAND); private Point startPoint; @@ -42,7 +42,7 @@ final class StageMouse implements MouseListener, Mou private boolean isMouseDown; private int xPosition = 0; - public StageMouse(T stage) { + public StageMouse(ChronographCanvas stage) { this.stage = stage; } diff --git a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StagePaint.java b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StagePaint.java index 0629317..13fb6cc 100644 --- a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StagePaint.java +++ b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StagePaint.java @@ -18,9 +18,9 @@ final class StagePaint implements PaintListener { - private final ChronographStageImpl sceneComposer; + private final ChronographCanvas sceneComposer; - public StagePaint(ChronographStageImpl sceneComposer) { + public StagePaint(ChronographCanvas sceneComposer) { this.sceneComposer = sceneComposer; } diff --git a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageResize.java b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageResize.java index a1223a4..a784f30 100644 --- a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageResize.java +++ b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageResize.java @@ -16,11 +16,11 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; -final class StageResize implements Listener { +final class StageResize implements Listener { - private final T stage; + private final ChronographCanvas stage; - public StageResize(T stage) { + public StageResize(ChronographCanvas stage) { this.stage = stage; } diff --git a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouseWheel.java b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageWheel.java similarity index 88% rename from bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouseWheel.java rename to bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageWheel.java index 1a5bded..c000804 100644 --- a/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageMouseWheel.java +++ b/bundles/org.eclipse.chronograph.swt/src/org/eclipse/chronograph/internal/swt/stage/StageWheel.java @@ -17,11 +17,11 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; -final class StageMouseWheel implements Listener { +final class StageWheel implements Listener { - private final T stage; + private final ChronographCanvas stage; - public StageMouseWheel(T stage) { + public StageWheel(ChronographCanvas stage) { this.stage = stage; } diff --git a/bundles/org.eclipse.chronograph.viewer/src/org/eclipse/chronograph/viewer/ChronographViewer.java b/bundles/org.eclipse.chronograph.viewer/src/org/eclipse/chronograph/viewer/ChronographViewer.java index a9037ed..51c9813 100644 --- a/bundles/org.eclipse.chronograph.viewer/src/org/eclipse/chronograph/viewer/ChronographViewer.java +++ b/bundles/org.eclipse.chronograph.viewer/src/org/eclipse/chronograph/viewer/ChronographViewer.java @@ -26,18 +26,17 @@ import org.eclipse.chronograph.internal.swt.SectionStyler; import org.eclipse.chronograph.internal.swt.StageStyler; import org.eclipse.chronograph.internal.swt.StatusStyler; -import org.eclipse.chronograph.internal.swt.stage.ChronographStage; -import org.eclipse.chronograph.internal.swt.stage.ChronographStageImpl; +import org.eclipse.chronograph.internal.swt.stage.ChronographCanvas; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; public class ChronographViewer { - private final ChronographStage stage; + private final ChronographCanvas stage; private final List stylers; public ChronographViewer(Composite parent, ContainerProvider provider) { - this.stage = new ChronographStageImpl(parent, provider); + this.stage = new ChronographCanvas(parent, provider); this.stage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); this.stage.navigateToUnit(UnitConverter.localDatetoUnits(LocalDate.now().minusDays(7))); stylers = new ArrayList<>();