Esempio n. 1
0
    @Override
    public void windowDeactivated(WindowEvent e) {
      int result = checkAndSave();
      switch (result) {
        case NOTHING:
          break;
        case CANCEL:
          if (yLayer != null) {
            if (yLayer.data != null) {
              for (ImageEntry ie : yLayer.data) {
                ie.discardTmp();
              }
            }
            yLayer.updateBufferAndRepaint();
          }
          break;
        case AGAIN:
          actionPerformed(null);
          break;
        case DONE:
          Main.pref.put("geoimage.timezone", formatTimezone(timezone));
          Main.pref.put("geoimage.delta", Long.toString(delta * 1000));
          Main.pref.put("geoimage.showThumbs", yLayer.useThumbs);

          yLayer.useThumbs = cbShowThumbs.isSelected();
          yLayer.startLoadThumbs();

          // Search whether an other layer has yet defined some bounding box.
          // If none, we'll zoom to the bounding box of the layer with the photos.
          boolean boundingBoxedLayerFound = false;
          for (Layer l : Main.map.mapView.getAllLayers()) {
            if (l != yLayer) {
              BoundingXYVisitor bbox = new BoundingXYVisitor();
              l.visitBoundingBox(bbox);
              if (bbox.getBounds() != null) {
                boundingBoxedLayerFound = true;
                break;
              }
            }
          }
          if (!boundingBoxedLayerFound) {
            BoundingXYVisitor bbox = new BoundingXYVisitor();
            yLayer.visitBoundingBox(bbox);
            Main.map.mapView.zoomTo(bbox);
          }

          if (yLayer.data != null) {
            for (ImageEntry ie : yLayer.data) {
              ie.applyTmp();
            }
          }

          yLayer.updateBufferAndRepaint();

          break;
        default:
          throw new IllegalStateException();
      }
    }
  /**
   * Extracts the address information from the given primitive into a newly created {@link Node}.
   * The new node is added into the JOSM database.
   *
   * <p>If the extraction in not applicable, nothing happens.
   *
   * @param primitive the {@link Way} from which the address will be extracted
   */
  @Override
  public void apply(OsmPrimitive primitive) {

    if (!isApplicable(primitive)) return;

    Way way = (Way) primitive;

    BoundingXYVisitor visitor = new BoundingXYVisitor();
    way.accept(visitor);

    Node addrNode = new Node(visitor.getBounds().getCenter());

    for (String key : way.keySet()) if (key.startsWith("addr")) addrNode.put(key, way.get(key));

    for (String key : addrNode.keySet()) way.remove(key);

    Main.main.getCurrentDataSet().addPrimitive(addrNode);
  }