Skip to content

Commit

Permalink
#28 Adapt Chronograph for Passage Operator
Browse files Browse the repository at this point in the history
Rework "swt.stage" package

Signed-off-by: Alexander Fedorov <[email protected]>
  • Loading branch information
ruspl-afed committed May 14, 2020
1 parent e82084d commit 7876b8a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -136,20 +135,16 @@ public void handleEvent(final Event event) {
}

private void initListeners() {
StageMouse<ChronographStage> msListener = new StageMouse<>(this);
StageMouseWheel<ChronographStage> msWheelListener = new StageMouseWheel<>(this);
StageResize<ChronographStage> 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;
}
Expand All @@ -173,7 +168,6 @@ protected void horizontalScroll(Event event) {
redraw();
}

@Override
public void updateScrollers() {
if (bricks == null || bricks.isEmpty()) {
return;
Expand All @@ -183,7 +177,6 @@ public void updateScrollers() {
scrollBarHorizontal.setSelection(pXhint);
}

@Override
public void handleResize() {
Rectangle rect = getBounds();
Rectangle client = getClientArea();
Expand Down Expand Up @@ -308,7 +301,6 @@ public Rectangle getBounds() {
return new Rectangle(0, 0, super.getBounds().width, pY);
}

@Override
public Rectangle getMainBounds() {
return boundsGlobal;
}
Expand Down Expand Up @@ -340,7 +332,6 @@ private void calculateSectionBounds(Area area, Collection<Section> sections, int
}
}

@Override
public void calculateObjectBounds() {
Rectangle clientArea = super.getClientArea();
visiableArea = new AreaImpl(clientArea.x, clientArea.y, clientArea.width, clientArea.height);
Expand Down Expand Up @@ -428,7 +419,6 @@ private void drawSelectedObjects(final GC gc, Area area, final Collection<? exte
}
}

@Override
public void navigateToUnit(int hint) {
pX = hint * pxlHint * stageScale;
getHint();
Expand Down Expand Up @@ -457,12 +447,10 @@ public void clearSections() {
redraw();
}

@Override
public int getScale() {
return stageScale;
}

@Override
public List<? extends Brick> getDrawingObjects() {
return registry.getBricks();
}
Expand All @@ -483,7 +471,6 @@ private void updateStageScale() {
}
}

@Override
public void scaleUp() {
checkWidget();
stageScale--;
Expand All @@ -493,7 +480,6 @@ public void scaleUp() {
navigateToUnit(pXhint);
}

@Override
public void scaleDown() {
checkWidget();
stageScale++;
Expand All @@ -507,12 +493,10 @@ public void redraw() {
super.redraw();
}

@Override
public int getPositionByX() {
return pX;
}

@Override
public void setPositionByX(int x) {
this.pX = x;
}
Expand All @@ -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);
}
Expand All @@ -550,7 +522,6 @@ public void removeSelected(Brick brick) {
bricksSelected.remove(brick);
}

@Override
public void addRemoveSelected(Brick brick) {
List<Brick> markedBriks = new ArrayList<Brick>();
for (Brick selectedBrick : bricksSelected) {
Expand All @@ -567,7 +538,6 @@ public void addRemoveSelected(Brick brick) {
}
}

@Override
public void setProvider(ContainerProvider provider) {
this.dataProvider = provider;
this.labelProvider = provider.getLabelProvider();
Expand All @@ -577,15 +547,13 @@ public void setProvider(ContainerProvider provider) {
this.redraw();
}

@Override
public void setZoomLevelDown() {
this.zoom++;
this.calculateObjectBounds();
this.redraw();

}

@Override
public void setZoomLevelUp() {
this.zoom--;
if (this.zoom < 1) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
*
* @param <T>
*/
final class StageMouse<T extends ChronographStage> 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;
private Tracker tracker;
private boolean isMouseDown;
private int xPosition = 0;

public StageMouse(T stage) {
public StageMouse(ChronographCanvas stage) {
this.stage = stage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

final class StageResize<T extends ChronographStage> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

final class StageMouseWheel<T extends ChronographStage> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Styler> 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<>();
Expand Down

0 comments on commit 7876b8a

Please sign in to comment.