Changeset 6271 in josm for trunk


Ignore:
Timestamp:
2013-09-30T02:51:34+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #9116 - Remember active layer in session

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

Legend:

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

    r6245 r6271  
    6767        private final boolean zip;
    6868        private List<Layer> layers;
     69        private Layer active;
    6970        private List<Runnable> postLoadTasks;
    7071        private ViewportData viewport;
     
    122123                            if (canceled) return;
    123124                            Main.main.addLayer(l);
     125                        }
     126                        if (active != null) {
     127                            Main.map.mapView.setActiveLayer(active);
    124128                        }
    125129                        if (noMap) {
     
    158162                    reader.loadSession(file, zip, monitor);
    159163                    layers = reader.getLayers();
     164                    active = reader.getActive();
    160165                    postLoadTasks = reader.getPostLoadTasks();
    161166                    viewport = reader.getViewport();
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r6267 r6271  
    123123            layersOut.add(layer);
    124124        }
    125 
    126         SessionWriter sw = new SessionWriter(layersOut, exporters, dependencies, zip);
     125       
     126        int active = -1;
     127        Layer activeLayer = Main.map.mapView.getActiveLayer();
     128        if (activeLayer != null) {
     129            active = layersOut.indexOf(activeLayer);
     130        }
     131
     132        SessionWriter sw = new SessionWriter(layersOut, active, exporters, dependencies, zip);
    127133        try {
    128134            sw.write(file);
     
    157163        }
    158164
     165        /**
     166         * Initializes action.
     167         */
    159168        public void initialize() {
    160169            layers = new ArrayList<Layer>(Main.map.mapView.getAllLayersAsList());
     
    196205        }
    197206
    198         public Component build() {
     207        protected Component build() {
    199208            JPanel p = new JPanel(new GridBagLayout());
    200209            JPanel ip = new JPanel(new GridBagLayout());
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r6245 r6271  
    8989    private ZipFile zipFile;
    9090    private List<Layer> layers = new ArrayList<Layer>();
     91    private int active = -1;
    9192    private List<Runnable> postLoadTasks = new ArrayList<Runnable>();
    9293    private ViewportData viewport;
     
    9798    public List<Layer> getLayers() {
    9899        return layers;
     100    }
     101
     102    /**
     103     * @return active layer, or {@code null} if not set
     104     * @since 6271
     105     */
     106    public Layer getActive() {
     107        // layers is in reverse order because of the way TreeMap is built
     108        return (active >= 0 && active < layers.size()) ? layers.get(layers.size()-1-active) : null;
    99109    }
    100110
     
    327337        if (layersEl == null) return;
    328338
     339        String activeAtt = layersEl.getAttribute("active");
     340        try {
     341            active = (activeAtt != null && !activeAtt.isEmpty()) ? Integer.parseInt(activeAtt)-1 : -1;
     342        } catch (NumberFormatException e) {
     343            Main.warn("Unsupported value for 'active' layer attribute. Ignoring it. Error was: "+e.getMessage());
     344            active = -1;
     345        }
     346       
    329347        MultiMap<Integer, Integer> deps = new MultiMap<Integer, Integer>();
    330348        Map<Integer, Element> elems = new HashMap<Integer, Element>();
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r6142 r6271  
    8080    }
    8181
    82     private List<Layer> layers;
    83     private Map<Layer, SessionLayerExporter> exporters;
    84     private MultiMap<Layer, Layer> dependencies;
    85     private boolean zip;
     82    private final List<Layer> layers;
     83    private final int active;
     84    private final Map<Layer, SessionLayerExporter> exporters;
     85    private final MultiMap<Layer, Layer> dependencies;
     86    private final boolean zip;
    8687
    8788    private ZipOutputStream zipOut;
    8889
    89     public SessionWriter(List<Layer> layers, Map<Layer, SessionLayerExporter> exporters,
     90    /**
     91     * Constructs a new {@code SessionWriter}.
     92     * @param layers The ordered list of layers to save
     93     * @param active The index of active layer in {@code layers} (starts to 0). Ignored if set to -1
     94     * @param exporters The exprters to use to save layers
     95     * @param zip {@code true} if a joz archive has to be created, {@code false otherwise}
     96     * @since 6271
     97     */
     98    public SessionWriter(List<Layer> layers, int active, Map<Layer, SessionLayerExporter> exporters,
    9099                MultiMap<Layer, Layer> dependencies, boolean zip) {
    91100        this.layers = layers;
     101        this.active = active;
    92102        this.exporters = exporters;
    93103        this.dependencies = dependencies;
     
    182192
    183193        Element layersEl = doc.createElement("layers");
     194        if (active >= 0) {
     195            layersEl.setAttribute("active", Integer.toString(active+1));
     196        }
    184197        root.appendChild(layersEl);
    185198
Note: See TracChangeset for help on using the changeset viewer.