diff --git a/LibPeakaboo/src/main/java/org/peakaboo/app/Settings.java b/LibPeakaboo/src/main/java/org/peakaboo/app/Settings.java index a136686a..33842e6f 100644 --- a/LibPeakaboo/src/main/java/org/peakaboo/app/Settings.java +++ b/LibPeakaboo/src/main/java/org/peakaboo/app/Settings.java @@ -5,6 +5,8 @@ import java.nio.file.Files; import java.util.logging.Level; +import org.peakaboo.framework.cyclops.visualization.palette.Gradient; +import org.peakaboo.framework.cyclops.visualization.palette.Gradients; import org.peakaboo.framework.druthers.settings.DummySettingsStore; import org.peakaboo.framework.druthers.settings.SettingsStore; import org.peakaboo.framework.druthers.settings.YamlSettingsStore; @@ -122,9 +124,8 @@ private static void writeHeapConfig() { cfgContents = cfgContents.replace("java-options=-XX:MaxRAMPercentage=75", jvmOption); File userCFG = Env.userCFGFile(Version.PROGRAM_NAME); Files.writeString(userCFG.toPath(), cfgContents); - } catch (IOException e) { + } catch (IOException | RuntimeException e) { PeakabooLog.get().log(Level.WARNING, "Cannot write to per-user Peakaboo.cfg file", e); - throw new RuntimeException(e); } @@ -132,5 +133,16 @@ private static void writeHeapConfig() { } + private static final String MAP_PALETTE = "org.peakaboo.app.map-palette"; + public static void setDefaultMapPalette(Gradient g) { + provider.set(MAP_PALETTE, g.getName()); + writeHeapConfig(); + } + + public static Gradient getDefaultMapPalette() { + String name = provider.get(MAP_PALETTE, Gradients.DEFAULT.getName()); + return Gradients.forName(name).orElse(Gradients.DEFAULT); + } + } diff --git a/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/MapSettingsController.java b/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/MapSettingsController.java index 91a1fe89..bad583cb 100644 --- a/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/MapSettingsController.java +++ b/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/MapSettingsController.java @@ -1,7 +1,9 @@ package org.peakaboo.controller.mapper.settings; import java.io.File; +import java.util.List; +import org.peakaboo.app.Settings; import org.peakaboo.controller.mapper.MapUpdateType; import org.peakaboo.controller.mapper.MappingController; import org.peakaboo.framework.cyclops.Bounds; @@ -16,8 +18,7 @@ * * @author NAS */ -public class MapSettingsController extends EventfulType -{ +public class MapSettingsController extends EventfulType { //SOURCE DATA private MappingController mapController; @@ -32,13 +33,13 @@ public class MapSettingsController extends EventfulType private int spectrumSteps = 15; private boolean contour = false; - private Gradient colourGradient = Gradients.DEFAULT; + private Gradient colourGradient = Settings.getDefaultMapPalette(); private float zoom = 1f; public File lastFolder = null; + - public MapSettingsController(MappingController mapController) { setMappingController(mapController); @@ -103,8 +104,7 @@ public void setColourGradient(Gradient gradient) this.colourGradient = gradient; updateListeners(MapUpdateType.UI_OPTIONS); } - - + public Gradient getColourGradient() { return this.colourGradient; diff --git a/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/SavedMapSettingsController.java b/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/SavedMapSettingsController.java index 22de4069..b32fa729 100644 --- a/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/SavedMapSettingsController.java +++ b/LibPeakaboo/src/main/java/org/peakaboo/controller/mapper/settings/SavedMapSettingsController.java @@ -1,5 +1,6 @@ package org.peakaboo.controller.mapper.settings; +import org.peakaboo.app.Settings; import org.peakaboo.framework.cyclops.visualization.palette.Gradients; public class SavedMapSettingsController { @@ -22,7 +23,7 @@ public void loadInto(MapSettingsController controller) { controller.setShowDatasetTitle(drawDataSetTitle); controller.setSpectrumSteps(spectrumSteps); controller.setContours(contour); - controller.setColourGradient(Gradients.forName(colourPalette).orElse(Gradients.DEFAULT)); + controller.setColourGradient(Gradients.forName(colourPalette).orElse(Settings.getDefaultMapPalette())); } diff --git a/LibPeakaboo/src/main/java/org/peakaboo/display/map/MapRenderSettings.java b/LibPeakaboo/src/main/java/org/peakaboo/display/map/MapRenderSettings.java index 3d9c7dc6..9e67b937 100644 --- a/LibPeakaboo/src/main/java/org/peakaboo/display/map/MapRenderSettings.java +++ b/LibPeakaboo/src/main/java/org/peakaboo/display/map/MapRenderSettings.java @@ -1,5 +1,6 @@ package org.peakaboo.display.map; +import org.peakaboo.app.Settings; import org.peakaboo.calibration.BasicDetectorProfile; import org.peakaboo.calibration.DetectorProfile; import org.peakaboo.display.map.modes.MapModeRegistry; @@ -24,7 +25,7 @@ public class MapRenderSettings { public String mapTitle = ""; public MapScaleMode scalemode = MapScaleMode.ABSOLUTE; - public Gradient gradient = Gradients.DEFAULT; + public Gradient gradient = Settings.getDefaultMapPalette(); public boolean darkmode = false; public boolean contours = false; public int contourSteps = 15; diff --git a/LibPeakaboo/src/main/java/org/peakaboo/mapping/Mapping.java b/LibPeakaboo/src/main/java/org/peakaboo/mapping/Mapping.java index 2c0ecc3a..e53ecb78 100644 --- a/LibPeakaboo/src/main/java/org/peakaboo/mapping/Mapping.java +++ b/LibPeakaboo/src/main/java/org/peakaboo/mapping/Mapping.java @@ -24,6 +24,8 @@ import org.peakaboo.framework.cyclops.spectrum.ArraySpectrum; import org.peakaboo.framework.cyclops.spectrum.Spectrum; import org.peakaboo.framework.cyclops.spectrum.SpectrumView; +import org.peakaboo.framework.cyclops.visualization.palette.Gradient; +import org.peakaboo.framework.cyclops.visualization.palette.Gradients; import org.peakaboo.framework.plural.streams.StreamExecutor; import org.peakaboo.mapping.rawmap.RawMap; import org.peakaboo.mapping.rawmap.RawMapSet; @@ -40,6 +42,17 @@ private Mapping() { //Not Constructable } + public static final List MAP_PALETTES = List.of( + Gradients.SPECTRUM, + Gradients.GEORGIA, + Gradients.IRON, + Gradients.NAVIA, + Gradients.LAJOLLA, + Gradients.OSLO, + Gradients.MONOCHROME, + Gradients.INV_MONOCHROME + ); + /** * Generates a map based on the given inputs. Returns a {@link StreamExecutor} which can execute this task asynchronously and return the result * @param dataset the {@link DataSet} providing access to data diff --git a/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapMenuView.java b/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapMenuView.java index ddd186ea..41082936 100644 --- a/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapMenuView.java +++ b/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapMenuView.java @@ -31,6 +31,7 @@ import org.peakaboo.framework.stratus.components.ui.options.OptionCheckBox; import org.peakaboo.framework.stratus.components.ui.options.OptionRadioButton; import org.peakaboo.framework.stratus.components.ui.options.OptionSize; +import org.peakaboo.mapping.Mapping; public class MapMenuView extends JPopupMenu { @@ -47,14 +48,9 @@ public MapMenuView(MappingController controller) { ButtonGroup paletteGroup = new ButtonGroup(); OptionBlock paletteBlock = new OptionBlock(); - paletteBlock.add(makeOpt(Gradients.SPECTRUM, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.GEORGIA, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.IRON, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.NAVIA, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.LAJOLLA, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.OSLO, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.MONOCHROME, paletteBlock, paletteGroup)); - paletteBlock.add(makeOpt(Gradients.INV_MONOCHROME, paletteBlock, paletteGroup)); + for (var g : Mapping.MAP_PALETTES) { + paletteBlock.add(makeOpt(g, paletteBlock, paletteGroup)); + } OptionBlocksPanel blockPanel = new OptionBlocksPanel(OptionSize.SMALL, paletteBlock); panel.add(blockPanel, BorderLayout.WEST); @@ -120,7 +116,7 @@ private void set(Gradient g) { this.controller.getSettings().setColourGradient(g); } - private ImageIcon gradientToIcon(Gradient g) { + public static ImageIcon gradientToIcon(Gradient g) { int width = 64; int height = 16; diff --git a/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapSelectionListener.java b/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapSelectionListener.java index 7ccfe09e..28a70cfe 100644 --- a/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapSelectionListener.java +++ b/SwingUI/src/main/java/org/peakaboo/ui/swing/mapping/components/MapSelectionListener.java @@ -99,7 +99,6 @@ public void mouseMoved(MouseEvent e) { @Override public void mouseWheelMoved(MouseWheelEvent wheel) { - System.out.println("Event " + wheel); int moves = wheel.getWheelRotation(); double factor = Math.pow(1.1f, Math.abs(moves)); diff --git a/SwingUI/src/main/java/org/peakaboo/ui/swing/options/AdvancedOptionsPanel.java b/SwingUI/src/main/java/org/peakaboo/ui/swing/options/AdvancedOptionsPanel.java index e73901be..1a03c82e 100644 --- a/SwingUI/src/main/java/org/peakaboo/ui/swing/options/AdvancedOptionsPanel.java +++ b/SwingUI/src/main/java/org/peakaboo/ui/swing/options/AdvancedOptionsPanel.java @@ -12,6 +12,7 @@ import java.util.stream.Collectors; import javax.swing.ButtonGroup; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.SwingConstants; @@ -32,11 +33,14 @@ import org.peakaboo.framework.autodialog.view.swing.layouts.SwingLayoutFactory; import org.peakaboo.framework.bolt.plugin.core.BoltPlugin; import org.peakaboo.framework.bolt.plugin.core.PluginDescriptor; +import org.peakaboo.framework.cyclops.visualization.palette.Gradient; import org.peakaboo.framework.stratus.api.Spacing; import org.peakaboo.framework.stratus.api.Stratus; import org.peakaboo.framework.stratus.api.icons.IconFactory; import org.peakaboo.framework.stratus.api.icons.IconSize; import org.peakaboo.framework.stratus.components.panels.ClearPanel; +import org.peakaboo.framework.stratus.components.stencil.Stencil; +import org.peakaboo.framework.stratus.components.stencil.StencilListCellRenderer; import org.peakaboo.framework.stratus.components.ui.header.HeaderLayer; import org.peakaboo.framework.stratus.components.ui.options.OptionBlock; import org.peakaboo.framework.stratus.components.ui.options.OptionBlocksPanel; @@ -47,11 +51,13 @@ import org.peakaboo.framework.stratus.components.ui.options.OptionSidebar; import org.peakaboo.framework.stratus.components.ui.options.OptionSidebar.Entry; import org.peakaboo.framework.stratus.components.ui.options.OptionSize; +import org.peakaboo.mapping.Mapping; import org.peakaboo.tier.Tier; import org.peakaboo.tier.TierUIAutoGroup; import org.peakaboo.ui.swing.app.AccentedBrightTheme; import org.peakaboo.ui.swing.app.DesktopSettings; import org.peakaboo.ui.swing.app.PeakabooIcons; +import org.peakaboo.ui.swing.mapping.components.MapMenuView; import org.peakaboo.ui.swing.plotting.PlotPanel; public class AdvancedOptionsPanel extends HeaderLayer { @@ -194,6 +200,40 @@ private OptionBlocksPanel makePerformancePanel(PlotController controller) { private OptionBlocksPanel makeAppPanel(PlotController controller) { + + OptionBlock mapsBlock = new OptionBlock(); + + var stencil = new Stencil() { + + private JLabel label; + + { + this.label = new JLabel(); + this.setLayout(new BorderLayout()); + this.add(label, BorderLayout.CENTER); + this.label.setBorder(Spacing.bLarge()); + this.label.setIconTextGap(Spacing.large); + } + + @Override + protected void onSetValue(Gradient g, boolean selected) { + this.label.setText(g.getName()); + this.label.setIcon(MapMenuView.gradientToIcon(g)); + } + }; + + var paletteCombo = new JComboBox(Mapping.MAP_PALETTES.toArray(new Gradient[] {})); + paletteCombo.setRenderer(new StencilListCellRenderer<>(stencil)); + paletteCombo.setSelectedItem(Settings.getDefaultMapPalette()); + paletteCombo.addActionListener(e -> { + Gradient sel = (Gradient) paletteCombo.getSelectedItem(); + Settings.setDefaultMapPalette(sel); + }); + var palettes = new OptionCustomComponent(mapsBlock, paletteCombo, false); + palettes.withTitle("Map Palette").withSize(OptionSize.LARGE); + mapsBlock.add(palettes); + + OptionBlock uxBlock = new OptionBlock(); var colours = AccentedBrightTheme.accentColours; @@ -224,7 +264,7 @@ private OptionBlocksPanel makeAppPanel(PlotController controller) { .withListener(DesktopSettings::setFirstrun); startup.add(firstrun); - return new OptionBlocksPanel(uxBlock, startup); + return new OptionBlocksPanel(mapsBlock, uxBlock, startup); }