-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #680 - Charts - Button to easily show/hide grid lines
- Loading branch information
1 parent
ca81623
commit cc64c10
Showing
8 changed files
with
203 additions
and
9 deletions.
There are no files selected for viewing
Binary file added
BIN
+376 Bytes
chemclipse/plugins/org.eclipse.chemclipse.rcp.ui.icons/icons/16x16/grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ion.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/actions/GridLineEditAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ChartGridSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters