Changeset 7534 in josm for trunk


Ignore:
Timestamp:
2014-09-14T17:11:14+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10511 - add unit test

Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r7052 r7534  
    4848
    4949/**
    50  * Join Areas (i.e. closed ways and multipolygons)
     50 * Join Areas (i.e. closed ways and multipolygons).
     51 * @since 2575
    5152 */
    5253public class JoinAreasAction extends JosmAction {
     
    5758
    5859    /**
    59      * This helper class describes join ares action result.
     60     * This helper class describes join areas action result.
    6061     * @author viesturs
    61      *
    6262     */
    6363    public static class JoinAreasResult {
     
    394394
    395395    /**
    396      * Gets called whenever the shortcut is pressed or the menu entry is selected
    397      * Checks whether the selected objects are suitable to join and joins them if so
     396     * Gets called whenever the shortcut is pressed or the menu entry is selected.
     397     * Checks whether the selected objects are suitable to join and joins them if so.
    398398     */
    399399    @Override
    400400    public void actionPerformed(ActionEvent e) {
    401         LinkedList<Way> ways = new LinkedList<>(Main.main.getCurrentDataSet().getSelectedWays());
     401        join(Main.main.getCurrentDataSet().getSelectedWays());
     402    }
     403
     404    /**
     405     * Joins the given ways.
     406     * @param ways Ways to join
     407     * @since 7534
     408     */
     409    public void join(Collection<Way> ways) {
    402410        addedRelations.clear();
    403411
     
    471479                }
    472480                DataSet ds = Main.main.getCurrentDataSet();
    473                 ds.setSelected(allWays);
    474                 Main.map.mapView.repaint();
     481                if (ds != null) {
     482                    ds.setSelected(allWays);
     483                    Main.map.mapView.repaint();
     484                }
    475485            } else {
    476486                new Notification(
     
    479489                        .show();
    480490            }
    481         }
    482         catch (UserCancelException exception) {
     491        } catch (UserCancelException exception) {
    483492            //revert changes
    484493            //FIXME: this is dirty hack
     
    915924    /**
    916925     * This is a method splits way into smaller parts, using the prepared nodes list as split points.
    917      * Uses  SplitWayAction.splitWay for the heavy lifting.
     926     * Uses {@link SplitWayAction#splitWay} for the heavy lifting.
    918927     * @return list of split ways (or original ways if no splitting is done).
    919928     */
     
    924933
    925934        if (chunks.size() > 1) {
    926             SplitWayResult split = SplitWayAction.splitWay(Main.main.getEditLayer(), way, chunks, Collections.<OsmPrimitive>emptyList());
     935            SplitWayResult split = SplitWayAction.splitWay(getEditLayer(), way, chunks, Collections.<OsmPrimitive>emptyList());
    927936
    928937            //execute the command, we need the results
     
    12541263     * @return list of polygons, or null if too complex relation encountered.
    12551264     */
    1256     private List<Multipolygon> collectMultipolygons(List<Way> selectedWays) {
     1265    private List<Multipolygon> collectMultipolygons(Collection<Way> selectedWays) {
    12571266
    12581267        List<Multipolygon> result = new ArrayList<>();
     
    13801389
    13811390    /**
    1382      * Removes a given OsmPrimitive from all relations
     1391     * Removes a given OsmPrimitive from all relations.
    13831392     * @param osm Element to remove from all relations
    13841393     * @return List of relations with roles the primitives was part of
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r6890 r7534  
    8484            putValue("toolbar", toolbarId);
    8585        }
    86         if (registerInToolbar) {
     86        if (registerInToolbar && Main.toolbar != null) {
    8787            Main.toolbar.register(this);
    8888        }
     
    205205     */
    206206    protected static OsmDataLayer getEditLayer() {
    207         return Main.main.getEditLayer();
     207        return Main.main != null ? Main.main.getEditLayer() : null;
    208208    }
    209209
     
    214214     */
    215215    protected static DataSet getCurrentDataSet() {
    216         return Main.main.getCurrentDataSet();
     216        return Main.main != null ? Main.main.getCurrentDataSet() : null;
    217217    }
    218218
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r7005 r7534  
    358358            newWays.add(wayToAdd);
    359359            wayToAdd.setNodes(chunkIt.next());
    360             commandList.add(new AddCommand(layer,wayToAdd));
     360            commandList.add(new AddCommand(layer, wayToAdd));
    361361            newSelection.add(wayToAdd);
    362 
    363362        }
    364363        boolean warnmerole = false;
     
    381380                if (rm.isWay() && rm.getMember() == way) {
    382381                    boolean insert = true;
    383                     if ("restriction".equals(type))
    384                     {
     382                    if ("restriction".equals(type)) {
    385383                        /* this code assumes the restriction is correct. No real error checking done */
    386384                        String role = rm.getRole();
    387                         if("from".equals(role) || "to".equals(role))
    388                         {
     385                        if("from".equals(role) || "to".equals(role)) {
    389386                            OsmPrimitive via = null;
    390387                            for (RelationMember rmv : r.getMembers()) {
    391                                 if("via".equals(rmv.getRole())){
     388                                if ("via".equals(rmv.getRole())){
    392389                                    via = rmv.getMember();
    393390                                }
    394391                            }
    395392                            List<Node> nodes = new ArrayList<>();
    396                             if(via != null) {
    397                                 if(via instanceof Node) {
     393                            if (via != null) {
     394                                if (via instanceof Node) {
    398395                                    nodes.add((Node)via);
    399                                 } else if(via instanceof Way) {
     396                                } else if (via instanceof Way) {
    400397                                    nodes.add(((Way)via).lastNode());
    401398                                    nodes.add(((Way)via).firstNode());
     
    403400                            }
    404401                            Way res = null;
    405                             for(Node n : nodes) {
     402                            for (Node n : nodes) {
    406403                                if(changedWay.isFirstLastNode(n)) {
    407404                                    res = way;
    408405                                }
    409406                            }
    410                             if(res == null)
    411                             {
     407                            if (res == null) {
    412408                                for (Way wayToAdd : newWays) {
    413409                                    for(Node n : nodes) {
     
    417413                                    }
    418414                                }
    419                                 if(res != null)
    420                                 {
     415                                if (res != null) {
    421416                                    if (c == null) {
    422417                                        c = new Relation(r);
     
    429424                                insert = false;
    430425                            }
    431                         }
    432                         else if(!"via".equals(role)) {
     426                        } else if(!"via".equals(role)) {
    433427                            warnme = true;
    434428                        }
    435                     }
    436                     else if (!("route".equals(type)) && !("multipolygon".equals(type))) {
     429                    } else if (!("route".equals(type)) && !("multipolygon".equals(type))) {
    437430                        warnme = true;
    438431                    }
     
    441434                    }
    442435
    443                     if(insert)
    444                     {
     436                    if (insert) {
    445437                        if (rm.hasRole() && !nowarnroles.contains(rm.getRole())) {
    446438                            warnmerole = true;
     
    484476                    }
    485477                }
    486                 i_c++; i_r++;
     478                i_c++;
     479                i_r++;
    487480            }
    488481
    489482            if (c != null) {
    490                 commandList.add(new ChangeCommand(layer,r, c));
     483                commandList.add(new ChangeCommand(layer, r, c));
    491484            }
    492485        }
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r7484 r7534  
    923923
    924924    protected void refreshTitle() {
    925         boolean dirty = editLayer != null && (editLayer.requiresSaveToFile() || (editLayer.requiresUploadToServer() && !editLayer.isUploadDiscouraged()));
    926         ((JFrame) Main.parent).setTitle((dirty ? "* " : "") + tr("Java OpenStreetMap Editor"));
    927         ((JFrame) Main.parent).getRootPane().putClientProperty("Window.documentModified", dirty);
     925        if (Main.parent != null) {
     926            boolean dirty = editLayer != null &&
     927                    (editLayer.requiresSaveToFile() || (editLayer.requiresUploadToServer() && !editLayer.isUploadDiscouraged()));
     928            ((JFrame) Main.parent).setTitle((dirty ? "* " : "") + tr("Java OpenStreetMap Editor"));
     929            ((JFrame) Main.parent).getRootPane().putClientProperty("Window.documentModified", dirty);
     930        }
    928931    }
    929932
Note: See TracChangeset for help on using the changeset viewer.