Changeset 33345 in osm for applications/editors


Ignore:
Timestamp:
2017-05-30T23:16:08+02:00 (7 years ago)
Author:
giackserva
Message:

fix #josm14859

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

Legend:

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

    r33055 r33345  
    88import java.beans.PropertyChangeListener;
    99import java.util.ArrayList;
    10 import java.util.Collection;
     10import java.util.Collections;
    1111import java.util.HashMap;
    1212import java.util.List;
     
    1818import org.openstreetmap.josm.actions.RenameLayerAction;
    1919import org.openstreetmap.josm.data.Bounds;
    20 import org.openstreetmap.josm.data.SelectionChangedListener;
    2120import org.openstreetmap.josm.data.osm.OsmPrimitive;
    22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2321import org.openstreetmap.josm.data.osm.Relation;
    2422import org.openstreetmap.josm.data.osm.Way;
     
    4644 */
    4745public final class PTAssistantLayer extends Layer
    48         implements SelectionChangedListener, PropertyChangeListener, LayerChangeListener {
    49 
    50     private static PTAssistantLayer layer;
     46        implements PropertyChangeListener, LayerChangeListener {
     47
    5148    private List<OsmPrimitive> primitives = new ArrayList<>();
    5249    private PTAssistantPaintVisitor paintVisitor;
     
    5451    private HashMap<Way, List<Character>> wayColoring = new HashMap<>();
    5552
    56     private PTAssistantLayer() {
     53    public PTAssistantLayer() {
    5754        super("pt_assistant layer");
    5855        KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);
    5956        Main.getLayerManager().addLayerChangeListener(this);
    60         layer = this;
    61     }
    62 
    63     public static PTAssistantLayer getLayer() {
    64         if (layer == null) {
    65             new PTAssistantLayer();
    66         }
    67         return layer;
     57        Main.getLayerManager().addLayer(this);
    6858    }
    6959
     
    135125    }
    136126
     127    public void setPrimitives(List<OsmPrimitive> primitives)
     128    {
     129        this.primitives.clear();
     130        this.primitives.addAll(primitives);
     131    }
     132
    137133    @Override
    138134    public void paint(final Graphics2D g, final MapView mv, Bounds bounds) {
     
    193189
    194190    /**
    195      * Listens to a selection change
    196      */
    197     @Override
    198     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    199 
    200         ArrayList<Relation> routes = new ArrayList<>();
    201 
    202         for (OsmPrimitive primitive : newSelection) {
    203             if (primitive.getType().equals(OsmPrimitiveType.RELATION)) {
    204                 Relation relation = (Relation) primitive;
    205                 if (RouteUtils.isTwoDirectionRoute(relation)) {
    206                     routes.add(relation);
    207                 }
    208 
    209             }
    210         }
    211 
    212         if (!routes.isEmpty()) {
    213             this.primitives.clear();
    214             this.primitives.addAll(routes);
    215             if (!Main.getLayerManager().containsLayer(this)) {
    216                 Main.getLayerManager().addLayer(this);
    217             }
    218         }
    219 
    220     }
    221 
    222     /**
    223191     * Listens to a focus change, sets the primitives attribute to the route
    224192     * relation in the top Relation Editor and repaints the map
     
    239207
    240208                if (RouteUtils.isTwoDirectionRoute(relation)) {
    241 
    242209                    this.repaint(relation);
    243210
    244211                }
    245 
    246212            }
    247213        }
     
    296262        }
    297263
     264        if (event.getRemovedLayer() instanceof OsmDataLayer && event.getSource().getLayersOfType(OsmDataLayer.class).size() < 1)
     265            event.scheduleRemoval(Collections.singleton(this));
     266
     267        if(event.getRemovedLayer() == this)
     268                PTAssistantLayerManager.PTLM.resetLayer();
     269    }
     270
     271    @Override
     272    public synchronized void destroy() {
     273        KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(this);
     274        Main.getLayerManager().removeLayerChangeListener(this);
     275        super.destroy();
    298276    }
    299277}
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java

    r33055 r33345  
    2121import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    2222import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    23 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer;
     23import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager;
    2424import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    2525
     
    197197
    198198        // make the current relation purple in the pt_assistant layer:
    199         PTAssistantLayer.getLayer().repaint(r);
     199        PTAssistantLayerManager.PTLM.getLayer().repaint(r);
    200200
    201201    }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r33321 r33345  
    3636import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay;
    3737import org.openstreetmap.josm.plugins.pt_assistant.gui.IncompleteMembersDownloadDialog;
    38 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer;
     38import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager;
    3939import org.openstreetmap.josm.plugins.pt_assistant.gui.ProceedDialog;
    4040import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     
    6060        public static final int ERROR_CODE_STOP_AREA_COMPARE_RELATIONS = 3764;
    6161
    62         private PTAssistantLayer layer;
    63 
    6462        public PTAssistantValidatorTest() {
    6563                super(tr("Public Transport Assistant tests"),
    6664                                tr("Check if route relations are compatible with public transport version 2"));
    6765
    68                 layer = PTAssistantLayer.getLayer();
    69                 DataSet.addSelectionListener(layer);
     66                DataSet.addSelectionListener(PTAssistantLayerManager.PTLM);
    7067
    7168        }
     
    491488                if (testError.getPrimitives().iterator().next().getType().equals(OsmPrimitiveType.RELATION)) {
    492489                        Relation relationToBeFixed = (Relation) testError.getPrimitives().iterator().next();
    493                         this.layer.repaint(relationToBeFixed);
     490                        PTAssistantLayerManager.PTLM.getLayer().repaint(relationToBeFixed);
    494491                }
    495492
     
    568565
    569566        public void addFixVariants(List<List<PTWay>> fixVariants) {
    570                 layer.addFixVariants(fixVariants);
     567                PTAssistantLayerManager.PTLM.getLayer().addFixVariants(fixVariants);
    571568        }
    572569
    573570        public void clearFixVariants() {
    574                 layer.clearFixVariants();
     571                PTAssistantLayerManager.PTLM.getLayer().clearFixVariants();
    575572        }
    576573
    577574        public List<PTWay> getFixVariant(Character c) {
    578                 return layer.getFixVariant(c);
     575                return PTAssistantLayerManager.PTLM.getLayer().getFixVariant(c);
    579576        }
    580577
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r33108 r33345  
    3737import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop;
    3838import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay;
    39 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer;
     39import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayerManager;
    4040import org.openstreetmap.josm.plugins.pt_assistant.utils.StopToWayAssigner;
    4141
     
    114114        /**
    115115         * Used for unit tests
    116          * 
     116         *
    117117         * @param error
    118118         *            test error
     
    637637
    638638        /**
    639          * Finds fixes using sorting and removal. 
     639         * Finds fixes using sorting and removal.
    640640         */
    641641        protected void findFixes() {
     
    897897                final PTAssistantValidatorTest test = (PTAssistantValidatorTest) testError.getTester();
    898898                test.addFixVariants(fixVariants);
    899                 PTAssistantLayer.getLayer().repaint((Relation) testError.getPrimitives().iterator().next());
     899                PTAssistantLayerManager.PTLM.getLayer().repaint((Relation) testError.getPrimitives().iterator().next());
    900900
    901901                // prepare the variables for the key listener:
     
    906906                Main.map.mapView.addKeyListener(new KeyListener() {
    907907
     908                        @Override
    908909                        public void keyTyped(KeyEvent e) {
    909910                                // TODO Auto-generated method stub
    910911                        }
    911912
     913                        @Override
    912914                        public void keyPressed(KeyEvent e) {
    913915                                Character typedKey = e.getKeyChar();
     
    925927                        }
    926928
     929                        @Override
    927930                        public void keyReleased(KeyEvent e) {
    928931                                // TODO Auto-generated method stub
Note: See TracChangeset for help on using the changeset viewer.