Ignore:
Timestamp:
2007-09-24T01:36:24+02:00 (17 years ago)
Author:
framm
Message:

This commit is a manual merge of all changes that have been made to
the intermediate "core_0.5" branch on the main OSM repository,
bevore JOSM was moved to openstreetmap.de.

Changes incorporated here:

r4464@svn.openstreetmap.org
r4466@svn.openstreetmap.org
r4468@svn.openstreetmap.org
r4469@svn.openstreetmap.org
r4479@svn.openstreetmap.org

Location:
branch/0.5/src/org/openstreetmap/josm/gui
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branch/0.5/src/org/openstreetmap/josm/gui/ConflictResolver.java

    r298 r329  
    3838import org.openstreetmap.josm.data.conflict.ConflictItem;
    3939import org.openstreetmap.josm.data.conflict.DeleteConflict;
    40 import org.openstreetmap.josm.data.conflict.FromConflict;
    4140import org.openstreetmap.josm.data.conflict.PositionConflict;
    4241import org.openstreetmap.josm.data.conflict.PropertyConflict;
    43 import org.openstreetmap.josm.data.conflict.SegmentConflict;
    44 import org.openstreetmap.josm.data.conflict.ToConflict;
    4542import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4643import org.openstreetmap.josm.tools.GBC;
     
    140137                possibleConflicts.add(new DeleteConflict());
    141138                possibleConflicts.add(new PositionConflict());
    142                 possibleConflicts.add(new FromConflict());
    143                 possibleConflicts.add(new ToConflict());
    144                 possibleConflicts.add(new SegmentConflict());
    145139                TreeSet<String> allkeys = new TreeSet<String>();
    146140                for (Entry<OsmPrimitive, OsmPrimitive> e : conflicts.entrySet()) {
  • branch/0.5/src/org/openstreetmap/josm/gui/GettingStarted.java

    r312 r329  
    4848                panel = new JPanel(new GridBagLayout());
    4949               
     50                panel.add(new JLabel("<html><h2>You are running a technology preview with support for <i>API 0.5</i>.</h2>" +
     51                                "<h3>API 0.5 supports object relationships, and segments have been removed.</h3>" +
     52                                "<h3>This version is hard-coded to use the API 0.5 running on <i>openstreetmap.gryph.de</i> which has data from a recent planet file."+
     53                                "<br>Please be gentle with that machine and request only moderate bounding boxes.<br>" +
     54                                "<br>Username and password are also hardcoded, so your real username and password are not transmitted.<br>" +
     55                "</h3>"), GBC.eol());
     56               
     57                addLine("wiki", "Read the [Wiki page on API 0.5]");
    5058                addGettingStarted();
    5159                addGettingHelp();
     
    8694                else if (e.getActionCommand().equals("help"))
    8795                        Main.main.menu.help.actionPerformed(e);
     96                else if (e.getActionCommand().equals("wiki"))
     97                        OpenBrowser.displayUrl("http://wiki.openstreetmap.org/index.php?title=OSM_Protocol_Version_0.5");
    8898                else if (e.getActionCommand().equals("tutorial"))
    8999                        OpenBrowser.displayUrl("http://josm.openstreetmap.de/wiki/TutorialVideos");
  • branch/0.5/src/org/openstreetmap/josm/gui/MainMenu.java

    r298 r329  
    1818import org.openstreetmap.josm.actions.CombineWayAction;
    1919import org.openstreetmap.josm.actions.DownloadAction;
    20 import org.openstreetmap.josm.actions.DownloadIncompleteAction;
    2120import org.openstreetmap.josm.actions.ExitAction;
    2221import org.openstreetmap.josm.actions.GpxExportAction;
     
    2625import org.openstreetmap.josm.actions.PreferencesAction;
    2726import org.openstreetmap.josm.actions.RedoAction;
    28 import org.openstreetmap.josm.actions.ReorderAction;
    29 import org.openstreetmap.josm.actions.ReverseSegmentAction;
     27import org.openstreetmap.josm.actions.ReverseWayAction;
    3028import org.openstreetmap.josm.actions.SaveAction;
    3129import org.openstreetmap.josm.actions.SaveAsAction;
     
    5654        public final OpenAction open = new OpenAction();
    5755        public final DownloadAction download = new DownloadAction();
    58         public final Action reverseSegment = new ReverseSegmentAction();
     56        public final Action reverseWay = new ReverseWayAction();
    5957        public final Action splitWay = new SplitWayAction();
    6058        public final Action combineWay = new CombineWayAction();
    6159        public final Action alignInCircle = new AlignInCircleAction();
    6260        public final Action alignInLine = new AlignInLineAction();
    63         public final Action reorder = new ReorderAction();
    6461        public final Action upload = new UploadAction();
    6562        public final Action save = new SaveAction(null);
     
    7067        public final HelpAction help = new HelpAction();
    7168        public final Action about = new AboutAction();
    72         public final DownloadIncompleteAction downloadIncomplete = new DownloadIncompleteAction();
    7369       
    7470        public final JMenu layerMenu = new JMenu(tr("Layer"));
     
    117113                toolsMenu.add(alignInLine);
    118114                toolsMenu.addSeparator();
    119                 toolsMenu.add(reverseSegment);
    120                 toolsMenu.add(reorder);
     115                toolsMenu.add(reverseWay);
    121116                toolsMenu.addSeparator();
    122117                toolsMenu.add(splitWay);
     
    126121                connectionMenu.setMnemonic('C');
    127122                connectionMenu.add(download);
    128                 connectionMenu.add(downloadIncomplete);
    129123                connectionMenu.add(upload);
    130124                add(connectionMenu);
  • branch/0.5/src/org/openstreetmap/josm/gui/MapFrame.java

    r312 r329  
    1515import org.openstreetmap.josm.Main;
    1616import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
    17 import org.openstreetmap.josm.actions.mapmode.AddWayAction;
    1817import org.openstreetmap.josm.actions.mapmode.DeleteAction;
    1918import org.openstreetmap.josm.actions.mapmode.MapMode;
     
    2423import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
    2524import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     25import org.openstreetmap.josm.gui.dialogs.RelationListDialog;
    2626import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
    2727import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     
    8585                toolBarActions.add(new IconToggleButton(new AddNodeGroup(this)));
    8686                toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
    87                 toolBarActions.add(new IconToggleButton(new AddWayAction(this)));
    8887                toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
    8988
     
    104103                addToggleDialog(conflictDialog = new ConflictDialog());
    105104                addToggleDialog(new CommandStackDialog(this));
     105                addToggleDialog(new RelationListDialog());
    106106
    107107                // status line below the map
  • branch/0.5/src/org/openstreetmap/josm/gui/MapStatus.java

    r298 r329  
    126126                                        OsmPrimitive osmNearest = null;
    127127                                        // Set the text label in the bottom status bar
    128                                         osmNearest = mv.getNearest(ms.mousePos, (ms.modifiers & MouseEvent.ALT_DOWN_MASK) != 0);
     128                                        osmNearest = mv.getNearest(ms.mousePos);
    129129                                        if (osmNearest != null) {
    130130                                                NameVisitor visitor = new NameVisitor();
  • branch/0.5/src/org/openstreetmap/josm/gui/MapView.java

    r304 r329  
    8585
    8686                // listend to selection changes to redraw the map
    87                 DataSet.listeners.add(new SelectionChangedListener(){
     87                DataSet.selListeners.add(new SelectionChangedListener(){
    8888                        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    8989                                repaint();
  • branch/0.5/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r306 r329  
    44import java.awt.Point;
    55import java.util.Collection;
    6 import java.util.Collections;
    76import java.util.HashSet;
    8 import java.util.List;
    97
    108import javax.swing.JComponent;
     
    1614import org.openstreetmap.josm.data.osm.Node;
    1715import org.openstreetmap.josm.data.osm.OsmPrimitive;
    18 import org.openstreetmap.josm.data.osm.Segment;
    1916import org.openstreetmap.josm.data.osm.Way;
     17import org.openstreetmap.josm.data.osm.WaySegment;
    2018import org.openstreetmap.josm.data.projection.Projection;
    2119
     
    147145
    148146        /**
    149          * @return the nearest way to the screen point given.
    150          */
    151         public final Way getNearestWay(Point p) {
     147         * @return the nearest way segment to the screen point given that is not
     148         * in ignore.
     149         *
     150         * @param p the point for which to search the nearest segment.
     151         * @param ignore a collection of segments which are not to be returned.
     152         * May be null.
     153         */
     154        public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) {
    152155                Way minPrimitive = null;
     156                int minI = 0;
    153157                double minDistanceSq = Double.MAX_VALUE;
    154158                for (Way w : Main.ds.ways) {
    155159                        if (w.deleted)
    156160                                continue;
    157                         for (Segment ls : w.segments) {
    158                                 if (ls.deleted || ls.incomplete)
     161                        Node lastN = null;
     162                        int i = -2;
     163                        for (Node n : w.nodes) {
     164                                i++;
     165                                if (n.deleted) continue;
     166                                if (lastN == null) {
     167                                        lastN = n;
    159168                                        continue;
    160                                 Point A = getPoint(ls.from.eastNorth);
    161                                 Point B = getPoint(ls.to.eastNorth);
     169                                }
     170                                if (ignore != null && ignore.contains(new WaySegment(w, i))) {
     171                                        continue;
     172                                }
     173                                Point A = getPoint(lastN.eastNorth);
     174                                Point B = getPoint(n.eastNorth);
    162175                                double c = A.distanceSq(B);
    163176                                double a = p.distanceSq(B);
     
    167180                                        minDistanceSq = perDist;
    168181                                        minPrimitive = w;
    169                                 }
     182                                        minI = i;
     183                                }
     184                                lastN = n;
    170185                        }
    171186                }
    172                 return minPrimitive;
    173         }
    174 
    175         /**
    176          * @return the nearest segment to the screen point given
    177          *
    178          * @param p the point for which to search the nearest segment.
    179          */
    180         public final Segment getNearestSegment(Point p) {
    181                 List<Segment> e = Collections.emptyList();
    182                 return getNearestSegment(p, e);
     187                return minPrimitive == null ? null : new WaySegment(minPrimitive, minI);
     188        }
     189
     190        /**
     191         * @return the nearest way segment to the screen point given.
     192         */
     193        public final WaySegment getNearestWaySegment(Point p) {
     194                return getNearestWaySegment(p, null);
    183195        }
    184196       
    185197        /**
    186          * @return the nearest segment to the screen point given that is not
    187          * in ignoreThis.
    188          *
    189          * @param p the point for which to search the nearest segment.
    190          * @param ignore a collection of segments which are not to be returned. Must not be null.
    191          */
    192         public final Segment getNearestSegment(Point p, Collection<Segment> ignore) {
    193                 Segment minPrimitive = null;
    194                 double minDistanceSq = Double.MAX_VALUE;
    195                 // segments
    196                 for (Segment ls : Main.ds.segments) {
    197                         if (ls.deleted || ls.incomplete || ignore.contains(ls))
    198                                 continue;
    199                         Point A = getPoint(ls.from.eastNorth);
    200                         Point B = getPoint(ls.to.eastNorth);
    201                         double c = A.distanceSq(B);
    202                         double a = p.distanceSq(B);
    203                         double b = p.distanceSq(A);
    204                         double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared
    205                         if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) {
    206                                 minDistanceSq = perDist;
    207                                 minPrimitive = ls;
    208                         }
    209                 }
    210                 return minPrimitive;
     198         * @return the nearest way to the screen point given.
     199         */
     200        public final Way getNearestWay(Point p) {
     201                WaySegment nearestWaySeg = getNearestWaySegment(p);
     202                return nearestWaySeg == null ? null : nearestWaySeg.way;
    211203    }
    212204
     
    217209         * nearest node is returned.
    218210         *
    219          * If no node is found, search for pending segments.
    220          *
    221          * If no such segment is found, and a non-pending segment is
    222          * within 10 pixel to p, this segment is returned, except when
    223          * <code>wholeWay</code> is <code>true</code>, in which case the
    224          * corresponding Way is returned.
    225          *
    226          * If no segment is found and the point is within an area, return that
    227          * area.
    228          *
    229          * If no area is found, return <code>null</code>.
     211         * If no node is found, search for near ways.
     212         *
     213         * If nothing is found, return <code>null</code>.
    230214         *
    231215         * @param p                              The point on screen.
    232          * @param segmentInsteadWay Whether the segment (true) or only the whole
    233          *                                               way should be returned.
    234216         * @return      The primitive, that is nearest to the point p.
    235217         */
     218        public OsmPrimitive getNearest(Point p) {
     219                OsmPrimitive osm = getNearestNode(p);
     220                if (osm == null)
     221                        osm = getNearestWay(p);
     222                return osm;
     223        }
     224
     225        @Deprecated
    236226        public OsmPrimitive getNearest(Point p, boolean segmentInsteadWay) {
    237                 OsmPrimitive osm = getNearestNode(p);
    238                 if (osm == null && !segmentInsteadWay)
    239                         osm = getNearestWay(p);
    240                 if (osm == null)
    241                         osm = getNearestSegment(p);
    242                 return osm;
     227                return getNearest(p);
    243228        }
    244229
    245230        /**
    246231         * @return A list of all objects that are nearest to
    247          * the mouse. To do this, first the nearest object is
    248          * determined.
    249          *
    250          * If its a node, return all segments and
    251          * streets the node is part of, as well as all nodes
    252          * (with their segments and ways) with the same
    253          * location.
    254          *
    255          * If its a segment, return all ways this segment
    256          * belongs to as well as all segments that are between
    257          * the same nodes (in both direction) with all their ways.
     232         * the mouse.  Does a simple sequential scan on all the data.
    258233         *
    259234         * @return A collection of all items or <code>null</code>
     
    262237         */
    263238        public Collection<OsmPrimitive> getAllNearest(Point p) {
    264                 OsmPrimitive osm = getNearest(p, true);
    265                 if (osm == null)
    266                         return null;
    267                 Collection<OsmPrimitive> c = new HashSet<OsmPrimitive>();
    268                 c.add(osm);
    269                 if (osm instanceof Node) {
    270                         Node node = (Node)osm;
    271                         for (Node n : Main.ds.nodes)
    272                                 if (!n.deleted && n.coor.equals(node.coor))
    273                                         c.add(n);
    274                         for (Segment ls : Main.ds.segments)
    275                                 // segments never match nodes, so they are skipped by contains
    276                                 if (!ls.deleted && !ls.incomplete && (c.contains(ls.from) || c.contains(ls.to)))
    277                                         c.add(ls);
    278                 }
    279                 if (osm instanceof Segment) {
    280                         Segment line = (Segment)osm;
    281                         for (Segment ls : Main.ds.segments)
    282                                 if (!ls.deleted && ls.equalPlace(line))
    283                                         c.add(ls);
    284                 }
    285                 if (osm instanceof Node || osm instanceof Segment) {
     239                Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>();
    286240                        for (Way w : Main.ds.ways) {
    287                                 if (w.deleted)
     241                        if (w.deleted) continue;
     242                        Node lastN = null;
     243                        for (Node n : w.nodes) {
     244                                if (n.deleted) continue;
     245                                if (lastN == null) {
     246                                        lastN = n;
    288247                                        continue;
    289                                 for (Segment ls : w.segments) {
    290                                         if (!ls.deleted && !ls.incomplete && c.contains(ls)) {
    291                                                 c.add(w);
     248                                }
     249                                Point A = getPoint(lastN.eastNorth);
     250                                Point B = getPoint(n.eastNorth);
     251                                double c = A.distanceSq(B);
     252                                double a = p.distanceSq(B);
     253                                double b = p.distanceSq(A);
     254                                double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared
     255                                if (perDist < 100 && a < c+100 && b < c+100) {
     256                                        nearest.add(w);
    292257                                                break;
    293258                                        }
    294                                 }
     259                                lastN = n;
     260                                }
     261                        }
     262                for (Node n : Main.ds.nodes) {
     263                        if (!n.deleted && getPoint(n.eastNorth).distanceSq(p) < 100) {
     264                                nearest.add(n);
    295265                        }
    296266                }
    297                 return c;
     267                return nearest.isEmpty() ? null : nearest;
    298268        }
    299269
  • branch/0.5/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java

    r298 r329  
    55
    66import javax.swing.DefaultListCellRenderer;
     7import javax.swing.JLabel;
    78import javax.swing.JList;
     9import javax.swing.JTable;
     10import javax.swing.ListCellRenderer;
     11import javax.swing.table.DefaultTableCellRenderer;
     12import javax.swing.table.TableCellRenderer;
    813
    914import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1217/**
    1318 * Renderer that renders the objects from an OsmPrimitive as data.
     19 *
     20 * Can be used in lists and tables.
     21 *
    1422 * @author imi
     23 * @author Frederik Ramm <frederik@remote.org>
    1524 */
    16 public class OsmPrimitivRenderer extends DefaultListCellRenderer {
     25public class OsmPrimitivRenderer implements ListCellRenderer, TableCellRenderer {
    1726
     27        /**
     28         * NameVisitor provides proper names and icons for OsmPrimitives
     29         */
    1830        private NameVisitor visitor = new NameVisitor();
    1931
    20         @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    21                 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    22                 if (value != null) {
     32        /**
     33         * Default list cell renderer - delegate for ListCellRenderer operation
     34         */
     35        private DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer();
     36       
     37        /**
     38         * Default table cell renderer - delegate for TableCellRenderer operation
     39         */
     40        private DefaultTableCellRenderer defaultTableCellRenderer = new DefaultTableCellRenderer();
     41
     42        /**
     43         * Adapter method supporting the ListCellRenderer interface.
     44         */
     45        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
     46                Component def = defaultListCellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     47                return renderer(def, (OsmPrimitive) value);
     48        }
     49
     50        /**
     51         * Adapter method supporting the TableCellRenderer interface.
     52         */
     53        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     54                Component def = defaultTableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     55                return renderer(def, (OsmPrimitive) value);
     56        }
     57       
     58        /**
     59         * Internal method that stuffs information into the rendering component
     60         * provided that it's a kind of JLabel.
     61         * @param def the rendering component
     62         * @param value the OsmPrimtive to render
     63         * @return the modified rendering component
     64         */
     65        private Component renderer(Component def, OsmPrimitive value) {
     66                if (def != null && value != null && def instanceof JLabel) {
    2367                        ((OsmPrimitive)value).visit(visitor);
    24                         setText(visitor.name);
    25                         setIcon(visitor.icon);
     68                        ((JLabel)def).setText(visitor.name);
     69                        ((JLabel)def).setIcon(visitor.icon);
    2670                }
    27                 return this;
     71                return def;
    2872        }
     73       
    2974}
  • branch/0.5/src/org/openstreetmap/josm/gui/SelectionManager.java

    r298 r329  
    2525import org.openstreetmap.josm.data.osm.Node;
    2626import org.openstreetmap.josm.data.osm.OsmPrimitive;
    27 import org.openstreetmap.josm.data.osm.Segment;
    2827import org.openstreetmap.josm.data.osm.Way;
    2928
     
    282281         * modifier.
    283282         * @param alt Whether the alt key was pressed, which means select all objects
    284          *              that are touched, instead those which are completly covered. Also
    285          *              select whole ways instead of segments.
     283         *              that are touched, instead those which are completly covered.
    286284         */
    287285        public Collection<OsmPrimitive> getObjectsInRectangle(Rectangle r, boolean alt) {
     
    293291
    294292                if (clicked) {
    295                         OsmPrimitive osm = nc.getNearest(center, alt);
     293                        OsmPrimitive osm = nc.getNearest(center);
    296294                        if (osm != null)
    297295                                selection.add(osm);
     
    303301                        }
    304302                       
    305                         // pending segments
    306                         for (Segment s : Main.ds.segments)
    307                                 if (!s.deleted && rectangleContainSegment(r, alt, s))
    308                                         selection.add(s);
    309 
    310303                        // ways
    311304                        for (Way w : Main.ds.ways) {
    312                                 if (w.deleted)
    313                                         continue;
    314                                 boolean someSelectableSegment = false;
    315                                 boolean wholeWaySelected = true;
    316                                 for (Segment s : w.segments) {
    317                                         if (s.incomplete)
     305                                if (w.deleted || w.nodes.isEmpty())
    318306                                                continue;
    319                                         someSelectableSegment = true;
    320                                         if (!rectangleContainSegment(r, alt, s)) {
    321                                                 wholeWaySelected = false;
     307                                if (alt) {
     308                                        for (Node n : w.nodes) {
     309                                                if (r.contains(nc.getPoint(n.eastNorth))) {
     310                                                        selection.add(w);
    322311                                                break;
    323312                                        }
    324313                                }
    325                                 if (someSelectableSegment && wholeWaySelected)
    326                                         selection.add(w);
     314                                } else {
     315                                        boolean allIn = true;
     316                                        for (Node n : w.nodes) {
     317                                                if (!r.contains(nc.getPoint(n.eastNorth))) {
     318                                                        allIn = false;
     319                                                        break;
    327320                        }
    328321                }
     322                                        if (allIn) selection.add(w);
     323                                }
     324        }
     325                }
    329326                return selection;
    330         }
    331 
    332         /**
    333          * Decide whether the segment is in the rectangle Return
    334          * <code>true</code>, if it is in or false if not.
    335          *
    336          * @param r                     The rectangle, in which the segment has to be.
    337          * @param alt           Whether user pressed the Alt key
    338          * @param ls            The segment.
    339          * @return <code>true</code>, if the Segment was added to the selection.
    340          */
    341         private boolean rectangleContainSegment(Rectangle r, boolean alt, Segment ls) {
    342                 if (ls.incomplete)
    343                         return false;
    344                 if (alt) {
    345                         Point p1 = nc.getPoint(ls.from.eastNorth);
    346                         Point p2 = nc.getPoint(ls.to.eastNorth);
    347                         if (r.intersectsLine(p1.x, p1.y, p2.x, p2.y))
    348                                 return true;
    349                 } else {
    350                         if (r.contains(nc.getPoint(ls.from.eastNorth))
    351                                         && r.contains(nc.getPoint(ls.to.eastNorth)))
    352                                 return true;
    353                 }
    354                 return false;
    355327        }
    356328       
  • branch/0.5/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r301 r329  
    3333import org.openstreetmap.josm.data.SelectionChangedListener;
    3434import org.openstreetmap.josm.data.osm.DataSet;
     35import org.openstreetmap.josm.data.osm.Relation;
     36import org.openstreetmap.josm.data.osm.RelationMember;
    3537import org.openstreetmap.josm.data.osm.Node;
    3638import org.openstreetmap.josm.data.osm.OsmPrimitive;
    37 import org.openstreetmap.josm.data.osm.Segment;
    3839import org.openstreetmap.josm.data.osm.Way;
    3940import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
     
    8889                add(buttonPanel, BorderLayout.SOUTH);
    8990
    90                 DataSet.listeners.add(new SelectionChangedListener(){
     91                DataSet.selListeners.add(new SelectionChangedListener(){
    9192                        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    9293                                displaylist.clearSelection();
     
    130131                                model.addElement(osm);
    131132                for (OsmPrimitive osm : this.conflicts.keySet())
    132                         if (osm instanceof Segment)
    133                                 model.addElement(osm);
    134                 for (OsmPrimitive osm : this.conflicts.keySet())
    135133                        if (osm instanceof Way)
    136134                                model.addElement(osm);
     
    155153                                g.drawRect(p.x-1, p.y-1, 2, 2);
    156154                        }
    157                         public void visit(Segment ls) {
    158                                 if (ls.incomplete)
    159                                         return;
    160                                 Point p1 = nc.getPoint(ls.from.eastNorth);
    161                                 Point p2 = nc.getPoint(ls.to.eastNorth);
     155                        public void visit(Node n1, Node n2) {
     156                                Point p1 = nc.getPoint(n1.eastNorth);
     157                                Point p2 = nc.getPoint(n2.eastNorth);
    162158                                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    163159                        }
    164160                        public void visit(Way w) {
    165                                 for (Segment ls : w.segments)
    166                                         visit(ls);
     161                                Node lastN = null;
     162                                for (Node n : w.nodes) {
     163                                        if (lastN == null) {
     164                                                lastN = n;
     165                                                continue;
     166                                        }
     167                                        visit(lastN, n);
     168                                        lastN = n;
     169                                }
     170                        }
     171                        public void visit(Relation e) {
     172                                for (RelationMember em : e.members)
     173                                        em.member.visit(this);
    167174                        }
    168175                };
  • branch/0.5/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java

    r298 r329  
    144144                revertButton.putClientProperty("help", "Dialog/History/Revert");
    145145               
    146                 DataSet.listeners.add(this);
     146                DataSet.selListeners.add(this);
    147147        }
    148148
  • branch/0.5/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r301 r329  
    4848import org.openstreetmap.josm.data.osm.DataSet;
    4949import org.openstreetmap.josm.data.osm.OsmPrimitive;
     50import org.openstreetmap.josm.data.osm.Relation;
     51import org.openstreetmap.josm.data.osm.RelationMember;
     52import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
    5053import org.openstreetmap.josm.gui.MapFrame;
    5154import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
     55import org.openstreetmap.josm.gui.tagging.ForwardActionListener;
    5256import org.openstreetmap.josm.gui.tagging.TaggingCellRenderer;
    53 import org.openstreetmap.josm.gui.tagging.ForwardActionListener;
    5457import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    5558import org.openstreetmap.josm.tools.AutoCompleteComboBox;
     
    7780
    7881        /**
     82         * Used to display relation names in the membership table
     83         */
     84        private NameVisitor nameVisitor = new NameVisitor();
     85       
     86        /**
    7987         * Watches for double clicks and from editing or new property, depending on the
    8088         * location, the click was.
     
    8593                        if (e.getClickCount() < 2)
    8694                                return;
    87                         if (e.getSource() instanceof JScrollPane)
    88                                 add();
    89                         else {
     95       
     96                        if (e.getSource() == propertyTable)
     97                        {
    9098                                int row = propertyTable.rowAtPoint(e.getPoint());
    91                                 edit(row);
    92                         }
    93                 }
    94         }
    95 
    96         /**
    97          * Edit the value in the table row
    98          * @param row   The row of the table, from which the value is edited.
    99          */
    100         void edit(int row) {
    101                 String key = data.getValueAt(row, 0).toString();
     99                                if (row > -1) {
     100                                        propertyEdit(row);
     101                                        return;
     102                        }
     103                        } else if (e.getSource() == membershipTable) {
     104                                int row = membershipTable.rowAtPoint(e.getPoint());
     105                                if (row > -1) {
     106                                        membershipEdit(row);
     107                                        return;
     108                                }
     109                        }
     110                        add();
     111                }
     112        }
     113
     114        /**
     115         * Edit the value in the properties table row
     116         * @param row The row of the table from which the value is edited.
     117         */
     118        void propertyEdit(int row) {
     119                String key = propertyData.getValueAt(row, 0).toString();
    102120                Collection<OsmPrimitive> sel = Main.ds.getSelected();
    103121                if (sel.isEmpty()) {
     
    118136                p.add(keyField, GBC.eol().fill(GBC.HORIZONTAL));
    119137                               
    120                 final JComboBox combo = (JComboBox)data.getValueAt(row, 1);
     138                final JTextField valueField = new JTextField((String)propertyData.getValueAt(row, 1));
    121139                p.add(new JLabel(tr("Value")), GBC.std());
    122140                p.add(Box.createHorizontalStrut(10), GBC.std());
    123                 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL));
     141                p.add(valueField, GBC.eol().fill(GBC.HORIZONTAL));
    124142
    125143                final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){
    126144                        @Override public void selectInitialValue() {
    127                                 combo.requestFocusInWindow();
    128                                 combo.getEditor().selectAll();
     145                                valueField.requestFocusInWindow();
     146                                valueField.selectAll();
    129147                        }
    130148                };
    131149                final JDialog dlg = optionPane.createDialog(Main.parent, tr("Change values?"));
    132                 combo.getEditor().addActionListener(new ActionListener(){
     150                valueField.addActionListener(new ActionListener(){
    133151                        public void actionPerformed(ActionEvent e) {
    134152                                optionPane.setValue(JOptionPane.OK_OPTION);
     
    136154                        }
    137155                });
    138                 String oldComboEntry = combo.getEditor().getItem().toString();
    139156                dlg.setVisible(true);
    140157
     
    142159                if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE ||
    143160                                (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) {
    144                         combo.getEditor().setItem(oldComboEntry);
    145                         return;
    146                 }
    147 
    148                 String value = combo.getEditor().getItem().toString();
     161                        return;
     162                }
     163
     164                String value = valueField.getText();
    149165                if (value.equals(tr("<different>")))
    150166                        return;
     
    164180                }
    165181
    166                 if (!key.equals(newkey) || value == null)
    167182                        selectionChanged(sel); // update whole table
    168 
    169183                Main.parent.repaint(); // repaint all - drawing could have been changed
     184        }
     185
     186        /**
     187         * This simply fires up an relation editor for the relation shown; everything else
     188         * is the editor's business.
     189         *
     190         * @param row
     191         */
     192        void membershipEdit(int row) { 
     193                final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0));
     194                editor.setVisible(true);
    170195        }
    171196
     
    197222                        }
    198223                }
    199                 for (int i = 0; i < data.getRowCount(); ++i)
    200                         allData.remove(data.getValueAt(i, 0));
     224                for (int i = 0; i < propertyData.getRowCount(); ++i)
     225                        allData.remove(propertyData.getValueAt(i, 0));
    201226                final AutoCompleteComboBox keys = new AutoCompleteComboBox();
    202227                keys.setPossibleItems(allData.keySet());
     
    249274         */
    250275        private void delete(int row) {
    251                 String key = data.getValueAt(row, 0).toString();
     276                String key = propertyData.getValueAt(row, 0).toString();
    252277                Collection<OsmPrimitive> sel = Main.ds.getSelected();
    253278                Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null));
     
    258283         * The property data.
    259284         */
    260         private final DefaultTableModel data = new DefaultTableModel(){
     285        private final DefaultTableModel propertyData = new DefaultTableModel() {
    261286                @Override public boolean isCellEditable(int row, int column) {
    262287                        return false;
    263288                }
    264289                @Override public Class<?> getColumnClass(int columnIndex) {
    265                         return columnIndex == 1 ? JComboBox.class : String.class;
     290                        return String.class;
    266291                }
    267292        };
     293
     294        /**
     295         * The membership data.
     296         */
     297        private final DefaultTableModel membershipData = new DefaultTableModel() {
     298                @Override public boolean isCellEditable(int row, int column) {
     299                        return false;
     300                }
     301                @Override public Class<?> getColumnClass(int columnIndex) {
     302                        return columnIndex == 1 ? Relation.class : String.class;
     303                }
     304        };
     305       
    268306        /**
    269307         * The properties list.
    270308         */
    271         private final JTable propertyTable = new JTable(data);
     309        private final JTable propertyTable = new JTable(propertyData);
     310        private final JTable membershipTable = new JTable(membershipData);
     311
    272312        public JComboBox taggingPresets = new JComboBox();
    273313
     
    277317         */
    278318        public PropertiesDialog(MapFrame mapFrame) {
    279                 super(tr("Properties"), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150);
     319                super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150);
    280320
    281321                if (TaggingPresetPreference.taggingPresets.size() > 0) {
     
    300340                taggingPresets.setRenderer(new TaggingCellRenderer());
    301341
    302                 data.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
     342                // setting up the properties table
     343               
     344                propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
    303345                propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    304                 propertyTable.setDefaultRenderer(JComboBox.class, new DefaultTableCellRenderer(){
     346       
     347                propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){
    305348                        @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    306349                                Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    307350                                if (c instanceof JLabel) {
    308                                         String str = ((JComboBox)value).getEditor().getItem().toString();
     351                                        String str = (String) value;
    309352                                        ((JLabel)c).setText(str);
    310353                                        if (str.equals(tr("<different>")))
     
    314357                        }
    315358                });
    316                 propertyTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer(){
     359               
     360                // setting up the membership table
     361               
     362                membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role")});
     363                membershipTable.setRowSelectionAllowed(false);
     364               
     365                membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
    317366                        @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    318                                 return super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
     367                                Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
     368                                if (c instanceof JLabel) {
     369                                        nameVisitor.visit((Relation)value);
     370                                        ((JLabel)c).setText(nameVisitor.name);
     371                                }
     372                                return c;
    319373                        }
    320374                });
     375               
     376                // combine both tables and wrap them in a scrollPane
     377                JPanel bothTables = new JPanel();
     378                bothTables.setLayout(new GridBagLayout());
     379                bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
     380                bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH));
     381                bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
     382                bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH));
     383               
    321384                DblClickWatch dblClickWatch = new DblClickWatch();
    322385                propertyTable.addMouseListener(dblClickWatch);
    323                 JScrollPane scrollPane = new JScrollPane(propertyTable);
     386                membershipTable.addMouseListener(dblClickWatch);
     387                JScrollPane scrollPane = new JScrollPane(bothTables);
    324388                scrollPane.addMouseListener(dblClickWatch);
    325389                add(scrollPane, BorderLayout.CENTER);
     
    335399                                                JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit."));
    336400                                        else
    337                                                 edit(sel);
     401                                                propertyEdit(sel);
    338402                                } else if (e.getActionCommand().equals("Delete")) {
    339403                                        if (sel == -1)
     
    344408                        }
    345409                };
     410               
    346411                buttonPanel.add(createButton(marktr("Add"),tr("Add a new key/value pair to all objects"), KeyEvent.VK_A, buttonAction));
    347412                buttonPanel.add(createButton(marktr("Edit"),tr( "Edit the value of the selected key for all objects"), KeyEvent.VK_E, buttonAction));
     
    349414                add(buttonPanel, BorderLayout.SOUTH);
    350415
    351                 DataSet.listeners.add(this);
     416                DataSet.selListeners.add(this);
    352417        }
    353418
     
    375440                if (propertyTable.getCellEditor() != null)
    376441                        propertyTable.getCellEditor().cancelCellEditing();
    377                 data.setRowCount(0);
     442
     443                // re-load property data
     444               
     445                propertyData.setRowCount(0);
    378446
    379447                Map<String, Integer> valueCount = new HashMap<String, Integer>();
     
    391459                }
    392460                for (Entry<String, Collection<String>> e : props.entrySet()) {
    393                         JComboBox value = new JComboBox(e.getValue().toArray());
    394                         value.setEditable(true);
    395                         value.getEditor().setItem(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next());
    396                         data.addRow(new Object[]{e.getKey(), value});
     461                        String value=(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next());
     462                        propertyData.addRow(new Object[]{e.getKey(), value});
     463                }
     464               
     465                // re-load membership data
     466                // this is rather expensive since we have to walk through all members of all existing relationships.
     467                // could use back references here for speed if necessary.
     468               
     469                membershipData.setRowCount(0);
     470               
     471                Map<Relation, Integer> valueCountM = new HashMap<Relation, Integer>();
     472                TreeMap<Relation, Collection<String>> roles = new TreeMap<Relation, Collection<String>>();
     473                for (Relation r : Main.ds.relations) {
     474                        for (RelationMember m : r.members) {
     475                                if (newSelection.contains(m.member)) {
     476                                        Collection<String> value = roles.get(r);
     477                                        if (value == null) {
     478                                                value = new TreeSet<String>();
     479                                                roles.put(r, value);
     480                                        }
     481                                        value.add(m.role);
     482                                        valueCountM.put(r, valueCount.containsKey(r) ? valueCount.get(r)+1 : 1);
     483                                }
     484                        }
     485                }
     486               
     487                for (Entry<Relation, Collection<String>> e : roles.entrySet()) {
     488                        //JComboBox value = new JComboBox(e.getValue().toArray());
     489                        //value.setEditable(true);
     490                        //value.getEditor().setItem(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next());
     491                        String value = e.getValue().size() > 1 || valueCountM.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next();
     492                        membershipData.addRow(new Object[]{e.getKey(), value});
    397493                }
    398494        }
  • branch/0.5/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r298 r329  
    8080                selectionChanged(Main.ds.getSelected());
    8181
    82                 DataSet.listeners.add(this);
     82                DataSet.selListeners.add(this);
    8383        }
    8484
  • branch/0.5/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r298 r329  
    5454                selectionChanged(Main.ds.getSelected());
    5555               
    56                 DataSet.listeners.add(this);
     56                DataSet.selListeners.add(this);
    5757        }
    5858
  • branch/0.5/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r312 r329  
    3434import org.openstreetmap.josm.data.osm.DataSet;
    3535import org.openstreetmap.josm.data.osm.DataSource;
     36import org.openstreetmap.josm.data.osm.Relation;
    3637import org.openstreetmap.josm.data.osm.Node;
    3738import org.openstreetmap.josm.data.osm.OsmPrimitive;
    38 import org.openstreetmap.josm.data.osm.Segment;
    3939import org.openstreetmap.josm.data.osm.Way;
    4040import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    6060                public final int[] normal = new int[3];         
    6161                public final int[] deleted = new int[3];
    62                 public final String[] names = {"node", "segment", "way"};
     62                public final String[] names = {"node", "way", "relation"};
    6363
    6464                private void inc(final OsmPrimitive osm, final int i) {
     
    7272                }
    7373
    74                 public void visit(final Segment ls) {
    75                         inc(ls, 1);
    76                 }
    77 
    7874                public void visit(final Way w) {
     75                        inc(w, 1);
     76                }
     77                public void visit(final Relation w) {
    7978                        inc(w, 2);
    8079                }
     
    133132         * Draw all primitives in this layer but do not draw modified ones (they
    134133         * are drawn by the edit layer).
    135          * Draw nodes last to overlap the segments they belong to.
     134         * Draw nodes last to overlap the ways they belong to.
    136135         */
    137136        @Override public void paint(final Graphics g, final MapView mv) {
     
    163162                String tool = "";
    164163                tool += undeletedSize(data.nodes)+" "+trn("node", "nodes", undeletedSize(data.nodes))+", ";
    165                 tool += undeletedSize(data.segments)+" "+trn("segment", "segments", undeletedSize(data.segments))+", ";
    166164                tool += undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways));
    167165                if (associatedFile != null)
     
    222220                        for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();)
    223221                                cleanIterator(it, processedSet);
    224                         for (final Iterator<Segment> it = data.segments.iterator(); it.hasNext();)
    225                                 cleanIterator(it, processedSet);
    226222                        for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();)
    227223                                cleanIterator(it, processedSet);
  • branch/0.5/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java

    r298 r329  
    3838import org.openstreetmap.josm.data.osm.DataSet;
    3939import org.openstreetmap.josm.data.osm.Node;
    40 import org.openstreetmap.josm.data.osm.Segment;
    4140import org.openstreetmap.josm.data.osm.Way;
    4241import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    7170                        for (Collection<GpsPoint> c : data) {
    7271                                Way w = new Way();
    73                                 Node start = null;
    7472                                for (GpsPoint p : c) {
    75                                         Node end = new Node(p.latlon);
    76                                         ds.nodes.add(end);
    77                                         if (start != null) {
    78                                                 Segment segment = new Segment(start,end);
    79                                                 w.segments.add(segment);
    80                                                 ds.segments.add(segment);
    81                                         }
    82                                         start = end;
     73                                        Node n = new Node(p.latlon);
     74                                        ds.nodes.add(n);
     75                                        w.nodes.add(n);
    8376                                }
    8477                                ds.ways.add(w);
Note: See TracChangeset for help on using the changeset viewer.