Changeset 16544 in josm for trunk/src


Ignore:
Timestamp:
2020-06-07T09:47:48+02:00 (4 years ago)
Author:
simon04
Message:

fix #19321 - ComboMultiSelect: fix preferred width

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java

    r16526 r16544  
    1414import java.util.Collection;
    1515import java.util.Collections;
     16import java.util.Comparator;
    1617import java.util.List;
    1718import java.util.Objects;
     
    2021import java.util.concurrent.CopyOnWriteArraySet;
    2122import java.util.stream.Collectors;
     23import java.util.stream.IntStream;
    2224
    2325import javax.swing.ImageIcon;
     
    114116            }
    115117
     118            if (index == -1) {
     119                // Take the longest element for the preferred width (#19321)
     120                // We do not want the editor to have the maximum height of all entries. Return a dummy with bogus height.
     121                IntStream.range(0, list.getModel().getSize())
     122                        .mapToObj(i -> getListCellRendererComponent(list, list.getModel().getElementAt(i), i, isSelected, cellHasFocus))
     123                        .map(Component::getPreferredSize)
     124                        .max(Comparator.comparingInt(dim -> dim.width))
     125                        .ifPresent(dim -> lbl.setPreferredSize(new Dimension(dim.width, 10)));
     126                return lbl;
     127            }
     128
    116129            // Only return cached size, item is not shown
    117130            if (!list.isShowing() && item.preferredWidth != -1 && item.preferredHeight != -1) {
    118                 if (index == -1) {
    119                     lbl.setPreferredSize(new Dimension(item.preferredWidth, 10));
    120                 } else {
    121                     lbl.setPreferredSize(new Dimension(item.preferredWidth, item.preferredHeight));
    122                 }
     131                lbl.setPreferredSize(new Dimension(item.preferredWidth, item.preferredHeight));
    123132                return lbl;
    124133            }
     
    144153            item.preferredHeight = (short) lbl.getPreferredSize().height;
    145154
    146             // We do not want the editor to have the maximum height of all
    147             // entries. Return a dummy with bogus height.
    148             if (index == -1) {
    149                 lbl.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10));
    150             }
    151155            return lbl;
    152156        }
Note: See TracChangeset for help on using the changeset viewer.