From 32016d5401050e43c56ccb0cd7ba6dfb1a39137c Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Fri, 4 Apr 2014 16:13:09 -0500 Subject: [PATCH] Issue #2920 Allow strings to use mulitple styles. Former-commit-id: ba3638effd48445bd00b8ef5e3771f05910c2af1 --- .../uf/viz/core/AbstractGraphicsTarget.java | 45 +++--- .../raytheon/uf/viz/core/DrawableString.java | 54 ++++++- .../raytheon/uf/viz/core/IGraphicsTarget.java | 41 +++--- .../ext/GeneralCanvasRenderingExtension.java | 6 +- .../ext/KmlCanvasRenderingExtension.java | 7 +- .../graphics/DispatchGraphicsTarget.java | 53 +------ .../events/strings/DrawStringEvent.java | 34 +++-- .../viz/core/gl/internal/GLTarget.java | 138 ++++++++++-------- 8 files changed, 196 insertions(+), 182 deletions(-) diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsTarget.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsTarget.java index 548268afa9..397c74bdc0 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsTarget.java @@ -62,10 +62,11 @@ import com.raytheon.uf.viz.core.exception.VizException; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * Jun 25, 2012 bsteffen Initial creation - * Jul 18, 2013 2189 mschenke Added ability to specify font type + * Date Ticket# Engineer Description + * ------------- -------- ----------- -------------------------- + * Jun 25, 2012 bsteffen Initial creation + * Jul 18, 2013 2189 mschenke Added ability to specify font type + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * @@ -179,8 +180,8 @@ public abstract class AbstractGraphicsTarget implements IGraphicsTarget { } if (bounds != null) { - if (parameters.textStyle == TextStyle.BLANKED - || parameters.textStyle == TextStyle.BOXED) { + if (parameters.getTextStyles().contains(TextStyle.BOXED) + || parameters.getTextStyles().contains(TextStyle.BLANKED)) { maxWidth += 1.0f; } bounds.setRect(0, 0, maxWidth, totalHeight); @@ -397,8 +398,14 @@ public abstract class AbstractGraphicsTarget implements IGraphicsTarget { HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Double rotation) throws VizException { - drawString(font, text, x, y, z, textStyle, color, horizontalAlignment, - verticalAlignment, rotation, 1.0f, 1.0f); + DrawableString params = new DrawableString(text, color); + params.font = font; + params.setCoordinates(x, y, z); + params.addTextStyle(textStyle); + params.horizontalAlignment = horizontalAlignment; + params.verticallAlignment = verticalAlignment; + params.rotation = rotation != null ? rotation : 0.0; + drawStrings(params); } @Override @@ -418,30 +425,12 @@ public abstract class AbstractGraphicsTarget implements IGraphicsTarget { DrawableString params = new DrawableString(text, colors); params.font = font; params.setCoordinates(x, y, z); - params.textStyle = textStyle; + params.addTextStyle(textStyle); params.horizontalAlignment = horizontalAlignment; params.verticallAlignment = verticalAlignment; drawStrings(params); } - @Override - public void drawString(IFont font, String string, double xPos, double yPos, - double zPos, TextStyle textStyle, RGB color, - HorizontalAlignment horizontalAlignment, - VerticalAlignment verticalAlignment, Double rotation, float alpha, - double magnification) throws VizException { - DrawableString params = new DrawableString(string, color); - params.font = font; - params.setCoordinates(xPos, yPos, zPos); - params.textStyle = textStyle; - params.horizontalAlignment = horizontalAlignment; - params.verticallAlignment = verticalAlignment; - params.rotation = rotation != null ? rotation : 0.0; - params.basics.alpha = alpha; - params.magnification = magnification; - drawStrings(params); - } - @Override public Rectangle2D getStringBounds(IFont font, String text) { if (font == null) { @@ -466,7 +455,7 @@ public abstract class AbstractGraphicsTarget implements IGraphicsTarget { TextStyle style) { DrawableString params = new DrawableString(text, (RGB[]) null); params.font = font; - params.textStyle = style; + params.addTextStyle(style); return getStringsBounds(params); } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableString.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableString.java index 7d54d56b0c..1086cf910c 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableString.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableString.java @@ -19,6 +19,8 @@ **/ package com.raytheon.uf.viz.core; +import java.util.EnumSet; + import org.eclipse.swt.graphics.RGB; import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment; @@ -34,9 +36,10 @@ import com.raytheon.uf.viz.core.drawables.IFont; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * Dec 14, 2010 mschenke Initial creation + * Date Ticket# Engineer Description + * ------------- -------- ----------- -------------------------- + * Dec 14, 2010 mschenke Initial creation + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * @@ -71,9 +74,12 @@ public class DrawableString extends AbstractDrawableObject { /** The colors to use for the strings */ private RGB[] colors; - /** The text style to use when drawing */ + /** @deprecated use {@link #addTextStyle(TextStyle)} */ + @Deprecated public TextStyle textStyle = TextStyle.NORMAL; + private EnumSet textStyles = EnumSet.noneOf(TextStyle.class); + /** The color of the shadow created when using TextStyle.DROP_SHADOW */ public RGB shadowColor = new RGB(0, 0, 0); @@ -95,6 +101,7 @@ public class DrawableString extends AbstractDrawableObject { this.verticallAlignment = that.verticallAlignment; this.magnification = that.magnification; this.rotation = that.rotation; + this.textStyles = that.textStyles; this.textStyle = that.textStyle; this.shadowColor = that.shadowColor; this.boxColor = that.boxColor; @@ -184,4 +191,43 @@ public class DrawableString extends AbstractDrawableObject { return colors; } + public void addTextStyle(TextStyle textStyle) { + textStyles.add(textStyle); + /* + * This check is the best we can do to support targets that don't know + * about textStyles yet. + */ + if (this.textStyle == null) { + this.textStyle = textStyle; + } + } + + public void removeTextStyle(TextStyle textStyle) { + textStyles.remove(textStyle); + /* + * This check is the best we can do to support targets that don't know + * about textStyles yet. + */ + if (textStyle == this.textStyle) { + if (textStyles.isEmpty()) { + this.textStyle = null; + } else { + this.textStyle = textStyles.iterator().next(); + } + } + } + + public EnumSet getTextStyles() { + EnumSet textStyles = this.textStyles.clone(); + /* + * Add in textStyle to support any renderables that don't know about + * textStyles yet. + */ + if (textStyle != null) { + textStyles.add(textStyle); + } + return textStyles; + + } + } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java index 115183b8c7..84d227b861 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java @@ -46,20 +46,22 @@ import com.raytheon.uf.viz.core.exception.VizException; /** * - * Base for any graphics target (GL, Swing, AWT, Postscript, etc.) + * Base class for accessing all the drawing functionality available for + * displaying things on a renderable display. * *
  * 
