Ticket #14408: plugins-conflation-fix-and-improvement.diff

File plugins-conflation-fix-and-improvement.diff, 56.2 KB (added by Tyndare, 9 years ago)

PATCH

  • josm/plugins/conflation/.checkstyle

     
     1<?xml version="1.0" encoding="UTF-8"?>
     2
     3<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
     4  <local-check-config name="JOSM" location="/JOSM/tools/checkstyle/josm_checks.xml" type="project" description="">
     5    <additional-data name="protect-config-file" value="false"/>
     6  </local-check-config>
     7  <fileset name="all" enabled="true" check-config-name="JOSM" local="true">
     8    <file-match-pattern match-pattern="." include-pattern="true"/>
     9  </fileset>
     10  <filter name="DerivedFiles" enabled="true"/>
     11  <filter name="FilesFromPackage" enabled="true">
     12    <filter-data value="src/com"/>
     13  </filter>
     14</fileset-config>
  • josm/plugins/conflation/.project

     
    1515                        <arguments>
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflateMatchCommand.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    4 import java.util.ArrayList;
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
     7import java.util.Arrays;
    58import java.util.Collection;
    6 import java.util.Collections;
     9import java.util.HashSet;
    710import java.util.List;
     11import java.util.stream.Collectors;
     12
    813import javax.swing.Icon;
     14
    915import org.openstreetmap.josm.command.AddPrimitivesCommand;
    1016import org.openstreetmap.josm.command.Command;
    1117import org.openstreetmap.josm.command.PseudoCommand;
    1218import org.openstreetmap.josm.data.osm.DataSet;
    1319import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1420import org.openstreetmap.josm.data.osm.PrimitiveData;
     21import org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry.ReplaceGeometryException;
    1522import org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry.ReplaceGeometryUtils;
    16 import static org.openstreetmap.josm.tools.I18n.tr;
    1723import org.openstreetmap.josm.tools.ImageProvider;
    1824import org.openstreetmap.josm.tools.UserCancelException;
    1925
     26
    2027/**
    2128 * Command to conflate one object with another.
    2229 */
    2330public class ConflateMatchCommand extends Command {
     31
     32    private final DataSet sourceDataSet;
     33    private final DataSet targetDataSet;
    2434    private final SimpleMatch match;
    2535    private final SimpleMatchList matches;
    26     private final Command replaceCommand;
     36    private Command replaceCommand = null;
    2737    private AddPrimitivesCommand addPrimitivesCommand = null;
    2838
    2939    public ConflateMatchCommand(SimpleMatch match,
     
    3141        super(settings.getSubjectLayer());
    3242        this.match = match;
    3343        this.matches = matches;
    34        
    35         DataSet sourceDataSet = settings.getReferenceDataSet();
    36         DataSet targetDataSet = settings.getSubjectDataSet();
    37         // copy objects from reference dataset
    38         if (targetDataSet != sourceDataSet) {
    39             // TODO: use MergeCommand instead?
    40             List<PrimitiveData> newObjects = ConflationUtils.copyObjects(sourceDataSet, match.getReferenceObject());
    41 
    42             // FIXME: bad form to execute command in constructor, how to fix?
    43             addPrimitivesCommand = new AddPrimitivesCommand(newObjects, newObjects, settings.getSubjectLayer());
    44             if (!addPrimitivesCommand.executeCommand())
    45                 throw new AssertionError();
    46         }
    47 
    48         // need to copy from other layer before this?
    49         replaceCommand = ReplaceGeometryUtils.buildReplaceCommand(
    50                             match.getSubjectObject(),
    51                             targetDataSet.getPrimitiveById(match.getReferenceObject().getPrimitiveId()));
    52 
    53         if (addPrimitivesCommand != null)
    54             addPrimitivesCommand.undoCommand();
    55         if (replaceCommand == null) {
    56             throw new UserCancelException();
    57         }
     44        this.sourceDataSet = settings.getReferenceDataSet();
     45        this.targetDataSet = settings.getSubjectDataSet();
    5846    }
    5947
    6048    @Override
    6149    public boolean executeCommand() {
    62         if (addPrimitivesCommand != null) {
    63             if (!addPrimitivesCommand.executeCommand())
    64                 return false;
     50        boolean ok = true;
     51        try {
     52            if (targetDataSet != sourceDataSet) {
     53                if (addPrimitivesCommand == null) {
     54                    List<PrimitiveData> newObjects = ConflationUtils.copyObjects(sourceDataSet, match.getReferenceObject(), targetDataSet);
     55                    addPrimitivesCommand = new AddPrimitivesCommand(newObjects, newObjects, getLayer());
     56                }
     57                if (!addPrimitivesCommand.executeCommand()) {
     58                    ok = false;
     59                    addPrimitivesCommand = null;
     60                }
     61            }
     62            if (ok) {
     63                if (replaceCommand == null) {
     64                    replaceCommand = ReplaceGeometryUtils.buildReplaceCommand(
     65                                        match.getSubjectObject(),
     66                                        targetDataSet.getPrimitiveById(match.getReferenceObject().getPrimitiveId()));
     67                    if (replaceCommand == null) {
     68                        // Throwing an exception is the only way I found to be sure
     69                        // the command is not added to the undo list.
     70                        throw new ReplaceGeometryException(tr("Canceled"));
     71                    }
     72                }
     73                if (replaceCommand.executeCommand()) {
     74                    matches.remove(match);
     75                } else {
     76                    ok = false;
     77                }
     78            }
     79        } catch (RuntimeException e) {
     80            ok = false;
     81            throw e;
     82        } finally {
     83            if (!ok) {
     84                replaceCommand = null;
     85                if (addPrimitivesCommand != null) {
     86                    addPrimitivesCommand.undoCommand();
     87                    addPrimitivesCommand = null;
     88                }
     89            }
    6590        }
    66         if (!replaceCommand.executeCommand())
    67             return false;
    68         matches.remove(match);
    69 
    70         return true;
     91        return ok;
    7192    }
    72    
     93
    7394    @Override
    7495    public void undoCommand() {
    75         replaceCommand.undoCommand();
    76         if (addPrimitivesCommand != null)
     96        if (replaceCommand != null) {
     97            replaceCommand.undoCommand();
     98            matches.add(match);
     99        }
     100        if (addPrimitivesCommand != null) {
    77101            addPrimitivesCommand.undoCommand();
    78         matches.add(match);
     102        }
    79103    }
    80    
     104
    81105    @Override
    82106    public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    83107        throw new UnsupportedOperationException("Not supported yet.");
     
    88112        //TODO: make more descriptive
    89113        return tr("Conflate object pair");
    90114    }
    91    
     115
    92116    @Override
    93117    public Icon getDescriptionIcon() {
    94118        return ImageProvider.get("dialogs", "conflation");
    95119    }
    96    
     120
    97121    @Override
    98122    public Collection<? extends OsmPrimitive> getParticipatingPrimitives() {
    99         return Collections.singleton(match.getSubjectObject());
     123        Collection<OsmPrimitive> prims = new HashSet<>();
     124        if (addPrimitivesCommand != null)
     125            prims.addAll(addPrimitivesCommand.getParticipatingPrimitives());
     126        if (replaceCommand != null)
     127            prims.addAll(replaceCommand.getParticipatingPrimitives());
     128        return prims;
    100129    }
    101    
     130
    102131    @Override
    103132    public Collection<PseudoCommand> getChildren() {
    104         if (replaceCommand == null)
    105             return null;
    106 
    107         Collection<PseudoCommand> children = new ArrayList<>();
    108         if (addPrimitivesCommand != null)
    109             children.add(addPrimitivesCommand);
    110         children.addAll(replaceCommand.getChildren());
    111         return children;
     133        return Arrays.asList(addPrimitivesCommand, replaceCommand).stream()
     134            .filter(c -> c != null)
     135            .collect(Collectors.toList());
    112136    }
    113137}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflateUnmatchedObjectCommand.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import java.util.ArrayList;
     
    2930        this.unmatchedObjects = unmatchedObjects;
    3031        this.listModel = listModel;
    3132
    32         List<PrimitiveData> newObjects = ConflationUtils.copyObjects(sourceDataLayer.data, unmatchedObjects);
     33        List<PrimitiveData> newObjects = ConflationUtils.copyObjects(sourceDataLayer.data, unmatchedObjects, targetDataLayer.data);
    3334
    3435        addPrimitivesCommand = new AddPrimitivesCommand(newObjects, newObjects, targetDataLayer);
    3536    }
     
    6970        return unmatchedObjects;
    7071    }
    7172
    72 
    7373    @Override
    7474    public Collection<PseudoCommand> getChildren() {
    7575        Collection<PseudoCommand> children = new ArrayList<>();
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationLayer.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import static org.openstreetmap.josm.tools.I18n.tr;
     
    3132 */
    3233public class ConflationLayer extends Layer {
    3334    protected SimpleMatchList matches;
    34    
     35
    3536    public ConflationLayer(SimpleMatchList matches) {
    3637        super(tr("Conflation"));
    3738        this.matches = matches;
    3839    }
    39    
     40
    4041    public ConflationLayer() {
    4142        this(null);
    4243    }
     
    8889                g2.draw(path);
    8990            }
    9091        }
    91 
    92        
    9392    }
    9493
    95    
    9694    @Override
    9795    public Icon getIcon() {
    9896        // TODO: change icon
     
    121119            OsmPrimitive reference = match.getReferenceObject();
    122120            OsmPrimitive subject = match.getSubjectObject();
    123121            if (reference != null && reference instanceof Node)
    124                 v.visit((Node)reference);
     122                v.visit((Node) reference);
    125123            if (subject != null && subject instanceof Node)
    126                 v.visit((Node)subject);
     124                v.visit((Node) subject);
    127125        }
    128126    }
    129127
     
    142140                    SeparatorLayerAction.INSTANCE,
    143141                    new LayerListPopup.InfoAction(this)};
    144142    }
    145    
     143
    146144    public void setMatches(SimpleMatchList matches) {
    147145        this.matches = matches;
    148146        // TODO: does repaint automatically occur?
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationPlugin.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    4 import java.awt.GraphicsEnvironment;
    5 
    65import org.openstreetmap.josm.gui.MapFrame;
    76import org.openstreetmap.josm.plugins.Plugin;
    87import org.openstreetmap.josm.plugins.PluginInformation;
    98
    109public class ConflationPlugin extends Plugin {
    1110
    12     private ConflationToggleDialog dialog = null;
    13 
    1411    /**
    1512     * constructor
    1613     */
     
    2118    // add dialog the first time the mapframe is loaded
    2219    @Override
    2320    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    24         if (oldFrame == null && newFrame != null && !GraphicsEnvironment.isHeadless()) {
    25             if (dialog == null) {
    26                 dialog = new ConflationToggleDialog(this);
    27             }
    28             newFrame.addToggleDialog(dialog);
     21        if (oldFrame == null && newFrame != null) {
     22            newFrame.addToggleDialog(new ConflationToggleDialog(this));
    2923        }
    3024    }
    3125}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationToggleDialog.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import static org.openstreetmap.josm.tools.I18n.marktr;
     
    1819import java.util.Arrays;
    1920import java.util.Collection;
    2021import java.util.HashSet;
    21 import java.util.LinkedList;
    2222import java.util.List;
    2323import java.util.Map;
    2424import java.util.Set;
     
    4848import org.openstreetmap.josm.actions.JosmAction;
    4949import org.openstreetmap.josm.command.Command;
    5050import org.openstreetmap.josm.data.SelectionChangedListener;
     51import org.openstreetmap.josm.data.osm.DataSet;
    5152import org.openstreetmap.josm.data.osm.OsmPrimitive;
    5253import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    5354import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
     
    6263import org.openstreetmap.josm.gui.SideButton;
    6364import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    6465import org.openstreetmap.josm.gui.layer.Layer;
     66import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     67import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     68import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     69import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    6570import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
    6671import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    6772import org.openstreetmap.josm.plugins.jts.JTSConverter;
     
    8186import com.vividsolutions.jump.task.TaskMonitor;
    8287
    8388public class ConflationToggleDialog extends ToggleDialog
    84 implements SelectionChangedListener, DataSetListener, SimpleMatchListListener {
     89implements SelectionChangedListener, DataSetListener, SimpleMatchListListener, LayerChangeListener {
    8590
    86     public final static String TITLE_PREFIX = tr("Conflation");
    87     public final static String PREF_PREFIX = "conflation";
     91    public static final String TITLE_PREFIX = tr("Conflation");
     92    public static final String PREF_PREFIX = "conflation";
    8893    JTabbedPane tabbedPane;
    8994    JTable matchTable;
    9095    JList<OsmPrimitive> referenceOnlyList;
     
    116121            public void windowClosed(WindowEvent e) {
    117122                // "Generate matches" was clicked
    118123                if (settingsDialog.getValue() == 1) {
     124                    clear(true, true, false);
    119125                    settings = settingsDialog.getSettings();
    120126                    performMatching();
    121127                }
     
    139145
    140146        matchTable.setRowSelectionAllowed(true);
    141147        matchTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     148        matchTable.setAutoCreateRowSorter(true);
    142149
    143150        referenceOnlyListModel = new UnmatchedObjectListModel();
    144151        referenceOnlyList = new JList<>(referenceOnlyListModel);
     
    326333    }
    327334
    328335    @Override
     336    public void showNotify() {
     337        super.showNotify();
     338        DataSet.addSelectionListener(this);
     339        Main.getLayerManager().addLayerChangeListener(this);
     340    }
     341
     342    @Override
     343    public void hideNotify() {
     344        super.hideNotify();
     345        DataSet.removeSelectionListener(this);
     346        Main.getLayerManager().removeLayerChangeListener(this);
     347        clear(true, true, true);
     348        settingsDialog.clear(true, true);
     349    }
     350
     351    private void clear(boolean shouldClearReference, boolean shouldClearSubject, boolean shouldRemoveConflationLayer) {
     352        if (shouldRemoveConflationLayer && (conflationLayer != null)) {
     353            if (Main.getLayerManager().containsLayer(conflationLayer)) {
     354                Main.getLayerManager().removeLayer(conflationLayer);
     355            }
     356            conflationLayer = null;
     357        }
     358        if (settings != null) {
     359            if (shouldClearReference) {
     360                DataSet dataSet = settings.getReferenceDataSet();
     361                if (dataSet != null) {
     362                    dataSet.removeDataSetListener(this);
     363                    settings.setReferenceDataSet(null);
     364                }
     365                settings.setReferenceLayer(null);
     366                settings.setReferenceSelection(null);
     367            }
     368            if (shouldClearSubject) {
     369                DataSet dataSet = settings.getSubjectDataSet();
     370                if (dataSet != null) {
     371                    dataSet.removeDataSetListener(this);
     372                    settings.setSubjectDataSet(null);
     373                }
     374                settings.setSubjectLayer(null);
     375                settings.setSubjectSelection(null);
     376            }
     377        }
     378        referenceOnlyListModel.clear();
     379        subjectOnlyListModel.clear();
     380        setMatches(new SimpleMatchList());
     381    }
     382   
     383    private void setMatches(SimpleMatchList matchList) {
     384        matches.clear();
     385        matches.removeAllConflationListChangedListener();
     386        matches = matchList;
     387        matchTableModel.setMatches(matches);
     388        matches.addConflationListChangedListener(conflateAction);
     389        matches.addConflationListChangedListener(removeAction);
     390        matches.addConflationListChangedListener(this);
     391        if (conflationLayer != null) {
     392            conflationLayer.setMatches(matches);
     393        }
     394    }
     395
     396    @Override
    329397    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    330         // TODO
     398        if (newSelection.size() > 0) {
     399            referenceOnlyList.getSelectionModel().clearSelection();
     400            subjectOnlyList.getSelectionModel().clearSelection();
     401            matchTable.getSelectionModel().clearSelection();
     402            boolean ensureVisible = true;
     403            for (OsmPrimitive item: newSelection) {
     404                addObjectToSelection(item, ensureVisible);
     405                ensureVisible = false;
     406            }
     407        }
     408    }
     409
     410    private boolean addObjectToSelection(OsmPrimitive object, boolean ensureVisible) {
     411        int index = referenceOnlyListModel.indexOf(object);
     412        if (index >= 0) {
     413            referenceOnlyList.getSelectionModel().addSelectionInterval(index, index);
     414            if (ensureVisible) {
     415                tabbedPane.setSelectedIndex(1);
     416                referenceOnlyList.ensureIndexIsVisible(index);
     417            }
     418            return true;
     419        }
     420        index = subjectOnlyListModel.indexOf(object);
     421        if (index >= 0) {
     422            subjectOnlyList.getSelectionModel().addSelectionInterval(index, index);
     423            if (ensureVisible) {
     424                tabbedPane.setSelectedIndex(2);
     425                subjectOnlyList.ensureIndexIsVisible(index);
     426            }
     427            return true;
     428        }
     429        index = 0;
     430        for (SimpleMatch c : matches) {
     431            if ((c.getSubjectObject() == object) || (c.getReferenceObject() == object)) {
     432                break;
     433            }
     434            index++;
     435        }
     436        if (index < matches.size()) {
     437            index = matchTable.convertRowIndexToView(index);
     438            matchTable.getSelectionModel().addSelectionInterval(index, index);
     439            if (ensureVisible) {
     440                tabbedPane.setSelectedIndex(0);
     441                matchTable.scrollRectToVisible(new Rectangle(matchTable.getCellRect(index, 0, true)));
     442            }
     443            return true;
     444        }
     445        return false;
    331446    }
    332447
    333448    private Collection<SimpleMatch> getSelectedFromTable() {
    334449        ListSelectionModel lsm = matchTable.getSelectionModel();
    335450        Collection<SimpleMatch> selMatches = new HashSet<>();
    336451        for (int i = lsm.getMinSelectionIndex(); i <= lsm.getMaxSelectionIndex(); i++) {
    337             if (lsm.isSelectedIndex(i) && i < matches.size()) {
    338                 selMatches.add(matches.get(i));
     452            if (lsm.isSelectedIndex(i) && (i < matches.size())) {
     453                int modelIndex = matchTable.convertRowIndexToModel(i);
     454                if (modelIndex < matches.size()) {
     455                    selMatches.add(matches.get(modelIndex));
     456                }
    339457            }
    340458        }
    341459        return selMatches;
     
    352470            //TODO: do something!
    353471        }
    354472    }
     473
    355474    protected static class ConflatePopupMenu extends JPopupMenu {
    356475
    357         static public void launch(Component parent) {
     476        public static void launch(Component parent) {
    358477            JPopupMenu menu = new ConflatePopupMenu();
    359478            Rectangle r = parent.getBounds();
    360479            menu.show(parent, r.x, r.y + r.height);
     
    380499
    381500        private final String columnName;
    382501
    383         public ColorTableCellRenderer(String column) {
     502        ColorTableCellRenderer(String column) {
    384503            this.columnName = column;
    385504            setOpaque(true);
    386505        }
     
    409528        }
    410529    }
    411530
    412     static public class LayerListCellRenderer extends DefaultListCellRenderer {
     531    public static class LayerListCellRenderer extends DefaultListCellRenderer {
    413532
    414533        @Override
    415534        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
     
    429548     */
    430549    class RemoveMatchCommand extends Command {
    431550        private final Collection<SimpleMatch> toRemove;
    432         public RemoveMatchCommand(Collection<SimpleMatch> toRemove) {
     551        RemoveMatchCommand(Collection<SimpleMatch> toRemove) {
    433552            this.toRemove = toRemove;
    434553        }
    435554
     
    462581        private final UnmatchedObjectListModel model;
    463582        private final Collection<OsmPrimitive> objects;
    464583
    465         public RemoveUnmatchedObjectCommand(UnmatchedObjectListModel model,
     584        RemoveUnmatchedObjectCommand(UnmatchedObjectListModel model,
    466585                Collection<OsmPrimitive> objects) {
    467586            this.model = model;
    468587            this.objects = objects;
     
    500619
    501620    class RemoveAction extends JosmAction implements SimpleMatchListListener, ChangeListener, ListSelectionListener {
    502621
    503         public RemoveAction() {
     622        RemoveAction() {
    504623            super(tr("Remove"), "dialogs/delete", tr("Remove selected matches"),
    505624                    null, false);
    506625        }
     626       
    507627        @Override
    508628        public void actionPerformed(ActionEvent e) {
    509629            Component selComponent = getSelectedTabComponent();
     
    540660            }
    541661
    542662        }
     663       
    543664        @Override
    544665        public void simpleMatchListChanged(SimpleMatchList list) {
    545666        }
     
    562683
    563684    class ConflateAction extends JosmAction implements SimpleMatchListListener, ChangeListener, ListSelectionListener {
    564685
    565         public ConflateAction() {
     686        ConflateAction() {
    566687            // TODO: make sure shortcuts make sense
    567688            super(tr("Conflate"), "dialogs/conflation", tr("Conflate selected objects"),
    568689                    Shortcut.registerShortcut("conflation:replace", tr("Conflation: {0}", tr("Replace")),
     
    571692
    572693        @Override
    573694        public void actionPerformed(ActionEvent e) {
    574             if (getSelectedTabComponent().equals(matchTable))
    575                 conflateMatchActionPerformed();
    576             else if (getSelectedTabComponent().equals(referenceOnlyList))
    577                 conflateUnmatchedObjectActionPerformed();
     695            try {
     696                DataSet.removeSelectionListener(ConflationToggleDialog.this);
     697                if (getSelectedTabComponent().equals(matchTable))
     698                    conflateMatchActionPerformed();
     699                else if (getSelectedTabComponent().equals(referenceOnlyList))
     700                    conflateUnmatchedObjectActionPerformed();
     701            } finally {
     702                DataSet.addSelectionListener(ConflationToggleDialog.this);
     703            }
    578704        }
    579705
    580706        private void conflateUnmatchedObjectActionPerformed() {
     
    587713
    588714        private void conflateMatchActionPerformed() {
    589715            SimpleMatch nextSelection = matches.findNextSelection();
    590             List<Command> cmds = new LinkedList<>();
     716            //List<Command> cmds = new LinkedList<>();
    591717            try {
    592718                // iterate over selected matches in reverse order since they will be removed as we go
    593719                List<SimpleMatch> selMatches = new ArrayList<>(matches.getSelected());
    594720                for (SimpleMatch c : selMatches) {
    595 
    596721                    ConflateMatchCommand conflateCommand;
    597722                    try {
    598723                        conflateCommand = new ConflateMatchCommand(c, matches, settings);
    599724                    } catch (UserCancelException ex) {
    600725                        break;
    601726                    }
    602                     cmds.add(conflateCommand);
    603 
    604727                    // FIXME: how to chain commands which change relations? (see below)
     728                    //cmds.add(conflateCommand);
    605729                    Main.main.undoRedo.add(conflateCommand);
    606730                }
    607731            } catch (ReplaceGeometryException ex) {
     
    659783     * the list (either matches or single primitives).
    660784     *
    661785     */
    662     class ZoomToListSelectionAction extends JosmAction implements ListSelectionListener{
    663         public ZoomToListSelectionAction() {
     786    class ZoomToListSelectionAction extends JosmAction implements ListSelectionListener {
     787        ZoomToListSelectionAction() {
    664788            super(tr("Zoom to selected primitive(s)"), "dialogs/autoscale/selection", tr("Zoom to selected primitive(s)"),
    665789                    null, false);
    666790        }
     
    692816     * the list (either matches or single primitives).
    693817     *
    694818     */
    695     class SelectListSelectionAction extends JosmAction implements ListSelectionListener{
    696         public SelectListSelectionAction() {
     819    class SelectListSelectionAction extends JosmAction implements ListSelectionListener {
     820        SelectListSelectionAction() {
    697821            super(tr("Select selected primitive(s)"), "dialogs/select", tr("Select the primitives currently selected in the list"),
    698822                    null, false);
    699823        }
     
    730854                    //FIXME: this doesn't seem to be working
    731855                    int row = matchTable.rowAtPoint(evt.getPoint());
    732856                    matchTable.getSelectionModel().addSelectionInterval(row, row);
    733                 }
    734                 else if (c == subjectOnlyList || c == referenceOnlyList) {
    735                     int idx = ((JList<?>)c).locationToIndex(evt.getPoint());
     857                } else if (c == subjectOnlyList || c == referenceOnlyList) {
     858                    int idx = ((JList<?>) c).locationToIndex(evt.getPoint());
    736859                    if (idx < 0)
    737860                        return;
    738                     ((JList<?>)c).setSelectedIndex(idx);
     861                    ((JList<?>) c).setSelectedIndex(idx);
    739862                }
    740863            }
    741864
     
    747870     * The popup menu for the selection list
    748871     */
    749872    class SelectionPopup extends JPopupMenu {
    750         public SelectionPopup() {
     873        SelectionPopup() {
    751874            matchTable.getSelectionModel().addListSelectionListener(zoomToListSelectionAction);
    752875            subjectOnlyList.addListSelectionListener(zoomToListSelectionAction);
    753876            referenceOnlyList.addListSelectionListener(zoomToListSelectionAction);
     
    767890
    768891    @Override
    769892    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    770         List<? extends OsmPrimitive> prims = event.getPrimitives();
    771         for (OsmPrimitive p : prims) {
    772             // TODO: use hashmap
    773             for (SimpleMatch c : matches) {
    774                 if (c.getReferenceObject().equals(p) || c.getSubjectObject().equals(p)) {
    775                     matches.remove(c);
    776                     break;
     893        if (settings != null) {
     894            DataSet dataSet = event.getDataset();
     895            if (dataSet == settings.getReferenceDataSet()) {
     896                for (OsmPrimitive p : event.getPrimitives()) {
     897                    // TODO: use hashmap
     898                    for (SimpleMatch c : matches) {
     899                        if (c.getReferenceObject().equals(p)) {
     900                            matches.remove(c);
     901                            break;
     902                        }
     903                    }
     904                    referenceOnlyListModel.removeElement(p);
     905                }
     906            } else if (dataSet == settings.getSubjectDataSet()) {
     907                for (OsmPrimitive p : event.getPrimitives()) {
     908                    // TODO: use hashmap
     909                    for (SimpleMatch c : matches) {
     910                        if (c.getSubjectObject().equals(p)) {
     911                            matches.remove(c);
     912                            break;
     913                        }
     914                    }
     915                    subjectOnlyListModel.removeElement(p);
    777916                }
    778917            }
    779 
    780             referenceOnlyListModel.removeElement(p);
    781             subjectOnlyListModel.removeElement(p);
    782918        }
    783919    }
    784920
     
    808944
    809945    /**
    810946     * Create FeatureSchema using union of all keys from all selected primitives
    811      * @param prims
    812      * @return
    813947     */
    814948    private FeatureSchema createSchema(Collection<OsmPrimitive> prims) {
    815949        Set<String> keys = new HashSet<>();
     
    8781012        FeatureCollection refColl = new FeatureDataset(allFeatures.getFeatureSchema());
    8791013        FeatureCollection subColl = new FeatureDataset(allFeatures.getFeatureSchema());
    8801014        for (Feature f : allFeatures.getFeatures()) {
    881             OsmFeature osmFeature = (OsmFeature)f;
     1015            OsmFeature osmFeature = (OsmFeature) f;
    8821016            if (settings.getReferenceSelection().contains(osmFeature.getPrimitive()))
    8831017                refColl.add(osmFeature);
    8841018            if (settings.getSubjectSelection().contains(osmFeature.getPrimitive()))
     
    9091043        SimpleMatchList list = new SimpleMatchList();
    9101044        for (Map.Entry<Feature, Matches> entry: map.entrySet()) {
    9111045            OsmFeature target = (OsmFeature) entry.getKey();
    912             OsmFeature subject = (OsmFeature)entry.getValue().getTopMatch();
     1046            OsmFeature subject = (OsmFeature) entry.getValue().getTopMatch();
    9131047            if (target != null && subject != null)
    9141048                list.add(new SimpleMatch(target.getPrimitive(), subject.getPrimitive(),
    9151049                        entry.getValue().getTopScore()));
     
    9211055    }
    9221056
    9231057    private void performMatching() {
    924         matches = generateMatches(settings);
     1058        setMatches(generateMatches(settings));
    9251059
    9261060        // populate unmatched objects
    9271061        List<OsmPrimitive> referenceOnly = new ArrayList<>(settings.getReferenceSelection());
     
    9381072
    9391073        updateTabTitles();
    9401074
    941         matchTableModel.setMatches(matches);
    942         matches.addConflationListChangedListener(matchTableModel);
    943         matches.addConflationListChangedListener(conflateAction);
    944         matches.addConflationListChangedListener(removeAction);
    945         matches.addConflationListChangedListener(this);
    9461075        settings.getSubjectDataSet().addDataSetListener(this);
    9471076        settings.getReferenceDataSet().addDataSetListener(this);
    9481077        // add conflation layer
    9491078        try {
    9501079            if (conflationLayer == null) {
    9511080                conflationLayer = new ConflationLayer(matches);
     1081            }
     1082            if (!Main.getLayerManager().containsLayer(conflationLayer)) {
    9521083                Main.getLayerManager().addLayer(conflationLayer);
    9531084            }
    9541085        } catch (Exception ex) {
     
    9741105            updateTabTitles();
    9751106        }
    9761107    }
     1108
     1109    @Override
     1110    public void layerAdded(LayerAddEvent e) {
     1111        // Nothing to do
     1112    }
     1113
     1114    @Override
     1115    public void layerRemoving(LayerRemoveEvent e) {
     1116        Layer removedLayer = e.getRemovedLayer();
     1117        if (settings != null) {
     1118            boolean shouldclearReferenceSettings = removedLayer == settings.getReferenceLayer();
     1119            boolean shouldclearSubjectSettings = removedLayer == settings.getSubjectLayer();
     1120            if (shouldclearReferenceSettings || shouldclearSubjectSettings) {
     1121                clear(shouldclearReferenceSettings, shouldclearSubjectSettings, true);
     1122            }
     1123        }
     1124        this.settingsDialog.layerRemoving(e);
     1125    }
     1126
     1127    @Override
     1128    public void layerOrderChanged(LayerOrderChangeEvent e) {
     1129        // Nothing to do
     1130    }
    9771131}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationUtils.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import java.util.ArrayList;
    56import java.util.Collection;
    67import java.util.Collections;
    78import java.util.List;
     9import java.util.stream.Collectors;
     10
    811import org.openstreetmap.josm.Main;
    912import org.openstreetmap.josm.data.coor.EastNorth;
    1013import org.openstreetmap.josm.data.coor.LatLon;
     
    1518
    1619public final class ConflationUtils {
    1720
     21    private ConflationUtils() {}
     22
    1823    public static EastNorth getCenter(OsmPrimitive prim) {
    1924        LatLon center = prim.getBBox().getTopLeft().getCenter(prim.getBBox().getBottomRight());
    2025        return Main.map.mapView.getProjection().latlon2eastNorth(center);
    2126    }
    2227
    23     public static List<PrimitiveData> copyObjects(DataSet sourceDataSet, OsmPrimitive primitive) {
    24         return copyObjects(sourceDataSet, Collections.singleton(primitive));
     28    public static List<PrimitiveData> copyObjects(DataSet sourceDataSet, OsmPrimitive primitive, DataSet destDataSet) {
     29        return copyObjects(sourceDataSet, Collections.singleton(primitive), destDataSet);
    2530    }
    2631
    27     public static List<PrimitiveData> copyObjects(DataSet sourceDataSet, Collection<OsmPrimitive> primitives) {
     32    public static List<PrimitiveData> copyObjects(DataSet sourceDataSet, Collection<OsmPrimitive> primitives, DataSet destDataSet) {
    2833
    2934        Collection<OsmPrimitive> origSelection = sourceDataSet.getSelected();
    3035        sourceDataSet.setSelected(primitives);
     
    3439        //restore selection
    3540        sourceDataSet.setSelected(origSelection);
    3641
    37         List<PrimitiveData> newObjects = new ArrayList<>();
    38         for (OsmPrimitive p : newDataSet.allPrimitives()) {
    39             newObjects.add(p.save());
    40         }
    41         return newObjects;
     42        return newDataSet.allPrimitives().stream()
     43                .filter(p -> destDataSet.getPrimitiveById(p.getPrimitiveId()) == null)
     44                .map(p -> p.save())
     45                .collect(Collectors.toCollection(ArrayList::new));
    4246    }
    4347}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/MatchFinderPanel.java

     
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.conflation;
    23
    34import static org.openstreetmap.josm.tools.I18n.tr;
     
    2627import com.vividsolutions.jcs.conflate.polygonmatch.IdenticalFeatureFilter;
    2728import com.vividsolutions.jcs.conflate.polygonmatch.OneToOneFCMatchFinder;
    2829
    29 
    3030public class MatchFinderPanel extends JPanel {
    3131    private final JComboBox<String> matchFinderComboBox;
    3232    private final CentroidDistanceComponent centroidDistanceComponent;
     
    3535        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    3636        setBorder(new CompoundBorder(
    3737                BorderFactory.createTitledBorder(tr("Match finder settings")),
    38                 BorderFactory.createEmptyBorder(5,5,5,5)));
     38                BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    3939
    4040        String[] matchFinderStrings = {"DisambiguatingFCMatchFinder", "OneToOneFCMatchFinder" };
    4141        matchFinderComboBox = new JComboBox<>(matchFinderStrings);
     
    7272    abstract class DistanceComponent extends AbstractScoreComponent {
    7373        SpinnerNumberModel threshDistanceSpinnerModel;
    7474
    75         public DistanceComponent(String title) {
     75        DistanceComponent(String title) {
    7676            setBorder(new CompoundBorder(
    7777                    BorderFactory.createTitledBorder(tr(title)),
    78                     BorderFactory.createEmptyBorder(5,5,5,5)));
     78                    BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    7979
    8080            JPanel panel = new JPanel();
    8181            panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
     
    9999    }
    100100
    101101    class CentroidDistanceComponent extends DistanceComponent {
    102         public CentroidDistanceComponent() {
     102        CentroidDistanceComponent() {
    103103            super(tr("Centroid distance"));
    104104        }
    105105
     
    112112    }
    113113
    114114    class HausdorffDistanceComponent extends DistanceComponent {
    115         public HausdorffDistanceComponent() {
     115        HausdorffDistanceComponent() {
    116116            super(tr("Hausdorff distance"));
    117117        }
    118118
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/OsmFeature.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import com.vividsolutions.jump.feature.AbstractBasicFeature;
     
    1617    /**
    1718     * Create a copy of the OSM geometry
    1819     * TODO: update from underlying primitive
    19      * @param prim
    2020     */
    2121    public OsmFeature(OsmPrimitive prim, JTSConverter jtsConverter) {
    2222        super(new FeatureSchema());
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SettingsDialog.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import static org.openstreetmap.josm.tools.I18n.tr;
     
    2627import org.openstreetmap.josm.data.osm.Relation;
    2728import org.openstreetmap.josm.data.osm.Way;
    2829import org.openstreetmap.josm.gui.ExtendedDialog;
     30import org.openstreetmap.josm.gui.layer.Layer;
    2931import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     32import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    3033import org.openstreetmap.josm.tools.ImageProvider;
    3134
    3235/**
     
    9295
    9396        referencePanel.setBorder(new CompoundBorder(
    9497                BorderFactory.createTitledBorder(tr("Reference")),
    95                 BorderFactory.createEmptyBorder(5,5,5,5)));
     98                BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    9699        referencePanel.setAlignmentX(LEFT_ALIGNMENT);
    97100        referencePanel.setLayout(new BoxLayout(referencePanel,
    98101                BoxLayout.PAGE_AXIS));
     
    129132
    130133        subjectPanel.setBorder(new CompoundBorder(
    131134                BorderFactory.createTitledBorder(tr("Subject")),
    132                 BorderFactory.createEmptyBorder(5,5,5,5)));
     135                BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    133136        subjectPanel.setAlignmentX(LEFT_ALIGNMENT);
    134137        subjectPanel.setLayout(new BoxLayout(subjectPanel, BoxLayout.PAGE_AXIS));
    135138
     
    172175
    173176    /**
    174177     * Matches are actually generated in windowClosed event in ConflationToggleDialog
    175      *
    176      * @param buttonIndex
    177      * @param evt
    178178     */
    179179    @Override
    180180    protected void buttonAction(int buttonIndex, ActionEvent evt) {
    181181        // "Generate matches" as clicked
    182182        if (buttonIndex == 0) {
    183183            if (referenceSelection.isEmpty() || subjectSelection.isEmpty()) {
    184                 JOptionPane.showMessageDialog(Main.parent, tr("Selections must be made for both reference and subject."), tr("Incomplete selections"), JOptionPane.ERROR_MESSAGE);
     184                JOptionPane.showMessageDialog(Main.parent,
     185                        tr("Selections must be made for both reference and subject."), tr("Incomplete selections"),
     186                        JOptionPane.ERROR_MESSAGE);
    185187                return;
    186188            }
    187189        }
     
    220222
    221223    class RestoreSubjectAction extends JosmAction {
    222224
    223         public RestoreSubjectAction() {
     225        RestoreSubjectAction() {
    224226            super(tr("Restore"), null, tr("Restore subject selection"), null, false);
    225227        }
    226228
     
    236238
    237239    class RestoreReferenceAction extends JosmAction {
    238240
    239         public RestoreReferenceAction() {
     241        RestoreReferenceAction() {
    240242            super(tr("Restore"), null, tr("Restore reference selection"), null, false);
    241243        }
    242244
     
    252254
    253255    class FreezeSubjectAction extends JosmAction {
    254256
    255         public FreezeSubjectAction() {
     257        FreezeSubjectAction() {
    256258            super(tr("Freeze"), null, tr("Freeze subject selection"), null, false);
    257259        }
    258260
     
    267269            //            subjectDataSet.addDataSetListener(tableModel); FIXME:
    268270            subjectLayer = Main.getLayerManager().getEditLayer();
    269271            if (subjectDataSet == null || subjectLayer == null) {
    270                 JOptionPane.showMessageDialog(Main.parent, tr("No valid OSM data layer present."), tr("Error freezing selection"), JOptionPane.ERROR_MESSAGE);
     272                JOptionPane.showMessageDialog(Main.parent,
     273                    tr("No valid OSM data layer present."), tr("Error freezing selection"),
     274                    JOptionPane.ERROR_MESSAGE);
    271275                return;
    272276            }
    273277            subjectSelection.clear();
    274278            subjectSelection.addAll(subjectDataSet.getSelected());
    275279            if (subjectSelection.isEmpty()) {
    276                 JOptionPane.showMessageDialog(Main.parent, tr("Nothing is selected, please try again."), tr("Empty selection"), JOptionPane.ERROR_MESSAGE);
     280                JOptionPane.showMessageDialog(Main.parent,
     281                        tr("Nothing is selected, please try again."), tr("Empty selection"),
     282                        JOptionPane.ERROR_MESSAGE);
    277283                return;
    278284            }
    279285            update();
     
    282288
    283289    class FreezeReferenceAction extends JosmAction {
    284290
    285         public FreezeReferenceAction() {
     291        FreezeReferenceAction() {
    286292            super(tr("Freeze"), null, tr("Freeze reference selection"), null, false);
    287293        }
    288294
     
    297303            //            referenceDataSet.addDataSetListener(this); FIXME:
    298304            referenceLayer = Main.getLayerManager().getEditLayer();
    299305            if (referenceDataSet == null || referenceLayer == null) {
    300                 JOptionPane.showMessageDialog(Main.parent, tr("No valid OSM data layer present."), tr("Error freezing selection"), JOptionPane.ERROR_MESSAGE);
     306                JOptionPane.showMessageDialog(Main.parent,
     307                        tr("No valid OSM data layer present."), tr("Error freezing selection"),
     308                        JOptionPane.ERROR_MESSAGE);
    301309                return;
    302310            }
    303311            referenceSelection.clear();
    304312            referenceSelection.addAll(referenceDataSet.getSelected());
    305313            if (referenceSelection.isEmpty()) {
    306                 JOptionPane.showMessageDialog(Main.parent, tr("Nothing is selected, please try again."), tr("Empty selection"), JOptionPane.ERROR_MESSAGE);
     314                JOptionPane.showMessageDialog(Main.parent,
     315                        tr("Nothing is selected, please try again."), tr("Empty selection"),
     316                        JOptionPane.ERROR_MESSAGE);
    307317                return;
    308318            }
    309319            update();
     
    331341            subjectLayerLabel.setText(subjectLayer.getName());
    332342            subjectSelectionLabel.setText(tr("{0}: {1} / {2}: {3} / {4}: {5}",
    333343                    "Relations", numRelations, "Ways", numWays, "Nodes", numNodes));
     344        } else {
     345            subjectLayerLabel.setText("(none)");
     346            subjectSelectionLabel.setText(tr("{0}: 0 / {1}: 0 / {2}: 0",
     347                    "Relations", "Ways", "Nodes"));           
    334348        }
    335349        numNodes = 0;
    336350        numWays = 0;
     
    348362            referenceLayerLabel.setText(referenceLayer.getName());
    349363            referenceSelectionLabel.setText(tr("{0}: {1} / {2}: {3} / {4}: {5}",
    350364                    "Relations", numRelations, "Ways", numWays, "Nodes", numNodes));
     365        } else {
     366            referenceLayerLabel.setText("(none)");
     367            referenceSelectionLabel.setText(tr("{0}: 0 / {1}: 0 / {2}: 0",
     368                    "Relations", "Ways", "Nodes"));           
    351369        }
    352370
    353371        //FIXME: properly update match finder settings
    354372    }
     373   
     374    /**
     375     * To be called when a layer is removed.
     376     * Clear any reference to the removed layer.
     377     * @param e the layer remove event.
     378     */
     379    public void layerRemoving(LayerRemoveEvent e) {
     380        Layer removedLayer = e.getRemovedLayer();
     381        this.clear(removedLayer == referenceLayer, removedLayer == subjectLayer);
     382    }
     383   
     384    /**
     385     * Clear some settings.
     386     * @param shouldClearReference if "Reference" settings should be cleared.
     387     * @param shouldClearSubject if "Subject" settings should be cleared.
     388     */
     389    public void clear(boolean shouldClearReference, boolean shouldClearSubject) {
     390        if (shouldClearReference || shouldClearSubject) {
     391            if (shouldClearReference) {
     392                referenceLayer = null;
     393                referenceDataSet = null;
     394                referenceSelection.clear();
     395            }
     396            if (shouldClearSubject) {
     397                subjectLayer = null;
     398                subjectDataSet = null;
     399                subjectSelection.clear();
     400            }
     401            update();
     402        }
     403    }
     404
    355405}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SimpleMatch.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4243    public Object getDistance() {
    4344        return distance;
    4445    }
    45 }
    46  Pas de fin de ligne à la fin du fichier
     46}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SimpleMatchList.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    4 import java.util.*;
     5import java.util.ArrayList;
     6import java.util.Collection;
     7import java.util.Collections;
     8import java.util.Iterator;
     9import java.util.LinkedList;
     10import java.util.List;
    511import java.util.concurrent.CopyOnWriteArrayList;
    612import org.openstreetmap.josm.data.osm.OsmPrimitive;
    713
     
    148154    public void addConflationListChangedListener(SimpleMatchListListener listener) {
    149155        listeners.addIfAbsent(listener);
    150156    }
     157   
     158    public void removeConflationListChangedListener(SimpleMatchListListener listener) {
     159        listeners.remove(listener);
     160    }
     161   
     162    public void removeAllConflationListChangedListener() {
     163        listeners.clear();
     164    }
    151165
    152     public void fireListChanged(){
     166    public void fireListChanged() {
    153167        for (SimpleMatchListListener l : listeners) {
    154168            l.simpleMatchListChanged(this);
    155169        }
    156170    }
    157171   
    158     public void fireSelectionChanged(){
     172    public void fireSelectionChanged() {
    159173        for (SimpleMatchListListener l : listeners) {
    160174            l.simpleMatchSelectionChanged(selected);
    161175        }
     
    167181   
    168182    /**
    169183     * Set which {@see SimpleMatch} is currently selected. Set to null to clear selection.
    170      * @param match
    171184     */
    172185    public void setSelected(SimpleMatch match) {
    173186        if (match != null)
     
    184197        selected.addAll(matches);
    185198        fireSelectionChanged();
    186199    }
    187 }
    188  Pas de fin de ligne à la fin du fichier
     200}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SimpleMatchListListener.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import java.util.Collection;
     
    1011     *
    1112     * @param list The new list.
    1213     */
    13     public void simpleMatchListChanged(SimpleMatchList list);
     14    void simpleMatchListChanged(SimpleMatchList list);
    1415   
    1516    /**
    1617     * Informs the listener that the conflation list selection has changed.
    1718     *
    1819     * @param selected The newly selected conflation match.
    1920     */
    20     public void simpleMatchSelectionChanged(Collection<SimpleMatch> selected);
    21 }
    22  Pas de fin de ligne à la fin du fichier
     21    void simpleMatchSelectionChanged(Collection<SimpleMatch> selected);
     22}
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SimpleMatchSettings.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import com.vividsolutions.jcs.conflate.polygonmatch.FCMatchFinder;
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SimpleMatchesTableModel.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import java.util.Collection;
     
    1617
    1718    private SimpleMatchList matches = null;
    1819    // TODO: make columns dynamic
    19     private final static String[] columnNames = {tr("Reference"), tr("Subject"), "Distance (m)", "Score", "Tags"};
     20    private static final String[] columnNames = {tr("Reference"), tr("Subject"), "Distance (m)", "Score", "Tags"};
    2021
    2122    @Override
    2223    public int getColumnCount() {
     
    7071
    7172    @Override
    7273    public Class<?> getColumnClass(int c) {
    73         return getValueAt(0, c).getClass();
     74        Object value = getValueAt(0, c);
     75        if (value != null) {
     76            return value.getClass();
     77        } else {
     78            return Object.class;
     79        }
    7480    }
    7581
    7682    /**
     
    8490     * @param matches the matches to set
    8591     */
    8692    public void setMatches(SimpleMatchList matches) {
    87         this.matches = matches;
    88         fireTableDataChanged();
     93        if (matches != this.matches) {
     94            if (this.matches != null) {
     95                this.matches.removeConflationListChangedListener(this);
     96            }
     97            this.matches = matches;
     98            if (matches != null) {
     99                matches.addConflationListChangedListener(this);
     100            }
     101            fireTableDataChanged();
     102        }
    89103    }
    90104
    91105    @Override
  • josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/UnmatchedObjectListModel.java

     
    1 // License: GPL. See LICENSE file for details. Copyright 2012 by Josh Doe and others.
     1// License: GPL. For details, see LICENSE file.
     2// Copyright 2012 by Josh Doe and others.
    23package org.openstreetmap.josm.plugins.conflation;
    34
    45import java.util.Collection;