private void openVPFCoveragePanel(VPFDatabase db, VPFLayer layer) {
   VPFCoveragePanel panel = new VPFCoveragePanel(getWwd(), db);
   panel.setLayer(layer);
   JFrame frame = new JFrame(db.getName());
   frame.setResizable(true);
   frame.setAlwaysOnTop(true);
   frame.add(panel);
   frame.pack();
   WWUtil.alignComponent(this, frame, AVKey.CENTER);
   frame.setVisible(true);
 }
  public ViewViewVolume() {
    this.getContentPane().setLayout(new BorderLayout(5, 5));

    this.wwp = new WWPanel(new Dimension(650, 500));
    this.getContentPane().add(wwp);

    this.pack();
    this.setResizable(true);

    WWUtil.alignComponent(null, this, AVKey.CENTER);

    this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
  }
  /**
   * Create a surface polygon from a KML GroundOverlay.
   *
   * @param tc the current {@link KMLTraversalContext}.
   * @param overlay the {@link gov.nasa.worldwind.ogc.kml.KMLGroundOverlay} to render as a polygon.
   * @throws NullPointerException if the geometry is null.
   * @throws IllegalArgumentException if the parent placemark or the traversal context is null.
   */
  public KMLSurfacePolygonImpl(KMLTraversalContext tc, KMLGroundOverlay overlay) {
    if (tc == null) {
      String msg = Logging.getMessage("nullValue.TraversalContextIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (overlay == null) {
      String msg = Logging.getMessage("nullValue.ParentIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    this.parent = overlay;

    // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad
    Position.PositionList corners = overlay.getPositions();
    this.setOuterBoundary(corners.list);

    if (overlay.getName() != null) this.setValue(AVKey.DISPLAY_NAME, overlay.getName());

    if (overlay.getDescription() != null)
      this.setValue(AVKey.BALLOON_TEXT, overlay.getDescription());

    if (overlay.getSnippetText() != null)
      this.setValue(AVKey.SHORT_DESCRIPTION, overlay.getSnippetText());

    String colorStr = overlay.getColor();
    if (!WWUtil.isEmpty(colorStr)) {
      Color color = WWUtil.decodeColorABGR(colorStr);

      ShapeAttributes attributes = new BasicShapeAttributes();
      attributes.setDrawInterior(true);
      attributes.setInteriorMaterial(new Material(color));
      this.setAttributes(attributes);
    }
  }
Example #4
0
  protected void doDrawOnTo(BufferedImageRaster canvas) {
    Sector sector = this.getSector();
    if (null == sector) {
      String message = Logging.getMessage("nullValue.SectorIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (!sector.intersects(canvas.getSector())) {
      return;
    }

    java.awt.Graphics2D g2d = null;
    java.awt.Shape prevClip = null;
    java.awt.Composite prevComposite = null;
    java.lang.Object prevInterpolation = null, prevAntialiasing = null;

    try {
      int canvasWidth = canvas.getWidth();
      int canvasHeight = canvas.getHeight();

      // Apply the transform that correctly maps the image onto the canvas.
      java.awt.geom.AffineTransform transform =
          this.computeSourceToDestTransform(
              this.getWidth(),
              this.getHeight(),
              this.getSector(),
              canvasWidth,
              canvasHeight,
              canvas.getSector());

      AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
      Rectangle2D rect = op.getBounds2D(this.getBufferedImage());

      int clipWidth =
          (int) Math.ceil((rect.getMaxX() >= canvasWidth) ? canvasWidth : rect.getMaxX());
      int clipHeight =
          (int) Math.ceil((rect.getMaxY() >= canvasHeight) ? canvasHeight : rect.getMaxY());

      if (clipWidth <= 0 || clipHeight <= 0) {
        return;
      }

      g2d = canvas.getGraphics();

      prevClip = g2d.getClip();
      prevComposite = g2d.getComposite();
      prevInterpolation = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
      prevAntialiasing = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);

      // Set the alpha composite for appropriate alpha blending.
      g2d.setComposite(java.awt.AlphaComposite.SrcOver);
      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g2d.drawImage(this.getBufferedImage(), transform, null);
    }
    //        catch (java.awt.image.ImagingOpException ioe)
    //        {
    //            // If we catch a ImagingOpException, then the transformed image has a width or
    // height of 0.
    //            // This indicates that there is no intersection between the source image and the
    // canvas,
    //            // or the intersection is smaller than one pixel.
    //        }
    //        catch (java.awt.image.RasterFormatException rfe)
    //        {
    //            // If we catch a RasterFormatException, then the transformed image has a width or
    // height of 0.
    //            // This indicates that there is no intersection between the source image and the
    // canvas,
    //            // or the intersection is smaller than one pixel.
    //        }
    catch (Throwable t) {
      String reason = WWUtil.extractExceptionReason(t);
      Logging.logger().log(java.util.logging.Level.SEVERE, reason, t);
    } finally {
      // Restore the previous clip, composite, and transform.
      try {
        if (null != g2d) {
          if (null != prevClip) g2d.setClip(prevClip);

          if (null != prevComposite) g2d.setComposite(prevComposite);

          if (null != prevInterpolation)
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, prevInterpolation);

          if (null != prevAntialiasing)
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, prevAntialiasing);
        }
      } catch (Throwable t) {
        Logging.logger().log(java.util.logging.Level.FINEST, WWUtil.extractExceptionReason(t), t);
      }
    }
  }
  /**
   * Create an screen image.
   *
   * @param tc the current {@link KMLTraversalContext}.
   * @param overlay the <i>Overlay</i> element containing.
   * @throws NullPointerException if the traversal context is null.
   * @throws IllegalArgumentException if the parent overlay or the traversal context is null.
   */
  public KMLScreenImageImpl(KMLTraversalContext tc, KMLScreenOverlay overlay) {
    this.parent = overlay;

    if (tc == null) {
      String msg = Logging.getMessage("nullValue.TraversalContextIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (overlay == null) {
      String msg = Logging.getMessage("nullValue.ParentIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    KMLVec2 xy = this.parent.getScreenXY();
    if (xy != null) {
      this.screenOffset =
          new Offset(
              xy.getX(),
              xy.getY(),
              KMLUtil.kmlUnitsToWWUnits(xy.getXunits()),
              KMLUtil.kmlUnitsToWWUnits(xy.getYunits()));
    }

    xy = this.parent.getOverlayXY();
    if (xy != null) {
      this.imageOffset =
          new Offset(
              xy.getX(),
              xy.getY(),
              KMLUtil.kmlUnitsToWWUnits(xy.getXunits()),
              KMLUtil.kmlUnitsToWWUnits(xy.getYunits()));
    }

    this.setRotation(overlay.getRotation());

    xy = this.parent.getRotationXY();
    if (xy != null) {
      setRotationOffset(
          new Offset(
              xy.getX(),
              xy.getY(),
              KMLUtil.kmlUnitsToWWUnits(xy.getXunits()),
              KMLUtil.kmlUnitsToWWUnits(xy.getYunits())));
    }

    String colorStr = overlay.getColor();
    if (colorStr != null) {
      Color color = WWUtil.decodeColorABGR(colorStr);
      this.setColor(color);
    }

    // Compute desired image size, and the scale factor that will make it that size
    KMLVec2 kmlSize = this.parent.getSize();
    if (kmlSize != null) {
      Size size = new Size();
      size.setWidth(
          getSizeMode(kmlSize.getX()),
          kmlSize.getX(),
          KMLUtil.kmlUnitsToWWUnits(kmlSize.getXunits()));
      size.setHeight(
          getSizeMode(kmlSize.getY()),
          kmlSize.getY(),
          KMLUtil.kmlUnitsToWWUnits(kmlSize.getYunits()));
      this.setSize(size);
    }
  }
  /**
   * Export the placemark attributes to KML as a {@code <Style>} element. The {@code output} object
   * will receive the data. This object must be one of: java.io.Writer<br>
   * java.io.OutputStream<br>
   * javax.xml.stream.XMLStreamWriter
   *
   * @param output Object to receive the generated KML.
   * @throws XMLStreamException If an exception occurs while writing the KML
   * @see #export(String, Object)
   */
  protected void exportAsKML(Object output) throws XMLStreamException {
    XMLStreamWriter xmlWriter = null;
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    boolean closeWriterWhenFinished = true;

    if (output instanceof XMLStreamWriter) {
      xmlWriter = (XMLStreamWriter) output;
      closeWriterWhenFinished = false;
    } else if (output instanceof Writer) {
      xmlWriter = factory.createXMLStreamWriter((Writer) output);
    } else if (output instanceof OutputStream) {
      xmlWriter = factory.createXMLStreamWriter((OutputStream) output);
    }

    if (xmlWriter == null) {
      String message = Logging.getMessage("Export.UnsupportedOutputObject");
      Logging.logger().warning(message);
      throw new IllegalArgumentException(message);
    }

    xmlWriter.writeStartElement("Style");

    // Line style
    xmlWriter.writeStartElement("LineStyle");

    final Color lineColor = this.getOutlineMaterial().getDiffuse();
    if (lineColor != null) {
      xmlWriter.writeStartElement("color");
      xmlWriter.writeCharacters(KMLExportUtil.stripHexPrefix(WWUtil.encodeColorABGR(lineColor)));
      xmlWriter.writeEndElement();

      xmlWriter.writeStartElement("colorMode");
      xmlWriter.writeCharacters("normal");
      xmlWriter.writeEndElement();
    }

    final Double lineWidth = this.getOutlineWidth();
    if (lineWidth != null) {
      xmlWriter.writeStartElement("width");
      xmlWriter.writeCharacters(Double.toString(lineWidth));
      xmlWriter.writeEndElement();
    }

    xmlWriter.writeEndElement(); // LineStyle

    // Poly style
    xmlWriter.writeStartElement("PolyStyle");

    final Color fillColor = this.getInteriorMaterial().getDiffuse();
    if (fillColor != null) {
      xmlWriter.writeStartElement("color");
      xmlWriter.writeCharacters(KMLExportUtil.stripHexPrefix(WWUtil.encodeColorABGR(fillColor)));
      xmlWriter.writeEndElement();

      xmlWriter.writeStartElement("colorMode");
      xmlWriter.writeCharacters("normal");
      xmlWriter.writeEndElement();
    }

    xmlWriter.writeStartElement("fill");
    xmlWriter.writeCharacters(kmlBoolean(isDrawInterior()));
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("outline");
    xmlWriter.writeCharacters(kmlBoolean(isDrawOutline()));
    xmlWriter.writeEndElement();

    xmlWriter.writeEndElement(); // PolyStyle
    xmlWriter.writeEndElement(); // Style

    xmlWriter.flush();
    if (closeWriterWhenFinished) xmlWriter.close();
  }