Changeset 8507 in josm


Ignore:
Timestamp:
2015-06-20T00:27:53+02:00 (4 years ago)
Author:
simon04
Message:

fix #10593 - Preference, mappaint/preset/validator sources: indicate added/active items by gray/green checkmark

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r8492 r8507  
    1818import java.awt.event.MouseAdapter;
    1919import java.awt.event.MouseEvent;
     20import java.beans.PropertyChangeEvent;
     21import java.beans.PropertyChangeListener;
    2022import java.io.BufferedReader;
    2123import java.io.File;
     
    4951import javax.swing.DefaultListSelectionModel;
    5052import javax.swing.Icon;
     53import javax.swing.ImageIcon;
    5154import javax.swing.JButton;
    5255import javax.swing.JCheckBox;
     
    134137        this.lstAvailableSources = new JList<>(availableSourcesModel);
    135138        this.lstAvailableSources.setSelectionModel(selectionModel);
    136         this.lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer());
     139        final SourceEntryListCellRenderer listCellRenderer = new SourceEntryListCellRenderer();
     140        this.lstAvailableSources.setCellRenderer(listCellRenderer);
    137141        this.availableSourcesUrl = availableSourcesUrl;
    138142        this.sourceProviders = sourceProviders;
     
    164168        }
    165169
     170        activeSourcesModel.addTableModelListener(new TableModelListener() {
     171            @Override
     172            public void tableChanged(TableModelEvent e) {
     173                listCellRenderer.updateSources(activeSourcesModel.getSources());
     174                lstAvailableSources.repaint();
     175            }
     176        });
     177        tblActiveSources.addPropertyChangeListener(new PropertyChangeListener() {
     178            @Override
     179            public void propertyChange(PropertyChangeEvent evt) {
     180                listCellRenderer.updateSources(activeSourcesModel.getSources());
     181                lstAvailableSources.repaint();
     182            }
     183        });
    166184        activeSourcesModel.addTableModelListener(new TableModelListener() {
    167185            // Force swing to show horizontal scrollbars for the JTable
     
    12151233
    12161234    static class SourceEntryListCellRenderer extends JLabel implements ListCellRenderer<ExtendedSourceEntry> {
     1235
     1236        private final ImageIcon GREEN_CHECK = ImageProvider.getIfAvailable("misc", "green_check");
     1237        private final ImageIcon GRAY_CHECK = ImageProvider.getIfAvailable("misc", "gray_check");
     1238        private final Map<String, SourceEntry> entryByUrl = new HashMap<>();
     1239
    12171240        @Override
    12181241        public Component getListCellRendererComponent(JList<? extends ExtendedSourceEntry> list, ExtendedSourceEntry value,
     
    12321255            setOpaque(true);
    12331256            setToolTipText(value.getTooltip());
     1257            final SourceEntry sourceEntry = entryByUrl.get(value.url);
     1258            setIcon(sourceEntry == null ? null : sourceEntry.active ? GREEN_CHECK : GRAY_CHECK);
    12341259            return this;
     1260        }
     1261
     1262        public void updateSources(List<SourceEntry> sources) {
     1263            synchronized (entryByUrl) {
     1264                entryByUrl.clear();
     1265                for (SourceEntry i : sources) {
     1266                    entryByUrl.put(i.url, i);
     1267                }
     1268            }
    12351269        }
    12361270    }
Note: See TracChangeset for help on using the changeset viewer.