From fcbd4cc9ee49d339ce52e6838c9b66a0be47923c Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Fri, 16 May 2014 12:50:48 -0500 Subject: [PATCH] Omaha #3163 Add support for reading colored text styles from future versions of collaboration. Former-commit-id: 08f7d7b8dd4f0350eb7c2c74f8328b4c71a46ef9 [formerly 67e68732d60b29c03a3828434bdce3e744c7167a] [formerly 79ef4a530164c4021821493c18bd26ebd7fbef93 [formerly 63d4e9f1e2bf95792fa82d101ce59f23e2cbdaf9]] Former-commit-id: 79ef4a530164c4021821493c18bd26ebd7fbef93 Former-commit-id: 126f47f7253b50d845e019fa5c38ba82fc4eb0ab --- .../META-INF/MANIFEST.MF | 8 +- .../events/strings/DrawStringEvent.java | 156 ++++++++++++++++-- 2 files changed, 146 insertions(+), 18 deletions(-) diff --git a/cave/com.raytheon.uf.viz.remote.graphics/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.remote.graphics/META-INF/MANIFEST.MF index 3f6d00a262..3760201478 100644 --- a/cave/com.raytheon.uf.viz.remote.graphics/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.remote.graphics/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Remote Graphics Bundle-SymbolicName: com.raytheon.uf.viz.remote.graphics;singleton:=true -Bundle-Version: 1.14.0.qualifier +Bundle-Version: 1.14.1.qualifier Bundle-Activator: com.raytheon.uf.viz.remote.graphics.Activator Bundle-Vendor: RAYTHEON Bundle-RequiredExecutionEnvironment: JavaSE-1.6 @@ -10,11 +10,11 @@ Bundle-ActivationPolicy: lazy Eclipse-RegisterBuddy: com.raytheon.uf.viz.core Eclipse-BuddyPolicy: dependent Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", - com.raytheon.uf.viz.core;bundle-version="1.14.1", + com.raytheon.uf.viz.core;bundle-version="1.14.3", com.raytheon.uf.common.colormap, com.raytheon.viz.ui;bundle-version="1.14.0", - com.raytheon.uf.common.util, - com.raytheon.uf.common.geospatial, + com.raytheon.uf.common.util;bundle-version="1.14.0", + com.raytheon.uf.common.geospatial;bundle-version="1.14.0", javax.measure Export-Package: com.raytheon.uf.viz.remote.graphics, com.raytheon.uf.viz.remote.graphics.events, 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 f6ba80fa91..5f91f8b404 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 @@ -21,6 +21,8 @@ package com.raytheon.uf.viz.remote.graphics.events.strings; import java.util.Arrays; import java.util.EnumSet; +import java.util.Map; +import java.util.Map.Entry; import org.eclipse.swt.graphics.RGB; @@ -45,6 +47,8 @@ import com.raytheon.uf.viz.remote.graphics.objects.DispatchingFont; * ------------- -------- ----------- -------------------------- * May 10, 2012 mschenke Initial creation * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. + * mAY 16, 2014 3163 bsteffen Add support for reading colored text styles. + * * * * @@ -55,6 +59,16 @@ import com.raytheon.uf.viz.remote.graphics.objects.DispatchingFont; @DynamicSerialize public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { + /** + * Flipping this boolean breaks support for older clients. The plan is to + * phase in the style colors over multiple releases to ensure that each + * release is compatible with the previous release, however if there is a + * use case requiring support sooner then it is safe to flip this flag + * assuming all clients support it. + */ + private static boolean SUPPORT_STYLE_COLORS = Boolean + .getBoolean("collaboration.supportStringStyleColors"); + @DynamicSerializeElement private int fontId = -1; @@ -73,13 +87,40 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { @DynamicSerializeElement private VerticalAlignment verticalAlignment; + /** + * For backwards compatibility this field should never be set, but for + * forward compatibility it can be deserialized. + * + * @see DrawStringEvent#SUPPORT_STYLE_COLORS + */ @DynamicSerializeElement + private Map textStyleColorMap; + + /** + * @deprecated Once backwards compatibility is not needed switch to + * {@link #textStyleColorMap} + * @see DrawStringEvent#SUPPORT_STYLE_COLORS + */ + @DynamicSerializeElement + @Deprecated private EnumSet textStyles; + /** + * @deprecated Once backwards compatibility is not needed switch to + * {@link #textStyleColorMap} + * @see DrawStringEvent#SUPPORT_STYLE_COLORS + */ @DynamicSerializeElement + @Deprecated private RGB boxColor; + + /** + * @deprecated Once backwards compatibility is not needed switch to + * {@link #textStyleColorMap} + */ @DynamicSerializeElement + @Deprecated private RGB shadowColor; @DynamicSerializeElement @@ -131,6 +172,9 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { if (!textStyles.equals(diffEvent.textStyles)) { diffObject.textStyles = diffEvent.textStyles; } + if (diffEvent.textStyleColorMap != null) { + diffObject.textStyleColorMap = diffEvent.textStyleColorMap; + } return diffObject; } @@ -169,18 +213,19 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { if (diffObject.textStyles != null) { textStyles = diffObject.textStyles; } + if (diffObject.textStyleColorMap != null) { + textStyleColorMap = diffObject.textStyleColorMap; + } } public void setDrawableString(DrawableString string) { this.text = string.getText(); this.colors = string.getColors(); this.alpha = string.basics.alpha; - this.boxColor = string.boxColor; - this.shadowColor = string.shadowColor; + this.xOrColors = string.basics.xOrColors; this.horizontalAlignment = string.horizontalAlignment; this.verticalAlignment = string.verticallAlignment; - this.textStyles = string.getTextStyles(); this.magnification = string.magnification; this.point = new double[] { string.basics.x, string.basics.y, string.basics.z }; @@ -188,22 +233,53 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { if (string.font instanceof DispatchingFont) { fontId = ((DispatchingFont) string.font).getObjectId(); } + Map textStyleColorMap = string.getTextStyleColorMap(); + if (textStyleColorMap != null && !textStyleColorMap.isEmpty()) { + if (SUPPORT_STYLE_COLORS) { + this.textStyleColorMap = textStyleColorMap; + } else { + this.textStyles = EnumSet.copyOf(textStyleColorMap.keySet()); + if (textStyleColorMap.containsKey(TextStyle.BOXED)) { + this.boxColor = textStyleColorMap.get(TextStyle.BLANKED); + } + if (textStyleColorMap.containsKey(TextStyle.DROP_SHADOW)) { + this.shadowColor = textStyleColorMap + .get(TextStyle.DROP_SHADOW); + } + } + } + } public DrawableString getDrawableString() { DrawableString ds = new DrawableString(text, colors); ds.basics.alpha = alpha; ds.basics.xOrColors = xOrColors; - ds.boxColor = boxColor; - ds.shadowColor = shadowColor; + ds.horizontalAlignment = horizontalAlignment; ds.verticallAlignment = verticalAlignment; - for (TextStyle textStyle : textStyles) { - ds.addTextStyle(textStyle); - } ds.magnification = magnification; ds.setCoordinates(point[0], point[1], point[2]); ds.rotation = rotation; + if (textStyleColorMap != null) { + for (Entry entry : textStyleColorMap.entrySet()) { + ds.addTextStyle(entry.getKey(), entry.getValue()); + } + }else{ + if(textStyles != null){ + for(TextStyle style : textStyles){ + if (style.equals(TextStyle.BOXED)) { + ds.addTextStyle(style); + ds.addTextStyle(TextStyle.BLANKED, boxColor); + } else if (style.equals(TextStyle.DROP_SHADOW)) { + ds.addTextStyle(style, shadowColor); + + } else { + ds.addTextStyle(style); + } + } + } + } return ds; } @@ -304,6 +380,14 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { return textStyles; } + public Map getTextStyleColorMap() { + return textStyleColorMap; + } + + public void setTextStyleColorMap(Map textStyleColorMap) { + this.textStyleColorMap = textStyleColorMap; + } + /** * @param textStyles * the textStyles to set @@ -402,11 +486,42 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { this.xOrColors = xOrColors; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Float.floatToIntBits(alpha); + result = prime * result + + ((boxColor == null) ? 0 : boxColor.hashCode()); + result = prime * result + Arrays.hashCode(colors); + result = prime * result + fontId; + result = prime + * result + + ((horizontalAlignment == null) ? 0 : horizontalAlignment + .hashCode()); + long temp; + temp = Double.doubleToLongBits(magnification); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + Arrays.hashCode(point); + temp = Double.doubleToLongBits(rotation); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + + ((shadowColor == null) ? 0 : shadowColor.hashCode()); + result = prime * result + Arrays.hashCode(text); + result = prime + * result + + ((textStyleColorMap == null) ? 0 : textStyleColorMap + .hashCode()); + result = prime * result + + ((textStyles == null) ? 0 : textStyles.hashCode()); + result = prime + * result + + ((verticalAlignment == null) ? 0 : verticalAlignment + .hashCode()); + result = prime * result + (xOrColors ? 1231 : 1237); + return result; + } + @Override public boolean equals(Object obj) { if (this == obj) @@ -437,9 +552,22 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { if (Double.doubleToLongBits(rotation) != Double .doubleToLongBits(other.rotation)) return false; + if (shadowColor == null) { + if (other.shadowColor != null) + return false; + } else if (!shadowColor.equals(other.shadowColor)) + return false; if (!Arrays.equals(text, other.text)) return false; - if (!textStyles.equals(other.textStyles)) + if (textStyleColorMap == null) { + if (other.textStyleColorMap != null) + return false; + } else if (!textStyleColorMap.equals(other.textStyleColorMap)) + return false; + if (textStyles == null) { + if (other.textStyles != null) + return false; + } else if (!textStyles.equals(other.textStyles)) return false; if (verticalAlignment != other.verticalAlignment) return false;