Example #1
0
 public static ReferencedEnvelope toEnvelope(WorldArea worldArea) {
   if (worldArea != null) {
     WorldLocation bottomLeft = worldArea.getBottomLeft();
     WorldLocation topRight = worldArea.getTopRight();
     return new ReferencedEnvelope(
         bottomLeft.getLong(),
         topRight.getLong(),
         bottomLeft.getLat(),
         topRight.getLat(),
         LATLONG);
   }
   return new ReferencedEnvelope(LATLONG);
 }
  /**
   * over-ridden method, where we write out our data
   *
   * @param theData the data to plot
   * @param out the stream to write to
   * @throws java.io.IOException file-related troubles
   */
  protected final void plotData(MWC.GUI.Layers theData, java.io.BufferedWriter out)
      throws java.io.IOException {

    java.text.DateFormat df = new java.text.SimpleDateFormat("ddHHmm");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));

    // work through the layers
    int num = _theData.size();
    for (int i = 0; i < num; i++) {
      Layer l = (Layer) _theData.elementAt(i);
      Enumeration<Editable> iter = l.elements();
      while (iter.hasMoreElements()) {
        Object oj = iter.nextElement();
        if (oj instanceof Debrief.Wrappers.FixWrapper) {
          Debrief.Wrappers.FixWrapper fw = (Debrief.Wrappers.FixWrapper) oj;
          WorldLocation pos = fw.getLocation();

          if (fw.getSymbolShowing()) {
            String lbl = fw.getName();
            writeBox(out, pos.getLong(), pos.getLat(), pos.getDepth(), fw.getColor(), lbl);
          }

          if (fw.getLabelShowing()) {
            String str = DebriefFormatDateTime.toStringHiRes(fw.getTime());
            writeText(out, pos.getLong(), pos.getLat(), pos.getDepth(), str, fw.getColor());
          }
        }
      }
    }

    // now draw the line connectors
    num = _theData.size();
    for (int i = 0; i < num; i++) {
      Layer l = (Layer) _theData.elementAt(i);
      Enumeration<Editable> iter = l.elements();
      int len = 0;
      while (iter.hasMoreElements()) {
        Object oj = iter.nextElement();

        if (oj instanceof MWC.GenericData.WatchableList) {
          // just check that we haven't got any dangling Fix lines
          // waiting to be finished
          if (len > 0) {
            // we have clearly written some fixes to the file, write the footer
            writeLineFooter(out, len);
            len = 0;
          }

          MWC.GenericData.WatchableList tw = (MWC.GenericData.WatchableList) oj;
          java.awt.Color col = tw.getColor();
          writeLineHeader(out, col);
        }

        if (oj instanceof Debrief.Wrappers.FixWrapper) {
          len++;
          Debrief.Wrappers.FixWrapper fw = (Debrief.Wrappers.FixWrapper) oj;
          WorldLocation pos = fw.getLocation();

          writeLineEntry(out, pos.getLong(), pos.getLat(), pos.getDepth());
        }
      }

      if (len > 0) {
        // we have clearly written some fixes to the file, write the footer
        writeLineFooter(out, len);
      }
    }
  }
Example #3
0
 public static Coordinate toCoord(WorldLocation val) {
   return new Coordinate(val.getLong(), val.getLat(), val.getDepth());
 }
Example #4
0
  /** put our keywords into the XML description */
  protected static String swapKeywords(
      final DetectionEvent detection,
      final Status currentLocation,
      final String weapon,
      final TargetType theTarget) {
    // amend string template to include available parameters
    final Float brg_degs = detection.getBearing();
    final WorldDistance rng = detection.getRange();

    // take a copy of the string
    String working = new String(weapon);

    // swap the bearing
    if (brg_degs != null) {
      final String brg_val = "" + brg_degs.floatValue();
      working = replaceAll(working, "$BRG$", brg_val);
    }

    // swap the range
    if (rng != null) {
      final String rng_val = "" + rng.getValueIn(WorldDistance.YARDS);
      working = replaceAll(working, "$RNG$", rng_val);
    }

    // insert the location of the target
    if (brg_degs != null) {
      final float brg_val = brg_degs.floatValue();

      // do we know range?
      if (rng != null) {
        // yes, compute target location
        final WorldVector newVector =
            new WorldVector(
                MWC.Algorithms.Conversions.Degs2Rads(brg_val),
                rng.getValueIn(WorldDistance.DEGS),
                0);
        final WorldLocation newLoc = currentLocation.getLocation().add(newVector);

        // produce strings from this location
        final String theDepth = "" + newLoc.getDepth();
        final String theLat = "" + newLoc.getLat();
        final String theLong = "" + newLoc.getLong();

        // put these strings into the new behaviour
        working = replaceAll(working, "$TGT_DEPTH$", theDepth);
        working = replaceAll(working, "$TGT_LAT$", theLat);
        working = replaceAll(working, "$TGT_LONG$", theLong);

      } else {
        // no, send the weapon down a bearing for XXXX yds
        // compute target location
        final double TGT_RANGE = 5000;
        final WorldVector newVector =
            new WorldVector(
                MWC.Algorithms.Conversions.Degs2Rads(brg_val),
                MWC.Algorithms.Conversions.Yds2Degs(TGT_RANGE),
                0);
        final WorldLocation newLoc = currentLocation.getLocation().add(newVector);

        // produce strings from this location
        final String theDepth = "" + newLoc.getDepth();
        final String theLat = "" + newLoc.getLat();
        final String theLong = "" + newLoc.getLong();

        // put these strings into the new behaviour
        working = replaceAll(working, "$TGT_DEPTH$", theDepth);
        working = replaceAll(working, "$TGT_LAT$", theLat);
        working = replaceAll(working, "$TGT_LONG$", theLong);
      }
    }

    if (theTarget != null) {
      // output the XML header stuff
      // output the plot
      final java.io.StringWriter newString = new StringWriter();
      //      final com.sun.xml.tree.XmlDocument doc = new com.sun.xml.tree.XmlDocument();
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      Document doc = null;
      try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.newDocument();
        final org.w3c.dom.Element type =
            ASSET.Util.XML.Decisions.Util.TargetTypeHandler.getElement(theTarget, doc);
        doc.appendChild(type);
        doc.setNodeValue(type.getTagName());
        //    doc.changeNodeOwner(type);
        //   doc.setSystemId("ASSET XML Version 1.0");

        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(newString);
        transformer.transform(source, result);
      } catch (ParserConfigurationException e) {
        e.printStackTrace(); // To change body of catch statement use Options | File Templates.
      } catch (DOMException e) {
        e.printStackTrace(); // To change body of catch statement use Options | File Templates.
      } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
        transformerFactoryConfigurationError
            .printStackTrace(); // To change body of catch statement use Options | File Templates.
      } catch (TransformerException e) {
        e.printStackTrace(); // To change body of catch statement use Options | File Templates.
      }

      //      // ok, we should be done now
      //      try
      //      {
      //        doc.write(newString);
      //      }
      //      catch(java.io.IOException e)
      //      {
      //        e.printStackTrace();
      //      }

      // try to extract the <target type portion
      if (newString != null) {
        final String val = newString.toString();
        final String startIdentifier = "<TargetType";
        final String endIdentifier = "</TargetType";
        final int start = val.indexOf(startIdentifier);
        final int end = val.lastIndexOf(endIdentifier);
        final String detail = val.substring(start, end + endIdentifier.length() + 1);

        // lastly, replace the string
        working = replaceAll(working, "<TargetType/>", detail);
      }
    }

    return working;
  }