Changeset 12419 in josm for trunk/src/org


Ignore:
Timestamp:
2017-06-21T12:37:36+02:00 (7 years ago)
Author:
michael2402
Message:

GPX color selector: Highlight current color.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java

    r12402 r12419  
    1717import java.util.HashMap;
    1818import java.util.List;
     19import java.util.function.Supplier;
    1920import java.util.stream.Collectors;
    2021
     
    9394        addContentEntry(new GammaFilterSlider());
    9495        addContentEntry(new SharpnessSlider());
    95         addContentEntry(new ColorSelector());
     96        addContentEntry(new ColorSelector(model::getSelectedLayers));
    9697    }
    9798
     
    527528     * @author Michael Zangl
    528529     */
    529     private class ColorSelector extends JPanel implements LayerVisibilityMenuEntry {
    530 
    531         private final Border NORMAL_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2);
    532         private final Border SELECTED_BORDER = BorderFactory.createLineBorder(Color.BLACK, 2);
     530    private static class ColorSelector extends JPanel implements LayerVisibilityMenuEntry {
     531
     532        private static final Border NORMAL_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2);
     533        private static final Border SELECTED_BORDER = BorderFactory.createLineBorder(Color.BLACK, 2);
    533534
    534535        // TODO: Nicer color palette
    535         private final Color[] COLORS = new Color[] {
     536        private static final Color[] COLORS = new Color[] {
    536537                Color.RED,
    537538                Color.ORANGE,
     
    542543                Color.GRAY,
    543544        };
     545        private final Supplier<List<Layer>> layerSupplier;
    544546        private final HashMap<Color, JPanel> panels = new HashMap<>();
    545547
    546         ColorSelector() {
     548        ColorSelector(Supplier<List<Layer>> layerSupplier) {
    547549            super(new GridBagLayout());
     550            this.layerSupplier = layerSupplier;
    548551            add(new JLabel(tr("Color")), GBC.eol().insets(24 + 10, 0, 0, 0));
    549552            for (Color color : COLORS) {
     
    563566                @Override
    564567                public void mouseClicked(MouseEvent e) {
    565                     List<Layer> layers = model.getSelectedLayers();
     568                    List<Layer> layers = layerSupplier.get();
    566569                    for (Layer l : layers) {
    567570                        if (l instanceof GpxLayer) {
     
    574577            add(colorPanel, GBC.std().weight(1, 1).fill().insets(5));
    575578            panels.put(color, colorPanel);
     579
     580            List<Color> colors = layerSupplier.get().stream().map(l -> l.getColorProperty().get()).distinct().collect(Collectors.toList());
     581            if (colors.size() == 1) {
     582                highlightColor(colors.get(0));
     583            }
    576584        }
    577585
     
    585593                setVisible(true);
    586594                highlightColor(colors.get(0));
    587             } else if (colors.size() > 0) {
     595            } else if (colors.size() > 1) {
    588596                setVisible(true);
    589597                highlightColor(null);
Note: See TracChangeset for help on using the changeset viewer.