Beispiel #1
0
  /**
   * This function takes an OMGraphicList and loads each one with the array representing the records
   * in the dbf file. Each graphics stores the graphic in its object slot.
   */
  public void loadDbfModelIntoGraphics(OMGraphicList list) {
    if (list != null && dbfModel.getRowCount() > 0) {
      int numgraphics = list.size();

      for (int i = 0; i < numgraphics; i++) {
        try {
          OMGraphic omg = list.getOMGraphicAt(i);
          Integer recnum = (Integer) (omg.getAttribute(ShapeConstants.SHAPE_INDEX_ATTRIBUTE));
          // OFF BY ONE!!! The shape record numbers
          // assigned to the records start with 0, while
          // everything else we do starts with 0. The DbfTableModel
          // follows java convention and starts at 0. The integer
          // stored in the OMG should know it too.
          Object inforec = dbfModel.getRecord(recnum.intValue());
          omg.putAttribute(ShapeConstants.SHAPE_DBF_INFO_ATTRIBUTE, inforec);
        } catch (ClassCastException cce) {
          if (Debug.debugging("shape")) {
            cce.printStackTrace();
          }
        } catch (NullPointerException npe) {
          npe.printStackTrace();
        }
      }
    }
  }
Beispiel #2
0
  /** Read a cache of OMGraphics */
  public OMGraphicList readCachedGraphics(URL url) throws java.io.IOException {

    if (Debug.debugging("areas")) {
      Debug.output("Reading cached graphics");
    }

    OMGraphicList omgraphics = new OMGraphicList();

    if (url != null) {
      omgraphics.readGraphics(url);
    }
    return omgraphics;
  }
  public void paint(Graphics g) {
    if (layer == null) {
      logger.warning("NULL layer, skipping...");
      return;
    }

    OMGraphicList list = layer.getList();
    Projection proj = layer.getProjection();
    Graphics2D g2 = (Graphics2D) g;

    if (layer.isProjectionOK(proj)) {

      if (getBuffer() == null) {
        // Not sure how we get here, but it's here just in case so that
        // the list might get painted if it exists and the buffered
        // image wasn't created.
        logger.fine("creating image buffer in paint");
        if (list != null) {
          setBuffer(createAndPaintImageBuffer(list));
        }
      }

      BufferedImage bufferedImage = getBuffer();

      setCompositeOnGraphics(g2);

      if (bufferedImage != null) {

        AffineTransform af = new AffineTransform();
        af.translate(offset.getX(), offset.getY());
        g2.drawRenderedImage((BufferedImage) bufferedImage, af);
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("RenderingPolicy:" + layer.getName() + ": rendering buffer");
        }

      } else if (list != null) {
        super.setRenderingHints(g);
        list.render(g);

        if (logger.isLoggable(Level.FINE)) {
          logger.fine(layer.getName() + ": rendering list directly");
        }
      }
    } else if (logger.isLoggable(Level.FINE)) {
      logger.fine(
          layer.getName()
              + ".paint(): "
              + (list == null ? "NULL list, skipping..." : " skipping due to projection."));
    }
  }
 @Override
 public void render(Graphics gr) {
   Graphics2D image = (Graphics2D) gr;
   image.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   super.render(image);
 }
Beispiel #5
0
 /** {@inheritDoc} */
 @Override
 public synchronized OMGraphicList prepare() {
   if (getProjection() == null) {
     return graphics;
   }
   graphics.project(getProjection(), true);
   return graphics;
 }
  /**
   * Create a graphical representation of the object. The constructor calls the abstract
   * createGraphic method of this class to create the custom graphic which is then added to the
   * OMGraphicList. This method also sets the SimpleBeanObject's id as the appObject associated with
   * the created graphic.
   */
  public CustomGraphic(SimpleBeanObject object) {

    super(1);

    setTraverseMode(OMGraphicList.LAST_ADDED_ON_TOP);

    graphic = createGraphic(object);

    super.add(graphic);

    putAttribute(OMGraphic.APP_OBJECT, new Long(object.getId()));
  }
Beispiel #7
0
 /** {@inheritDoc} */
 @Override
 public void dispose() {
   synchronized (graphics) {
     graphics.clear();
   }
   synchronized (this) {
     if (timer != null) {
       timer.stop();
     }
   }
   super.dispose();
 }
 protected BufferedImage createAndPaintImageBuffer(OMGraphicList list) {
   BufferedImage bufferedImage = null;
   if (list != null && layer != null) {
     int w = layer.getProjection().getWidth();
     int h = layer.getProjection().getHeight();
     bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
     Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
     super.setRenderingHints(g2d);
     list.render(g2d);
     if (logger.isLoggable(Level.FINE)) {
       logger.fine(layer.getName() + ": rendering list into buffer");
     }
   }
   return bufferedImage;
 }
