Changeset 1828 in josm


Ignore:
Timestamp:
2009-07-25T11:19:33+02:00 (9 years ago)
Author:
Gubaer
Message:

new: tree-like browser for child relations
new: action/task for recursively downloading all child relations. Use case: download a complete network with cycle routes in one step
applied #2953: patch by cjw - Sorting a relation adds new members or crashes

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
4 added
6 edited

Legend:

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

    r1822 r1828  
    4040import javax.swing.KeyStroke;
    4141import javax.swing.SwingUtilities;
     42import javax.swing.event.ChangeEvent;
     43import javax.swing.event.ChangeListener;
    4244import javax.swing.event.DocumentEvent;
    4345import javax.swing.event.DocumentListener;
     
    9294    private AutoCompletionCache acCache;
    9395    private AutoCompletionList acList;
     96    private ReferringRelationsBrowser referrerBrowser;
    9497    private ReferringRelationsBrowserModel referrerModel;
    9598
     
    152155        tabbedPane.add(tr("Tags and Members"), pnl);
    153156        if (relation != null && relation.id > 0) {
    154             tabbedPane.add(tr("Parent Relations"), new ReferringRelationsBrowser(getLayer(), referrerModel, this));
    155         }
     157            referrerBrowser = new ReferringRelationsBrowser(getLayer(), referrerModel, this);
     158            tabbedPane.add(tr("Parent Relations"), referrerBrowser);
     159        }
     160        tabbedPane.add(tr("Child Relations"), new ChildRelationBrowser(getLayer(), relation));
     161        tabbedPane.addChangeListener(
     162                new ChangeListener() {
     163                    public void stateChanged(ChangeEvent e) {
     164                        JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
     165                        int index = sourceTabbedPane.getSelectedIndex();
     166                        String title = sourceTabbedPane.getTitleAt(index);
     167                        if (title.equals(tr("Parent Relations"))) {
     168                            referrerBrowser.init();
     169                        }
     170                    }
     171                }
     172        );
    156173
    157174        getContentPane().add(tabbedPane, BorderLayout.CENTER);
     
    765782            Shortcut.registerShortcut("relationeditor:sort", tr("Relation Editor: Sort"), KeyEvent.VK_T,
    766783                    Shortcut.GROUP_MNEMONIC);
    767             setEnabled(false);
     784            //setEnabled(false);
    768785        }
    769786
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1822 r1828  
    415415         */
    416416
    417         if (map.isEmpty())
     417        if (map.isEmpty()) {
    418418            // empty relation or incomplete members
    419419            return;
     420        }
    420421        segments = new Vector<LinkedList<Integer>>();
    421         // add first member of relation, not strictly necessary
    422         if (map.remove(0, members.get(0))) {
     422
     423        while (!map.isEmpty()) {
     424            // find an element for the next segment
     425            // try first element in relation if we just started
     426            // otherwise, or if first element is another relation, just fetch some element from the
     427            // map
     428            Integer next;
     429            if ((segments.size() == 0) && map.remove(0, members.get(0))) {
     430                next = 0;
     431            } else {
     432                next = map.pop();
     433                if (next == null) {
     434                    break;
     435                }
     436            }
     437
    423438            segment = new LinkedList<Integer>();
    424             segment.add(Integer.valueOf(0));
     439            segment.add(next);
    425440            segments.add(segment);
    426         }
    427         while (!map.isEmpty()) {
    428             segment = segments.lastElement();
    429441
    430442            do {
     
    516528            } while (something_done);
    517529
    518             Integer next = map.pop();
    519             if (next == null) {
    520                 break;
    521             }
    522 
     530        }
     531        if (segments.size() > 0) {
     532            // append map.remaining() to segments list (as a single segment)
    523533            segment = new LinkedList<Integer>();
    524             segment.add(next);
     534            segment.addAll(map.getRemaining());
    525535            segments.add(segment);
    526         }
    527         // append map.remaining() to segments list (as a single segment)
    528         segment = new LinkedList<Integer>();
    529         segment.addAll(map.getRemaining());
    530         segments.add(segment);
    531 
    532         // now we need to actually re-order the relation members
    533         ArrayList<RelationMember> newmembers = new ArrayList<RelationMember>();
    534         for (LinkedList<Integer> segment2 : segments) {
    535             for (Integer p : segment2) {
    536                 newmembers.add(members.get(p));
    537             }
    538         }
    539         members.clear();
    540         members.addAll(newmembers);
    541 
    542         fireTableDataChanged();
     536
     537            // now we need to actually re-order the relation members
     538            ArrayList<RelationMember> newmembers = new ArrayList<RelationMember>();
     539            for (LinkedList<Integer> segment2 : segments) {
     540                for (Integer p : segment2) {
     541                    newmembers.add(members.get(p));
     542                }
     543            }
     544            members.clear();
     545            members.addAll(newmembers);
     546
     547            fireTableDataChanged();
     548        }
    543549    }
    544550
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowser.java

    r1811 r1828  
    5858    private final GenericRelationEditor relationEditor;
    5959
     60    /** state flag for this browser. Initially initialized is false.
     61     * It becomes initialized after the first download of the parent
     62     * relations.
     63     */
     64    private boolean initialized;
     65
    6066    /**
    6167     * build the GUI
     
    8995        this.layer = layer;
    9096        build();
     97    }
     98
     99
     100    /**
     101     * Replies true this browser has initialized itself by downloading the reference relations
     102     * parents.
     103     *
     104     * @return true this browser has initialized itself by downloading the reference relations
     105     * parents; false, otherwise
     106     */
     107    public boolean isInitialized() {
     108        return initialized;
     109    }
     110
     111    public void init() {
     112        if (initialized) return;
     113        initialized = true;
     114        boolean full = cbReadFull.isSelected();
     115        ReloadTask task = new ReloadTask(full, relationEditor);
     116        Main.worker.submit(task);
    91117    }
    92118
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java

    r1806 r1828  
    66import javax.swing.AbstractListModel;
    77
    8 import org.openstreetmap.josm.data.osm.DataSet;
    98import org.openstreetmap.josm.data.osm.Relation;
    109import org.openstreetmap.josm.data.osm.RelationMember;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java

    r1804 r1828  
    2222 */
    2323public class RelationDialogManager extends WindowAdapter implements LayerChangeListener{
     24
     25    /** keeps track of open relation editors */
     26    static RelationDialogManager relationDialogManager;
     27
     28    /**
     29     * Replies the singleton {@see RelationDialogManager}
     30     *
     31     * @return the singleton {@see RelationDialogManager}
     32     */
     33    static public RelationDialogManager getRelationDialogManager() {
     34        if (RelationDialogManager.relationDialogManager == null) {
     35            RelationDialogManager.relationDialogManager = new RelationDialogManager();
     36            Layer.listeners.add(RelationDialogManager.relationDialogManager);
     37        }
     38        return RelationDialogManager.relationDialogManager;
     39    }
    2440
    2541    /**
     
    251267        }
    252268    }
     269
    253270}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

    r1804 r1828  
    1313import org.openstreetmap.josm.data.osm.RelationMember;
    1414import org.openstreetmap.josm.gui.ExtendedDialog;
    15 import org.openstreetmap.josm.gui.layer.Layer;
    1615import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1716
    1817public abstract class RelationEditor extends ExtendedDialog {
    1918
    20     /** keeps track of open relation editors */
    21     static private RelationDialogManager relationDialogManager;
     19    /** the list of registered relation editor classes */
     20    private static ArrayList<Class<RelationEditor>> editors = new ArrayList<Class<RelationEditor>>();
    2221
    2322    /**
    24      * Replies the singleton {@see RelationDialogManager}
     23     * Registers a relation editor class. Depending on the type of relation to be edited
     24     * {@see #getEditor(OsmDataLayer, Relation, Collection)} will create an instance of
     25     * this class.
    2526     *
    26      * @return the singleton {@see RelationDialogManager}
     27     * @param clazz the class
    2728     */
    28     static public RelationDialogManager getRelationDialogManager() {
    29         if (relationDialogManager == null) {
    30             relationDialogManager = new RelationDialogManager();
    31             Layer.listeners.add(relationDialogManager);
     29    public void registerRelationEditor(Class<RelationEditor> clazz) {
     30        if (clazz == null) return;
     31        if (!editors.contains(clazz)) {
     32            editors.add(clazz);
    3233        }
    33         return relationDialogManager;
    3434    }
    35 
    36     public static ArrayList<Class<RelationEditor>> editors = new ArrayList<Class<RelationEditor>>();
    3735
    3836    /**
     
    8179            }
    8280        }
    83         if (getRelationDialogManager().isOpenInEditor(layer, r))
    84             return getRelationDialogManager().getEditorForRelation(layer, r);
     81        if (RelationDialogManager.getRelationDialogManager().isOpenInEditor(layer, r))
     82            return RelationDialogManager.getRelationDialogManager().getEditorForRelation(layer, r);
    8583        else {
    8684            RelationEditor editor = new GenericRelationEditor(layer, r, selectedMembers);
    87             getRelationDialogManager().positionOnScreen(editor);
    88             getRelationDialogManager().register(layer, r, editor);
     85            RelationDialogManager.getRelationDialogManager().positionOnScreen(editor);
     86            RelationDialogManager.getRelationDialogManager().register(layer, r, editor);
    8987            return editor;
    9088        }
Note: See TracChangeset for help on using the changeset viewer.