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

code style (checkstyle, sonar)

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.