Ignore:
Timestamp:
2012-02-10T04:42:04+01:00 (13 years ago)
Author:
joshdoe
Message:

conflation: begin rework to use Replace Geometry from utilsplugin2, see #josm7374

Location:
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationLayer.java

    r26023 r27742  
    1212import java.awt.Point;
    1313import java.awt.geom.GeneralPath;
     14import java.util.Iterator;
     15import java.util.List;
     16import java.util.Map;
    1417import org.openstreetmap.josm.actions.RenameLayerAction;
    1518
    1619
    1720import org.openstreetmap.josm.data.Bounds;
    18 import org.openstreetmap.josm.data.conflict.Conflict;
    19 import org.openstreetmap.josm.data.conflict.ConflictCollection;
    2021import org.openstreetmap.josm.data.osm.DataSet;
    2122import org.openstreetmap.josm.data.osm.Node;
     
    2728import org.openstreetmap.josm.gui.layer.Layer;
    2829import org.openstreetmap.josm.gui.layer.Layer.SeparatorLayerAction;
    29 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     30import org.openstreetmap.josm.plugins.conflation.ConflationOptionsPanel.ConflationCandidate;
    3031import org.openstreetmap.josm.tools.ImageProvider;
    3132
     
    3536 * @author Josh Doe <josh@joshdoe.com>
    3637 */
    37 public class ConflationLayer extends OsmDataLayer implements LayerChangeListener {
    38     // TODO: this really shouldn't be OsmDataLayer, but easy to use conflict dialog
    39 
    40     ConflictCollection conflicts;
    41 
    42     public ConflationLayer(DataSet ds, ConflictCollection conflicts) {
    43         super(ds, tr("Conflation symbols"), null);
     38public class ConflationLayer extends Layer implements LayerChangeListener {
     39    protected List<ConflationCandidate> candidates;
     40    protected ConflationCandidate selectedCandidate = null;
     41   
     42    public ConflationLayer(DataSet ds, List<ConflationCandidate> candidates) {
     43        super(tr("Conflation"));
    4444        MapView.addLayerChangeListener(this);
    45         this.conflicts = conflicts;
     45        this.candidates = candidates;
    4646    }
    4747
     
    5454        Graphics2D g2 = g;
    5555        BasicStroke line = new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    56         g2.setColor(Color.blue);
    5756        g2.setStroke(line);
    58 
    59         GeneralPath path = new GeneralPath();
    6057
    6158        final double PHI = Math.toRadians(20);
    6259        final double cosPHI = Math.cos(PHI);
    6360        final double sinPHI = Math.sin(PHI);
    64 
    65         for (Conflict c : conflicts) {
    66             OsmPrimitive p = c.getMy();
    67             OsmPrimitive q = c.getTheir();
    68             if (p != null && q != null) {
     61        for (Iterator<ConflationCandidate> it = this.candidates.iterator(); it.hasNext();) {
     62            ConflationCandidate candidate = it.next();
     63            if (candidate.equals(selectedCandidate)) {
     64                g2.setColor(Color.blue);
     65            } else {
     66                g2.setColor(Color.cyan);
     67            }
     68            OsmPrimitive src = candidate.getSource();
     69            OsmPrimitive tgt = candidate.getTarget();
     70            if (src != null && tgt != null) {
     71                GeneralPath path = new GeneralPath();
    6972                // we have a pair, so draw line between them, FIXME: not good to use getCenter() from here, move to utils?
    70                 Point p1 = mv.getPoint(ConflationOptionsPanel.getCenter(p));
    71                 Point p2 = mv.getPoint(ConflationOptionsPanel.getCenter(q));
     73                Point p1 = mv.getPoint(ConflationOptionsPanel.getCenter(src));
     74                Point p2 = mv.getPoint(ConflationOptionsPanel.getCenter(tgt));
    7275                path.moveTo(p1.x, p1.y);
    7376                path.lineTo(p2.x, p2.y);
     
    8891                    }
    8992                }
     93                g2.draw(path);
    9094            }
    91             // TODO: handle other than just Node->Node cases
    92             // TODO: draw color coded circle around unmatched nodes
    9395        }
    9496
    95         g2.draw(path);
     97       
    9698    }
    9799
     
    120122    @Override
    121123    public void visitBoundingBox(BoundingXYVisitor v) {
    122         //TODO: handle Way/Relation types
    123         for (Conflict c : conflicts) {
    124             OsmPrimitive my = c.getMy();
    125             OsmPrimitive their = c.getTheir();
    126             if (my != null && my instanceof Node)
    127                 v.visit((Node)my);
    128             if (their != null && their instanceof Node)
    129                 v.visit((Node)their);
     124        for (Iterator<ConflationCandidate> it = this.candidates.iterator(); it.hasNext();) {
     125            ConflationCandidate candidate = it.next();
     126            OsmPrimitive src = candidate.getSource();
     127            OsmPrimitive tgt = candidate.getTarget();
     128            if (src != null && src instanceof Node)
     129                v.visit((Node)src);
     130            if (tgt != null && tgt instanceof Node)
     131                v.visit((Node)tgt);
    130132        }
    131133    }
     
    164166     * @return the set of conflicts currently managed in this layer
    165167     */
    166     public ConflictCollection getConflicts() {
    167         return conflicts;
     168    public List<ConflationCandidate> getCandidates() {
     169        return this.candidates;
     170    }
     171   
     172    public void setSelectedCandidate(ConflationCandidate c) {
     173        selectedCandidate = c;
    168174    }
    169175}
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationOptionsPanel.form

    r26023 r27742  
    1 <?xml version="1.1" encoding="UTF-8" ?>
     1<?xml version="1.0" encoding="UTF-8" ?>
    22
    33<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
     
    6969                <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
    7070                  <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
    71                     <TitledBorder title="My Set"/>
     71                    <TitledBorder title="Target Selection"/>
    7272                  </Border>
    7373                </Property>
     
    144144                  </Properties>
    145145                  <Events>
    146                     <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="freezeMySetButtonActionPerformed"/>
     146                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="freezeTargetSelectionActionPerformed"/>
    147147                  </Events>
    148148                </Component>
     
    201201                <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
    202202                  <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
    203                     <TitledBorder title="Their Set"/>
     203                    <TitledBorder title="Source Selection"/>
    204204                  </Border>
    205205                </Property>
     
    276276                  </Properties>
    277277                  <Events>
    278                     <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="freezeTheirSelectionButtonActionPerformed"/>
     278                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="freezeSourceSelectionActionPerformed"/>
    279279                  </Events>
    280280                </Component>
     
    360360            <DimensionLayout dim="0">
    361361              <Group type="103" groupAlignment="0" attributes="0">
    362                   <Group type="102" alignment="1" attributes="0">
    363                       <EmptySpace pref="578" max="32767" attributes="0"/>
    364                       <Component id="criteriaTabConflateButton" min="-2" max="-2" attributes="0"/>
    365                       <EmptySpace max="-2" attributes="0"/>
    366                   </Group>
    367                   <Group type="102" alignment="0" attributes="0">
    368                       <EmptySpace max="-2" attributes="0"/>
    369                       <Component id="jPanel2" min="-2" max="-2" attributes="0"/>
    370                       <EmptySpace pref="292" max="32767" attributes="0"/>
     362                  <Group type="102" attributes="0">
     363                      <EmptySpace max="-2" attributes="0"/>
     364                      <Group type="103" groupAlignment="0" attributes="0">
     365                          <Group type="102" alignment="1" attributes="0">
     366                              <EmptySpace min="0" pref="568" max="32767" attributes="0"/>
     367                              <Component id="criteriaTabConflateButton" min="-2" max="-2" attributes="0"/>
     368                          </Group>
     369                          <Group type="102" alignment="0" attributes="0">
     370                              <Component id="jPanel2" min="-2" max="-2" attributes="0"/>
     371                              <EmptySpace min="0" pref="282" max="32767" attributes="0"/>
     372                          </Group>
     373                      </Group>
     374                      <EmptySpace max="-2" attributes="0"/>
    371375                  </Group>
    372376              </Group>
     
    491495                          <Component id="jLabel8" min="-2" max="-2" attributes="0"/>
    492496                          <EmptySpace type="unrelated" max="-2" attributes="0"/>
    493                           <Component id="useMyTagsButton" min="-2" max="-2" attributes="0"/>
     497                          <Component id="replaceGeometryButton" min="-2" max="-2" attributes="0"/>
    494498                          <EmptySpace type="unrelated" max="-2" attributes="0"/>
    495499                          <Component id="useTheirTagsButton" min="-2" max="-2" attributes="0"/>
    496500                          <EmptySpace type="unrelated" max="-2" attributes="0"/>
    497501                          <Component id="jButton1" min="-2" max="-2" attributes="0"/>
    498                           <EmptySpace pref="300" max="32767" attributes="0"/>
     502                          <EmptySpace pref="252" max="32767" attributes="0"/>
    499503                      </Group>
    500504                  </Group>
     
    506510                          <Group type="103" groupAlignment="3" attributes="0">
    507511                              <Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
    508                               <Component id="useMyTagsButton" alignment="3" min="-2" max="-2" attributes="0"/>
     512                              <Component id="replaceGeometryButton" alignment="3" min="-2" max="-2" attributes="0"/>
    509513                              <Component id="useTheirTagsButton" alignment="3" min="-2" max="-2" attributes="0"/>
    510514                              <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
     
    516520              </Layout>
    517521              <SubComponents>
    518                 <Component class="javax.swing.JButton" name="useMyTagsButton">
    519                   <Properties>
    520                     <Property name="text" type="java.lang.String" value="My Tags"/>
     522                <Component class="javax.swing.JButton" name="replaceGeometryButton">
     523                  <Properties>
     524                    <Property name="text" type="java.lang.String" value="Replace Geometry"/>
    521525                  </Properties>
    522526                  <Events>
    523                     <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="useMyTagsButtonActionPerformed"/>
     527                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replaceGeometryButtonActionPerformed"/>
    524528                  </Events>
    525529                </Component>
     
    541545                </Component>
    542546              </SubComponents>
    543             </Container>
    544             <Container class="javax.swing.JPanel" name="tagMergerPlaceholderPanel">
    545               <Properties>
    546                 <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
    547                   <Dimension value="[661, 250]"/>
    548                 </Property>
    549               </Properties>
    550 
    551               <Layout>
    552                 <DimensionLayout dim="0">
    553                   <Group type="103" groupAlignment="0" attributes="0">
    554                       <EmptySpace min="0" pref="661" max="32767" attributes="0"/>
    555                   </Group>
    556                 </DimensionLayout>
    557                 <DimensionLayout dim="1">
    558                   <Group type="103" groupAlignment="0" attributes="0">
    559                       <EmptySpace min="0" pref="150" max="32767" attributes="0"/>
    560                   </Group>
    561                 </DimensionLayout>
    562               </Layout>
    563547            </Container>
    564548            <Component class="javax.swing.JButton" name="resolveButton">
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationOptionsPanel.java

    r26023 r27742  
    1010
    1111import java.awt.Component;
    12 import java.util.ArrayList;
    13 import java.util.HashSet;
    14 
    15 import java.util.List;
    16 import java.util.Set;
     12import java.util.*;
    1713import javax.swing.DefaultListCellRenderer;
    1814import javax.swing.Icon;
     
    3026import org.openstreetmap.josm.Main;
    3127import org.openstreetmap.josm.command.Command;
    32 import org.openstreetmap.josm.data.conflict.Conflict;
    3328import org.openstreetmap.josm.data.conflict.ConflictCollection;
    3429import org.openstreetmap.josm.data.conflict.IConflictListener;
     
    3934import org.openstreetmap.josm.data.osm.TagCollection;
    4035import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    41 import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver;
    4236import org.openstreetmap.josm.gui.layer.Layer;
    4337import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     38
     39import org.openstreetmap.josm.plugins.conflation.ConflationUtils.*;
    4440
    4541/**
     
    5046    ConflationOptionsDialog dlg = null;
    5147    ConflationLayer conflationLayer = null;
    52     DataSet myDataSet = null;
    53     DataSet theirDataSet = null;
    54     ArrayList<OsmPrimitive> mySelection = null;
     48    DataSet targetDataSet = null;
     49    DataSet sourceDataSet = null;
     50    ArrayList<OsmPrimitive> targetSelection = null;
    5551    ArrayList<OsmPrimitive> theirSelection = null;
    56     OsmDataLayer myLayer = null;
     52    OsmDataLayer targetLayer = null;
    5753    OsmDataLayer theirLayer = null;
    58     ConflictCollection conflicts = null;
    59     ConflictResolver conflictResolver;
    60     OsmPrimitive[][] pairs;
    61     int[][] assignment;
    6254    MatchTableModel tableModel;
     55    List<ConflationCandidate> candidates = null;
    6356
    6457    /** Creates new form ConflationPanel */
     
    6659        initComponents();
    6760
    68         // add selection handler, to change ConflictResolver contents and center/zoom view
     61        // add selection handler, to center/zoom view
    6962        resultsTable.getSelectionModel().addListSelectionListener(
    7063                new MatchListSelectionHandler());
     
    7669        resultsTable.getColumnModel().getColumn(4).setCellRenderer(cr);
    7770
    78         // replace dummy panel with conflictResolver
    79         conflictResolver = new ConflictResolver();
    80         for (int i = 0; i < resultsPanel.getComponentCount(); i++) {
    81             if (resultsPanel.getComponent(i) == tagMergerPlaceholderPanel) {
    82                 resultsPanel.add(conflictResolver, i);
    83                 resultsPanel.remove(tagMergerPlaceholderPanel);
    84                 break;
    85             }
    86         }
    87         resultsPanel.validate();
    88 
    8971        this.dlg = dlg;
    90 
    91         conflicts = new ConflictCollection();
    9272
    9373        // set layer names to comboboxes
     
    144124        resultsTable = new javax.swing.JTable();
    145125        jPanel1 = new javax.swing.JPanel();
    146         useMyTagsButton = new javax.swing.JButton();
     126        replaceGeometryButton = new javax.swing.JButton();
    147127        jLabel8 = new javax.swing.JLabel();
    148128        useTheirTagsButton = new javax.swing.JButton();
    149129        jButton1 = new javax.swing.JButton();
    150         tagMergerPlaceholderPanel = new javax.swing.JPanel();
    151130        resolveButton = new javax.swing.JButton();
    152131
    153132        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));
    154133
    155         refSetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("My Set"));
     134        refSetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Target Selection"));
    156135
    157136        freezeMySetButton.setText("Freeze Selection");
    158137        freezeMySetButton.addActionListener(new java.awt.event.ActionListener() {
    159138            public void actionPerformed(java.awt.event.ActionEvent evt) {
    160                 freezeMySetButtonActionPerformed(evt);
     139                freezeTargetSelectionActionPerformed(evt);
    161140            }
    162141        });
     
    194173                    .addGroup(refSetPanelLayout.createSequentialGroup()
    195174                        .addComponent(freezeMySetButton)
    196                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 387, Short.MAX_VALUE)
     175                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 392, Short.MAX_VALUE)
    197176                        .addComponent(restoreMySetButton))
    198177                    .addGroup(refSetPanelLayout.createSequentialGroup()
     
    236215        );
    237216
    238         nonRefSetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Their Set"));
     217        nonRefSetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Source Selection"));
    239218
    240219        freezeTheirSelectionButton.setText("Freeze Selection");
    241220        freezeTheirSelectionButton.addActionListener(new java.awt.event.ActionListener() {
    242221            public void actionPerformed(java.awt.event.ActionEvent evt) {
    243                 freezeTheirSelectionButtonActionPerformed(evt);
     222                freezeSourceSelectionActionPerformed(evt);
    244223            }
    245224        });
     
    277256                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, nonRefSetPanelLayout.createSequentialGroup()
    278257                        .addComponent(freezeTheirSelectionButton)
    279                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 387, Short.MAX_VALUE)
     258                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 392, Short.MAX_VALUE)
    280259                        .addComponent(restoreTheirSetButton))
    281260                    .addGroup(nonRefSetPanelLayout.createSequentialGroup()
     
    403382        criteriaTabPanelLayout.setHorizontalGroup(
    404383            criteriaTabPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    405             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, criteriaTabPanelLayout.createSequentialGroup()
    406                 .addContainerGap(578, Short.MAX_VALUE)
    407                 .addComponent(criteriaTabConflateButton)
     384            .addGroup(criteriaTabPanelLayout.createSequentialGroup()
     385                .addContainerGap()
     386                .addGroup(criteriaTabPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     387                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, criteriaTabPanelLayout.createSequentialGroup()
     388                        .addGap(0, 568, Short.MAX_VALUE)
     389                        .addComponent(criteriaTabConflateButton))
     390                    .addGroup(criteriaTabPanelLayout.createSequentialGroup()
     391                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
     392                        .addGap(0, 282, Short.MAX_VALUE)))
    408393                .addContainerGap())
    409             .addGroup(criteriaTabPanelLayout.createSequentialGroup()
    410                 .addContainerGap()
    411                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    412                 .addContainerGap(292, Short.MAX_VALUE))
    413394        );
    414395        criteriaTabPanelLayout.setVerticalGroup(
     
    444425        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    445426
    446         useMyTagsButton.setText("My Tags");
    447         useMyTagsButton.addActionListener(new java.awt.event.ActionListener() {
    448             public void actionPerformed(java.awt.event.ActionEvent evt) {
    449                 useMyTagsButtonActionPerformed(evt);
     427        replaceGeometryButton.setText("Replace Geometry");
     428        replaceGeometryButton.addActionListener(new java.awt.event.ActionListener() {
     429            public void actionPerformed(java.awt.event.ActionEvent evt) {
     430                replaceGeometryButtonActionPerformed(evt);
    450431            }
    451432        });
     
    466447                .addComponent(jLabel8)
    467448                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    468                 .addComponent(useMyTagsButton)
     449                .addComponent(replaceGeometryButton)
    469450                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    470451                .addComponent(useTheirTagsButton)
    471452                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    472453                .addComponent(jButton1)
    473                 .addContainerGap(300, Short.MAX_VALUE))
     454                .addContainerGap(252, Short.MAX_VALUE))
    474455        );
    475456        jPanel1Layout.setVerticalGroup(
     
    479460                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    480461                    .addComponent(jLabel8)
    481                     .addComponent(useMyTagsButton)
     462                    .addComponent(replaceGeometryButton)
    482463                    .addComponent(useTheirTagsButton)
    483464                    .addComponent(jButton1))
     
    486467
    487468        resultsPanel.add(jPanel1);
    488 
    489         tagMergerPlaceholderPanel.setPreferredSize(new java.awt.Dimension(661, 250));
    490 
    491         javax.swing.GroupLayout tagMergerPlaceholderPanelLayout = new javax.swing.GroupLayout(tagMergerPlaceholderPanel);
    492         tagMergerPlaceholderPanel.setLayout(tagMergerPlaceholderPanelLayout);
    493         tagMergerPlaceholderPanelLayout.setHorizontalGroup(
    494             tagMergerPlaceholderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    495             .addGap(0, 661, Short.MAX_VALUE)
    496         );
    497         tagMergerPlaceholderPanelLayout.setVerticalGroup(
    498             tagMergerPlaceholderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    499             .addGap(0, 150, Short.MAX_VALUE)
    500         );
    501 
    502         resultsPanel.add(tagMergerPlaceholderPanel);
    503469
    504470        resolveButton.setText("Resolve");
     
    523489
    524490        // some initialization
    525         int n = mySelection.size();
     491        int n = targetSelection.size();
    526492        int m = theirSelection.size();
    527493        int maxLen = Math.max(n, m);
     
    531497        for (int i = 0; i < n; i++) {
    532498            for (int j = 0; j < m; j++) {
    533                 cost[i][j] = calcCost(mySelection.get(i), theirSelection.get(j));
     499                cost[i][j] = calcCost(targetSelection.get(i), theirSelection.get(j));
    534500            }
    535501        }
    536502
    537503        // perform assignment using Hungarian algorithm
    538         assignment = new int[maxLen][2];
    539         assignment = HungarianAlgorithm.hgAlgorithm(cost, "min");
    540 
    541         // create array of primitives based on indices from assignment
    542         pairs = new OsmPrimitive[maxLen][2];
     504        int[][] assignment = HungarianAlgorithm.hgAlgorithm(cost, "min");
     505        OsmPrimitive target, source;
     506        candidates = new LinkedList<ConflationCandidate>();
    543507        for (int i = 0; i < maxLen; i++) {
    544508            if (assignment[i][0] < n)
    545                 pairs[i][0] = mySelection.get(assignment[i][0]);
     509                target = targetSelection.get(assignment[i][0]);
    546510            else
    547                 pairs[i][0] = null;
     511                target = null;
    548512            if (assignment[i][1] < m)
    549                 pairs[i][1] = theirSelection.get(assignment[i][1]);
     513                source = theirSelection.get(assignment[i][1]);
    550514            else
    551                 pairs[i][1] = null;
    552 
    553             if (pairs[i][0] != null && pairs[i][1] != null) {
     515                source = null;
     516
     517            if (target != null && source != null) {
    554518                // TODO: do something!
    555                 conflicts.add(pairs[i][0], pairs[i][1]);
     519                candidates.add(new ConflationCandidate(source, target));
    556520            }
    557521        }
     
    559523        // add conflation layer
    560524        try {
    561             conflationLayer = new ConflationLayer(myLayer.data, conflicts);
     525            conflationLayer = new ConflationLayer(targetLayer.data, candidates);
    562526            Main.main.addLayer(conflationLayer);
    563527        } catch (Exception ex) {
     
    568532        resultsTable.setModel(tableModel);
    569533
    570         conflictResolver.populate(conflicts.get(0));
    571534        // print list of matched pairsalong with distance
    572535        // upon selection of one pair, highlight them and draw arrow
     
    579542
    580543    private void restoreMySetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreMySetButtonActionPerformed
    581         if (myLayer != null && myDataSet != null && mySelection != null && !mySelection.isEmpty()) {
    582             Main.map.mapView.setActiveLayer(myLayer);
    583             myLayer.setVisible(true);
    584             myDataSet.setSelected(mySelection);
     544        if (targetLayer != null && targetDataSet != null && targetSelection != null && !targetSelection.isEmpty()) {
     545            Main.map.mapView.setActiveLayer(targetLayer);
     546            targetLayer.setVisible(true);
     547            targetDataSet.setSelected(targetSelection);
    585548        }
    586549    }//GEN-LAST:event_restoreMySetButtonActionPerformed
    587550
    588551    private void restoreTheirSetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreTheirSetButtonActionPerformed
    589         if (theirLayer != null && theirDataSet != null && theirSelection != null && !theirSelection.isEmpty()) {
     552        if (theirLayer != null && sourceDataSet != null && theirSelection != null && !theirSelection.isEmpty()) {
    590553            Main.map.mapView.setActiveLayer(theirLayer);
    591554            theirLayer.setVisible(true);
    592             theirDataSet.setSelected(theirSelection);
     555            sourceDataSet.setSelected(theirSelection);
    593556        }
    594557    }//GEN-LAST:event_restoreTheirSetButtonActionPerformed
    595558
    596     private void freezeMySetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_freezeMySetButtonActionPerformed
    597         myDataSet = Main.main.getCurrentDataSet();
    598         myLayer = Main.main.getEditLayer();
    599         if (myDataSet == null || myLayer == null) {
     559    private void freezeTargetSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_freezeTargetSelectionActionPerformed
     560        targetDataSet = Main.main.getCurrentDataSet();
     561        targetLayer = Main.main.getEditLayer();
     562        if (targetDataSet == null || targetLayer == null) {
    600563            JOptionPane.showMessageDialog(Main.parent, tr("No valid OSM data layer present."),
    601564                    tr("Error freezing selection"), JOptionPane.ERROR_MESSAGE);
    602565            return;
    603566        }
    604         mySelection = new ArrayList<OsmPrimitive>(myDataSet.getSelected());
    605         if (mySelection.isEmpty()) {
     567        targetSelection = new ArrayList<OsmPrimitive>(targetDataSet.getSelected());
     568        if (targetSelection.isEmpty()) {
    606569            JOptionPane.showMessageDialog(Main.parent, tr("Nothing is selected, please try again."),
    607570                    tr("Empty selection"), JOptionPane.ERROR_MESSAGE);
     
    612575        int numWays = 0;
    613576        int numRelations = 0;
    614         for (OsmPrimitive p: mySelection) {
     577        for (OsmPrimitive p: targetSelection) {
    615578            switch(p.getType()) {
    616579            case NODE: numNodes++; break;
     
    620583        }
    621584
    622         myLayerLabel.setText(myLayer.getName());
     585        myLayerLabel.setText(targetLayer.getName());
    623586        myNodeCountLabel.setText(Integer.toString(numNodes));
    624587        myWayCountLabel.setText(Integer.toString(numWays));
    625588        myRelationCountLabel.setText(Integer.toString(numRelations));
    626     }//GEN-LAST:event_freezeMySetButtonActionPerformed
    627 
    628     private void freezeTheirSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_freezeTheirSelectionButtonActionPerformed
    629         theirDataSet = Main.main.getCurrentDataSet();
     589    }//GEN-LAST:event_freezeTargetSelectionActionPerformed
     590
     591    private void freezeSourceSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_freezeSourceSelectionActionPerformed
     592        sourceDataSet = Main.main.getCurrentDataSet();
    630593        theirLayer = Main.main.getEditLayer();
    631         if (theirDataSet == null || theirLayer == null) {
     594        if (sourceDataSet == null || theirLayer == null) {
    632595            JOptionPane.showMessageDialog(Main.parent, tr("No valid OSM data layer present."),
    633596                    tr("Error freezing selection"), JOptionPane.ERROR_MESSAGE);
    634597            return;
    635598        }
    636         theirSelection = new ArrayList<OsmPrimitive>(theirDataSet.getSelected());
     599        theirSelection = new ArrayList<OsmPrimitive>(sourceDataSet.getSelected());
    637600        if (theirSelection.isEmpty()) {
    638601            JOptionPane.showMessageDialog(Main.parent, tr("Nothing is selected, please try again."),
     
    644607        int numWays = 0;
    645608        int numRelations = 0;
    646         for (OsmPrimitive p: mySelection) {
     609        for (OsmPrimitive p: theirSelection) {
    647610            switch(p.getType()) {
    648611            case NODE: numNodes++; break;
     
    656619        theirWayCountLabel.setText(Integer.toString(numWays));
    657620        theirRelationCountLabel.setText(Integer.toString(numRelations));
    658     }//GEN-LAST:event_freezeTheirSelectionButtonActionPerformed
    659 
    660     private void useMyTagsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useMyTagsButtonActionPerformed
    661         int[] rows = resultsTable.getSelectedRows();
    662     }//GEN-LAST:event_useMyTagsButtonActionPerformed
     621    }//GEN-LAST:event_freezeSourceSelectionActionPerformed
    663622
    664623    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
     
    667626
    668627    private void resolveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resolveButtonActionPerformed
    669         if (!conflictResolver.isResolvedCompletely()) {
    670             JOptionPane.showMessageDialog(Main.parent, tr("Unresolved differences remain, please fix remaining differences."),
    671                     tr("Conflict not resolved completely"), JOptionPane.ERROR_MESSAGE);
    672                     return;
    673         }
    674         Command cmd = conflictResolver.buildResolveCommand();
    675         Main.main.undoRedo.add(cmd);
     628        // FIXME: perform replace geometry
     629        //Main.main.undoRedo.add(cmd);
    676630    }//GEN-LAST:event_resolveButtonActionPerformed
     631
     632    private void replaceGeometryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceGeometryButtonActionPerformed
     633       
     634    }//GEN-LAST:event_replaceGeometryButtonActionPerformed
    677635
    678636    static public class LayerListCellRenderer extends DefaultListCellRenderer {
     
    725683
    726684        public int getRowCount() {
    727             return conflicts.size();
     685            return candidates.size();
    728686        }
    729687
     
    735693        public Object getValueAt(int row, int col) {
    736694            if (col == 0)
    737                 return conflicts.get(row).getMy();
     695                return candidates.get(row).getSource();
    738696            if (col == 1)
    739                 return conflicts.get(row).getTheir();
     697                return candidates.get(row).getTarget();
    740698            if (col == 4) {
    741699                HashSet<OsmPrimitive> set = new HashSet<OsmPrimitive>();
    742                 set.add(conflicts.get(row).getMy());
    743                 set.add(conflicts.get(row).getTheir());
     700                set.add(candidates.get(row).getSource());
     701                set.add(candidates.get(row).getTarget());
    744702                TagCollection tags = TagCollection.unionOfAllPrimitives(set);
    745703                Set<String> keys = tags.getKeysWithMultipleValues();
     
    804762            // only one item selected, show tags and zoom/center map
    805763            if (!lsm.isSelectionEmpty() && firstIndex == lastIndex) {
    806                 Conflict<?> c = conflicts.get(firstIndex);
    807                 conflictResolver.populate(c);
     764                ConflationCandidate c = candidates.get(firstIndex);
     765               
     766                conflationLayer.setSelectedCandidate(c);
     767               
     768                targetDataSet.setSelected(Arrays.asList(c.getTarget(), c.getSource()));
    808769               
    809770                ArrayList<OsmPrimitive> sel = new ArrayList<OsmPrimitive>();
    810                 sel.add(c.getMy());
    811                 sel.add(c.getTheir());
     771                sel.add(c.getSource());
     772                sel.add(c.getTarget());
    812773
    813774                BoundingXYVisitor box = new BoundingXYVisitor();
     
    835796        System.err.println("1 conflict has been resolved.");
    836797        refreshView();
     798    }
     799   
     800    public class ConflationCandidate {
     801        protected OsmPrimitive source;
     802        protected OsmPrimitive target;
     803       
     804        public ConflationCandidate(OsmPrimitive source, OsmPrimitive target) {
     805            if (source == null || target == null) {
     806                throw new IllegalArgumentException("Invalid source or target");
     807            }
     808            this.source = source;
     809            this.target = target;
     810        }
     811       
     812        public OsmPrimitive getSource() {
     813            return source;
     814        }
     815       
     816        public OsmPrimitive getTarget() {
     817            return target;
     818        }
    837819    }
    838820
     
    865847    private javax.swing.JPanel objectTabPanel;
    866848    private javax.swing.JPanel refSetPanel;
     849    private javax.swing.JButton replaceGeometryButton;
    867850    private javax.swing.JButton resolveButton;
    868851    private javax.swing.JButton restoreMySetButton;
     
    871854    private javax.swing.JTabbedPane resultsTabPanel;
    872855    private javax.swing.JTable resultsTable;
    873     private javax.swing.JPanel tagMergerPlaceholderPanel;
    874856    private javax.swing.JLabel theirLayerLabel;
    875857    private javax.swing.JLabel theirNodeCountLabel;
    876858    private javax.swing.JLabel theirRelationCountLabel;
    877859    private javax.swing.JLabel theirWayCountLabel;
    878     private javax.swing.JButton useMyTagsButton;
    879860    private javax.swing.JButton useTheirTagsButton;
    880861    // End of variables declaration//GEN-END:variables
Note: See TracChangeset for help on using the changeset viewer.