Skip to content

Commit

Permalink
Fixed #680 - Charts - Button to easily show/hide grid lines
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Jul 9, 2021
1 parent ca81623 commit cc64c10
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,5 @@ public static String getLocation(String fileName, String size) {
String IMAGE_INCLUDE_INTERCEPT = PATH_PREFIX + "includeIntercept.gif";
String IMAGE_LOWER_MIN_AREA = PATH_PREFIX + "lowerMinArea.gif";
String IMAGE_HIGHER_MAX_AREA = PATH_PREFIX + "higherMaxArea.gif";
String IMAGE_GRID = PATH_PREFIX + "grid.png";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2021 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.actions;

import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory;
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage;
import org.eclipse.chemclipse.ux.extension.xxd.ui.charts.ChromatogramChart;
import org.eclipse.chemclipse.ux.extension.xxd.ui.swt.ChartGridSupport;
import org.eclipse.chemclipse.ux.extension.xxd.ui.swt.editors.ExtendedChromatogramUI;
import org.eclipse.jface.action.Action;
import org.eclipse.swtchart.extensions.core.IChartSettings;

public class GridLineEditAction extends Action {

private ChartGridSupport chartGridSupport = new ChartGridSupport();
private ExtendedChromatogramUI extendedChromatogramUI;

public GridLineEditAction(ExtendedChromatogramUI extendedChromatogramUI) {

super("GridLine", ApplicationImageFactory.getInstance().getImageDescriptor(IApplicationImage.IMAGE_GRID, IApplicationImage.SIZE_16x16));
setToolTipText("Toggle the chart grid lines.");
this.extendedChromatogramUI = extendedChromatogramUI;
}

@Override
public void run() {

ChromatogramChart chromatogramChart = extendedChromatogramUI.getChromatogramChart();
IChartSettings chartSettings = chromatogramChart.getChartSettings();
boolean isGridDisplayed = chartGridSupport.isGridDisplayed(chartSettings);
chartGridSupport.showGrid(chartSettings, !isGridDisplayed);
chromatogramChart.applySettings(chartSettings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2021 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.swt;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swtchart.LineStyle;
import org.eclipse.swtchart.extensions.core.IAxisSettings;
import org.eclipse.swtchart.extensions.core.IChartSettings;

public class ChartGridSupport {

private Map<IAxisSettings, LineStyle> axisSettingsInitial = new HashMap<>();

public boolean isGridDisplayed(IChartSettings chartSettings) {

List<IAxisSettings> axisSettingsList = getAxisSettings(chartSettings);
for(IAxisSettings axisSettings : axisSettingsList) {
if(isGridDisplayed(axisSettings)) {
return true;
}
}
//
return false;
}

public void showGrid(IChartSettings chartSettings, boolean show) {

List<IAxisSettings> axisSettingsList = getAxisSettings(chartSettings);
for(IAxisSettings axisSettings : axisSettingsList) {
showGrid(axisSettings, show);
}
}

private void showGrid(IAxisSettings axisSettings, boolean show) {

if(axisSettings.isVisible()) {
if(show) {
LineStyle lineStyle = axisSettingsInitial.getOrDefault(axisSettings, LineStyle.DOT);
axisSettings.setGridLineStyle(lineStyle);
} else {
persistInitialState(axisSettings);
axisSettings.setGridLineStyle(LineStyle.NONE);
}
}
}

private void persistInitialState(IAxisSettings axisSettings) {

if(!axisSettingsInitial.containsKey(axisSettings)) {
axisSettingsInitial.put(axisSettings, axisSettings.getGridLineStyle());
}
}

private boolean isGridDisplayed(IAxisSettings axisSettings) {

return axisSettings.isVisible() && !LineStyle.NONE.equals(axisSettings.getGridLineStyle());
}

private List<IAxisSettings> getAxisSettings(IChartSettings chartSettings) {

List<IAxisSettings> axisSettingsList = new ArrayList<>();
/*
* Primary Axis X/Y
*/
axisSettingsList.add(chartSettings.getPrimaryAxisSettingsX());
axisSettingsList.add(chartSettings.getPrimaryAxisSettingsY());
/*
* Secondary Axes X/Y
*/
for(IAxisSettings axisSettings : chartSettings.getSecondaryAxisSettingsListX()) {
axisSettingsList.add(axisSettings);
}
//
for(IAxisSettings axisSettings : chartSettings.getSecondaryAxisSettingsListY()) {
axisSettingsList.add(axisSettings);
}
//
return axisSettingsList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public class ExtendedChromatogramOverlayUI extends Composite implements IExtende
private AtomicReference<DataShiftControllerUI> toolbarDataShift = new AtomicReference<>();
private Button buttonToolbarRulerDetails;
private AtomicReference<RulerDetailsUI> toolbarRulerDetails = new AtomicReference<>();
private Button buttonChartGrid;
private AtomicReference<ChromatogramRulerChart> chartControl = new AtomicReference<>();
private ChartGridSupport chartGridSupport = new ChartGridSupport();
//
private Label labelStatus;
private Combo comboOverlayType;
Expand Down Expand Up @@ -151,6 +153,7 @@ private void initialize() {
enableToolbar(toolbarNamedTraces, false);
enableToolbar(toolbarDataShift, buttonToolbarDataShift, IMAGE_SHIFT, TOOLTIP_SHIFT, false);
enableToolbar(toolbarRulerDetails, buttonToolbarRulerDetails, IMAGE_RULER, TOOLTIP_RULER, false);
enableChartGrid(chartControl, buttonChartGrid, IMAGE_CHART_GRID, chartGridSupport);
//
toolbarDataShift.get().setScrollableChart(chartControl.get());
toolbarRulerDetails.get().setScrollableChart(chartControl.get());
Expand All @@ -166,7 +169,7 @@ private Composite createToolbarMain(Composite parent) {

Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
composite.setLayout(new GridLayout(9, false));
composite.setLayout(new GridLayout(10, false));
//
labelStatus = createLabelStatus(composite);
comboOverlayType = createOverlayTypeCombo(composite);
Expand All @@ -176,6 +179,7 @@ private Composite createToolbarMain(Composite parent) {
createButtonToggleChartLegend(composite, chartControl, IMAGE_LEGEND);
createResetButton(composite);
createNewOverlayPartButton(composite);
buttonChartGrid = createButtonToggleChartGrid(composite, chartControl, IMAGE_CHART_GRID, chartGridSupport);
createSettingsButton(composite);
//
return composite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public class ExtendedScanChartUI extends Composite implements IExtendedPartUI {
private Button buttonCopyTraces;
private Button buttonSave;
private Button buttonDeleteOptimized;
private ScanChartUI scanChartUI;
//
private Button buttonChartGrid;
private AtomicReference<ScanChartUI> chartControl = new AtomicReference<>();
private ChartGridSupport chartGridSupport = new ChartGridSupport();
//
private Combo comboDataType;
private Combo comboSignalType;
Expand Down Expand Up @@ -189,6 +192,8 @@ private void updateScan(IScan scan) {
private void updateScanChart(IScan scan) {

IScanMSD optimizedMassSpectrum = getOptimizedScanMSD();
ScanChartUI scanChartUI = chartControl.get();
//
if(optimizedMassSpectrum != null) {
scanChartUI.setInput(optimizedMassSpectrum);
} else {
Expand All @@ -210,7 +215,7 @@ private void createControl() {
createToolbarInfo(composite);
createToolbarTypes(composite);
createToolbarEdit(composite);
scanChartUI = createScanChart(composite);
createScanChart(composite);
//
initialize();
}
Expand All @@ -220,6 +225,7 @@ private void initialize() {
enableToolbar(toolbarInfo, buttonToolbarInfo, IApplicationImage.IMAGE_INFO, TOOLTIP_INFO, true);
enableToolbar(toolbarTypes, buttonToolbarTypes, IMAGE_TYPES, TOOLTIP_TYPES, false);
enableToolbar(toolbarEdit, buttonToolbarEdit, IMAGE_EDIT, TOOLTIP_EDIT, false);
enableChartGrid(chartControl, buttonChartGrid, IMAGE_CHART_GRID, chartGridSupport);
//
updateButtons();
}
Expand All @@ -228,7 +234,7 @@ private void createToolbarMain(Composite parent) {

Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
composite.setLayout(new GridLayout(12, false));
composite.setLayout(new GridLayout(13, false));
//
labelEdit = createInfoLabelEdit(composite);
labelSubtract = createInfoLabelSubtract(composite);
Expand All @@ -241,6 +247,7 @@ private void createToolbarMain(Composite parent) {
createResetButton(composite);
buttonSave = createSaveButton(composite);
buttonDeleteOptimized = createDeleteOptimizedButton(composite);
buttonChartGrid = createButtonToggleChartGrid(composite, chartControl, IMAGE_CHART_GRID, chartGridSupport);
createSettingsButton(composite);
//
buttonToolbarEdit.addSelectionListener(new SelectionAdapter() {
Expand Down Expand Up @@ -450,7 +457,7 @@ private Combo createDataType(Composite parent) {
public void widgetSelected(SelectionEvent e) {

String selection = combo.getText();
scanChartUI.setDataType(DataType.valueOf(selection));
chartControl.get().setDataType(DataType.valueOf(selection));
updateScanChart(scan);
}
});
Expand All @@ -469,7 +476,7 @@ private Combo createSignalType(Composite parent) {
public void widgetSelected(SelectionEvent e) {

String selection = combo.getText();
scanChartUI.setSignalType(SignalType.valueOf(selection));
chartControl.get().setSignalType(SignalType.valueOf(selection));
updateScanChart(scan);
}
});
Expand Down Expand Up @@ -545,6 +552,7 @@ private void updateLabel(CLabel label, String message) {

private void updateButtons() {

buttonChartGrid.setEnabled(true);
boolean enabled = isMassSpectrum();
//
scanIdentifierUI.setEnabled(enabled || isWaveSpectrum());
Expand Down Expand Up @@ -676,11 +684,12 @@ private void createToolbarInfo(Composite parent) {
toolbarInfo.set(informationUI);
}

private ScanChartUI createScanChart(Composite parent) {
private void createScanChart(Composite parent) {

ScanChartUI scanChartUI = new ScanChartUI(parent, SWT.BORDER);
scanChartUI.setLayoutData(new GridData(GridData.FILL_BOTH));
return scanChartUI;
//
chartControl.set(scanChartUI);
}

private void setDetectorSignalType(IScan scan) {
Expand All @@ -703,6 +712,7 @@ private void setDetectorSignalType(IScan scan) {
/*
* Data / Signal Type
*/
ScanChartUI scanChartUI = chartControl.get();
scanChartUI.setDataType(DataType.valueOf(comboDataType.getText()));
scanChartUI.setSignalType(SignalType.valueOf(comboSignalType.getText()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swtchart.extensions.core.IChartSettings;
import org.eclipse.swtchart.extensions.core.ScrollableChart;

public interface IExtendedPartUI {
Expand All @@ -52,6 +53,7 @@ public interface IExtendedPartUI {
String TOOLTIP_TYPES = "the types toolbar.";
String TOOLTIP_LEGEND = "the chart legend.";
String TOOLTIP_LEGEND_MARKER = "the chart legend marker.";
String TOOLTIP_CHART_GRID = "the chart grid.";
//
String IMAGE_INFO = IApplicationImage.IMAGE_INFO;
String IMAGE_RESULTS = IApplicationImage.IMAGE_RESULTS;
Expand All @@ -61,6 +63,7 @@ public interface IExtendedPartUI {
String IMAGE_LEGEND = IApplicationImage.IMAGE_TAG;
String IMAGE_LEGEND_MARKER = IApplicationImage.IMAGE_CHART_LEGEND_MARKER;
String IMAGE_EDIT_ENTRY = IApplicationImage.IMAGE_EDIT_ENTRY;
String IMAGE_CHART_GRID = IApplicationImage.IMAGE_GRID;

default Button createButton(Composite parent, String text, String tooltip, String image) {

Expand Down Expand Up @@ -122,6 +125,30 @@ public void widgetSelected(SelectionEvent e) {
return button;
}

default Button createButtonToggleChartGrid(Composite parent, AtomicReference<? extends ScrollableChart> chartControl, String image, ChartGridSupport chartGridSupport) {

Button button = new Button(parent, SWT.PUSH);
button.setText("");
setButtonImage(button, image, PREFIX_ENABLE, PREFIX_DISABLE, TOOLTIP_CHART_GRID, false);
button.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {

ScrollableChart scrollableChart = chartControl.get();
if(scrollableChart != null) {
IChartSettings chartSettings = scrollableChart.getChartSettings();
boolean isGridDisplayed = !chartGridSupport.isGridDisplayed(chartSettings);
chartGridSupport.showGrid(scrollableChart.getChartSettings(), isGridDisplayed);
scrollableChart.applySettings(chartSettings);
setButtonImage(button, image, PREFIX_ENABLE, PREFIX_DISABLE, TOOLTIP_CHART_GRID, isGridDisplayed);
}
}
});
//
return button;
}

default Button createButtonToggleChartLegend(Composite parent, AtomicReference<? extends ScrollableChart> scrollableChart, String image) {

Button button = new Button(parent, SWT.PUSH);
Expand Down Expand Up @@ -241,6 +268,15 @@ default void enableEdit(AtomicReference<? extends ExtendedTableViewer> viewer, B
}
}

default void enableChartGrid(AtomicReference<? extends ScrollableChart> chartControl, Button button, String image, ChartGridSupport chartGridSupport) {

ScrollableChart scrollableChart = chartControl.get();
if(scrollableChart != null) {
boolean isGridDisplayed = chartGridSupport.isGridDisplayed(scrollableChart.getChartSettings());
setButtonImage(button, image, PREFIX_ENABLE, PREFIX_DISABLE, TOOLTIP_CHART_GRID, isGridDisplayed);
}
}

default void setButtonImage(Button button, String image, String prefixActivate, String prefixDeactivate, String tooltip, boolean enabled) {

button.setImage(ApplicationImageFactory.getInstance().getImage(image, IApplicationImage.SIZE_16x16, enabled));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.eclipse.chemclipse.swt.ui.support.Fonts;
import org.eclipse.chemclipse.ux.extension.ui.support.PartSupport;
import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator;
import org.eclipse.chemclipse.ux.extension.xxd.ui.actions.GridLineEditAction;
import org.eclipse.chemclipse.ux.extension.xxd.ui.actions.ILabelEditSettings;
import org.eclipse.chemclipse.ux.extension.xxd.ui.actions.TargetLabelEditAction;
import org.eclipse.chemclipse.ux.extension.xxd.ui.calibration.RetentionIndexUI;
Expand Down Expand Up @@ -912,17 +913,18 @@ private EditorToolBar createToolbarMain(Composite parent) {

EditorToolBar editorToolBar = new EditorToolBar(parent);
processorToolbar = new ProcessorToolbar(editorToolBar, processTypeSupport, this::isValidSupplier, this::executeSupplier);
//
editorToolBar.addAction(createLabelsAction());
editorToolBar.addAction(createToggleToolbarAction("Info", "the info toolbar.", IApplicationImage.IMAGE_INFO, TOOLBAR_INFO));
editorToolBar.createCombo(this::initComboViewerSeparationColumn, true, 150);
chromatogramReferencesUI = new ChromatogramReferencesUI(editorToolBar, this::setChromatogramSelectionInternal);
editorToolBar.addAction(createToggleToolbarAction("Edit", "the edit toolbar.", IApplicationImage.IMAGE_EDIT, TOOLBAR_EDIT));
editorToolBar.addAction(createToggleToolbarAction("Alignment", "the chromatogram alignment toolbar.", IApplicationImage.IMAGE_ALIGN_CHROMATOGRAMS, TOOLBAR_CHROMATOGRAM_ALIGNMENT));
editorToolBar.addAction(createToggleToolbarAction("Methods", "the method toolbar.", IApplicationImage.IMAGE_METHOD, TOOLBAR_METHOD));
//
createResetButton(editorToolBar);
editorToolBar.enableToolbarTextPage(preferenceStore, PREFERENCE_SHOW_TOOLBAR_TEXT);
processorToolbar.enablePreferencePage(preferenceStore, PreferenceConstants.P_CHROMATOGRAM_PROCESSOR_TOOLBAR);
editorToolBar.addAction(createGridLineAction());
editorToolBar.addPreferencePages(new Supplier<Collection<? extends IPreferencePage>>() {

@Override
Expand Down Expand Up @@ -1188,6 +1190,11 @@ public ExtendedChromatogramUI getChromatogramUI() {
return targetLabelEditAction;
}

private GridLineEditAction createGridLineAction() {

return new GridLineEditAction(this);
}

private ExtendedChromatogramUI getExtendedChromatogramUI() {

return this;
Expand Down

0 comments on commit cc64c10

Please sign in to comment.