Changeset 9674 in josm for trunk/src


Ignore:
Timestamp:
2016-01-29T21:47:58+01:00 (9 years ago)
Author:
Don-vip
Message:

code style (checkstyle, sonar)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r9668 r9674  
    55
    66import java.awt.Component;
     7import java.awt.Rectangle;
    78import java.awt.event.ActionEvent;
    89import java.awt.event.ActionListener;
    910import java.awt.event.KeyEvent;
    10 import java.awt.Rectangle;
     11import java.util.Collections;
    1112import java.util.List;
    1213
     
    1920import org.openstreetmap.josm.Main;
    2021import org.openstreetmap.josm.data.osm.Relation;
    21 import org.openstreetmap.josm.gui.layer.Layer;
    22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    23 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2422import org.openstreetmap.josm.gui.DefaultNameFormatter;
    2523import org.openstreetmap.josm.gui.MapView;
    2624import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    2725import org.openstreetmap.josm.gui.SideButton;
     26import org.openstreetmap.josm.gui.layer.Layer;
     27import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     28import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2829import org.openstreetmap.josm.tools.Shortcut;
    2930
     
    3132 * Action for accessing recent relations.
    3233 */
    33 public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener{
     34public class RecentRelationsAction implements ActionListener, CommandQueueListener, LayerChangeListener {
    3435
    3536    private final SideButton editButton;
     
    3940    /**
    4041     * Constructs a new <code>RecentRelationsAction</code>.
     42     * @param editButton edit button
    4143     */
    4244    public RecentRelationsAction(SideButton editButton) {
     
    6163    }
    6264
     65    /**
     66     * Enables arrow button.
     67     */
    6368    public void enableArrow() {
    6469        arrow.setEnabled(getLastRelation() != null);
    6570    }
    6671
     72    /**
     73     * Returns the last relation.
     74     * @return the last relation
     75     */
    6776    public static Relation getLastRelation() {
    6877        List<Relation> recentRelations = getRecentRelationsOnActiveLayer();
    69         if (recentRelations == null || recentRelations.isEmpty()) return null;
     78        if (recentRelations == null || recentRelations.isEmpty())
     79            return null;
    7080        for (Relation relation: recentRelations) {
    71             if (!isRelationListable(relation)) continue;
     81            if (!isRelationListable(relation))
     82                continue;
    7283            return relation;
    7384        }
     
    7586    }
    7687
     88    /**
     89     * Determines if the given relation is listable in last relations.
     90     * @param relation relation
     91     * @return {@code true} if relation is non null, not deleted, and in current dataset
     92     */
    7793    public static boolean isRelationListable(Relation relation) {
    7894        return relation != null &&
     
    106122    }
    107123
     124    /**
     125     * Returns the list of recent relations on active layer.
     126     * @return the list of recent relations on active layer
     127     */
    108128    public static List<Relation> getRecentRelationsOnActiveLayer() {
    109         if (Main.map == null || Main.map.mapView == null) return null;
    110         Layer activeLayer = Main.map.mapView.getActiveLayer();
     129        if (!Main.isDisplayingMapView())
     130            return Collections.emptyList();
     131        Layer activeLayer = Main.main.getActiveLayer();
    111132        if (!(activeLayer instanceof OsmDataLayer)) {
    112             return null;
     133            return Collections.emptyList();
    113134        } else {
    114135            return ((OsmDataLayer) activeLayer).getRecentRelations();
     
    117138
    118139    protected static class RecentRelationsPopupMenu extends JPopupMenu {
    119         public static void launch(Component parent, KeyStroke keystroke) {
    120             List<Relation> recentRelations = getRecentRelationsOnActiveLayer();
    121             JPopupMenu menu = new RecentRelationsPopupMenu(recentRelations, keystroke);
    122             Rectangle r = parent.getBounds();
    123             menu.show(parent, r.x, r.y + r.height);
    124         }
    125 
    126140        /**
    127          * Constructs a new {@code SearchPopupMenu}.
     141         * Constructs a new {@code RecentRelationsPopupMenu}.
     142         * @param recentRelations list of recent relations
     143         * @param keystroke key stroke for the first menu item
    128144         */
    129145        public RecentRelationsPopupMenu(List<Relation> recentRelations, KeyStroke keystroke) {
    130146            boolean first = true;
    131147            for (Relation relation: recentRelations) {
    132                 if (!isRelationListable(relation)) continue;
     148                if (!isRelationListable(relation))
     149                    continue;
    133150                JMenuItem menuItem = new RecentRelationsMenuItem(relation);
    134151                if (first) {
     
    138155                add(menuItem);
    139156            }
     157        }
     158
     159        public static void launch(Component parent, KeyStroke keystroke) {
     160            Rectangle r = parent.getBounds();
     161            new RecentRelationsPopupMenu(getRecentRelationsOnActiveLayer(), keystroke).show(parent, r.x, r.y + r.height);
    140162        }
    141163    }
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r9670 r9674  
    2626import java.util.HashSet;
    2727import java.util.LinkedHashMap;
    28 import java.util.LinkedList;
    2928import java.util.List;
    3029import java.util.Map;
     
    426425
    427426    /**
    428      * merges the primitives in dataset <code>from</code> into the dataset of
    429      * this layer
     427     * merges the primitives in dataset <code>from</code> into the dataset of this layer
    430428     *
    431429     * @param from  the source data set
     
    437435            visitor.merge(progressMonitor);
    438436        } catch (DataIntegrityProblemException e) {
     437            Main.error(e);
    439438            JOptionPane.showMessageDialog(
    440439                    Main.parent,
     
    747746        for (String key : possibleKeys) {
    748747            String value = p.get(key);
    749             if (value != null) {
    750                 // Sanity checks
    751                 if (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value)) {
    752                     wpt.put(gpxKey, value);
    753                     break;
    754                 }
     748            // Sanity checks
     749            if (value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value))) {
     750                wpt.put(gpxKey, value);
     751                break;
    755752            }
    756753        }
     
    779776        @Override
    780777        public void actionPerformed(ActionEvent e) {
    781             final GpxData data = toGpxData();
    782             final GpxLayer gpxLayer = new GpxLayer(data, tr("Converted from: {0}", getName()));
     778            final GpxData gpxData = toGpxData();
     779            final GpxLayer gpxLayer = new GpxLayer(gpxData, tr("Converted from: {0}", getName()));
    783780            if (getAssociatedFile() != null) {
    784781                final String filename = getAssociatedFile().getName().replaceAll(Pattern.quote(".gpx.osm") + "$", "") + ".gpx";
     
    786783            }
    787784            Main.main.addLayer(gpxLayer);
    788             if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
    789                 Main.main.addLayer(new MarkerLayer(data, tr("Converted from: {0}", getName()), null, gpxLayer));
     785            if (Main.pref.getBoolean("marker.makeautomarkers", true) && !gpxData.waypoints.isEmpty()) {
     786                Main.main.addLayer(new MarkerLayer(gpxData, tr("Converted from: {0}", getName()), null, gpxLayer));
    790787            }
    791788            Main.main.removeLayer(OsmDataLayer.this);
     
    804801            return true;
    805802
    806         boolean layer_bounds_point = false;
     803        boolean layerBoundsPoint = false;
    807804        for (DataSource src : this.data.dataSources) {
    808805            if (src.bounds.contains(coor)) {
    809                 layer_bounds_point = true;
     806                layerBoundsPoint = true;
    810807                break;
    811808            }
    812809        }
    813         return layer_bounds_point;
     810        return layerBoundsPoint;
    814811    }
    815812
     
    942939    @Override
    943940    public boolean checkSaveConditions() {
    944         if (isDataSetEmpty()) {
    945             if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
    946                 @Override
    947                 public Integer call() {
    948                     ExtendedDialog dialog = new ExtendedDialog(
    949                             Main.parent,
    950                             tr("Empty document"),
    951                             new String[] {tr("Save anyway"), tr("Cancel")}
    952                     );
    953                     dialog.setContent(tr("The document contains no data."));
    954                     dialog.setButtonIcons(new String[] {"save", "cancel"});
    955                     return dialog.showDialog().getValue();
    956                 }
    957             })) {
    958                 return false;
    959             }
    960         }
    961 
    962         ConflictCollection conflicts = getConflicts();
    963         if (conflicts != null && !conflicts.isEmpty()) {
    964             if (1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
    965                 @Override
    966                 public Integer call() {
    967                     ExtendedDialog dialog = new ExtendedDialog(
    968                             Main.parent,
    969                             /* I18N: Display title of the window showing conflicts */
    970                             tr("Conflicts"),
    971                             new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}
    972                     );
    973                     dialog.setContent(
    974                             tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"));
    975                     dialog.setButtonIcons(new String[] {"save", "cancel"});
    976                     return dialog.showDialog().getValue();
    977                 }
    978             })) {
    979                 return false;
    980             }
     941        if (isDataSetEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
     942            @Override
     943            public Integer call() {
     944                ExtendedDialog dialog = new ExtendedDialog(
     945                        Main.parent,
     946                        tr("Empty document"),
     947                        new String[] {tr("Save anyway"), tr("Cancel")}
     948                );
     949                dialog.setContent(tr("The document contains no data."));
     950                dialog.setButtonIcons(new String[] {"save", "cancel"});
     951                return dialog.showDialog().getValue();
     952            }
     953        })) {
     954            return false;
     955        }
     956
     957        ConflictCollection conflictsCol = getConflicts();
     958        if (conflictsCol != null && !conflictsCol.isEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() {
     959            @Override
     960            public Integer call() {
     961                ExtendedDialog dialog = new ExtendedDialog(
     962                        Main.parent,
     963                        /* I18N: Display title of the window showing conflicts */
     964                        tr("Conflicts"),
     965                        new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}
     966                );
     967                dialog.setContent(
     968                        tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"));
     969                dialog.setButtonIcons(new String[] {"save", "cancel"});
     970                return dialog.showDialog().getValue();
     971            }
     972        })) {
     973            return false;
    981974        }
    982975        return true;
     
    1006999        if (file == null && isRenamed()) {
    10071000            String filename = Main.pref.get("lastDirectory") + '/' + getName();
    1008             if (!OsmImporter.FILE_FILTER.acceptName(filename)) filename = filename + '.' + extension;
     1001            if (!OsmImporter.FILE_FILTER.acceptName(filename))
     1002                filename = filename + '.' + extension;
    10091003            file = new File(filename);
    10101004        }
  • trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java

    r9670 r9674  
    284284     */
    285285    public FileChooserManager doCreateFileChooser() {
    286         File file = new File(curDir);
     286        File f = new File(curDir);
    287287        // Use native dialog is preference is set, unless an unsupported selection mode is specifically wanted
    288288        if (PROP_USE_NATIVE_FILE_DIALOG.get() && NativeFileChooser.supportsSelectionMode(selectionMode)) {
    289             fc = new NativeFileChooser(file);
     289            fc = new NativeFileChooser(f);
    290290        } else {
    291             fc = new SwingFileChooser(file);
     291            fc = new SwingFileChooser(f);
    292292        }
    293293
     
    332332     */
    333333    public AbstractFileChooser openFileChooser(Component parent) {
    334         if (fc == null) doCreateFileChooser();
     334        if (fc == null)
     335            doCreateFileChooser();
    335336
    336337        if (parent == null) {
     
    347348        }
    348349
    349         if (!open) {
    350             File file = fc.getSelectedFile();
    351             if (!SaveActionBase.confirmOverwrite(file)) {
    352                 return null;
    353             }
     350        if (!open && !SaveActionBase.confirmOverwrite(fc.getSelectedFile())) {
     351            return null;
    354352        }
    355353        return fc;
     
    357355
    358356    /**
    359      * Opens the file chooser dialog, then checks if filename has the given extension. If not, adds the extension and asks for overwrite if filename exists.
     357     * Opens the file chooser dialog, then checks if filename has the given extension.
     358     * If not, adds the extension and asks for overwrite if filename exists.
    360359     *
    361360     * @return the {@code File} or {@code null} if the user cancelled the dialog.
Note: See TracChangeset for help on using the changeset viewer.