Changeset 1596 in josm for trunk/src


Ignore:
Timestamp:
2009-05-18T00:07:01+02:00 (16 years ago)
Author:
framm
Message:
  • added primitive code to relation editor that shows whether or not two subsequent members are linked
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r1439 r1596  
    112112        return false;
    113113    }
     114   
     115    public RelationMember firstMember() {
     116        return (members.size() == 0) ? null : members.get(0);
     117    }
     118    public RelationMember lastMember() {
     119        return (members.size() == 0) ? null : members.get(members.size() -1);
     120    }
    114121}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationEditor.java

    r1554 r1596  
    3737import org.openstreetmap.josm.data.osm.DataSet;
    3838import org.openstreetmap.josm.data.osm.DataSource;
     39import org.openstreetmap.josm.data.osm.Node;
    3940import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4041import org.openstreetmap.josm.data.osm.Relation;
    4142import org.openstreetmap.josm.data.osm.RelationMember;
     43import org.openstreetmap.josm.data.osm.Way;
    4244import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
    4345import org.openstreetmap.josm.gui.ExtendedDialog;
     
    195197        // setting up the member table
    196198
    197         memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By")});
     199        memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By"), tr("linked")});
    198200        memberTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    199201        memberTable.getColumnModel().getColumn(1).setCellRenderer(new OsmPrimitivRenderer());
     
    366368
    367369        memberData.setRowCount(0);
    368         for (RelationMember em : clone.members) {
    369             memberData.addRow(new Object[]{em.role, em.member});
     370        for (int i=0; i<clone.members.size(); i++) {
     371           
     372            // this whole section is aimed at finding out whether the
     373            // relation member is "linked" with the next, i.e. whether
     374            // (if both are ways) these ways are connected. It should
     375            // really produce a much more beautiful output (with a linkage
     376            // symbol somehow places betweeen the two member lines!), and
     377            // it should cache results, so... FIXME ;-)
     378           
     379            RelationMember em = clone.members.get(i);
     380            boolean linked = false;
     381            Node n1 = null;
     382            Node n2 = null;
     383            RelationMember m = em;
     384            while (true) {
     385                if (m.member instanceof Way) {
     386                    n1 = ((Way) m.member).lastNode();
     387                    break;
     388                } else if (em.member instanceof Relation) {
     389                    m = ((Relation)m.member).lastMember();
     390                } else {
     391                    break;
     392                }
     393            }
     394            if (i<clone.members.size()-1) {
     395                m = clone.members.get(i+1);
     396                while (true) {
     397                    if (m.member instanceof Way) {
     398                        n2 = ((Way) (m.member)).firstNode();
     399                        break;
     400                    } else if (em.member instanceof Relation) {
     401                        m = ((Relation)(m.member)).firstMember();
     402                    } else {
     403                        break;
     404                    }
     405                }
     406            }
     407            linked = (n1 != null) && n1.equals(n2);
     408           
     409            // end of section to determine linkedness.
     410           
     411            memberData.addRow(new Object[]{em.role, em.member, linked ? tr("yes") : tr("no")});
    370412        }
    371413        status.setText(tr("Members: {0}", clone.members.size()));
Note: See TracChangeset for help on using the changeset viewer.