Skip to content

Commit

Permalink
#28 Adapt Chronograph for Passage Operator
Browse files Browse the repository at this point in the history
Move area->rectangle function to "swt" bundle

Signed-off-by: Alexander Fedorov <[email protected]>
  • Loading branch information
ruspl-afed committed May 14, 2020
1 parent aa0ab0d commit d9186c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.chronograph.internal.api.providers.StageLabelProvider;
import org.eclipse.chronograph.internal.base.AreaImpl;
import org.eclipse.chronograph.internal.base.DataRegistry;
import org.eclipse.chronograph.internal.swt.AreaRectangle;
import org.eclipse.chronograph.internal.swt.BrickStyler;
import org.eclipse.chronograph.internal.swt.GroupStyler;
import org.eclipse.chronograph.internal.swt.RulerStyler;
Expand All @@ -51,6 +52,8 @@

public final class ChronographStageImpl extends Canvas implements ChronographStage {

private final AreaRectangle areaRectangle;

private static final int VERTICAL_SCROLLBAR_PAGE_INC = 15;
private static final int SCALE_DEFAULT = 5;
private int pX;
Expand Down Expand Up @@ -84,6 +87,7 @@ public ChronographStageImpl(Composite parent, ContainerProvider provider) {

public ChronographStageImpl(Composite parent, int style, ContainerProvider provider) {
super(parent, style);
this.areaRectangle = new AreaRectangle();
this.dataProvider = provider;
this.labelProvider = provider.getLabelProvider();
bricksSelected = new ArrayList<>();
Expand Down Expand Up @@ -134,8 +138,7 @@ public void handleEvent(final Event event) {

private void initListeners() {
StageMouse<ChronographStage> msListener = new StageMouse<>(this);
StageMouseWheel<ChronographStage> msWheelListener = new StageMouseWheel<>(
this);
StageMouseWheel<ChronographStage> msWheelListener = new StageMouseWheel<>(this);
StageResize<ChronographStage> resizeListener = new StageResize<>(this);
addPaintListener(new StagePaint(this));
addMouseListener(msListener);
Expand Down Expand Up @@ -204,7 +207,7 @@ public void redraw(Rectangle rectangle) {
public void repaint(PaintEvent event) {
GC gc = event.gc;
// drawing
Rectangle stageRectangle = ChronographStageUtil.areaToRectangle(visiableArea);
Rectangle stageRectangle = areaRectangle.apply(visiableArea);
INSTANCE.getDrawingStagePainter().draw(gc, stageRectangle);
for (ChronographStageRulerRenderer painter : INSTANCE.getDrawingRulersPainter()) {
painter.draw(gc, stageRectangle, stageScale, pxlHint, pXhint, pX);
Expand All @@ -227,23 +230,23 @@ public void repaint(PaintEvent event) {
drawSelectedObjects(gc, area, markedBricks);
}
}
Rectangle groupRectangle = ChronographStageUtil.areaToRectangle(area);
Rectangle groupRectangle = areaRectangle.apply(area);
INSTANCE.getDrawingGroupPainter().draw(gc, labelProvider.getText(subgroup), groupRectangle,
getDisplay(), SectionStyler.getSectionWidth(), pYhint);
}
Area area = getDrawingArea(group);
if (area == null) {
continue;
}
Rectangle groupRectangle = ChronographStageUtil.areaToRectangle(area);
Rectangle groupRectangle = areaRectangle.apply(area);
INSTANCE.getDrawingGroupPainter().draw(gc, labelProvider.getText(group), groupRectangle, getDisplay(),
SectionStyler.getSectionWidth(), pYhint);
}
Area area = groupsAreas.get(section.id());
if (area == null) {
continue;
}
Rectangle sectionRectangle = ChronographStageUtil.areaToRectangle(area);
Rectangle sectionRectangle = areaRectangle.apply(area);
INSTANCE.getDrawingSectionPainter().draw(gc, labelProvider.getText(section), sectionRectangle, getDisplay(),
SectionStyler.getSectionWidth(), pYhint);
}
Expand Down Expand Up @@ -398,7 +401,7 @@ public void accept(Brick brick) {
calculateObjectPosition(brick, area, pXhint, pYhint, pxlHint);
Area brickArea = getDrawingArea(brick);
if (brickArea != null) {
Rectangle rectangleArea = ChronographStageUtil.areaToRectangle(brickArea);
Rectangle rectangleArea = areaRectangle.apply(brickArea);
INSTANCE.getContentPainter().draw(brick, gc, rectangleArea, pYhint);
String label = labelProvider.getText(brick);
INSTANCE.getLabelPainter().drawLabel(label, brick.position(), gc, rectangleArea, pYhint);
Expand All @@ -418,7 +421,7 @@ private void drawSelectedObjects(final GC gc, Area area, final Collection<? exte
if (brickArea == null) {
continue;
}
Rectangle rectangleArea = ChronographStageUtil.areaToRectangle(brickArea);
Rectangle rectangleArea = areaRectangle.apply(brickArea);
INSTANCE.getSelectedContentPainter().draw(brick, gc, rectangleArea, pYhint);
String label = labelProvider.getText(brick);
INSTANCE.getLabelPainter().drawLabel(label, brick.position(), gc, rectangleArea, pYhint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
* initial API and implementation
*******************************************************************************/

package org.eclipse.chronograph.swt.internal.stage;
package org.eclipse.chronograph.internal.swt;

import java.util.function.Function;

import org.eclipse.chronograph.internal.api.Area;
import org.eclipse.swt.graphics.Rectangle;

/**
*
* Utility class intended to convert {@link Area} to {@link Rectangle}
* Сonverts {@link Area} to {@link Rectangle}
*
*/
public class ChronographStageUtil {
public static Rectangle areaToRectangle(Area area) {
public final class AreaRectangle implements Function<Area, Rectangle> {

@Override
public Rectangle apply(Area area) {
return new Rectangle(area.x(), area.y(), area.width(), area.height());
}
}

0 comments on commit d9186c6

Please sign in to comment.