Ignore:
Timestamp:
2017-09-01T01:07:32+02:00 (7 years ago)
Author:
michael2402
Message:

See #15167: Make size of the OSM download panel fixed, only allow resizing for overpass.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r12694 r12705  
    1515import java.awt.event.WindowAdapter;
    1616import java.awt.event.WindowEvent;
    17 import java.beans.PropertyChangeListener;
    1817import java.util.ArrayList;
    1918import java.util.Arrays;
     
    6261public class DownloadDialog extends JDialog {
    6362
    64     /**
    65      * Preference properties
    66      */
    67     private static final String TAB_SPLIT_NAMESPACE = "download.tabsplit.";
    6863    private static final IntegerProperty DOWNLOAD_TAB = new IntegerProperty("download.tab", 0);
    6964    private static final IntegerProperty DOWNLOAD_SOURCE_TAB = new IntegerProperty("download-source.tab", 0);
     
    9792    protected SlippyMapChooser slippyMapChooser;
    9893    protected JPanel mainPanel;
    99     protected JSplitPane dialogSplit;
     94    protected DownloadDialogSplitPane dialogSplit;
    10095
    10196    /*
     
    144139        tpDownloadAreaSelectors.setMinimumSize(new Dimension(0, 0));
    145140
    146         dialogSplit = new JSplitPane(
    147                 JSplitPane.VERTICAL_SPLIT,
     141        dialogSplit = new DownloadDialogSplitPane(
    148142                downloadSourcesTab,
    149143                tpDownloadAreaSelectors);
    150         dialogSplit.addPropertyChangeListener(getDividerChangedListener());
    151144
    152145        ChangeListener tabChangedListener = getDownloadSourceTabChangeListener();
     
    556549            if (selectedComponent instanceof AbstractDownloadSourcePanel) {
    557550                AbstractDownloadSourcePanel<?> panel = (AbstractDownloadSourcePanel<?>) selectedComponent;
    558                 dialogSplit.setDividerLocation(Main.pref.getInteger(
    559                         TAB_SPLIT_NAMESPACE + panel.getSimpleName(),
    560                         panel.getMinimumSize().height));
    561             }
    562         };
    563     }
    564 
    565     /**
    566      * Creates a listener that react on dialog splitters movements to save users preferences.
    567      * @return A listener to save user preferred split of the dialog.
    568      */
    569     private PropertyChangeListener getDividerChangedListener() {
    570         return evt -> {
    571             if (evt.getPropertyName().equalsIgnoreCase(JSplitPane.DIVIDER_LOCATION_PROPERTY)) {
    572                 Component selectedComponent = downloadSourcesTab.getSelectedComponent();
    573                 if (selectedComponent instanceof AbstractDownloadSourcePanel) {
    574                     AbstractDownloadSourcePanel<?> panel = (AbstractDownloadSourcePanel<?>) selectedComponent;
    575                     Main.pref.put(
    576                             TAB_SPLIT_NAMESPACE + panel.getSimpleName(),
    577                             String.valueOf(dialogSplit.getDividerLocation())
    578                     );
    579                 }
     551                dialogSplit.setPolicy(panel.getSizingPolicy());
    580552            }
    581553        };
     
    659631        }
    660632    }
     633
     634    /**
     635     * A special split pane that acts according to a {@link DownloadSourceSizingPolicy}
     636     *
     637     * It attempts to size the top tab content correctly.
     638     *
     639     * @author Michael Zangl
     640     * @since 12705
     641     */
     642    private static class DownloadDialogSplitPane extends JSplitPane {
     643        private DownloadSourceSizingPolicy policy;
     644        private JTabbedPane topComponent;
     645
     646        DownloadDialogSplitPane(JTabbedPane newTopComponent, Component newBottomComponent) {
     647            super(VERTICAL_SPLIT, newTopComponent, newBottomComponent);
     648            this.topComponent = newTopComponent;
     649        }
     650
     651        public void setPolicy(DownloadSourceSizingPolicy policy) {
     652            this.policy = policy;
     653
     654            super.setDividerLocation(policy.getComponentHeight() + computeOffset());
     655            setDividerSize(policy.isHeightAdjustable() ? 10 : 0);
     656            setEnabled(policy.isHeightAdjustable());
     657        }
     658
     659        @Override
     660        public void doLayout() {
     661            // We need to force this height before the layout manager is run.
     662            // We cannot do this in the setDividerLocation, since the offset cannot be computed there.
     663            int offset = computeOffset();
     664            if (policy.isHeightAdjustable()) {
     665                policy.storeHeight(Math.max(getDividerLocation() - offset, 0));
     666            }
     667            super.setDividerLocation(policy.getComponentHeight() + offset);
     668            super.doLayout();
     669        }
     670
     671        /**
     672         * @return The difference between the content height and the divider location
     673         */
     674        private int computeOffset() {
     675            Component selectedComponent = topComponent.getSelectedComponent();
     676            return topComponent.getHeight() - (selectedComponent == null ? 0 : selectedComponent.getHeight());
     677        }
     678    }
    661679}
Note: See TracChangeset for help on using the changeset viewer.