add debug messages to SimpleChartUtility#tryApplyDefaultChartThemeToRenderer
package io.github.mzmine.gui.chartbasics.simplechart;
import com.google.common.primitives.Ints;
+import io.github.mzmine.gui.chartbasics.chartthemes.EStandardChartTheme;
import io.github.mzmine.gui.chartbasics.simplechart.datasets.ColoredXYDataset;
+import io.github.mzmine.main.MZmineConfiguration;
import io.github.mzmine.main.MZmineCore;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.jfree.chart.renderer.AbstractRenderer;
import org.jfree.data.xy.XYDataset;
@@ -32,6 +36,8 @@ import org.jfree.data.xy.XYDataset;
*/
public class SimpleChartUtility {
+ private static final Logger logger = Logger.getLogger(SimpleChartUtility.class.getName());
+
private SimpleChartUtility() {
}
@@ -47,8 +53,9 @@ public class SimpleChartUtility {
isLocalMaximum = false;
} else {
final double intensity = dataset.getYValue(series, item);
- isLocalMaximum = dataset.getYValue(series, item - 1) <= intensity
- && intensity >= dataset.getYValue(series, item + 1);
+ isLocalMaximum =
+ dataset.getYValue(series, item - 1) <= intensity && intensity >= dataset.getYValue(series,
+ item + 1);
}
return isLocalMaximum;
}
@@ -89,8 +96,8 @@ public class SimpleChartUtility {
// Check Y range..
final double intensity = dataset.getYValue(series, index);
- if (yMin <= intensity && intensity <= yMax && ((ColoredXYDataset) dataset)
- .isLocalMaximum(index)) {
+ if (yMin <= intensity && intensity <= yMax && ((ColoredXYDataset) dataset).isLocalMaximum(
+ index)) {
indices.add(index);
}
}
@@ -98,13 +105,39 @@ public class SimpleChartUtility {
return Ints.toArray(indices);
}
+ /**
+ * Applies the chart theme from the {@link MZmineConfiguration} to a renderer. This method can be
+ * safely used in renderer constructors to be up-to-date, all exceptions are caught.
+ *
+ * @param r
+ */
public static void tryApplyDefaultChartThemeToRenderer(AbstractRenderer r) {
+ if(r == null) {
+ return;
+ }
+
try {
- final Font itemLabelFont = MZmineCore.getConfiguration().getDefaultChartTheme()
- .getItemLabelFont();
+ final MZmineConfiguration configuration = MZmineCore.getConfiguration();
+ if (configuration == null) {
+ logger.fine(() -> "Cannot apply item label color, configuration == null.");
+ return;
+ }
+
+ final EStandardChartTheme chartTheme = configuration.getDefaultChartTheme();
+ if (chartTheme == null) {
+ logger.fine(() -> "Cannot apply item label color, chart theme == null.");
+ return;
+ }
+
+ final Font itemLabelFont = chartTheme.getItemLabelFont();
+ if (itemLabelFont == null) {
+ logger.fine(() -> "Cannot apply item label color, font == null.");
+ return;
+ }
+
r.setDefaultItemLabelFont(itemLabelFont);
} catch (Exception e) {
- // silent
+ logger.log(Level.WARNING, e.getMessage(), e);
}
}
}
