Esempio n. 1
0
  /**
   * Creates an outline of a text shape for better readability
   *
   * @param originalText
   * @param outlineSize desired width of the outline. Overrides the value in the RendererSettings
   *     object.
   * @return
   */
  public static ShapeInfo createTextOutline(ShapeInfo originalText, int outlineSize) {
    Shape outline = null;
    ShapeInfo siOutline = null;

    // int outlineSize = RendererSettings.getInstance().getTextOutlineWidth();

    outlineSize = Math.abs(outlineSize);

    Color textColor = null;

    try {
      if (originalText.getShape() != null) outline = new GeneralPath(originalText.getShape());
      else if (originalText.getTextLayout() != null) {
        outline =
            originalText
                .getTextLayout()
                .getOutline(
                    AffineTransform.getTranslateInstance(
                        originalText.getGlyphPosition().getX(),
                        originalText.getGlyphPosition().getY()));
      }
      siOutline = new ShapeInfo(outline);

      if (originalText.getFillColor() != null) textColor = originalText.getFillColor(); // shape
      else if (originalText.getLineColor() != null) // vs
      textColor = originalText.getLineColor(); // textlayout

      //            if(textColor.getRed() == 255 &&
      //                    textColor.getGreen() == 255 &&
      //                    textColor.getBlue() == 255)
      //                siOutline.setLineColor(Color.BLACK);
      //            else
      //                siOutline.setLineColor(Color.WHITE);

      if (originalText.getAffineTransform() != null)
        siOutline.setAffineTransform(new AffineTransform(originalText.getAffineTransform()));

      if (originalText.getTextBackgroundColor() != null) {
        siOutline.setLineColor(originalText.getTextBackgroundColor());
      } else siOutline.setLineColor(getIdealTextBackgroundColor(textColor));

      // siOutline.setStroke(new BasicStroke(2));
      siOutline.setStroke(
          new BasicStroke(outlineSize, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3));
    } catch (Exception exc) {
      ErrorLogger.LogException("SymbolDraw", "createTextOuline", exc);
    }
    return siOutline;
  }
