Skip to content

Commit

Permalink
Fixed #1337 - Time Ranges Chart - add a point selection position marker
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Mar 11, 2023
1 parent 3fb3d32 commit c50b9d7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2023 Lablicate GmbH.
*
* 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:
* Philip Wenig - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.ux.extension.xxd.ui.ranges;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.swt.ui.support.Colors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swtchart.IAxis;
import org.eclipse.swtchart.extensions.core.BaseChart;
import org.eclipse.swtchart.extensions.marker.AbstractBaseChartPaintListener;
import org.eclipse.swtchart.extensions.marker.IBaseChartPaintListener;

public class TimeRangePointsMarker extends AbstractBaseChartPaintListener implements IBaseChartPaintListener {

private List<Point> pointSelection = new ArrayList<>();

public TimeRangePointsMarker(BaseChart baseChart) {

super(baseChart);
}

public void setPointSelection(List<Point> pointSelection) {

this.pointSelection = pointSelection;
}

@Override
public void paintControl(PaintEvent e) {

if(!pointSelection.isEmpty()) {
BaseChart baseChart = getBaseChart();
IAxis axisX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
if(axisX != null) {
int size = pointSelection.size();
int last = size - 1;
for(int i = 0; i <= last; i++) {
/*
* It's a manual selection, hence
* x should be always > 0.
*/
Point point = pointSelection.get(i);
int x = point.x;
if(x > 0) {
GC gc = e.gc;
Color colorBackground = gc.getBackground();
Color colorForeground = gc.getForeground();
//
gc.setForeground(Colors.DARK_GRAY);
gc.setLineStyle(SWT.LINE_DASHDOT);
gc.drawLine(x, 0, x, e.height);
//
String label = getLabel(i, last);
Point labelSize = gc.textExtent(label);
gc.setBackground(Colors.DARK_GRAY);
gc.fillRectangle(x - 20, 15, 40, 25);
gc.setForeground(Colors.WHITE);
gc.drawText(label, x - (int)(labelSize.x / 2.0d), 19, SWT.DRAW_TRANSPARENT);
//
gc.setBackground(colorBackground);
gc.setForeground(colorForeground);
}
}
}
}
}

private String getLabel(int i, int last) {

if(i == 0) {
return "Start";
} else if(i == last) {
return "Stop";
} else {
return "Max";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class TimeRangesChart extends ChromatogramPeakChart {

private Cursor defaultCursor;
private BaselineSelectionPaintListener baselineSelectionPaintListener;
private BaselineSelectionPaintListener baselineSelectionPaintListener = new BaselineSelectionPaintListener();
//
private int xStart;
private int yStart;
Expand All @@ -55,6 +55,7 @@ public class TimeRangesChart extends ChromatogramPeakChart {
*/
private boolean pointSelectionActive = false;
private List<Point> pointSelection = new ArrayList<>();
private TimeRangePointsMarker timeRangePointsMarker = new TimeRangePointsMarker(getBaseChart());

public TimeRangesChart(Composite parent, int style) {

Expand Down Expand Up @@ -111,6 +112,7 @@ public void handleKeyDownEvent(Event event) {
if(isPointModus()) {
setCursor(SWT.CURSOR_CROSS);
pointSelection.clear();
timeRangePointsMarker.setPointSelection(pointSelection);
pointSelectionActive = true;
} else {
pointSelectionActive = false;
Expand Down Expand Up @@ -190,6 +192,7 @@ public void handleMouseUpEvent(Event event) {
if(isPointModus()) {
if(pointSelectionActive) {
pointSelection.add(new Point(event.x, event.y));
timeRangePointsMarker.setPointSelection(pointSelection);
}
} else {
stopBaselineSelection(event.x, event.y);
Expand All @@ -213,6 +216,7 @@ private void clearPointModus() {

pointSelectionActive = false;
pointSelection.clear();
timeRangePointsMarker.setPointSelection(pointSelection);
}

private boolean isPointModus() {
Expand All @@ -227,8 +231,8 @@ private void createControl() {
* Add the paint listeners to draw the selected peak range.
*/
IPlotArea plotArea = getBaseChart().getPlotArea();
baselineSelectionPaintListener = new BaselineSelectionPaintListener();
plotArea.addCustomPaintListener(baselineSelectionPaintListener);
plotArea.addCustomPaintListener(timeRangePointsMarker);
//
getBaseChart().addCustomRangeSelectionHandler(new ICustomSelectionHandler() {

Expand Down

0 comments on commit c50b9d7

Please sign in to comment.