Changeset 12705 in josm for trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
- Timestamp:
- 2017-09-01T01:07:32+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.