Skip to content

Commit

Permalink
see #7561 comment 24
Browse files Browse the repository at this point in the history
slightly modified 7561_storeHeight.patch, 

1a) When JOSM is closed or all layers are removed so that the "splash screen" is showed, the current height of each dialog is stored in the preferences file. The values are stored in preferencePrefix+".lastHeight".
1b) When JOSM is started or a first layer is opened, the previously stored values are restored.
2) The hard coded preferredHeight values are now also stored in preferencePrefix+".preferredHeight". The expert can change that value to a higher or lower value. When the sizes are refreshed because a dialog is added, removed or minimized the modified value is taken into account. With the current implementation the change is only taken into account when JOSM is stopped/started.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@14425 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
GerdP authored and GerdP committed Nov 16, 2018
1 parent 728d48f commit 1de9308
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void initialize(List<ToggleDialog> pAllDialogs) {
}

this.add(mSpltPane);
reconstruct(Action.ELEMENT_SHRINKS, null);
reconstruct(Action.RESTORE_SAVED, null);
}

/**
Expand Down Expand Up @@ -126,6 +126,10 @@ public enum Action {
* The panel was collapsed by the user.
*/
COLLAPSED_TO_DEFAULT,
/**
* Restore saved heights.
*/
RESTORE_SAVED,
/* INVISIBLE_TO_COLLAPSED, does not happen */
/**
* else. (Remaining elements have more space.)
Expand Down Expand Up @@ -186,7 +190,17 @@ public void reconstruct(Action action, ToggleDialog triggeredBy) {
/**
* Determine the panel geometry
*/
if (action == Action.ELEMENT_SHRINKS) {
if (action == Action.RESTORE_SAVED) {
for (int i = 0; i < n; ++i) {
final ToggleDialog dlg = allDialogs.get(i);
if (dlg.isDialogInDefaultView()) {
final int ph = dlg.getLastHeight();
final int ah = dlg.getSize().height;
dlg.setPreferredSize(new Dimension(Integer.MAX_VALUE, ah < 20 ? ph : ah));
}
}

} else if (action == Action.ELEMENT_SHRINKS) {
for (int i = 0; i < n; ++i) {
final ToggleDialog dlg = allDialogs.get(i);
if (dlg.isDialogInDefaultView()) {
Expand Down Expand Up @@ -236,7 +250,7 @@ public void reconstruct(Action action, ToggleDialog triggeredBy) {
final int hnTrig = hpTrig * s2 / (hpTrig + sumP);
triggeredBy.setPreferredSize(new Dimension(Integer.MAX_VALUE, hnTrig));

/** This is remainig for the other default view dialogs */
/** This is remaining for the other default view dialogs */
final int r = s2 - hnTrig;

/**
Expand Down
18 changes: 17 additions & 1 deletion src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public ToggleDialog(String name, String iconName, String tooltip, Shortcut short
setPreferredSize(new Dimension(0, preferredHeight));
/** Override any minimum sizes of child elements so the user can resize freely */
setMinimumSize(new Dimension(0, 0));
this.preferredHeight = preferredHeight;
this.preferredHeight = Config.getPref().getInt(preferencePrefix+".preferredHeight", preferredHeight);
toggleAction = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, shortcut, helpTopic());

isShowing = Config.getPref().getBoolean(preferencePrefix+".visible", defShow);
Expand Down Expand Up @@ -456,6 +456,7 @@ protected void setContentVisible(boolean visible) {

@Override
public void destroy() {
rememberHeight();
closeDetachedDialog();
if (isShowing) {
hideNotify();
Expand Down Expand Up @@ -996,4 +997,19 @@ private void refreshHidingButtons() {
}
stateChanged();
}

/**
* @return the last used height stored in preferences or preferredHeight
*/
public int getLastHeight() {
return Config.getPref().getInt(preferencePrefix+".lastHeight", preferredHeight);
}

/**
* Store the current height in preferences so that we can restore it.
*/
public void rememberHeight() {
int h = getHeight();
Config.getPref().put(preferencePrefix+".lastHeight", Integer.toString(h));
}
}

0 comments on commit 1de9308

Please sign in to comment.