Changeset 14418 in josm for trunk/src/org


Ignore:
Timestamp:
2018-11-07T22:38:38+01:00 (6 years ago)
Author:
michael2402
Message:

Fix #16945: Only store changed overpass height if user changes it. Add minimum size to overpass query / map view

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

Legend:

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

    r14391 r14418  
    1111import java.awt.GridBagLayout;
    1212import java.awt.event.ActionEvent;
     13import java.awt.event.ComponentAdapter;
     14import java.awt.event.ComponentEvent;
    1315import java.awt.event.InputEvent;
    1416import java.awt.event.KeyEvent;
     
    655657        private DownloadSourceSizingPolicy policy;
    656658        private final JTabbedPane topComponent;
     659        /**
     660         * If the height was explicitly set by the user.
     661         */
     662        private boolean heightAdjustedExplicitly;
    657663
    658664        DownloadDialogSplitPane(JTabbedPane newTopComponent, Component newBottomComponent) {
    659665            super(VERTICAL_SPLIT, newTopComponent, newBottomComponent);
    660666            this.topComponent = newTopComponent;
     667
     668            addComponentListener(new ComponentAdapter() {
     669                @Override
     670                public void componentResized(ComponentEvent e) {
     671                    // doLayout is called automatically when the component size decreases
     672                    // This seems to be the only way to call doLayout when the component size increases
     673                    // We need this since we sometimes want to increase the top component size.
     674                    revalidate();
     675                }
     676            });
     677
     678            addPropertyChangeListener(DIVIDER_LOCATION_PROPERTY, e -> {
     679                heightAdjustedExplicitly = true;
     680            });
    661681        }
    662682
     
    674694            // We cannot do this in the setDividerLocation, since the offset cannot be computed there.
    675695            int offset = computeOffset();
    676             if (policy.isHeightAdjustable()) {
     696            if (policy.isHeightAdjustable() && heightAdjustedExplicitly) {
    677697                policy.storeHeight(Math.max(getDividerLocation() - offset, 0));
    678698            }
    679             super.setDividerLocation(policy.getComponentHeight() + offset);
     699            // At least 30 pixel for map, if we have enough space
     700            int maxValidDividerLocation = getHeight() > 150 ? getHeight() - 40 : getHeight();
     701
     702            super.setDividerLocation(Math.min(policy.getComponentHeight() + offset, maxValidDividerLocation));
    680703            super.doLayout();
     704            // Order is important (set this after setDividerLocation/doLayout called the listener)
     705            this.heightAdjustedExplicitly = false;
    681706        }
    682707
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadSourceSizingPolicy.java

    r12707 r14418  
    33
    44import java.awt.Component;
     5import java.util.function.IntSupplier;
    56
    67import org.openstreetmap.josm.data.preferences.AbstractProperty;
     
    6768
    6869        private final AbstractProperty<Integer> preference;
     70        private IntSupplier minHeight;
    6971
    7072        /**
    7173         * Create a new {@link AdjustableDownloadSizePolicy}
    72          * @param preference The preference key to use
     74         * @param preference The preference to use
    7375         */
    7476        public AdjustableDownloadSizePolicy(AbstractProperty<Integer> preference) {
     77            this(preference, () -> 1);
     78        }
     79
     80        /**
     81         * Create a new {@link AdjustableDownloadSizePolicy}
     82         * @param preference The preference to use
     83         * @param minHeight A supplier that gives the minimum height of the component. Must be positive or 0.
     84         * @since 14418
     85         */
     86        public AdjustableDownloadSizePolicy(AbstractProperty<Integer> preference, IntSupplier minHeight) {
    7587            this.preference = preference;
     88            this.minHeight = minHeight;
    7689        }
    7790
    7891        @Override
    7992        public int getComponentHeight() {
    80             return Math.max(1, preference.get());
     93            int computedMinHeight = this.minHeight.getAsInt();
     94            if (computedMinHeight < 0) {
     95                throw new IllegalStateException("Illegal minimum component height:" + computedMinHeight);
     96            }
     97            return Math.max(computedMinHeight, preference.get());
    8198        }
    8299
  • trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java

    r13930 r14418  
    1616
    1717import javax.swing.AbstractAction;
     18import javax.swing.BorderFactory;
    1819import javax.swing.Icon;
    1920import javax.swing.JButton;
     
    164165                .forEach(button -> leftPanel.add(button, GBC.eol().anchor(GBC.CENTER)));
    165166            leftPanel.add(new JLabel(), GBC.eol().fill(GBC.VERTICAL));
     167            leftPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    166168
    167169            add(leftPanel, BorderLayout.WEST);
     
    285287        @Override
    286288        public DownloadSourceSizingPolicy getSizingPolicy() {
    287             return new AdjustableDownloadSizePolicy(PANEL_SIZE_PROPERTY);
     289            return new AdjustableDownloadSizePolicy(PANEL_SIZE_PROPERTY, () -> 50);
    288290        }
    289291
Note: See TracChangeset for help on using the changeset viewer.