Changeset 12705 in josm


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

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

Location:
trunk/src/org/openstreetmap/josm/gui/download
Files:
1 added
3 edited

Legend:

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

    r12684 r12705  
    88
    99import org.openstreetmap.josm.data.Bounds;
     10import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.FixedDownloadSourceSizePolicy;
    1011
    1112/**
     
    1617 */
    1718public abstract class AbstractDownloadSourcePanel<T> extends JPanel {
     19
     20    /**
     21     * A prefix to be used for tab height preferences
     22     */
     23    public static final String TAB_SPLIT_NAMESPACE = "download.tabsplit.";
    1824
    1925    /**
     
    107113     */
    108114    public abstract String getSimpleName();
     115
     116    /**
     117     * Gets the policy that defines how this component should be sized
     118     * @return The sizing policy. A fixed policy on default.
     119     * @since 12705
     120     */
     121    public DownloadSourceSizingPolicy getSizingPolicy() {
     122        return new FixedDownloadSourceSizePolicy(this);
     123    }
    109124}
  • 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}
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r12684 r12705  
    2929import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    3030import org.openstreetmap.josm.data.Bounds;
     31import org.openstreetmap.josm.data.preferences.AbstractProperty;
    3132import org.openstreetmap.josm.data.preferences.BooleanProperty;
     33import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3234import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    3335import org.openstreetmap.josm.gui.MainApplication;
     36import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.AdjustableDownloadSizePolicy;
    3437import org.openstreetmap.josm.gui.preferences.server.OverpassServerPreference;
    3538import org.openstreetmap.josm.gui.util.GuiHelper;
     
    4447 */
    4548public class OverpassDownloadSource implements DownloadSource<OverpassDownloadSource.OverpassDownloadData> {
     49
    4650
    4751    @Override
     
    8185    public static class OverpassDownloadSourcePanel extends AbstractDownloadSourcePanel<OverpassDownloadData> {
    8286
    83         private JosmTextArea overpassQuery;
    84         private OverpassQueryList overpassQueryList;
    85 
    8687        private static final String SIMPLE_NAME = "overpassdownloadpanel";
     88        private static final AbstractProperty<Integer> PANEL_SIZE_PROPERTY =
     89                new IntegerProperty(TAB_SPLIT_NAMESPACE + SIMPLE_NAME, 150).cached();
    8790        private static final BooleanProperty OVERPASS_QUERY_LIST_OPENED =
    8891                new BooleanProperty("download.overpass.query-list.opened", false);
    8992        private static final String ACTION_IMG_SUBDIR = "dialogs";
     93
     94        private JosmTextArea overpassQuery;
     95        private OverpassQueryList overpassQueryList;
    9096
    9197        /**
     
    278284        }
    279285
     286        @Override
     287        public DownloadSourceSizingPolicy getSizingPolicy() {
     288            return new AdjustableDownloadSizePolicy(PANEL_SIZE_PROPERTY);
     289        }
     290
    280291        /**
    281292         * Action that delegates snippet creation to {@link OverpassQueryList#createNewItem()}.
Note: See TracChangeset for help on using the changeset viewer.