- *     SOFTWARE HISTORY
+ * SOFTWARE HISTORY
  *    
- *     Date          Ticket#     Engineer    Description
- *     ------------ ----------  ----------- --------------------------
- *     7/1/06                    chammack    Initial Creation.
- *     7/19/10      #5952        bkowal      Created a new member and method that could
- *                                           track any needed updates to the Target extents.
- *                                           This functionality is primarily used by the
- *                                           Feature Following Zoom Tool at this time.
- *     7/18/13      #2189        mschenke    Added ability to specify font type
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 01, 2006           chammack    Initial Creation.
+ * Jul 19, 2010  5952     bkowal      Created a new member and method that could
+ *                                    track any needed updates to the Target extents.
+ *                                    This functionality is primarily used by the
+ *                                    Feature Following Zoom Tool at this time.
+ * Jul 18, 2013  2189     mschenke    Added ability to specify font type
+ * Apr 04, 2014  2920     bsteffen    Allow strings to use mulitple styles.
  * 
  * 
* @@ -79,7 +81,14 @@ public interface IGraphicsTarget extends IImagingExtension { /** Defines text characteristics */ public static enum TextStyle { - NORMAL, BLANKED, BOXED, WORD_WRAP, DROP_SHADOW, OUTLINE, UNDERLINE, OVERLINE, STRIKETHROUGH; + /** + * @deprecated Normal is indicated by adding no other styles to a + * {@link DrawableString} + */ + @Deprecated + NORMAL, + + BLANKED, BOXED, WORD_WRAP, DROP_SHADOW, UNDERLINE, OVERLINE, STRIKETHROUGH; }; /** @@ -858,16 +867,6 @@ public interface IGraphicsTarget extends IImagingExtension { HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) throws VizException; - /** - * Use drawStrings(DrawableString parameters) - */ - @Deprecated - public void drawString(IFont font, String string, double xPos, double yPos, - double zPos, TextStyle textStyle, RGB color, - HorizontalAlignment horizontalAlignment, - VerticalAlignment verticalAlignment, Double rotation, float alpha, - double magnification) throws VizException; - /** * Use getStringsBounds(DrawableStrings...) functions * diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java index bb8778b1cf..c6c3d6611d 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java @@ -27,6 +27,7 @@ import com.raytheon.uf.viz.core.DrawableImage; import com.raytheon.uf.viz.core.DrawableLine; import com.raytheon.uf.viz.core.DrawableString; import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.IGraphicsTarget.TextStyle; import com.raytheon.uf.viz.core.IView; import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.PixelExtent; @@ -49,6 +50,7 @@ import com.vividsolutions.jts.geom.Coordinate; * parameters, disable colormap interpolation * by default. * Jan 14, 2014 2313 bsteffen Add method to draw images. + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * @@ -76,7 +78,9 @@ public class GeneralCanvasRenderingExtension extends mapString.magnification = screenString.magnification; mapString.rotation = screenString.rotation; mapString.shadowColor = screenString.shadowColor; - mapString.textStyle = screenString.textStyle; + for (TextStyle textStyle : screenString.getTextStyles()) { + mapString.addTextStyle(textStyle); + } mapString.verticallAlignment = screenString.verticallAlignment; mapString.basics.alpha = screenString.basics.alpha; mapString.basics.xOrColors = screenString.basics.xOrColors; diff --git a/cave/com.raytheon.uf.viz.kml.export/src/com/raytheon/uf/viz/kml/export/graphics/ext/KmlCanvasRenderingExtension.java b/cave/com.raytheon.uf.viz.kml.export/src/com/raytheon/uf/viz/kml/export/graphics/ext/KmlCanvasRenderingExtension.java index 53829d10bc..15725b5b80 100644 --- a/cave/com.raytheon.uf.viz.kml.export/src/com/raytheon/uf/viz/kml/export/graphics/ext/KmlCanvasRenderingExtension.java +++ b/cave/com.raytheon.uf.viz.kml.export/src/com/raytheon/uf/viz/kml/export/graphics/ext/KmlCanvasRenderingExtension.java @@ -69,8 +69,9 @@ import de.micromata.opengis.kml.v_2_2_0.Vec2; * * Date Ticket# Engineer Description * ------------- -------- ----------- -------------------------- - * Jun 26, 2012 bsteffen Initial creation - * Jan 14, 2013 2313 bsteffen Add image rendering + * Jun 26, 2012 bsteffen Initial creation + * Jan 14, 2013 2313 bsteffen Add image rendering + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * @@ -309,7 +310,7 @@ public class KmlCanvasRenderingExtension extends } else if (VerticalAlignment.MIDDLE == string.verticallAlignment) { realY -= bounds.getY() / 2; } - if (string.textStyle == TextStyle.BLANKED) { + if (string.getTextStyles().contains(TextStyle.BLANKED)) { setColor(graphics, backgroundColor); graphics.fillRect((int) realX, (int) (realY + bounds.getY()), diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java index edff7e4cfb..ec575760d9 100644 --- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java @@ -107,9 +107,10 @@ import com.raytheon.uf.viz.remote.graphics.objects.DispatchingWireframeShape; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * Feb 28, 2012 mschenke Initial creation + * Date Ticket# Engineer Description + * ------------- -------- ----------- -------------------------- + * Feb 28, 2012 mschenke Initial creation + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * @@ -1147,7 +1148,7 @@ public class DispatchGraphicsTarget extends DispatchingObject DrawableString string = new DrawableString(text, color); string.setCoordinates(x, y, z); string.font = font; - string.textStyle = textStyle; + string.addTextStyle(textStyle); string.horizontalAlignment = horizontalAlignment; string.verticallAlignment = verticalAlignment; string.rotation = rotation; @@ -1180,7 +1181,7 @@ public class DispatchGraphicsTarget extends DispatchingObject DrawableString string = new DrawableString(text, color); string.setCoordinates(x, y, z); string.font = font; - string.textStyle = textStyle; + string.addTextStyle(textStyle); string.horizontalAlignment = horizontalAlignment; string.rotation = rotation; drawStrings(string); @@ -1212,52 +1213,12 @@ public class DispatchGraphicsTarget extends DispatchingObject DrawableString string = new DrawableString(text, colors); string.setCoordinates(x, y, z); string.font = font; - string.textStyle = textStyle; + string.addTextStyle(textStyle); string.horizontalAlignment = horizontalAlignment; string.verticallAlignment = verticalAlignment; drawStrings(string); } - /** - * @param font - * @param string - * @param xPos - * @param yPos - * @param zPos - * @param textStyle - * @param color - * @param horizontalAlignment - * @param verticalAlignment - * @param rotation - * @param alpha - * @param magnification - * @throws VizException - * @deprecated - * @see com.raytheon.uf.viz.core.IGraphicsTarget#drawString(com.raytheon.uf.viz.core.drawables.IFont, - * java.lang.String, double, double, double, - * com.raytheon.uf.viz.core.IGraphicsTarget.TextStyle, - * org.eclipse.swt.graphics.RGB, - * com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment, - * com.raytheon.uf.viz.core.IGraphicsTarget.VerticalAlignment, - * java.lang.Double, float, double) - */ - public void drawString(IFont font, String text, double x, double y, - double z, TextStyle textStyle, RGB color, - HorizontalAlignment horizontalAlignment, - VerticalAlignment verticalAlignment, Double rotation, float alpha, - double magnification) throws VizException { - DrawableString string = new DrawableString(text, color); - string.setCoordinates(x, y, z); - string.font = font; - string.textStyle = textStyle; - string.horizontalAlignment = horizontalAlignment; - string.verticallAlignment = verticalAlignment; - string.rotation = rotation; - string.basics.alpha = alpha; - string.magnification = magnification; - drawStrings(string); - } - /** * @param font * @param text diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/strings/DrawStringEvent.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/strings/DrawStringEvent.java index 1bfcc7921d..7a7d167907 100644 --- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/strings/DrawStringEvent.java +++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/strings/DrawStringEvent.java @@ -20,6 +20,7 @@ package com.raytheon.uf.viz.remote.graphics.events.strings; import java.util.Arrays; +import java.util.EnumSet; import org.eclipse.swt.graphics.RGB; @@ -40,9 +41,10 @@ import com.raytheon.uf.viz.remote.graphics.objects.DispatchingFont; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * May 10, 2012 mschenke Initial creation + * Date Ticket# Engineer Description + * ------------- -------- ----------- -------------------------- + * May 10, 2012 mschenke Initial creation + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * @@ -72,7 +74,7 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { private VerticalAlignment verticalAlignment; @DynamicSerializeElement - private TextStyle textStyle; + private EnumSet textStyles; @DynamicSerializeElement private RGB boxColor; @@ -126,8 +128,8 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { if (verticalAlignment != diffEvent.verticalAlignment) { diffObject.verticalAlignment = diffEvent.verticalAlignment; } - if (textStyle != diffEvent.textStyle) { - diffObject.textStyle = diffEvent.textStyle; + if (!textStyles.equals(diffEvent.textStyles)) { + diffObject.textStyles = diffEvent.textStyles; } return diffObject; } @@ -164,8 +166,8 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { if (diffObject.text != null) { text = diffObject.text; } - if (diffObject.textStyle != null) { - textStyle = diffObject.textStyle; + if (diffObject.textStyles != null) { + textStyles = diffObject.textStyles; } } @@ -178,7 +180,7 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { this.xOrColors = string.basics.xOrColors; this.horizontalAlignment = string.horizontalAlignment; this.verticalAlignment = string.verticallAlignment; - this.textStyle = string.textStyle; + this.textStyles = string.getTextStyles(); this.magnification = string.magnification; this.point = new double[] { string.basics.x, string.basics.y, string.basics.z }; @@ -196,7 +198,9 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { ds.shadowColor = shadowColor; ds.horizontalAlignment = horizontalAlignment; ds.verticallAlignment = verticalAlignment; - ds.textStyle = textStyle; + for (TextStyle textStyle : textStyles) { + ds.addTextStyle(textStyle); + } ds.magnification = magnification; ds.setCoordinates(point[0], point[1], point[2]); ds.rotation = rotation; @@ -296,16 +300,16 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { /** * @return the textStyle */ - public TextStyle getTextStyle() { - return textStyle; + public EnumSet getTextStyles() { + return textStyles; } /** * @param textStyle * the textStyle to set */ - public void setTextStyle(TextStyle textStyle) { - this.textStyle = textStyle; + public void setTextStyle(EnumSet textStyles) { + this.textStyles = textStyles; } /** @@ -435,7 +439,7 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { return false; if (!Arrays.equals(text, other.text)) return false; - if (textStyle != other.textStyle) + if (!textStyles.equals(other.textStyles)) return false; if (verticalAlignment != other.verticalAlignment) return false; diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java index c081c4a5c8..b2511511ad 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java @@ -30,6 +30,7 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -105,41 +106,45 @@ import com.sun.opengl.util.j2d.TextRenderer; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * 7/1/06 chammack Initial Creation. - * 7/24/07 njensen Colormaps can reload in drawRaster(). - * 10/01/07 467 brockwoo Fix for disabling interpolation of plot data textures - * 10/16/07 468 njensen drawString() supports rotation. - * 03/18/08 chammack Improve legend rendering - * 03/12/09 2092 njensen Added offscreen rendering support - * 07/01/10 6146 bkowal The offset that is needed to set the "Y" coordinate - * of the legend text that is drawn is now calculated based on - * the font size rather than being hard-coded. - * 07/08/10 6146 bkowal The font size will now be adjusted automatically by comparing - * the current size of the pane of interest to the overall - * size of the screen. - * 07/19/10 5952 bkowal GLTarget will now check for the existence of updated extents - * before drawing. A method has also been added to notify - * GLTarget of when there are updated extents to load. - * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap - * parameters, disable colormap - * interpolation by default. - * Apr 18, 2013 1638 mschenke Made string rendering always occur in canvas space so - * strings are always readable despite extent - * May 28, 2013 1638 mschenke Made sure {@link TextStyle#BLANKED} text is drawing correct size - * box around text - * Nov 4, 2013 2492 mschenke Switched colormap drawing to use 1D texture object for alpha mask - * Mar 3, 2014 2804 mschenke Added clipping pane field to only setup if changed + * Date Ticket# Engineer Description + * ------------- -------- ----------- ----------------------------------------- + * Jul 01, 2006 chammack Initial Creation. + * Jul 24, 2007 njensen Colormaps can reload in drawRaster(). + * Oct 01, 2007 467 brockwoo Fix for disabling interpolation of plot + * data textures + * Oct 16, 2007 468 njensen drawString() supports rotation. + * Mar 18, 2008 chammack Improve legend rendering + * Mar 12, 2009 2092 njensen Added offscreen rendering support + * Jul 01, 2010 6146 bkowal The offset that is needed to set the + * "Y" coordinate of the legend + * text that is drawn is now calculated based + * on the font size rather than being + * hard-coded. + * Jul 08, 2010 6146 bkowal The font size will now be adjusted + * automatically by comparing the current + * size of the pane of interest to the + * overall size of the screen. + * Jul 19, 2010 5952 bkowal GLTarget will now check for the existence + * of updated extents before drawing. A + * method has also been added to notify + * GLTarget of when there are updated extents + * to load. + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. + * Apr 18, 2013 1638 mschenke Made string rendering always occur in + * canvas space so strings are always + * readable despite extent + * May 28, 2013 1638 mschenke Made sure {@link TextStyle#BLANKED} text + * is drawing correct size box around text + * Nov 04, 2013 2492 mschenke Switched colormap drawing to use 1D + * texture object for alpha mask + * Mar 03, 2014 2804 mschenke Added clipping pane field to only setup + * if changed + * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * * * - * TODO The current code draws "flat" objects (circles, arcs, strings, etc...) - * on the plane z = the given z argument. Eventually, these objects should be - * oriented on a plane parallel to the camera's plane at the time they are - * drawn. For strings, we may want the plane they are drawn on to follow the - * camera plane as it moves, so that they are always readable to the user. - * * @author chammack * @version 1 * @@ -1871,12 +1876,14 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { // This loop just draws the box or a blank rectangle. for (DrawableString dString : parameters) { - switch (dString.textStyle) { - case BOXED: - case BLANKED: - case UNDERLINE: - case OVERLINE: - case STRIKETHROUGH: + EnumSet textStyles = dString.getTextStyles(); + boolean boxed = textStyles.contains(TextStyle.BOXED); + boolean blanked = textStyles.contains(TextStyle.BLANKED); + boolean underline = textStyles.contains(TextStyle.UNDERLINE); + boolean overline = textStyles.contains(TextStyle.OVERLINE); + boolean strikethrough = textStyles + .contains(TextStyle.STRIKETHROUGH); + if (boxed || blanked || underline || overline || strikethrough) { double yPos = dString.basics.y; VerticalAlignment verticalAlignment = dString.verticallAlignment; double fontPercentage = this @@ -1927,15 +1934,14 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { double x2 = xy[0] + width + scaleX; double y2 = (xy[1] - diff) + height + scaleY; - if (dString.textStyle == TextStyle.BOXED - || dString.textStyle == TextStyle.BLANKED) { + if (boxed || blanked) { gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL); - if (dString.textStyle == TextStyle.BOXED - && dString.boxColor != null) { + if (boxed && dString.boxColor != null) { gl.glColor4d(dString.boxColor.red / 255.0, dString.boxColor.green / 255.0, dString.boxColor.blue / 255.0, alpha); - } else { + } + if (blanked) { gl.glColor4d(backgroundColor.red / 255.0, backgroundColor.green / 255.0, backgroundColor.blue / 255.0, alpha); @@ -1944,10 +1950,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { gl.glRectd(x1, y2, x2, y1); } - if (dString.textStyle == TextStyle.BOXED - || dString.textStyle == TextStyle.UNDERLINE - || dString.textStyle == TextStyle.OVERLINE - || dString.textStyle == TextStyle.STRIKETHROUGH) { + if (boxed || underline || overline || strikethrough) { gl.glPolygonMode(GL.GL_BACK, GL.GL_LINE); RGB color = dString.getColors()[c]; @@ -1958,20 +1961,29 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { color.green / 255.0, color.blue / 255.0, alpha); - if (dString.textStyle == TextStyle.BOXED) { + if (boxed) { gl.glLineWidth(2); gl.glRectd(x1, y2, x2, y1); - } else { + } + if (underline) { gl.glLineWidth(1); - double percent; - if (dString.textStyle == TextStyle.UNDERLINE) { - percent = .2; - } else if (dString.textStyle == TextStyle.OVERLINE) { - percent = 1.; - } else { // TextStyle.STRIKETHROUGH - percent = .5; - } - double lineY = y1 + (y2 - y1) * percent; + double lineY = y1 + (y2 - y1) * .2; + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(x1, lineY); + gl.glVertex2d(x2, lineY); + gl.glEnd(); + } + if (overline) { + gl.glLineWidth(1); + double lineY = y1 + (y2 - y1); + gl.glBegin(GL.GL_LINES); + gl.glVertex2d(x1, lineY); + gl.glVertex2d(x2, lineY); + gl.glEnd(); + } + if (strikethrough) { + gl.glLineWidth(1); + double lineY = y1 + (y2 - y1) * .5; gl.glBegin(GL.GL_LINES); gl.glVertex2d(x1, lineY); gl.glVertex2d(x2, lineY); @@ -1991,9 +2003,6 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { gl.glRotated(-dString.rotation, 0.0, 0.0, 1.0); gl.glTranslated(-rotatedPoint[0], -rotatedPoint[1], 0.0); } - break; - default: - break; } } @@ -2016,7 +2025,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { "Font was not prepared using GLTarget"); } - if (dString.rotation != 0.0 && rotatedPoint == null) { + if (dString.rotation != 0.0) { if (textRenderer != null) { textRenderer.flush(); } @@ -2097,7 +2106,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { color.green / 255.0f, color.blue / 255.0f, alpha); } - if (dString.textStyle == TextStyle.WORD_WRAP) { + if (dString.getTextStyles().contains(TextStyle.WORD_WRAP)) { int i = 0; int j = -1; float y = xy[1]; @@ -2119,7 +2128,8 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { textRenderer.draw3D(string.substring(i), x, y, 0.0f, scaleY); - } else if (dString.textStyle == TextStyle.DROP_SHADOW) { + } else if (dString.getTextStyles().contains( + TextStyle.DROP_SHADOW)) { RGB shadowColor = dString.shadowColor; textRenderer.setColor(shadowColor.red / 255.0f, shadowColor.green / 255.0f,