コード例 #1
0
ファイル: MapView.java プロジェクト: H-Theking/josm
  private void onActiveLayerChanged(final Layer old) {
    fireActiveLayerChanged(old, activeLayer);

    /* This only makes the buttons look disabled. Disabling the actions as well requires
     * the user to re-select the tool after i.e. moving a layer. While testing I found
     * that I switch layers and actions at the same time and it was annoying to mind the
     * order. This way it works as visual clue for new users */
    for (final AbstractButton b : Main.map.allMapModeButtons) {
      MapMode mode = (MapMode) b.getAction();
      final boolean activeLayerSupported = mode.layerIsSupported(activeLayer);
      if (activeLayerSupported) {
        Main.registerActionShortcut(mode, mode.getShortcut()); // fix #6876
      } else {
        Main.unregisterShortcut(mode.getShortcut());
      }
      GuiHelper.runInEDTAndWait(
          new Runnable() {
            @Override
            public void run() {
              b.setEnabled(activeLayerSupported);
            }
          });
    }
    AudioPlayer.reset();
    repaint();
  }
コード例 #2
0
ファイル: MapView.java プロジェクト: H-Theking/josm
 /**
  * Moves the layer to the given new position. No event is fired, but repaints according to the new
  * Z-Order of the layers.
  *
  * @param layer The layer to move
  * @param pos The new position of the layer
  */
 public void moveLayer(Layer layer, int pos) {
   layerLock.writeLock().lock();
   layerLock.readLock().lock();
   EnumSet<LayerListenerType> listenersToFire;
   Layer oldActiveLayer = activeLayer;
   OsmDataLayer oldEditLayer = editLayer;
   try {
     try {
       int curLayerPos = layers.indexOf(layer);
       if (curLayerPos == -1) throw new IllegalArgumentException(tr("Layer not in list."));
       if (pos == curLayerPos) return; // already in place.
       layers.remove(curLayerPos);
       if (pos >= layers.size()) {
         layers.add(layer);
       } else {
         layers.add(pos, layer);
       }
       listenersToFire = setEditLayer(layers);
     } finally {
       layerLock.writeLock().unlock();
     }
     onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
     AudioPlayer.reset();
   } finally {
     layerLock.readLock().unlock();
   }
   repaint();
 }
コード例 #3
0
ファイル: MapView.java プロジェクト: H-Theking/josm
 @Override
 public void propertyChange(PropertyChangeEvent evt) {
   if (evt.getPropertyName().equals(Layer.VISIBLE_PROP)) {
     repaint();
   } else if (evt.getPropertyName().equals(Layer.OPACITY_PROP)) {
     Layer l = (Layer) evt.getSource();
     if (l.isVisible()) {
       changedLayer = l;
       repaint();
     }
   } else if (evt.getPropertyName().equals(OsmDataLayer.REQUIRES_SAVE_TO_DISK_PROP)
       || evt.getPropertyName().equals(OsmDataLayer.REQUIRES_UPLOAD_TO_SERVER_PROP)) {
     OsmDataLayer layer = (OsmDataLayer) evt.getSource();
     if (layer == getEditLayer()) {
       refreshTitle();
     }
   }
 }
