Changeset 12705 in josm
- Timestamp:
- 2017-09-01T01:07:32+02:00 (7 years ago)
- 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 8 8 9 9 import org.openstreetmap.josm.data.Bounds; 10 import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.FixedDownloadSourceSizePolicy; 10 11 11 12 /** … … 16 17 */ 17 18 public 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."; 18 24 19 25 /** … … 107 113 */ 108 114 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 } 109 124 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r12694 r12705 15 15 import java.awt.event.WindowAdapter; 16 16 import java.awt.event.WindowEvent; 17 import java.beans.PropertyChangeListener;18 17 import java.util.ArrayList; 19 18 import java.util.Arrays; … … 62 61 public class DownloadDialog extends JDialog { 63 62 64 /**65 * Preference properties66 */67 private static final String TAB_SPLIT_NAMESPACE = "download.tabsplit.";68 63 private static final IntegerProperty DOWNLOAD_TAB = new IntegerProperty("download.tab", 0); 69 64 private static final IntegerProperty DOWNLOAD_SOURCE_TAB = new IntegerProperty("download-source.tab", 0); … … 97 92 protected SlippyMapChooser slippyMapChooser; 98 93 protected JPanel mainPanel; 99 protected JSplitPane dialogSplit;94 protected DownloadDialogSplitPane dialogSplit; 100 95 101 96 /* … … 144 139 tpDownloadAreaSelectors.setMinimumSize(new Dimension(0, 0)); 145 140 146 dialogSplit = new JSplitPane( 147 JSplitPane.VERTICAL_SPLIT, 141 dialogSplit = new DownloadDialogSplitPane( 148 142 downloadSourcesTab, 149 143 tpDownloadAreaSelectors); 150 dialogSplit.addPropertyChangeListener(getDividerChangedListener());151 144 152 145 ChangeListener tabChangedListener = getDownloadSourceTabChangeListener(); … … 556 549 if (selectedComponent instanceof AbstractDownloadSourcePanel) { 557 550 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()); 580 552 } 581 553 }; … … 659 631 } 660 632 } 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 } 661 679 } -
trunk/src/org/openstreetmap/josm/gui/download/OverpassDownloadSource.java
r12684 r12705 29 29 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 30 30 import org.openstreetmap.josm.data.Bounds; 31 import org.openstreetmap.josm.data.preferences.AbstractProperty; 31 32 import org.openstreetmap.josm.data.preferences.BooleanProperty; 33 import org.openstreetmap.josm.data.preferences.IntegerProperty; 32 34 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 33 35 import org.openstreetmap.josm.gui.MainApplication; 36 import org.openstreetmap.josm.gui.download.DownloadSourceSizingPolicy.AdjustableDownloadSizePolicy; 34 37 import org.openstreetmap.josm.gui.preferences.server.OverpassServerPreference; 35 38 import org.openstreetmap.josm.gui.util.GuiHelper; … … 44 47 */ 45 48 public class OverpassDownloadSource implements DownloadSource<OverpassDownloadSource.OverpassDownloadData> { 49 46 50 47 51 @Override … … 81 85 public static class OverpassDownloadSourcePanel extends AbstractDownloadSourcePanel<OverpassDownloadData> { 82 86 83 private JosmTextArea overpassQuery;84 private OverpassQueryList overpassQueryList;85 86 87 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(); 87 90 private static final BooleanProperty OVERPASS_QUERY_LIST_OPENED = 88 91 new BooleanProperty("download.overpass.query-list.opened", false); 89 92 private static final String ACTION_IMG_SUBDIR = "dialogs"; 93 94 private JosmTextArea overpassQuery; 95 private OverpassQueryList overpassQueryList; 90 96 91 97 /** … … 278 284 } 279 285 286 @Override 287 public DownloadSourceSizingPolicy getSizingPolicy() { 288 return new AdjustableDownloadSizePolicy(PANEL_SIZE_PROPERTY); 289 } 290 280 291 /** 281 292 * Action that delegates snippet creation to {@link OverpassQueryList#createNewItem()}.
Note:
See TracChangeset
for help on using the changeset viewer.