Beispiel #9
0
  /**
   * DeterminePoliticalAreas goes over a list of omgraphics, and spits out a hashtable that holds
   * PoliticalArea objects for every area key. When an ID is found in the graphics, it is checked in
   * the hashtable for like graphics, and added to that PoliticalArea if found. If not found, a new
   * PoliticalArea is created and placed in the Hashtable. This will duplicate graphics if you call
   * it more than once for the same graphic list.
   *
   * @param graphicList the list of graphics. The top level graphic entries on the list represent
   *     areas.
   */
  public Hashtable determinePoliticalAreas(OMGraphicList graphicList, Hashtable poli_areas) {

    // Simple case. No graphics means an empty list of regions.
    String name = null;
    String key = null;

    if (graphicList != null) {
      int size = graphicList.size();
      for (int i = 0; i < size; i++) {
        OMGraphic graphic = graphicList.getOMGraphicAt(i);
        // below should be a vector like [ "Massachusetts",
        // "MA" ];

        Object obj = graphic.getAttribute(ShapeConstants.SHAPE_DBF_INFO_ATTRIBUTE);
        if (obj == null) {
          if (Debug.debugging("areas")) {
            Debug.error("AreaHandler: No attributes for graphic #" + i);
          }
          continue;
        }

        if (obj instanceof Vector) {
          Vector pair = (Vector) obj;

          name = (String) pair.elementAt(nameIndex);
          key = ((String) pair.elementAt(keyIndex)).toUpperCase().intern();
          if (Debug.debugging("areas")) {
            Debug.output("AreaHandler: looking at " + name + ", " + key);
          }
        } else if (obj instanceof String) {
          // Assume that the key is stored here, I guess.
          key = (String) obj;
          if (Debug.debugging("areas")) {
            Debug.output("AreaHandler: String app object, looking at " + key);
          }
        } else {
          if (Debug.debugging("areas")) {
            Debug.output("AreaHandler: Unidentified app object type " + obj);
          }
        }

        // Get the political area object for this keyiation.
        PoliticalArea area = (PoliticalArea) poli_areas.get(key);

        if (area == null) { // key is not in table
          area = new PoliticalArea(name, key);
          poli_areas.put(key, area); // add it to the table
          // AreaDrawParams adp =
          // (AreaDrawParams)drawingParams.get(key);
          // if (adp != null) {
          // area.setDrawingAttributes(adp.drawingAttributes);
          // }
        }

        // Add the graphic to the list for this political
        // area.
        area.addGraphic(graphic);
      }

      if (Debug.debugging("areas")) {
        Debug.output(
            "AreaHandler: Finished determinePoliticalAreas: "
                + poli_areas.size()
                + " areas defined.");
      }
    }

    return poli_areas;
  }
Beispiel #10
0
  /**
   * Prepares the graphics for the layer. This is where the getRectangle() method call is made on
   * the dted.
   *
   * <p>Occasionally it is necessary to abort a prepare call. When this happens, the map will set
   * the cancel bit in the LayerThread, (the thread that is running the prepare). If this Layer
   * needs to do any cleanups during the abort, it should do so, but return out of the prepare asap.
   */
  public synchronized OMGraphicList prepare() {

    if (isCancelled()) {
      Debug.message("dted", getName() + "|DTEDLayer.prepare(): aborted.");
      return null;
    }

    Projection projection = getProjection();

    if (projection == null) {
      Debug.error("DTED Layer needs to be added to the MapBean before it can draw images!");
      return new OMGraphicList();
    }

    DTEDCacheManager cache = getCache();

    if (!(projection instanceof EqualArc)) {
      // fireRequestInfoLine("DTED works faster with an Equal Arc projection (CADRG/LLXY).");
    }

    Debug.message("basic", getName() + "|DTEDLayer.prepare(): doing it");

    // Setting the OMGraphicsList for this layer. Remember, the
    // OMGraphicList is made up of OMGraphics, which are generated
    // (projected) when the graphics are added to the list. So,
    // after this call, the list is ready for painting.

    // call getRectangle();
    if (Debug.debugging("dted")) {
      Debug.output(
          getName()
              + "|DTEDLayer.prepare(): "
              + "calling getRectangle "
              + " with projection: "
              + projection
              + " ul = "
              + projection.getUpperLeft()
              + " lr = "
              + projection.getLowerRight());
    }

    OMGraphicList omGraphicList;

    if (projection.getScale() < maxScale) {
      omGraphicList = cache.getRectangle(projection);
    } else {
      fireRequestInfoLine("  The scale is too small for DTED viewing.");
      Debug.error(
          "DTEDLayer: scale (1:"
              + projection.getScale()
              + ") is smaller than minimum (1:"
              + maxScale
              + ") allowed.");
      omGraphicList = new OMGraphicList();
    }
    // ///////////////////
    // safe quit
    int size = 0;
    if (omGraphicList != null) {
      size = omGraphicList.size();
      Debug.message(
          "basic", getName() + "|DTEDLayer.prepare(): finished with " + size + " graphics");

      // // Don't forget to project them. Since they are only
      // // being recalled if the projection has changed, then we
      // // need to force a reprojection of all of them because the
      // // screen position has changed.
      // omGraphicList.project(projection, true);

    } else {
      Debug.message("basic", getName() + "|DTEDLayer.prepare(): finished with null graphics list");
    }

    return omGraphicList;
  }
 public synchronized OMGraphicList prepare() {
   OMGraphicList list = getList();
   list.generate(getProjection());
   return list;
 }
Beispiel #12
0
 /** Turn on anti-aliasing */
 @Override
 public void render(Graphics g) {
   Graphics2D image = (Graphics2D) g;
   image.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   super.render(image);
 }