コード例 #4
0
ファイル: MapView.java プロジェクト: H-Theking/josm
  /**
   * Add a layer to the current MapView. The layer will be added at topmost position.
   *
   * @param layer The layer to add
   */
  public void addLayer(Layer layer) {
    boolean isOsmDataLayer = layer instanceof OsmDataLayer;
    layerLock.writeLock().lock();
    layerLock.readLock().lock();
    EnumSet<LayerListenerType> listenersToFire = EnumSet.noneOf(LayerListenerType.class);
    Layer oldActiveLayer = activeLayer;
    OsmDataLayer oldEditLayer = editLayer;
    try {
      try {
        if (layer instanceof MarkerLayer && playHeadMarker == null) {
          playHeadMarker = PlayHeadMarker.create();
        }

        if (layer instanceof GpxLayer) {
          addGpxLayer((GpxLayer) layer);
        } else if (layers.isEmpty()) {
          layers.add(layer);
        } else if (layer.isBackgroundLayer()) {
          int i = 0;
          for (; i < layers.size(); i++) {
            if (layers.get(i).isBackgroundLayer()) {
              break;
            }
          }
          layers.add(i, layer);
        } else {
          layers.add(0, layer);
        }

        if (isOsmDataLayer || oldActiveLayer == null) {
          // autoselect the new layer
          listenersToFire.addAll(setActiveLayer(layer, true));
        }
      } finally {
        layerLock.writeLock().unlock();
      }

      fireLayerAdded(layer);
      if (isOsmDataLayer) {
        ((OsmDataLayer) layer).addLayerStateChangeListener(this);
      }
      onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
      layer.addPropertyChangeListener(this);
      Main.addProjectionChangeListener(layer);
      AudioPlayer.reset();
    } finally {
      layerLock.readLock().unlock();
    }
    if (!listenersToFire.isEmpty()) {
      repaint();
    }
  }
コード例 #5
0
ファイル: MapView.java プロジェクト: H-Theking/josm
 /**
  * Sets the active layer to <code>layer</code>. If <code>layer</code> is an instance of {@link
  * OsmDataLayer} also sets {@link #editLayer} to <code>layer</code>.
  *
  * @param layer the layer to be activate; must be one of the layers in the list of layers
  * @throws IllegalArgumentException if layer is not in the lis of layers
  */
 public void setActiveLayer(Layer layer) {
   layerLock.writeLock().lock();
   layerLock.readLock().lock();
   EnumSet<LayerListenerType> listenersToFire;
   Layer oldActiveLayer = activeLayer;
   OsmDataLayer oldEditLayer = editLayer;
   try {
     try {
       listenersToFire = setActiveLayer(layer, true);
     } finally {
       layerLock.writeLock().unlock();
     }
     onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
   } finally {
     layerLock.readLock().unlock();
   }
   repaint();
 }
コード例 #6
0
ファイル: MapView.java プロジェクト: H-Theking/josm
  /**
   * Remove the layer from the mapview. If the layer was in the list before, an LayerChange event is
   * fired.
   *
   * @param layer The layer to remove
   */
  public void removeLayer(Layer layer) {
    layerLock.writeLock().lock();
    layerLock.readLock().lock();

    EnumSet<LayerListenerType> listenersToFire = EnumSet.noneOf(LayerListenerType.class);
    Layer oldActiveLayer = activeLayer;
    OsmDataLayer oldEditLayer = editLayer;
    try {
      try {
        List<Layer> layersList = new ArrayList<>(layers);

        if (!layersList.remove(layer)) return;

        listenersToFire = setEditLayer(layersList);

        if (layer == activeLayer) {
          listenersToFire.addAll(setActiveLayer(determineNextActiveLayer(layersList), false));
        }

        if (layer instanceof OsmDataLayer) {
          ((OsmDataLayer) layer).removeLayerPropertyChangeListener(this);
        }

        layers.remove(layer);
        Main.removeProjectionChangeListener(layer);

      } finally {
        layerLock.writeLock().unlock();
      }
      onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire);
      fireLayerRemoved(layer);
      layer.removePropertyChangeListener(this);
      layer.destroy();
      AudioPlayer.reset();
    } finally {
      layerLock.readLock().unlock();
    }
    repaint();
  }
コード例 #7
0
ファイル: MapView.java プロジェクト: H-Theking/josm
 public void setVirtualNodesEnabled(boolean enabled) {
   if (virtualNodesEnabled != enabled) {
     virtualNodesEnabled = enabled;
     repaint();
   }
 }
コード例 #8
0
ファイル: MapView.java プロジェクト: H-Theking/josm
 @Override
 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
   repaint();
 }