/**
   * Called after Main.mapFrame is initialized. (After the first data is loaded). You can use this
   * callback to tweak the newFrame to your needs, as example install an alternative Painter.
   */
  @Override
  public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    super.mapFrameInitialized(oldFrame, newFrame);

    if (newFrame != null) {
      ElevationMapMode eleMode = new ElevationMapMode("Elevation profile", newFrame);
      newFrame.addMapMode(new IconToggleButton(eleMode));
      ElevationProfileDialog eleProfileDlg = new ElevationProfileDialog();
      eleProfileDlg.addModelListener(eleMode);
      eleProfileDlg.setProfileLayer(getCurrentLayer());
      newFrame.addToggleDialog(eleProfileDlg);
    }
  }
 public ImageryAdjustMapMode(MapFrame mapFrame) {
   super(
       tr("Adjust imagery"),
       "adjustimg",
       tr("Adjust the position of the selected imagery layer"),
       Shortcut.registerShortcut(
           "imageryadjust:adjustmode",
           tr("Mode: {0}", tr("Adjust imagery")),
           KeyEvent.VK_Y,
           Shortcut.ALT_CTRL),
       mapFrame,
       ImageProvider.getCursor("normal", "move"));
   MapFrame.addMapModeChangeListener(this);
 }
Пример #3
0
  @Override
  public void hookUpMapView() {
    mouseAdapter =
        new MouseAdapter() {
          private boolean isMapModeOk() {
            return Main.map.mapMode == null || isSupportedMapMode(Main.map.mapMode);
          }

          @Override
          public void mousePressed(MouseEvent e) {
            if (e.getButton() != MouseEvent.BUTTON1) return;
            if (isVisible() && isMapModeOk()) {
              Main.map.mapView.repaint();
            }
          }

          @Override
          public void mouseReleased(MouseEvent ev) {
            if (ev.getButton() != MouseEvent.BUTTON1) return;
            if (data == null || !isVisible() || !isMapModeOk()) return;

            for (int i = data.size() - 1; i >= 0; --i) {
              ImageEntry e = data.get(i);
              if (e.getPos() == null) {
                continue;
              }
              Point p = Main.map.mapView.getPoint(e.getPos());
              Rectangle r;
              if (useThumbs && e.hasThumbnail()) {
                Dimension d = scaledDimension(e.getThumbnail());
                r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
              } else {
                r =
                    new Rectangle(
                        p.x - icon.getIconWidth() / 2,
                        p.y - icon.getIconHeight() / 2,
                        icon.getIconWidth(),
                        icon.getIconHeight());
              }
              if (r.contains(ev.getPoint())) {
                clearOtherCurrentPhotos();
                currentPhoto = i;
                ImageViewerDialog.showImage(GeoImageLayer.this, e);
                Main.map.repaint();
                break;
              }
            }
          }
        };

    mapModeListener =
        new MapModeChangeListener() {
          @Override
          public void mapModeChange(MapMode oldMapMode, MapMode newMapMode) {
            if (newMapMode == null || isSupportedMapMode(newMapMode)) {
              Main.map.mapView.addMouseListener(mouseAdapter);
            } else {
              Main.map.mapView.removeMouseListener(mouseAdapter);
            }
          }
        };

    MapFrame.addMapModeChangeListener(mapModeListener);
    mapModeListener.mapModeChange(null, Main.map.mapMode);

    MapView.addLayerChangeListener(
        new LayerChangeListener() {
          @Override
          public void activeLayerChange(Layer oldLayer, Layer newLayer) {
            if (newLayer == GeoImageLayer.this) {
              // only in select mode it is possible to click the images
              Main.map.selectSelectTool(false);
            }
          }

          @Override
          public void layerAdded(Layer newLayer) {}

          @Override
          public void layerRemoved(Layer oldLayer) {
            if (oldLayer == GeoImageLayer.this) {
              stopLoadThumbs();
              Main.map.mapView.removeMouseListener(mouseAdapter);
              MapFrame.removeMapModeChangeListener(mapModeListener);
              currentPhoto = -1;
              if (data != null) {
                data.clear();
              }
              data = null;
              // stop listening to layer change events
              MapView.removeLayerChangeListener(this);
            }
          }
        });

    Main.map.mapView.addPropertyChangeListener(this);
    if (Main.map.getToggleDialog(ImageViewerDialog.class) == null) {
      ImageViewerDialog.newInstance();
      Main.map.addToggleDialog(ImageViewerDialog.getInstance());
    }
  }
Пример #4
0
  private void hook_up_mouse_events() {
    mouseAdapter =
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {

            if (e.getButton() != MouseEvent.BUTTON1) return;
            if (isVisible()) {
              Main.map.mapView.repaint();
            }
          }

          @Override
          public void mouseReleased(MouseEvent ev) {
            if (ev.getButton() != MouseEvent.BUTTON1) return;
            if (!isVisible()) return;

            for (int i = data.size() - 1; i >= 0; --i) {
              ImageEntry e = data.get(i);
              if (e.getPos() == null) {
                continue;
              }
              Point p = Main.map.mapView.getPoint(e.getPos());
              Rectangle r;
              if (e.thumbnail != null) {
                Dimension d = scaledDimension(e.thumbnail);
                r = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
              } else {
                r =
                    new Rectangle(
                        p.x - icon.getIconWidth() / 2,
                        p.y - icon.getIconHeight() / 2,
                        icon.getIconWidth(),
                        icon.getIconHeight());
              }
              if (r.contains(ev.getPoint())) {
                currentPhoto = i;
                ImageViewerDialog.showImage(GeoImageLayer.this, e);
                Main.map.repaint();
                break;
              }
            }
          }
        };

    mapModeListener =
        new MapModeChangeListener() {
          public void mapModeChange(MapMode oldMapMode, MapMode newMapMode) {
            if (newMapMode instanceof org.openstreetmap.josm.actions.mapmode.SelectAction) {
              Main.map.mapView.addMouseListener(mouseAdapter);
            } else {
              Main.map.mapView.removeMouseListener(mouseAdapter);
            }
          }
        };

    MapFrame.addMapModeChangeListener(mapModeListener);
    mapModeListener.mapModeChange(null, Main.map.mapMode);

    MapView.addLayerChangeListener(
        new LayerChangeListener() {
          public void activeLayerChange(Layer oldLayer, Layer newLayer) {
            if (newLayer == GeoImageLayer.this) {
              // only in select mode it is possible to click the images
              Main.map.selectSelectTool(false);
            }
          }

          public void layerAdded(Layer newLayer) {}

          public void layerRemoved(Layer oldLayer) {
            if (oldLayer == GeoImageLayer.this) {
              if (thumbsloader != null) {
                thumbsloader.stop = true;
              }
              Main.map.mapView.removeMouseListener(mouseAdapter);
              MapFrame.removeMapModeChangeListener(mapModeListener);
              currentPhoto = -1;
              data.clear();
              data = null;
              // stop listening to layer change events
              MapView.removeLayerChangeListener(this);
            }
          }
        });
  }
Пример #5
0
 @Override
 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
   if (newFrame != null) {
     newFrame.addToggleDialog(new WikipediaToggleDialog());
   }
 }