Esempio n. 2
0
  /**
   * Does the actual drawing of the Symbol. MilstdSymbol need to be properly populated via the
   * Render call first. Not for client use. They should Use IJavaRenderer.Draw or
   * IJavaRenderer.DrawDB
   *
   * @param symbols
   * @param destination surface to draw to
   * @param offsetX usually a negative value. if your clip.X is 40, offsetX should be -40
   * @param offsetY usually a negative value. if your clip.Y is 40, offsetY should be -40
   * @throws RendererException
   */
  public static void Draw(
      ArrayList<MilStdSymbol> symbols, Graphics2D destination, int offsetX, int offsetY)
      throws RendererException {
    Logger loggy = Logger.getLogger(ErrorLogger.LoggerName);
    try {

      if (symbols != null && destination != null) {

        destination.setRenderingHint(
            RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Stroke oldStroke = destination.getStroke();
        AffineTransform oldTransform = destination.getTransform();

        // loop through symbols and draw
        MilStdSymbol symbol;

        int unitCount = symbols.size();
        for (int lcv = 0; lcv < unitCount; lcv++) {
          symbol = symbols.get(lcv);

          // synchronized(destination)
          // {
          ArrayList<ShapeInfo> shapes = symbol.getSymbolShapes();
          if (shapes != null) {
            ShapeInfo siTemp;
            for (int i = 0; i < shapes.size(); i++) {
              siTemp = shapes.get(i);

              if (siTemp.getAffineTransform() != null) {
                AffineTransform atTemp = (AffineTransform) siTemp.getAffineTransform().clone();
                atTemp.preConcatenate(AffineTransform.getTranslateInstance(offsetX, offsetY));
                destination.setTransform(atTemp);
                // destination.setTransform(siTemp.getAffineTransform());
              } else destination.translate(offsetX, offsetY);

              if (siTemp.getStroke() != null) destination.setStroke(siTemp.getStroke());

              if (siTemp.getTexturePaint() != null) {
                TexturePaint tp = siTemp.getTexturePaint();
                destination.setPaint(tp);
                destination.fill(siTemp.getShape());
              } else if (siTemp.getFillColor() != null) {
                destination.setColor(siTemp.getFillColor());
                if (siTemp.getShape() != null) destination.fill(siTemp.getShape());
              }
              if (siTemp.getLineColor() != null) {
                destination.setColor(siTemp.getLineColor());

                Point2D point = null;
                if (siTemp.getShape() != null) destination.draw(siTemp.getShape());
                else if (siTemp.getGlyphVector() != null) {
                  point = siTemp.getGlyphPosition();
                  destination.drawGlyphVector(
                      siTemp.getGlyphVector(), (float) point.getX(), (float) point.getY());
                } else if (siTemp.getTextLayout() != null) {
                  point = siTemp.getGlyphPosition();
                  siTemp
                      .getTextLayout()
                      .draw(destination, (float) point.getX(), (float) point.getY());
                }
              }

              destination.setTransform(oldTransform);
              destination.setStroke(oldStroke);
            }

            // draw modifiers
            shapes = symbol.getModifierShapes();

            if (shapes != null) {
              for (int i = 0; i < shapes.size(); i++) {
                siTemp = shapes.get(i);

                if (siTemp.getAffineTransform() != null) {
                  AffineTransform atTemp = (AffineTransform) siTemp.getAffineTransform().clone();
                  atTemp.preConcatenate(AffineTransform.getTranslateInstance(offsetX, offsetY));
                  destination.setTransform(atTemp);
                  // destination.setTransform(siTemp.getAffineTransform());
                } else destination.translate(offsetX, offsetY);

                if (siTemp.getStroke() != null) destination.setStroke(siTemp.getStroke());

                if (siTemp.getFillColor() != null) {
                  destination.setColor(siTemp.getFillColor());
                  if (siTemp.getShape() != null) destination.fill(siTemp.getShape());
                  else // for deutch.  needs to set line color for text
                  {
                    siTemp.setLineColor(siTemp.getFillColor());
                    siTemp.setFillColor(null);
                  }
                }
                if (siTemp.getLineColor() != null) // change to else if when Deutch fixes above
                {
                  destination.setColor(siTemp.getLineColor());

                  Point2D point = null;
                  if (siTemp.getShape() != null) destination.draw(siTemp.getShape());
                  else if (siTemp.getGlyphVector() != null) {
                    point = siTemp.getGlyphPosition();
                    destination.drawGlyphVector(
                        siTemp.getGlyphVector(), (float) point.getX(), (float) point.getY());
                  } else if (siTemp.getTextLayout() != null) {
                    point = siTemp.getGlyphPosition();
                    siTemp
                        .getTextLayout()
                        .draw(destination, (float) point.getX(), (float) point.getY());
                  }
                }

                destination.setTransform(oldTransform);
              }
            }
          }
          // }
        }

        destination.setTransform(oldTransform);
        destination.setStroke(oldStroke);

      } else {
        // parameters are bad, throw exception
        String badValues = "Bad parameters passed: ";
        if (symbols == null) badValues += " symbols";
        if (destination == null) badValues += " destination";

        RendererException re = new RendererException(badValues, null);
        loggy.logp(Level.INFO, "SymbolDraw", "Draw()", "draw failure", re);
        throw re;
      }

    } catch (Exception exc) {
      RendererException re2 = new RendererException("Draw Operation Failed", exc);
      loggy.logp(Level.INFO, "SymbolDraw", "Draw()", "draw failure", re2);
      throw re2;
    }
  }
Esempio n. 3
0
  /**
   * Creates an outline for single point graphics
   *
   * @param symbolFrame
   * @param thickness
   * @return
   */
  public static ArrayList<ShapeInfo> createSinglePointOutline(
      ShapeInfo symbolFrame, int thickness, Color outlineColor) {
    ShapeInfo siOutline1 = null;
    ShapeInfo siOutline2 = null;
    ShapeInfo siOutline3 = null;
    ShapeInfo siOutline4 = null;
    ShapeInfo siOutline5 = null;
    ShapeInfo siOutline6 = null;
    ShapeInfo siOutline7 = null;
    ShapeInfo siOutline8 = null;
    AffineTransform afx1 = null;
    AffineTransform afx2 = null;
    AffineTransform afx3 = null;
    AffineTransform afx4 = null;
    AffineTransform afx5 = null;
    AffineTransform afx6 = null;
    AffineTransform afx7 = null;
    AffineTransform afx8 = null;
    ArrayList<ShapeInfo> outlineShapes = null;
    // int outlineSize = RendererSettings.getInstance().getTextOutlineWidth();

    Color lineColor = null;
    Color backgroundColor = null;

    try {
      int offset = 0;

      if (outlineColor == null) {
        backgroundColor = getIdealTextBackgroundColor(lineColor);
      } else {
        backgroundColor = outlineColor;
      }
      outlineShapes = new ArrayList<ShapeInfo>();

      if (symbolFrame.getTextLayout() != null) {
        outlineShapes = new ArrayList<ShapeInfo>();

        for (int i = 1; i <= thickness; i++) {

          offset = i;

          Point2D textPosition = null;
          if (symbolFrame.getModifierStringPosition() != null)
            textPosition =
                new Point2D.Double(
                    symbolFrame.getModifierStringPosition().getX(),
                    symbolFrame.getModifierStringPosition().getY());
          else textPosition = new Point2D.Double(0, 0);

          siOutline1 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX() - offset, textPosition.getY() - offset));
          siOutline2 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX() + offset, textPosition.getY() - offset));
          siOutline3 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX() - offset, textPosition.getY() + offset));
          siOutline4 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX() + offset, textPosition.getY() + offset));
          siOutline5 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX() - offset, textPosition.getY()));
          siOutline6 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX() + offset, textPosition.getY()));
          siOutline7 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX(), textPosition.getY() + offset));
          siOutline8 =
              new ShapeInfo(
                  symbolFrame.getTextLayout(),
                  new Point2D.Double(textPosition.getX(), textPosition.getY() - offset));

          siOutline1.setLineColor(backgroundColor);
          siOutline2.setLineColor(backgroundColor);
          siOutline3.setLineColor(backgroundColor);
          siOutline4.setLineColor(backgroundColor);
          siOutline5.setLineColor(backgroundColor);
          siOutline6.setLineColor(backgroundColor);
          siOutline7.setLineColor(backgroundColor);
          siOutline8.setLineColor(backgroundColor);

          Stroke tempStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3);
          siOutline1.setStroke(tempStroke);
          siOutline2.setStroke(tempStroke);
          siOutline3.setStroke(tempStroke);
          siOutline4.setStroke(tempStroke);
          siOutline5.setStroke(tempStroke);
          siOutline6.setStroke(tempStroke);
          siOutline7.setStroke(tempStroke);
          siOutline8.setStroke(tempStroke);

          if (symbolFrame.getAffineTransform() != null) {
            siOutline1.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline2.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline3.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline4.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline5.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline6.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline7.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline8.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
          }

          outlineShapes.add(siOutline1);
          outlineShapes.add(siOutline2);
          outlineShapes.add(siOutline3);
          outlineShapes.add(siOutline4);
          outlineShapes.add(siOutline5);
          outlineShapes.add(siOutline6);
          outlineShapes.add(siOutline7);
          outlineShapes.add(siOutline8);
        } // end for
      } // end if
      else if (symbolFrame.getGlyphVector() != null) {
        outlineShapes = new ArrayList<ShapeInfo>();

        for (int j = 1; j <= thickness; j++) {

          offset = j;

          Point2D textPosition =
              new Point2D.Double(
                  symbolFrame.getGlyphPosition().getX(), symbolFrame.getGlyphPosition().getY());

          siOutline1 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX() - offset, textPosition.getY() - offset));
          siOutline2 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX() + offset, textPosition.getY() - offset));
          siOutline3 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX() - offset, textPosition.getY() + offset));
          siOutline4 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX() + offset, textPosition.getY() + offset));
          siOutline5 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX() - offset, textPosition.getY()));
          siOutline6 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX() + offset, textPosition.getY()));
          siOutline7 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX(), textPosition.getY() + offset));
          siOutline8 =
              new ShapeInfo(
                  symbolFrame.getGlyphVector(),
                  new Point2D.Double(textPosition.getX(), textPosition.getY() - offset));

          if (symbolFrame.getShapeType() == ShapeInfo.SHAPE_TYPE_TG_SP_FRAME) {
            siOutline1.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline2.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline3.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline4.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline5.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline6.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline7.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
            siOutline8.setShapeType(ShapeInfo.SHAPE_TYPE_TG_SP_OUTLINE);
          }

          siOutline1.setLineColor(backgroundColor);
          siOutline2.setLineColor(backgroundColor);
          siOutline3.setLineColor(backgroundColor);
          siOutline4.setLineColor(backgroundColor);
          siOutline5.setLineColor(backgroundColor);
          siOutline6.setLineColor(backgroundColor);
          siOutline7.setLineColor(backgroundColor);
          siOutline8.setLineColor(backgroundColor);

          Stroke tempStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3);
          siOutline1.setStroke(tempStroke);
          siOutline2.setStroke(tempStroke);
          siOutline3.setStroke(tempStroke);
          siOutline4.setStroke(tempStroke);
          siOutline5.setStroke(tempStroke);
          siOutline6.setStroke(tempStroke);
          siOutline7.setStroke(tempStroke);
          siOutline8.setStroke(tempStroke);

          if (symbolFrame.getAffineTransform() != null) {
            siOutline1.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline2.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline3.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline4.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline5.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline6.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline7.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
            siOutline8.setAffineTransform(new AffineTransform(symbolFrame.getAffineTransform()));
          }

          outlineShapes.add(siOutline1);
          outlineShapes.add(siOutline2);
          outlineShapes.add(siOutline3);
          outlineShapes.add(siOutline4);
          outlineShapes.add(siOutline5);
          outlineShapes.add(siOutline6);
          outlineShapes.add(siOutline7);
          outlineShapes.add(siOutline8);
        } // end for

      } else if (symbolFrame.getShape() != null) {
        outlineShapes = new ArrayList<ShapeInfo>();

        for (int k = 1; k <= thickness; k++) {

          offset = k;

          siOutline1 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline2 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline3 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline4 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline5 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline6 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline7 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);
          siOutline8 =
              new ShapeInfo(symbolFrame.getShape(), ShapeInfo.SHAPE_TYPE_SINGLE_POINT_OUTLINE);

          siOutline1.setLineColor(backgroundColor);
          siOutline2.setLineColor(backgroundColor);
          siOutline3.setLineColor(backgroundColor);
          siOutline4.setLineColor(backgroundColor);
          siOutline5.setLineColor(backgroundColor);
          siOutline6.setLineColor(backgroundColor);
          siOutline7.setLineColor(backgroundColor);
          siOutline8.setLineColor(backgroundColor);

          Stroke tempStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3);
          siOutline1.setStroke(tempStroke);
          siOutline2.setStroke(tempStroke);
          siOutline3.setStroke(tempStroke);
          siOutline4.setStroke(tempStroke);
          siOutline5.setStroke(tempStroke);
          siOutline6.setStroke(tempStroke);
          siOutline7.setStroke(tempStroke);
          siOutline8.setStroke(tempStroke);

          if (symbolFrame.getAffineTransform() == null) {
            afx1 = new AffineTransform();
            afx2 = new AffineTransform();
            afx3 = new AffineTransform();
            afx4 = new AffineTransform();
            afx5 = new AffineTransform();
            afx6 = new AffineTransform();
            afx7 = new AffineTransform();
            afx8 = new AffineTransform();
          } else {
            afx1 = new AffineTransform(symbolFrame.getAffineTransform());
            afx2 = new AffineTransform(symbolFrame.getAffineTransform());
            afx3 = new AffineTransform(symbolFrame.getAffineTransform());
            afx4 = new AffineTransform(symbolFrame.getAffineTransform());
            afx5 = new AffineTransform(symbolFrame.getAffineTransform());
            afx6 = new AffineTransform(symbolFrame.getAffineTransform());
            afx7 = new AffineTransform(symbolFrame.getAffineTransform());
            afx8 = new AffineTransform(symbolFrame.getAffineTransform());
          }

          afx1.translate(-offset, -offset);
          afx2.translate(+offset, -offset);
          afx3.translate(-offset, +offset);
          afx4.translate(+offset, +offset);
          afx5.translate(-offset, 0);
          afx6.translate(+offset, 0);
          afx7.translate(0, +offset);
          afx8.translate(0, -offset);

          siOutline1.setAffineTransform(afx1);
          siOutline2.setAffineTransform(afx2);
          siOutline3.setAffineTransform(afx3);
          siOutline4.setAffineTransform(afx4);
          siOutline5.setAffineTransform(afx5);
          siOutline6.setAffineTransform(afx6);
          siOutline7.setAffineTransform(afx7);
          siOutline8.setAffineTransform(afx8);

          outlineShapes.add(siOutline1);
          outlineShapes.add(siOutline2);
          outlineShapes.add(siOutline3);
          outlineShapes.add(siOutline4);
          outlineShapes.add(siOutline5);
          outlineShapes.add(siOutline6);
          outlineShapes.add(siOutline7);
          outlineShapes.add(siOutline8);
        } // end for

      } else {
        String message = "ShapeInfo wasn't a TextLayout or a GlyphVector, returning null";
        ErrorLogger.LogMessage("SymbolDraw", "createTextOutlineQuick()", message, Level.FINEST);
        return null;
      }

      return outlineShapes;
    } catch (Exception exc) {
      ErrorLogger.LogException("SymbolDraw", "createTextOuline", exc);
    }
    return null;
  }