Exemplo n.º 1
0
  @Override
  public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    boolean modeChanged = false;
    if (mapMode == null || !mapMode.layerIsSupported(newLayer)) {
      MapMode newMapMode = getLastMapMode(newLayer);
      modeChanged = newMapMode != mapMode;
      if (newMapMode != null) {
        selectMapMode(
            newMapMode,
            newLayer); // it would be nice to select first supported mode when layer is first
                       // selected, but it don't work well with for example editgpx layer
      } else if (mapMode != null) {
        mapMode.exitMode(); // if new mode is null - simply exit from previous mode
      }
    }
    if (!modeChanged && mapMode != null) {
      // Let mapmodes know about new active layer
      mapMode.exitMode();
      mapMode.enterMode();
    }
    // invalidate repaint cache
    Main.map.mapView.preferenceChanged(null);

    // After all listeners notice new layer, some buttons will be disabled/enabled
    // and possibly need to be hidden/shown.
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            validateToolBarsVisibility();
          }
        });
  }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 3
0
  /**
   * Another version of the selectMapMode for changing layer action. Pass newly selected layer to
   * this method.
   *
   * @param newMapMode The new mode to set.
   * @param newLayer newly selected layer
   * @return {@code true} if mode is really selected
   */
  public boolean selectMapMode(MapMode newMapMode, Layer newLayer) {
    if (newMapMode == null || !newMapMode.layerIsSupported(newLayer)) return false;

    MapMode oldMapMode = this.mapMode;
    if (newMapMode == oldMapMode) return true;
    if (oldMapMode != null) {
      oldMapMode.exitMode();
    }
    this.mapMode = newMapMode;
    newMapMode.enterMode();
    lastMapMode.put(newLayer, newMapMode);
    fireMapModeChanged(oldMapMode, newMapMode);
    return true;
  }
 @Override
 public void enterMode() {
   super.enterMode();
   if (!hasImageryLayersToAdjust()) {
     warnNoImageryLayers();
     return;
   }
   List<ImageryLayer> layers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
   if (layers.size() == 1) {
     adjustingLayer = layers.get(0);
   } else {
     adjustingLayer = (ImageryLayer) askAdjustLayer(getVisibleLayers());
   }
   if (adjustingLayer == null) return;
   if (!adjustingLayer.isVisible()) {
     adjustingLayer.setVisible(true);
   }
   Main.map.mapView.addMouseListener(this);
   Main.map.mapView.addMouseMotionListener(this);
   listener =
       new TimedKeyReleaseListener() {
         @Override
         protected void doKeyReleaseEvent(KeyEvent evt) {
           if (releaseEvent.getKeyCode() == getShortcut().getKeyStroke().getKeyCode()) {
             if (oldMapMode != null && !(oldMapMode instanceof ImageryAdjustMapMode))
               Main.map.selectMapMode(oldMapMode);
           }
         }
       };
 }
 @Override
 public void exitMode() {
   super.exitMode();
   Main.map.mapView.removeMouseListener(this);
   Main.map.mapView.removeMouseMotionListener(this);
   adjustingLayer = null;
   listener.stop();
 }
 @Override
 public void enterMode() {
   if (!isEnabled()) {
     return;
   }
   super.enterMode();
   Main.map.mapView.setCursor(getCursor());
   Main.map.mapView.addMouseListener(this);
 }
 @Override
 public void actionPerformed(ActionEvent e) {
   super.actionPerformed(e);
 }
 @Override
 public void exitMode() {
   super.exitMode();
   Main.map.mapView.removeMouseListener(this);
 }
Exemplo n.º 9
0
 @Override
 public void enterMode() {
   super.enterMode();
   Main.map.mapView.addMouseListener(this);
   Main.map.mapView.addMouseMotionListener(this);
 }