From f097ddce45c03edf05b46e3e354a7baf4cdba44b Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Sat, 30 Dec 2023 17:01:46 +0000 Subject: [PATCH] Split pane positioner Handy little class for remembering and restoring the positions of jSplitPane's --- src/PamController/PamController.java | 2 +- src/PamView/panel/SplitPanePositionData.java | 62 +++++++++++++ src/PamView/panel/SplitPanePositioner.java | 95 ++++++++++++++++++++ src/pamguard/Pamguard.java | 6 +- 4 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 src/PamView/panel/SplitPanePositionData.java create mode 100644 src/PamView/panel/SplitPanePositioner.java diff --git a/src/PamController/PamController.java b/src/PamController/PamController.java index 93dc4205..d74cd730 100644 --- a/src/PamController/PamController.java +++ b/src/PamController/PamController.java @@ -2407,7 +2407,7 @@ public class PamController implements PamControllerInterface, PamSettings { if (dbc == null) { return null; } - return dbc.getDatabaseName(); + return dbc.getLongDatabaseName(); } return null; } diff --git a/src/PamView/panel/SplitPanePositionData.java b/src/PamView/panel/SplitPanePositionData.java new file mode 100644 index 00000000..b7207e6e --- /dev/null +++ b/src/PamView/panel/SplitPanePositionData.java @@ -0,0 +1,62 @@ +package PamView.panel; + +import java.io.Serializable; + +public class SplitPanePositionData implements Serializable { + + + public static final long serialVersionUID = 1L; + private int position; + private double propPosition; + private int height; + + + public SplitPanePositionData(int position, double propPosition, int height) { + super(); + this.position = position; + this.setHeight(height); + this.setPropPosition(propPosition); + } + + /** + * @return the position + */ + public int getPosition() { + return position; + } + + /** + * @param position the position to set + */ + public void setPosition(int position) { + this.position = position; + } + + /** + * @return the propPosition + */ + public double getPropPosition() { + return propPosition; + } + + /** + * @param propPosition the propPosition to set + */ + public void setPropPosition(double propPosition) { + this.propPosition = propPosition; + } + + /** + * @return the height + */ + public int getHeight() { + return height; + } + + /** + * @param height the height to set + */ + public void setHeight(int height) { + this.height = height; + } +} diff --git a/src/PamView/panel/SplitPanePositioner.java b/src/PamView/panel/SplitPanePositioner.java new file mode 100644 index 00000000..32642bde --- /dev/null +++ b/src/PamView/panel/SplitPanePositioner.java @@ -0,0 +1,95 @@ +package PamView.panel; + +import java.io.Serializable; + +import javax.swing.JSplitPane; +import javax.swing.SwingUtilities; + +import PamController.PamControlledUnitSettings; +import PamController.PamSettingManager; +import PamController.PamSettings; + +/** + * Class that will remember and reset the position of a split pane. Any split pane. + * Just call this constructor with a unique name and the splitPane and a default + * between 0 and 1 and it will register itself automatically with PamSettings. + * @author dg50 + * + */ +public class SplitPanePositioner implements PamSettings { + + private static final String unitType = "Split Pane Position"; + + private String unitName; + + private JSplitPane splitPane; + + /** + * Constructor for split pane positioner. Just call this constructor for each + * split pane, then forget about it. This will have been registered with + * PamSettings and will handle everything, restoring the split pane position + * when PAMGuard is restarted. + * @param unitName A unique name for the split pane. + * @param splitPane reference to an existing split pane. + * @param proportionalDefault default position (0 < position < 1). + */ + public SplitPanePositioner(String unitName, JSplitPane splitPane, double proportionalDefault) { + super(); + this.splitPane = splitPane; + this.unitName = unitName; + boolean exists = PamSettingManager.getInstance().registerSettings(this); + if (exists == false) { + // use the default + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + splitPane.setDividerLocation(proportionalDefault); + } + }); + } + } + + @Override + public String getUnitName() { + return unitName; + } + + @Override + public String getUnitType() { + return unitType; + } + + @Override + public Serializable getSettingsReference() { + System.out.printf("Save split position %s as %d out of %d\n", unitName, splitPane.getDividerLocation(), splitPane.getHeight()); + double propPosition = (double) splitPane.getDividerLocation() / (double) splitPane.getHeight(); + SplitPanePositionData posData = new SplitPanePositionData(splitPane.getDividerLocation(), propPosition, splitPane.getHeight()); + return posData; + } + + @Override + public long getSettingsVersion() { + return SplitPanePositionData.serialVersionUID; + } + + @Override + public boolean restoreSettings(PamControlledUnitSettings pamControlledUnitSettings) { + + SplitPanePositionData posData = (SplitPanePositionData) pamControlledUnitSettings.getSettings(); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + int newPos = posData.getPosition() + splitPane.getHeight() - posData.getHeight(); + System.out.printf("Set split %s position to %d or %3.3f of %d\n", unitName, + posData.getPosition(), posData.getPropPosition(), splitPane.getHeight()); + splitPane.setDividerLocation(posData.getPosition()); + } + }); + return true; + } + + + +} diff --git a/src/pamguard/Pamguard.java b/src/pamguard/Pamguard.java index a80c16cc..da9391ae 100644 --- a/src/pamguard/Pamguard.java +++ b/src/pamguard/Pamguard.java @@ -154,6 +154,7 @@ public class Pamguard { } catch (Exception e) { e.printStackTrace(); } + boolean showSplash = true; if (args != null) { int nArgs = args.length; int iArg = 0; @@ -172,6 +173,9 @@ public class Pamguard { runMode = PamController.RUN_NETWORKRECEIVER; System.out.println("PAMGUARD Network Reciever Mode"); } + else if (anArg.equalsIgnoreCase("-nosplash")) { + showSplash = false; + } // removed SEICHE switch when the two SEICHE modules were converted to plugins // else if (anArg.equalsIgnoreCase("-seiche")) { @@ -383,7 +387,7 @@ public class Pamguard { if(runMode == PamController.RUN_REMOTE) { spashTime = 0; } - if (spashTime > 0 && (PamGUIManager.getGUIType() != PamGUIManager.NOGUI)) { + if (showSplash && spashTime > 0 && (PamGUIManager.getGUIType() != PamGUIManager.NOGUI)) { new Splash(spashTime, chosenRunMode); } //