Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Aug 25, 2022
1 parent e3e51c5 commit 168cd7d
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ private void setPrimaryAxisSet(IChartSettings chartSettings) {
primaryAxisSettingsX.setGridLineStyle(LineStyle.NONE);
//
IPrimaryAxisSettings primaryAxisSettingsY = chartSettings.getPrimaryAxisSettingsY();
primaryAxisSettingsY.setTitle(Messages.getString(Messages.INTENSITY));
primaryAxisSettingsY.setTitle(Messages.getString(Messages.INTENSITY));
primaryAxisSettingsY.setDecimalFormat(new DecimalFormat(("0.0#E0"), new DecimalFormatSymbols(Locale.ENGLISH))); //$NON-NLS-1$
primaryAxisSettingsY.setColor(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
primaryAxisSettingsY.setGridLineStyle(LineStyle.NONE);
}

private void addSecondaryAxisSet(IChartSettings chartSettings) {

ISecondaryAxisSettings secondaryAxisSettingsX = new SecondaryAxisSettings(Messages.getString(Messages.MINUTES), new MillisecondsToMinuteConverter());
ISecondaryAxisSettings secondaryAxisSettingsX = new SecondaryAxisSettings(Messages.getString(Messages.MINUTES), new MillisecondsToMinuteConverter());
secondaryAxisSettingsX.setPosition(Position.Primary);
secondaryAxisSettingsX.setDecimalFormat(new DecimalFormat(("0.00"), new DecimalFormatSymbols(Locale.ENGLISH))); //$NON-NLS-1$
secondaryAxisSettingsX.setColor(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2020 Lablicate GmbH.
* Copyright (c) 2017, 2022 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -85,8 +85,6 @@ public void setCustomLabels(Map<Double, String> customLabels) {

if(customLabels != null) {
this.customLabels = customLabels;
} else {
customLabels = new HashMap<Double, String>();
}
}

Expand All @@ -95,7 +93,7 @@ private void initialize() {
numberOfHighestIntensitiesToLabel = 5;
barSeriesIonComparator = new BarSeriesIonComparator();
labelOption = LabelOption.EXACT;
customLabels = new HashMap<Double, String>();
customLabels = new HashMap<>();
//
IChartSettings chartSettings = getChartSettings();
chartSettings.setOrientation(SWT.HORIZONTAL);
Expand Down Expand Up @@ -187,7 +185,7 @@ private void printLabel(BarSeriesIon barSeriesIon, PaintEvent e) {

Point point = barSeriesIon.getPoint();
String label = getLabel(barSeriesIon.getMz());
boolean negative = (barSeriesIon.getIntensity() < 0) ? true : false;
boolean negative = (barSeriesIon.getIntensity() < 0);
Point labelSize = e.gc.textExtent(label);
int x = (int)(point.x + 0.5d - labelSize.x / 2.0d);
int y = point.y;
Expand Down Expand Up @@ -222,7 +220,7 @@ private String getLabel(double mz) {

private List<BarSeriesIon> getBarSeriesIonList() {

List<BarSeriesIon> barSeriesIons = new ArrayList<BarSeriesIon>();
List<BarSeriesIon> barSeriesIons = new ArrayList<>();
//
int widthPlotArea = getBaseChart().getPlotArea().getSize().x;
ISeries<?>[] series = getBaseChart().getSeriesSet().getSeries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void initialize() {
/*
* Create series.
*/
List<IBarSeriesData> barSeriesDataList = new ArrayList<IBarSeriesData>();
List<IBarSeriesData> barSeriesDataList = new ArrayList<>();
ISeriesData seriesData = SeriesConverter.getSeriesXY(SeriesConverter.BAR_SERIES_1);
//
IBarSeriesData barSeriesData = new BarSeriesData(seriesData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void initialize() throws Exception {
/*
* Create series.
*/
List<ILineSeriesData> lineSeriesDataList = new ArrayList<ILineSeriesData>();
List<ILineSeriesData> lineSeriesDataList = new ArrayList<>();
//
ISeriesData seriesData;
ILineSeriesData lineSeriesData;
Expand Down Expand Up @@ -229,7 +229,7 @@ private void initialize() throws Exception {
*/
IPlotArea plotArea = getBaseChart().getPlotArea();
LabelMarker labelMarker = new LabelMarker(getBaseChart());
List<String> labels = new ArrayList<String>();
List<String> labels = new ArrayList<>();
labels.add("2-Methoxy-4-vinylphenol");
labels.add("Ethanone, 1-(2-hydroxy-5-methylphenyl)-");
labels.add("4-Hydroxy-2-methylacetophenone");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 Lablicate GmbH.
* Copyright (c) 2017, 2022 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -129,11 +129,11 @@ public BaseChart(Composite parent, int style) {
* Rectangle range selection.
*/
userSelection = new UserSelection();
customRangeSelectionHandlers = new ArrayList<ICustomSelectionHandler>();
customPointSelectionHandlers = new ArrayList<ICustomSelectionHandler>();
seriesModificationListeners = new ArrayList<ISeriesModificationListener>();
seriesStatusListeners = new ArrayList<ISeriesStatusListener>();
selectedSeriesIds = new HashSet<String>();
customRangeSelectionHandlers = new ArrayList<>();
customPointSelectionHandlers = new ArrayList<>();
seriesModificationListeners = new ArrayList<>();
seriesStatusListeners = new ArrayList<>();
selectedSeriesIds = new HashSet<>();
initializeEventProcessors();
/*
* Create the default x and y axis.
Expand Down Expand Up @@ -165,27 +165,27 @@ public BaseChart(Composite parent, int style) {
yAxisPrimary.setDrawAxisLine(true);
yAxisPrimary.setIntegerDataPointAxis(false);
//
handledSelectionEvents = new Stack<double[]>();
handledSelectionEvents = new Stack<>();
redoSelection = null;
//
dataShiftHistory = new HashMap<String, List<double[]>>();
dataShiftHistory = new HashMap<>();
}

private void initializeEventProcessors() {

registeredEvents = new HashMap<Integer, Map<Integer, Map<Integer, List<IEventProcessor>>>>();
registeredEvents = new HashMap<>();
initializeEvents();
}

private void initializeEvents() {

registeredEvents.put(EVENT_MOUSE_DOUBLE_CLICK, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_MOUSE_WHEEL, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_MOUSE_DOWN, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_MOUSE_MOVE, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_MOUSE_UP, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_KEY_DOWN, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_KEY_UP, new HashMap<Integer, Map<Integer, List<IEventProcessor>>>());
registeredEvents.put(EVENT_MOUSE_DOUBLE_CLICK, new HashMap<>());
registeredEvents.put(EVENT_MOUSE_WHEEL, new HashMap<>());
registeredEvents.put(EVENT_MOUSE_DOWN, new HashMap<>());
registeredEvents.put(EVENT_MOUSE_MOVE, new HashMap<>());
registeredEvents.put(EVENT_MOUSE_UP, new HashMap<>());
registeredEvents.put(EVENT_KEY_DOWN, new HashMap<>());
registeredEvents.put(EVENT_KEY_UP, new HashMap<>());
}

public void clearEventProcessors() {
Expand All @@ -208,7 +208,7 @@ public void addEventProcessor(IHandledEventProcessor handledEventProcessor) {
int button = handledEventProcessor.getButton();
Map<Integer, List<IEventProcessor>> buttonEventProcessors = eventProcessors.get(button);
if(buttonEventProcessors == null) {
buttonEventProcessors = new HashMap<Integer, List<IEventProcessor>>();
buttonEventProcessors = new HashMap<>();
eventProcessors.put(button, buttonEventProcessors);
}
/*
Expand All @@ -218,7 +218,7 @@ public void addEventProcessor(IHandledEventProcessor handledEventProcessor) {
int stateMask = handledEventProcessor.getStateMask();
List<IEventProcessor> handledEventProcessors = buttonEventProcessors.get(stateMask);
if(handledEventProcessors == null) {
handledEventProcessors = new ArrayList<IEventProcessor>();
handledEventProcessors = new ArrayList<>();
}
handledEventProcessors.add(handledEventProcessor);
buttonEventProcessors.put(stateMask, handledEventProcessors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public class ChartSettings implements IChartSettings {
//
private IPrimaryAxisSettings primaryAxisSettingsX = new PrimaryAxisSettings(BaseChart.DEFAULT_TITLE_X_AXIS);
private IPrimaryAxisSettings primaryAxisSettingsY = new PrimaryAxisSettings(BaseChart.DEFAULT_TITLE_Y_AXIS);
private List<ISecondaryAxisSettings> secondaryAxisSettingsListX = new ArrayList<ISecondaryAxisSettings>();
private List<ISecondaryAxisSettings> secondaryAxisSettingsListY = new ArrayList<ISecondaryAxisSettings>();
private List<ISecondaryAxisSettings> secondaryAxisSettingsListX = new ArrayList<>();
private List<ISecondaryAxisSettings> secondaryAxisSettingsListY = new ArrayList<>();
//
private int orientation = SWT.HORIZONTAL;
private Color background;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class ScrollableChart extends Composite implements IScrollableChart, IEve
* This list contains all scrollable charts
* that are linked with the current editor.
*/
private List<ScrollableChart> linkedScrollableCharts = new ArrayList<ScrollableChart>();
private List<ScrollableChart> linkedScrollableCharts = new ArrayList<>();
//
private PositionMarker positionMarker;
private PlotCenterMarker plotCenterMarker;
Expand Down Expand Up @@ -573,8 +573,8 @@ protected ISeriesData calculateSeries(ISeriesData seriesData, int compressToLeng
* Capture the compressed data.
* The final size is not known yet.
*/
List<Double> xSeriesCompressed = new ArrayList<Double>();
List<Double> ySeriesCompressed = new ArrayList<Double>();
List<Double> xSeriesCompressed = new ArrayList<>();
List<Double> ySeriesCompressed = new ArrayList<>();
/*
* First x,y value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public class LineChart extends ScrollableChart {
public static final int NO_COMPRESSION = Integer.MAX_VALUE;

public LineChart() {

super();
}

public LineChart(Composite parent, int style) {

super(parent, style);
}

Expand All @@ -84,7 +86,7 @@ public void addSeriesData(List<ILineSeriesData> lineSeriesDataList, int compress
/*
* Suspend the update when adding new data to improve the performance.
*/
if(lineSeriesDataList != null && lineSeriesDataList.size() > 0) {
if(lineSeriesDataList != null && !lineSeriesDataList.isEmpty()) {
BaseChart baseChart = getBaseChart();
baseChart.suspendUpdate(true);
for(ILineSeriesData lineSeriesData : lineSeriesDataList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class LabelMarker extends AbstractBaseChartPaintListener implements IBaseChartPaintListener {

private Map<Integer, String> labels = new HashMap<Integer, String>();
private Map<Integer, String> labels = new HashMap<>();
private int indexSeries = -1;
private ISeries<?> serie;
private int orientation;
Expand All @@ -42,7 +42,7 @@ public LabelMarker(BaseChart baseChart) {

public void setLabels(List<String> labels, int indexSeries, int orientation) {

Map<Integer, String> labelsMap = new HashMap<Integer, String>();
Map<Integer, String> labelsMap = new HashMap<>();
int index = 0;
for(String label : labels) {
labelsMap.put(index++, label);
Expand All @@ -59,7 +59,7 @@ public void setLabels(Map<Integer, String> labels, int indexSeries, int orientat
public void setLabels(Map<Integer, String> labels, int orientation) {

this.orientation = orientation;
this.labels = (labels != null) ? labels : new HashMap<Integer, String>();
this.labels = (labels != null) ? labels : new HashMap<>();
}

public void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void addSeriesData(ICircularSeriesData model) {
* Get the series data and apply the settings.
*/
try {
ICircularSeriesSettings pieSeriesSettings = (ICircularSeriesSettings)model.getSettings();
ICircularSeriesSettings pieSeriesSettings = model.getSettings();
//
IChartSettings chartSettings = getChartSettings();
//
Expand Down Expand Up @@ -84,7 +84,7 @@ public void addSeriesData(ICircularSeriesData model) {
IHandledEventProcessor circularHandledEventProcessor = new CircularMouseDownEvent(this);
chartSettings.addHandledEventProcessor(circularHandledEventProcessor);
applySettings(chartSettings);
ICircularSeries<?> pieSeries = (ICircularSeries<?>)createCircularSeries(model, pieSeriesSettings);
ICircularSeries<?> pieSeries = createCircularSeries(model, pieSeriesSettings);
//
baseChart.applyCircularSeriesSettings(pieSeries, pieSeriesSettings);
} catch(SeriesException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -69,6 +69,7 @@ public class Title implements ITitle, PaintListener {
* the parent composite
*/
public Title(Chart parent) {

this.chart = parent;
text = DEFAULT_TEXT;
isVisible = true;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void setFont(Font font) {
if(font == null) {
this.font = defaultFont;
} else if(font.isDisposed()) {
throw new IllegalArgumentException(Messages.getString(Messages.DISPOSED_FONT_GIVEN));
throw new IllegalArgumentException(Messages.getString(Messages.DISPOSED_FONT_GIVEN));
} else {
this.font = font;
}
Expand Down Expand Up @@ -155,7 +156,7 @@ public void setForeground(Color color) {
if(color == null) {
foreground = Display.getDefault().getSystemColor(DEFAULT_FOREGROUND);
} else if(color.isDisposed()) {
throw new IllegalArgumentException(Messages.getString(Messages.DISPOSED_COLOR_GIVEN));
throw new IllegalArgumentException(Messages.getString(Messages.DISPOSED_COLOR_GIVEN));
} else {
foreground = color;
}
Expand Down

0 comments on commit 168cd7d

Please sign in to comment.