Ignore:
Timestamp:
2017-07-20T11:11:39+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] moved layer logic to the manager

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java

    r33461 r33462  
    22package org.openstreetmap.josm.plugins.pt_assistant;
    33
     4import java.awt.KeyboardFocusManager;
    45import java.util.ArrayList;
    56import java.util.List;
     
    910
    1011import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.data.osm.DataSet;
    1113import org.openstreetmap.josm.data.osm.Relation;
    1214import org.openstreetmap.josm.data.validation.OsmValidator;
     
    2527import org.openstreetmap.josm.plugins.pt_assistant.actions.SplitRoundaboutAction;
    2628import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment;
     29import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager;
    2730import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantPreferenceSetting;
    2831import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest;
     
    6063    public PTAssistantPlugin(PluginInformation info) {
    6164        super(info);
    62         Main.info("whatever you want");
    6365        OsmValidator.addTest(PTAssistantValidatorTest.class);
    6466
     67        DataSet.addSelectionListener(PTAssistantLayerManager.PTLM);
     68        KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(PTAssistantLayerManager.PTLM);
    6569        RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction();
    6670        EditHighlightedRelationsAction editHighlightedRelationsAction = new EditHighlightedRelationsAction();
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java

    r33429 r33462  
    44import java.awt.Graphics;
    55import java.awt.Graphics2D;
    6 import java.awt.KeyboardFocusManager;
    7 import java.beans.PropertyChangeEvent;
    8 import java.beans.PropertyChangeListener;
    96import java.util.ArrayList;
    107import java.util.Collections;
    118import java.util.HashMap;
    129import java.util.List;
     10import java.util.Map.Entry;
    1311
    1412import javax.swing.Action;
     
    2523import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    2624import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    27 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
    2825import org.openstreetmap.josm.gui.layer.Layer;
    2926import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     
    3532import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin;
    3633import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay;
    37 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    3834import org.openstreetmap.josm.tools.ImageProvider;
    3935
     
    4541 */
    4642public final class PTAssistantLayer extends Layer
    47         implements PropertyChangeListener, LayerChangeListener {
     43        implements LayerChangeListener {
    4844
    4945    private List<OsmPrimitive> primitives = new ArrayList<>();
     
    5450    public PTAssistantLayer() {
    5551        super("pt_assistant layer");
    56         KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);
    5752        Main.getLayerManager().addLayerChangeListener(this);
    5853        Main.getLayerManager().addLayer(this);
     
    9792        }
    9893
    99         for (Character currentFixVariantLetter : this.fixVariants.keySet()) {
    100             List<PTWay> fixVariant = this.fixVariants.get(currentFixVariantLetter);
     94        for (Entry<Character, List<PTWay>> entry : this.fixVariants.entrySet()) {
     95            Character currentFixVariantLetter = entry.getKey();
     96            List<PTWay> fixVariant = entry.getValue();
    10197            for (PTWay ptway : fixVariant) {
    10298                for (Way way : ptway.getWays()) {
     
    123119     */
    124120    public List<PTWay> getFixVariant(char c) {
    125         return this.fixVariants.get(Character.toUpperCase(c));
    126     }
    127 
    128     public void setPrimitives(List<OsmPrimitive> primitives) {
    129         this.primitives.clear();
    130         this.primitives.addAll(primitives);
     121        return fixVariants.get(Character.toUpperCase(c));
     122    }
     123
     124    public void setPrimitives(List<OsmPrimitive> newPrimitives) {
     125        primitives = new ArrayList<>(newPrimitives);
    131126    }
    132127
     
    140135        }
    141136
    142         paintVisitor.visitFixVariants(this.fixVariants, this.wayColoring);
     137        paintVisitor.visitFixVariants(fixVariants, wayColoring);
    143138
    144139    }
     
    188183    }
    189184
    190     /**
    191      * Listens to a focus change, sets the primitives attribute to the route
    192      * relation in the top Relation Editor and repaints the map
    193      */
    194     @Override
    195     public void propertyChange(PropertyChangeEvent evt) {
    196 
    197         if ("focusedWindow".equals(evt.getPropertyName())) {
    198 
    199             if (evt.getNewValue() == null) {
    200                 return;
    201             }
    202 
    203             if (evt.getNewValue().getClass().equals(GenericRelationEditor.class)) {
    204 
    205                 GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue();
    206                 Relation relation = editor.getRelation();
    207 
    208                 if (RouteUtils.isVersionTwoPTRoute(relation)) {
    209                     this.repaint(relation);
    210 
    211                 }
    212             }
    213         }
    214     }
     185
    215186
    216187    /**
     
    220191     */
    221192    public void repaint(Relation relation) {
    222         this.primitives.clear();
    223         this.primitives.add(relation);
     193        primitives.clear();
     194        primitives.add(relation);
    224195        if (!Main.getLayerManager().containsLayer(this)) {
    225196            Main.getLayerManager().addLayer(this);
     
    236207        }
    237208
    238         paintVisitor.visitFixVariants(this.fixVariants, this.wayColoring);
     209        paintVisitor.visitFixVariants(fixVariants, wayColoring);
    239210
    240211        Main.map.mapView.repaint();
     
    256227
    257228        if (event.getRemovedLayer() instanceof OsmDataLayer) {
    258             this.primitives.clear();
    259             this.fixVariants.clear();
    260             this.wayColoring.clear();
     229            primitives.clear();
     230            fixVariants.clear();
     231            wayColoring.clear();
    261232            Main.map.mapView.repaint();
    262233        }
     
    274245    @Override
    275246    public synchronized void destroy() {
    276         KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(this);
    277247        Main.getLayerManager().removeLayerChangeListener(this);
    278248        super.destroy();
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayerManager.java

    r33429 r33462  
    22package org.openstreetmap.josm.plugins.pt_assistant.gui;
    33
     4import java.beans.PropertyChangeEvent;
     5import java.beans.PropertyChangeListener;
    46import java.util.ArrayList;
    57import java.util.Collection;
     
    911import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1012import org.openstreetmap.josm.data.osm.Relation;
     13import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
    1114import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin;
    1215import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    1316
    14 public class PTAssistantLayerManager implements SelectionChangedListener {
     17public class PTAssistantLayerManager
     18    implements SelectionChangedListener, PropertyChangeListener {
    1519
    1620    public static final PTAssistantLayerManager PTLM = new PTAssistantLayerManager();
     
    5155        }
    5256    }
     57
     58    /**
     59     * Listens to a focus change, sets the primitives attribute to the route
     60     * relation in the top Relation Editor and repaints the map
     61     */
     62    @Override
     63    public void propertyChange(PropertyChangeEvent evt) {
     64
     65        if ("focusedWindow".equals(evt.getPropertyName())
     66                && evt.getNewValue() != null
     67                && GenericRelationEditor.class.equals(evt.getNewValue().getClass())) {
     68
     69            GenericRelationEditor editor = (GenericRelationEditor) evt.getNewValue();
     70            Relation relation = editor.getRelation();
     71
     72            if (RouteUtils.isVersionTwoPTRoute(relation)) {
     73                getLayer().repaint(relation);
     74            }
     75        }
     76    }
    5377}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r33452 r33462  
    1717import org.openstreetmap.josm.command.SelectCommand;
    1818import org.openstreetmap.josm.command.SequenceCommand;
    19 import org.openstreetmap.josm.data.osm.DataSet;
    2019import org.openstreetmap.josm.data.osm.Node;
    2120import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6463        super(tr("Public Transport Assistant tests"),
    6564                tr("Check if route relations are compatible with public transport version 2"));
    66 
    67         DataSet.addSelectionListener(PTAssistantLayerManager.PTLM);
    68 
    6965    }
    7066
Note: See TracChangeset for help on using the changeset viewer.