Skip to content

Commit

Permalink
Add option to set default map palette
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielsherry committed Jun 13, 2024
1 parent cd8778b commit d1572de
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 21 deletions.
16 changes: 14 additions & 2 deletions LibPeakaboo/src/main/java/org/peakaboo/app/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,15 +124,25 @@ 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);
}




}

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);
}


}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,8 +18,7 @@
*
* @author NAS
*/
public class MapSettingsController extends EventfulType<MapUpdateType>
{
public class MapSettingsController extends EventfulType<MapUpdateType> {

//SOURCE DATA
private MappingController mapController;
Expand All @@ -32,13 +33,13 @@ public class MapSettingsController extends EventfulType<MapUpdateType>

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);
Expand Down Expand Up @@ -103,8 +104,7 @@ public void setColourGradient(Gradient gradient)
this.colourGradient = gradient;
updateListeners(MapUpdateType.UI_OPTIONS);
}



public Gradient getColourGradient()
{
return this.colourGradient;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions LibPeakaboo/src/main/java/org/peakaboo/mapping/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +42,17 @@ private Mapping() {
//Not Constructable
}

public static final List<Gradient> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -194,6 +200,40 @@ private OptionBlocksPanel makePerformancePanel(PlotController controller) {

private OptionBlocksPanel makeAppPanel(PlotController controller) {


OptionBlock mapsBlock = new OptionBlock();

var stencil = new Stencil<Gradient>() {

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<Gradient>(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;
Expand Down Expand Up @@ -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);

}

Expand Down

0 comments on commit d1572de

Please sign in to comment.