/**
  * Constructs a new <code>RecentRelationsAction</code>.
  *
  * @param editButton edit button
  */
 public RecentRelationsAction(SideButton editButton) {
   this.editButton = editButton;
   arrow = editButton.createArrow(this);
   arrow.setToolTipText(tr("List of recent relations"));
   Main.main.undoRedo.addCommandQueueListener(this);
   MapView.addLayerChangeListener(this);
   enableArrow();
   shortcut =
       Shortcut.registerShortcut(
           "relationeditor:editrecentrelation",
           tr("Relation Editor: {0}", tr("Open recent relation")),
           KeyEvent.VK_ESCAPE,
           Shortcut.SHIFT);
   Main.registerActionShortcut(
       new AbstractAction() {
         @Override
         public void actionPerformed(ActionEvent e) {
           EditRelationAction.launchEditor(getLastRelation());
         }
       },
       shortcut);
 }
Exemple #2
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());
    }
  }
Exemple #3
0
 /**
  * Adds a layer change listener
  *
  * @param listener the listener. Ignored if null or already registered.
  * @param initialFire fire an active-layer-changed-event right after adding the listener in case
  *     there is a layer present (should be)
  */
 public static void addLayerChangeListener(LayerChangeListener listener, boolean initialFire) {
   addLayerChangeListener(listener);
   if (initialFire && Main.isDisplayingMapView()) {
     listener.activeLayerChange(null, Main.map.mapView.getActiveLayer());
   }
 }
Exemple #4
0
 /** Constructs a new Validator layer */
 public ValidatorLayer() {
   super(tr("Validation errors"));
   MapView.addLayerChangeListener(this);
 }
Exemple #5
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);
            }
          }
        });
  }
Exemple #6
0
  /**
   * Constructs a new {@code MapFrame}.
   *
   * @param contentPane The content pane used to register shortcuts in its {@link
   *     javax.swing.InputMap} and {@link javax.swing.ActionMap}
   * @param viewportData the initial viewport of the map. Can be null, then the viewport is derived
   *     from the layer data.
   */
  public MapFrame(JPanel contentPane, ViewportData viewportData) {
    setSize(400, 400);
    setLayout(new BorderLayout());

    mapView = new MapView(contentPane, viewportData);
    new FileDrop(mapView);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);

    leftPanel = new JPanel();
    leftPanel.setLayout(new GridBagLayout());
    leftPanel.add(mapView, GBC.std().fill());
    splitPane.setLeftComponent(leftPanel);

    dialogsPanel = new DialogsPanel(splitPane);
    splitPane.setRightComponent(dialogsPanel);

    /** All additional space goes to the mapView */
    splitPane.setResizeWeight(1.0);

    /** Some beautifications. */
    splitPane.setDividerSize(5);
    splitPane.setBorder(null);
    splitPane.setUI(
        new BasicSplitPaneUI() {
          @Override
          public BasicSplitPaneDivider createDefaultDivider() {
            return new BasicSplitPaneDivider(this) {
              @Override
              public void setBorder(Border b) {}
            };
          }
        });

    // JSplitPane supports F6 and F8 shortcuts by default, but we need them for Audio actions
    splitPane
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), new Object());
    splitPane
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), new Object());

    add(splitPane, BorderLayout.CENTER);

    dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS));
    dialogsPanel.setPreferredSize(
        new Dimension(Main.pref.getInteger("toggleDialogs.width", DEF_TOGGLE_DLG_WIDTH), 0));
    dialogsPanel.setMinimumSize(new Dimension(24, 0));
    mapView.setMinimumSize(new Dimension(10, 0));

    // toolBarActions, map mode buttons
    addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));
    addMapMode(new IconToggleButton(new LassoModeAction(), true));
    addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this)));
    addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this)));
    addMapMode(new IconToggleButton(new DeleteAction(this), true));
    addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
    addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
    addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), false));
    toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true);
    toolBarActions.setFloatable(false);

    // toolBarToggles, toggle dialog buttons
    LayerListDialog.createInstance(this);
    addToggleDialog(LayerListDialog.getInstance());
    addToggleDialog(propertiesDialog = new PropertiesDialog());
    addToggleDialog(selectionListDialog = new SelectionListDialog());
    addToggleDialog(relationListDialog = new RelationListDialog());
    addToggleDialog(new CommandStackDialog());
    addToggleDialog(new UserListDialog());
    addToggleDialog(new HistoryDialog(), true);
    addToggleDialog(conflictDialog = new ConflictDialog());
    addToggleDialog(validatorDialog = new ValidatorDialog());
    addToggleDialog(filterDialog = new FilterDialog());
    addToggleDialog(new ChangesetDialog(), true);
    addToggleDialog(new MapPaintDialog());
    toolBarToggle.setFloatable(false);

    // status line below the map
    statusLine = new MapStatus(this);
    MapView.addLayerChangeListener(this);

    boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null;
    if (unregisterTab) {
      for (JComponent c : allDialogButtons) c.setFocusTraversalKeysEnabled(false);
      for (JComponent c : allMapModeButtons) c.setFocusTraversalKeysEnabled(false);
    }
  }