Ignore:
Timestamp:
2012-03-01T06:08:16+01:00 (13 years ago)
Author:
joshdoe
Message:

conflation: add first minimally-functional version with major refactoring

Location:
applications/editors/josm/plugins/conflation
Files:
8 added
4 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/conflation/build.xml

    r27852 r27959  
    106106                <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.conflation.ConflationPlugin"/>
    107107                <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
    108                 <attribute name="Plugin-Description" value="Tool for conflating (merging) data"/>
     108                <attribute name="Plugin-Description" value="(Warning: Experimental!) Tool for conflating (merging) data"/>
    109109                <attribute name="Plugin-Icon" value="images/conflation.png"/>
    110110                <attribute name="Plugin-Requires" value="utilsplugin2"/>
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationLayer.java

    r27751 r27959  
    44import java.awt.BasicStroke;
    55import java.awt.Color;
    6 import javax.swing.Action;
    7 import javax.swing.Icon;
    8 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    9 import static org.openstreetmap.josm.tools.I18n.tr;
    10 
    116import java.awt.Graphics2D;
    127import java.awt.Point;
    138import java.awt.geom.GeneralPath;
    149import java.util.Iterator;
    15 import java.util.List;
    16 import java.util.Map;
     10import javax.swing.Action;
     11import javax.swing.Icon;
    1712import org.openstreetmap.josm.actions.RenameLayerAction;
    18 
    19 
    2013import org.openstreetmap.josm.data.Bounds;
    2114import org.openstreetmap.josm.data.osm.DataSet;
    2215import org.openstreetmap.josm.data.osm.Node;
    2316import org.openstreetmap.josm.data.osm.OsmPrimitive;
     17import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    2418import org.openstreetmap.josm.gui.MapView;
    2519import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     
    2822import org.openstreetmap.josm.gui.layer.Layer;
    2923import org.openstreetmap.josm.gui.layer.Layer.SeparatorLayerAction;
    30 import org.openstreetmap.josm.plugins.conflation.ConflationOptionsPanel.ConflationCandidate;
     24import static org.openstreetmap.josm.tools.I18n.tr;
    3125import org.openstreetmap.josm.tools.ImageProvider;
    3226
     
    3731 */
    3832public class ConflationLayer extends Layer implements LayerChangeListener {
    39     protected List<ConflationCandidate> candidates;
     33    protected ConflationCandidateList candidates;
    4034    protected ConflationCandidate selectedCandidate = null;
    4135   
    42     public ConflationLayer(DataSet ds, List<ConflationCandidate> candidates) {
     36    public ConflationLayer(DataSet ds, ConflationCandidateList candidates) {
    4337        super(tr("Conflation"));
    4438        MapView.addLayerChangeListener(this);
     
    6660                g2.setColor(Color.cyan);
    6761            }
    68             OsmPrimitive src = candidate.getSource();
    69             OsmPrimitive tgt = candidate.getTarget();
     62            OsmPrimitive src = candidate.getSourcePrimitive();
     63            OsmPrimitive tgt = candidate.getTargetPrimitive();
    7064            if (src != null && tgt != null) {
    7165                GeneralPath path = new GeneralPath();
    7266                // we have a pair, so draw line between them, FIXME: not good to use getCenter() from here, move to utils?
    73                 Point p1 = mv.getPoint(ConflationOptionsPanel.getCenter(src));
    74                 Point p2 = mv.getPoint(ConflationOptionsPanel.getCenter(tgt));
     67                Point p1 = mv.getPoint(ConflationUtils.getCenter(src));
     68                Point p2 = mv.getPoint(ConflationUtils.getCenter(tgt));
    7569                path.moveTo(p1.x, p1.y);
    7670                path.lineTo(p2.x, p2.y);
     
    124118        for (Iterator<ConflationCandidate> it = this.candidates.iterator(); it.hasNext();) {
    125119            ConflationCandidate candidate = it.next();
    126             OsmPrimitive src = candidate.getSource();
    127             OsmPrimitive tgt = candidate.getTarget();
     120            OsmPrimitive src = candidate.getSourcePrimitive();
     121            OsmPrimitive tgt = candidate.getTargetPrimitive();
    128122            if (src != null && src instanceof Node)
    129123                v.visit((Node)src);
     
    166160     * @return the set of conflicts currently managed in this layer
    167161     */
    168     public List<ConflationCandidate> getCandidates() {
     162    public ConflationCandidateList getCandidates() {
    169163        return this.candidates;
    170164    }
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationPlugin.java

    r27755 r27959  
    22package org.openstreetmap.josm.plugins.conflation;
    33
    4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    5 import static org.openstreetmap.josm.tools.I18n.marktr;
    6 import static org.openstreetmap.josm.tools.I18n.tr;
    7 
    84import java.awt.event.KeyEvent;
    9 import java.io.IOException;
    10 import java.util.logging.FileHandler;
    11 import java.util.logging.Logger;
    12 import javax.swing.JMenu;
    13 import javax.swing.JOptionPane;
    14 import org.openstreetmap.josm.Main;
    15 import org.openstreetmap.josm.gui.MainMenu;
     5import org.openstreetmap.josm.gui.MapFrame;
    166import org.openstreetmap.josm.plugins.Plugin;
    177import org.openstreetmap.josm.plugins.PluginInformation;
     8import org.openstreetmap.josm.tools.Shortcut;
    189
     10import static org.openstreetmap.josm.tools.I18n.tr;
    1911
    2012public class ConflationPlugin extends Plugin {
    2113
    22     ConflationAction action = null;
    23     Logger logger;
     14    private ConflationToggleDialog dialog = null;
    2415
    2516    /**
     
    2819    public ConflationPlugin(PluginInformation info) {
    2920        super(info);
     21    }
    3022
    31         try {
    32             logger = Logger.getLogger(ConflationPlugin.class.getName());
    33             FileHandler fh = new FileHandler("C:/temp/log.txt");
    34             logger.addHandler(fh);
    35         }
    36         catch (IOException e) {
    37             JOptionPane.showMessageDialog(Main.parent, "Failed to create log file",
    38                     "Failed to create logger", JOptionPane.ERROR_MESSAGE);
    39         }
    40 
    41         try {
    42             JMenu conflationMenu = Main.main.menu.addMenu(marktr("Conflation"), KeyEvent.VK_R,
    43                     Main.main.menu.defaultMenuPos, ht("/Plugin/Conflation"));
    44             MainMenu.add(conflationMenu, new ConflationAction());
    45 
    46 
    47         } catch (Exception e) {
    48             JOptionPane.showMessageDialog(Main.parent, e.toString(),
    49                     "Error adding conflation menu item", JOptionPane.ERROR_MESSAGE);
     23    // add dialog the first time the mapframe is loaded
     24    @Override
     25    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     26        if (oldFrame == null && newFrame != null) {
     27            if (dialog == null) {
     28                Shortcut shortcut = Shortcut.registerShortcut("Conflation", tr("Toggle: {0}", tr("Open Conflation")),
     29                        KeyEvent.VK_0, Shortcut.ALT_SHIFT);
     30                String name = "Conflation";
     31                String tooltip = "Activates the conflation plugin";
     32                dialog = new ConflationToggleDialog(tr(name), "conflation.png", tr(tooltip),
     33                        shortcut, 150, this);
     34            }
     35            newFrame.addToggleDialog(dialog);
    5036        }
    5137    }
Note: See TracChangeset for help on using the changeset viewer.