Changeset 1599 in josm for trunk/src/org


Ignore:
Timestamp:
2009-05-19T00:16:01+02:00 (15 years ago)
Author:
framm
Message:

create framework for type-specific relation editors

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs
Files:
2 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r1446 r1599  
    6363import org.openstreetmap.josm.gui.MapFrame;
    6464import org.openstreetmap.josm.gui.SideButton;
     65import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
     66import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    6567import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
    6668import org.openstreetmap.josm.gui.tagging.TaggingPreset;
     
    294296     */
    295297    void membershipEdit(int row) {
    296         final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0),
    297                 (Collection<RelationMember>) membershipData.getValueAt(row, 1) );
    298         editor.setVisible(true);
     298        RelationEditor.getEditor((Relation)membershipData.getValueAt(row, 0),
     299                (Collection<RelationMember>) membershipData.getValueAt(row, 1) ).setVisible(true);
    299300    }
    300301
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r1554 r1599  
    2727import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    2828import org.openstreetmap.josm.gui.SideButton;
     29import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    2930import org.openstreetmap.josm.gui.layer.DataChangeListener;
    3031import org.openstreetmap.josm.gui.layer.Layer;
     
    4041 * We don't have such dialogs for nodes, segments, and ways, because those
    4142 * objects are visible on the map and can be selected there. Relations are not.
    42  *
    43  * @author Frederik Ramm <frederik@remote.org>
    4443 */
    4544public class RelationListDialog extends ToggleDialog implements LayerChangeListener, DataChangeListener {
     
    6059            if (toEdit == null)
    6160                return;
    62            
    63             new RelationEditor(toEdit).setVisible(true);
     61            RelationEditor.getEditor(toEdit, null).setVisible(true);
    6462        }
    6563    });
     
    9593            public void actionPerformed(ActionEvent e) {
    9694                // call relation editor with null argument to create new relation
    97                 new RelationEditor(null).setVisible(true);
     95                RelationEditor.getEditor(null, null).setVisible(true);
    9896            }
    9997        }), GBC.std());
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r1566 r1599  
    1 package org.openstreetmap.josm.gui.dialogs;
     1package org.openstreetmap.josm.gui.dialogs.relation;
    22
    33import static org.openstreetmap.josm.tools.I18n.marktr;
     
    1111import java.awt.event.KeyEvent;
    1212import java.io.IOException;
    13 import java.text.Collator;
    1413import java.util.ArrayList;
    1514import java.util.Arrays;
    1615import java.util.Collection;
    17 import java.util.Collections;
    18 import java.util.Comparator;
    1916import java.util.Map.Entry;
    2017
     
    3734import org.openstreetmap.josm.data.osm.DataSet;
    3835import org.openstreetmap.josm.data.osm.DataSource;
     36import org.openstreetmap.josm.data.osm.Node;
    3937import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4038import org.openstreetmap.josm.data.osm.Relation;
    4139import org.openstreetmap.josm.data.osm.RelationMember;
     40import org.openstreetmap.josm.data.osm.Way;
    4241import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
    43 import org.openstreetmap.josm.gui.ExtendedDialog;
    4442import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    4543import org.openstreetmap.josm.gui.SideButton;
     44import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
    4645import org.openstreetmap.josm.io.OsmServerObjectReader;
    4746import org.openstreetmap.josm.tools.GBC;
     
    6059 *
    6160 */
    62 public class RelationEditor extends ExtendedDialog {
    63 
    64     /**
    65      * The relation that this editor is working on, and the clone made for
    66      * editing.
    67      */
    68     private final Relation relation;
    69     private final Relation clone;
     61public class GenericRelationEditor extends RelationEditor {
     62
    7063    private JLabel status;
    7164
     
    111104     * @param relation relation to edit, or null to create a new one.
    112105     */
    113     public RelationEditor(Relation relation)
    114     {
    115         this(relation, null);
    116     }
    117 
    118     /**
    119      * Creates a new relation editor for the given relation. The relation
    120      * will be saved if the user selects "ok" in the editor.
    121      *
    122      * If no relation is given, will create an editor for a new relation.
    123      *
    124      * @param relation relation to edit, or null to create a new one.
    125      */
    126     public RelationEditor(Relation relation, Collection<RelationMember> selectedMembers )
     106    public GenericRelationEditor(Relation relation, Collection<RelationMember> selectedMembers )
    127107    {
    128108        // Initalizes ExtendedDialog
    129         super(Main.parent,
    130                 relation == null
    131                     ? tr("Create new relation")
    132                     : (relation.id == 0
    133                             ? tr ("Edit new relation")
    134                             : tr("Edit relation #{0}", relation.id)
    135                        ),
    136                 new String[] { applyChangesText, tr("Cancel")},
    137                 false
    138         );
    139 
    140         this.relation = relation;
    141 
    142         if (relation == null) {
    143             // create a new relation
    144             this.clone = new Relation();
    145         } else {
    146             // edit an existing relation
    147             this.clone = new Relation(relation);
    148         }
     109        super(relation, selectedMembers);
    149110
    150111        JPanel bothTables = setupBasicLayout(selectedMembers);
     
    195156        // setting up the member table
    196157
    197         memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By")});
     158        memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By"), tr("linked")});
    198159        memberTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    199160        memberTable.getColumnModel().getColumn(1).setCellRenderer(new OsmPrimitivRenderer());
     
    326287     */
    327288    private void applyChanges() {
    328         if (RelationEditor.this.relation == null) {
     289        if (GenericRelationEditor.this.relation == null) {
    329290            // If the user wanted to create a new relation, but hasn't added any members or
    330291            // tags, don't add an empty relation
     
    333294            Main.main.undoRedo.add(new AddCommand(clone));
    334295            DataSet.fireSelectionChanged(Main.ds.getSelected());
    335         } else if (!RelationEditor.this.relation.realEqual(clone, true)) {
    336             Main.main.undoRedo.add(new ChangeCommand(RelationEditor.this.relation, clone));
     296        } else if (!GenericRelationEditor.this.relation.realEqual(clone, true)) {
     297            Main.main.undoRedo.add(new ChangeCommand(GenericRelationEditor.this.relation, clone));
    337298            DataSet.fireSelectionChanged(Main.ds.getSelected());
    338299        }
     
    366327
    367328        memberData.setRowCount(0);
    368         for (RelationMember em : clone.members) {
    369             memberData.addRow(new Object[]{em.role, em.member});
     329        for (int i=0; i<clone.members.size(); i++) {
     330           
     331            // this whole section is aimed at finding out whether the
     332            // relation member is "linked" with the next, i.e. whether
     333            // (if both are ways) these ways are connected. It should
     334            // really produce a much more beautiful output (with a linkage
     335            // symbol somehow places betweeen the two member lines!), and
     336            // it should cache results, so... FIXME ;-)
     337           
     338            RelationMember em = clone.members.get(i);
     339            boolean linked = false;
     340            Node n1 = null;
     341            Node n2 = null;
     342            RelationMember m = em;
     343            while (m != null) {
     344                if (m.member instanceof Way) {
     345                    n1 = ((Way) m.member).lastNode();
     346                    break;
     347                } else if (em.member instanceof Relation) {
     348                    m = ((Relation)m.member).lastMember();
     349                } else {
     350                    break;
     351                }
     352            }
     353            if (i<clone.members.size()-1) {
     354                m = clone.members.get(i+1);
     355                while (m != null) {
     356                    if (m.member instanceof Way) {
     357                        n2 = ((Way) (m.member)).firstNode();
     358                        break;
     359                    } else if (em.member instanceof Relation) {
     360                        m = ((Relation)(m.member)).firstMember();
     361                    } else {
     362                        break;
     363                    }
     364                }
     365            }
     366            linked = (n1 != null) && n1.equals(n2);
     367           
     368            // end of section to determine linkedness.
     369           
     370            memberData.addRow(new Object[]{em.role, em.member, linked ? tr("yes") : tr("no")});
    370371        }
    371372        status.setText(tr("Members: {0}", clone.members.size()));
Note: See TracChangeset for help on using the changeset viewer.