mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-25 08:32:32 +00:00
Split pane positioner
Handy little class for remembering and restoring the positions of jSplitPane's
This commit is contained in:
parent
f5c3ce06ce
commit
f097ddce45
@ -2407,7 +2407,7 @@ public class PamController implements PamControllerInterface, PamSettings {
|
||||
if (dbc == null) {
|
||||
return null;
|
||||
}
|
||||
return dbc.getDatabaseName();
|
||||
return dbc.getLongDatabaseName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
62
src/PamView/panel/SplitPanePositionData.java
Normal file
62
src/PamView/panel/SplitPanePositionData.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
95
src/PamView/panel/SplitPanePositioner.java
Normal file
95
src/PamView/panel/SplitPanePositioner.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user