/** * Creates a filled rectangle backdrop for the text * * @param originalText * @return */ public static ShapeInfo createTextBackgroundFill(ShapeInfo originalText) { Rectangle tempRect = null; ShapeInfo background = null; ShapeInfo returnVal = null; try { // tempRect = temp.getBounds(); tempRect = originalText .getTextLayout() .getPixelBounds( null, (float) originalText.getGlyphPosition().getX(), (float) originalText.getGlyphPosition().getY()); // tempRect.setRect(temp.getTextLayout().getBounds()); background = new ShapeInfo( new Rectangle( tempRect.x - 2, tempRect.y - 2, tempRect.width + 4, tempRect.height + 4)); if (originalText.getTextBackgroundColor() != null) { background.setFillColor(originalText.getTextBackgroundColor()); } else if (RendererSettings.getInstance().getLabelBackgroundColor() != null) { background.setFillColor(RendererSettings.getInstance().getLabelBackgroundColor()); } else { Color bgColor = null; if (originalText.getLineColor() != null) bgColor = getIdealTextBackgroundColor(originalText.getLineColor()); else if (originalText.getFillColor() != null) bgColor = getIdealTextBackgroundColor(originalText.getFillColor()); else bgColor = Color.white; background.setFillColor(bgColor); } if (originalText.getAffineTransform() != null) background.setAffineTransform(new AffineTransform(originalText.getAffineTransform())); returnVal = background; } catch (Exception exc) { ErrorLogger.LogException("SymbolDraw", "CreateTextBackgroundFill", exc); } return returnVal; }
/** * @param text * @param modifierValue * @param x * @param y * @param textColor Null == Black * @param textBackgroundColor null == renderer decides * @return */ public static ShapeInfo CreateModifierShapeInfo( TextLayout text, String modifierValue, double x, double y, Color textColor, Color textBackgroundColor) { try { ShapeInfo si = new ShapeInfo(text, new Point((int) x, (int) y)); // returnVal.setLineColor(textColor); if (textColor == null) textColor = Color.BLACK; int textRenderMethod = RendererSettings.getInstance().getTextRenderMethod(); AffineTransform at = null; // new AffineTransform(); if (textRenderMethod == RendererSettings.RenderMethod_SHAPES) { at = new AffineTransform(); at.translate(x, y); Shape label = text.getOutline(at); si = new ShapeInfo(label); si.setFillColor(textColor); } else if (textRenderMethod == RendererSettings.RenderMethod_NATIVE) { si = new ShapeInfo(text, new Point((int) x, (int) y)); si.setLineColor(textColor); } // for World Wind which just takes a string and x,y. si.setModifierString(modifierValue); si.setModifierStringPosition(new Point((int) x, (int) y)); si.setStroke(new BasicStroke(0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3)); si.setShapeType(ShapeInfo.SHAPE_TYPE_UNIT_DISPLAY_MODIFIER); if (textBackgroundColor != null) si.setTextBackgroundColor(textBackgroundColor); return si; } catch (Exception exc) { ErrorLogger.LogException("JavaRenderer", "CreateModifierShapeInfo", exc); return null; } }
/** * 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; } }