Ticket #12536: 12536.2.patch

File 12536.2.patch, 3.3 KB (added by GerdP, 6 years ago)

adjust divider also when resizing the popup

  • src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

     
    1111import java.awt.FlowLayout;
    1212import java.awt.GraphicsEnvironment;
    1313import java.awt.event.ActionEvent;
    14 import java.awt.event.WindowAdapter;
    15 import java.awt.event.WindowEvent;
    1614import java.beans.PropertyChangeEvent;
    1715import java.beans.PropertyChangeListener;
    1816import java.util.Collection;
     
    182180    protected final void build() {
    183181        getContentPane().setLayout(new BorderLayout());
    184182        updateTitle();
    185         spTagConflictTypes = new AutoAdjustingSplitPane(JSplitPane.VERTICAL_SPLIT);
     183        spTagConflictTypes = new AutoAdjustingSplitPane(JSplitPane.VERTICAL_SPLIT) {
     184            @Override
     185            public void propertyChange(PropertyChangeEvent evt) {
     186                // see #12536
     187                if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(evt.getPropertyName())) {
     188                    adjustDividerLocation();
     189                }
     190                super.propertyChange(evt);
     191            }
     192        };
    186193        spTagConflictTypes.setTopComponent(buildTagConflictResolverPanel());
    187194        spTagConflictTypes.setBottomComponent(buildRelationMemberConflictResolverPanel());
    188195        pnlButtons = buildButtonPanel();
    189196        getContentPane().add(pnlButtons, BorderLayout.SOUTH);
    190         addWindowListener(new AdjustDividerLocationAction());
    191197        HelpUtil.setHelpContext(getRootPane(), ht("/"));
    192198        InputMapUtils.addEscapeAction(getRootPane(), new CancelAction());
    193199    }
     
    343349        }
    344350
    345351        getContentPane().add(pnlButtons, BorderLayout.SOUTH);
    346         validate();
     352        getContentPane().validate();
    347353        adjustDividerLocation();
    348354        pnlRelationMemberConflictResolver.prepareForEditing();
    349355    }
     
    444450    private void adjustDividerLocation() {
    445451        int numTagDecisions = modelTagConflictResolver.getNumDecisions();
    446452        int numRelationDecisions = modelRelConflictResolver.getNumDecisions();
    447         if (numTagDecisions > 0 && numRelationDecisions > 0) {
    448             double nTop = 1.0 + numTagDecisions;
    449             double nBottom = 2.5 + numRelationDecisions;
    450             spTagConflictTypes.setDividerLocation(nTop/(nTop+nBottom));
    451         }
    452     }
    453453
    454     class AdjustDividerLocationAction extends WindowAdapter {
    455         @Override
    456         public void windowOpened(WindowEvent e) {
    457             adjustDividerLocation();
     454
     455        if (numTagDecisions > 0 && numRelationDecisions > 0 && getHeight() > 0) {
     456            // see #12536: Take the space for buttons and checkbox into account.
     457            double hPopup = getHeight();
     458            double h1 = (pnlRelationMemberConflictResolver.getHeight() + pnlTagConflictResolver.getHeight());
     459            double correction = h1 > 0 ? ((hPopup-h1)/hPopup) : 0;
     460
     461            double nTop = 3.5 + numTagDecisions;
     462            double nBottom = 5.5 + numRelationDecisions;
     463            spTagConflictTypes.setDividerLocation(nTop/(nTop+nBottom) - correction);
    458464        }
    459465    }
    460466