RE: [OpenMap Users] semi-transparent layers?

From: Hamilton, Kimberly D. <KDHAMILTON@northropgrumman.com>
Date: Wed Oct 30 2002 - 19:22:41 EST

Hi Don,
That worked perfectly. The resulting code is very simple so I don't know if
it's even worth posting, but here it is in case anyone's interested.
CompositeGraphicList extends from OMGraphicList. The only significant
methods, as you suggested, are generate() and render(). The other methods,
isRenderable(), fill(), and draw() had to be overridden from BasicGeometry
only because they use shape, which is of type GeneralPath instead of Area.

Thanks again!
Kim

*****************************************************
package mapgui.graphics;

import java.awt.*;
import java.util.*;
import java.awt.geom.*;

import com.bbn.openmap.omGraphics.*;
import com.bbn.openmap.proj.*;

public class CompositeGraphicList extends OMGraphicList {
  Area totalArea = new Area();

  /**
   * Prepare the graphics for rendering.
   * Call <code>getShape()</code> on each graphic, create an <code>
   * Area</code> object from each Shape, and add <code>Area</code>s
   * together.
   *
   * @param p a <code>Projection</code>
   * @param forceProjectAll if true, all the graphics on the list
   * are generated with the new projection. If false they are only
   * generated if getNeedToRegenerate() returns true
   */
  public void generate(Projection p, boolean forceProjectAll) {
    super.generate(p,true);

    Iterator iterator = iterator();
    Shape thisShape;
    Area thisArea;
    totalArea = new Area();

    while (iterator.hasNext()) {
      OMGraphic omg = (OMGraphic) iterator.next();
      thisShape = omg.getShape();
      thisArea = new Area(thisShape);
      totalArea.add(thisArea);
    }
    setNeedToRegenerate(false);
  }

  /**
   * Renders the <code>totalArea</code> object constructed in
   * <code>generate()</code>
   *
   * @param g the AWT Graphics context
   */
  public void render(Graphics g) {
    if (shouldRenderFill()) {
      setGraphicsForFill(g);
      fill(g);
    }

    if (shouldRenderEdge()) {
      setGraphicsForEdge(g);
      draw(g);
    }
  }

  /**
   * Overriden from <code>BasicGeometry</code> because it checks that
   * <code>shape</code> != null (which is of type <code>GeneralPath</code>
   * instead of <code>Area</code>)
   * @return boolean
   */
  public boolean isRenderable() {
    return (!getNeedToRegenerate() &&
            isVisible() && totalArea != null);
  }

  /**
   * Paint the graphic, as a filled area. Overriden from BasicGeometry.<P>
   *
   * This paints the graphic into the Graphics context. This is
   * similar to <code>paint()</code> function of
   * java.awt.Components. Note that if the graphic has not been
   * generated or if it isn't visible, it will not be
   * rendered. <P>
   *
   * This method used to be abstract, but with the conversion of
   * OMGeometrys to internally represent themselves as java.awt.Shape
   * objects, it's a more generic method. If the OMGeometry hasn't
   * been updated to use Shape objects, it should have its own
   * render method.
   *
   * @param g Graphics2D context to render into.
   */
  public void fill(Graphics g) {
    if (isRenderable()) {
      ((Graphics2D)g).fill(totalArea);
    }
  }

  /**
   * Paint the graphic, as an outlined shape. Overriden from
BasicGeometry.<P>
   *
   * This paints the graphic into the Graphics context. This is
   * similar to <code>paint()</code> function of
   * java.awt.Components. Note that if the graphic has not been
   * generated or if it isn't visible, it will not be
   * rendered. <P>
   *
   * This method used to be abstract, but with the conversion of
   * OMGeometrys to internally represent themselves as java.awt.Shape
   * objects, it's a more generic method. If the OMGeometry hasn't
   * been updated to use Shape objects, it should have its own
   * render method.
   *
   * @param g Graphics2D context to render into.
   */
  public void draw(Graphics g) {
    if (isRenderable()) {
      ((Graphics2D)g).draw(totalArea);
    }
  }
}
*****************************************************

-----Original Message-----
From: Don Dietrick [mailto:dietrick@bbn.com]
Sent: Wednesday, October 30, 2002 2:33 PM
To: Hamilton, Kimberly D.
Cc: 'openmap-users@bbn.com'
Subject: Re: [OpenMap Users] semi-transparent layers?

Here's something different - You could put all of your shapes in a
special OMGraphicList that does something like this - in it's generate
method, it calls OMGraphic.getShape() on each one of your shapes,
changes each one into a java.awt.geom.Area object, and then adds them
together to make one Area object. Then, in it's render method, it just
uses the one Area object. This assumes that all the shapes on the list
are supposed to be rendered with the same color, etc.

- Don

On Wednesday, October 30, 2002, at 05:18 PM, Hamilton, Kimberly D.
wrote:

> Hi Don,
> Thanks! I tried it out, and it actually worked better for me to
> manually
> tweak the transparency of the pixels returned by getRGB(), (such as:
> current_byte & 0x66FFFFFF) and pass that modified array to OMRaster.
> Calling OMRaster.setTransparent(value) caused a grey haze over the
> pixels
> where nothing was drawn -- I wanted that area to remain blank.
>
> This method is great if all shapes are x-y. However, some of my
> shapes are
> OMPolys consisting of lat/lon points connected by GreatCircle lines.
> I'll
> post a message describing the steps if I can get those types of shapes
> taken
> care of.
>
> Thanks again,
> Kim
>
>

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, BBN Technologies, dietrick@bbn.com
10 Moulton Street, Cambridge, MA 02138
617-873-3031 [fax]-2794
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed Oct 30 19:26:07 2002

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:33 EDT