Merge "Omaha #3163 Add support for reading colored text styles from future versions of collaboration." into omaha_14.4.1

Former-commit-id: cb6ef0e9a3 [formerly 6f3d40c96cafe8f0f05d539534607067a2a37776]
Former-commit-id: d79ef53ad0
This commit is contained in:
Nate Jensen 2014-05-19 11:46:10 -05:00 committed by Gerrit Code Review
commit 8a31eaf6e1
2 changed files with 146 additions and 18 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: Remote Graphics Bundle-Name: Remote Graphics
Bundle-SymbolicName: com.raytheon.uf.viz.remote.graphics;singleton:=true 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-Activator: com.raytheon.uf.viz.remote.graphics.Activator
Bundle-Vendor: RAYTHEON Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
@ -10,11 +10,11 @@ Bundle-ActivationPolicy: lazy
Eclipse-RegisterBuddy: com.raytheon.uf.viz.core Eclipse-RegisterBuddy: com.raytheon.uf.viz.core
Eclipse-BuddyPolicy: dependent Eclipse-BuddyPolicy: dependent
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", 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.uf.common.colormap,
com.raytheon.viz.ui;bundle-version="1.14.0", com.raytheon.viz.ui;bundle-version="1.14.0",
com.raytheon.uf.common.util, com.raytheon.uf.common.util;bundle-version="1.14.0",
com.raytheon.uf.common.geospatial, com.raytheon.uf.common.geospatial;bundle-version="1.14.0",
javax.measure javax.measure
Export-Package: com.raytheon.uf.viz.remote.graphics, Export-Package: com.raytheon.uf.viz.remote.graphics,
com.raytheon.uf.viz.remote.graphics.events, com.raytheon.uf.viz.remote.graphics.events,

View file

@ -21,6 +21,8 @@ package com.raytheon.uf.viz.remote.graphics.events.strings;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.swt.graphics.RGB; 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 * May 10, 2012 mschenke Initial creation
* Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles. * Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles.
* mAY 16, 2014 3163 bsteffen Add support for reading colored text styles.
*
* *
* </pre> * </pre>
* *
@ -55,6 +59,16 @@ import com.raytheon.uf.viz.remote.graphics.objects.DispatchingFont;
@DynamicSerialize @DynamicSerialize
public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent { 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 @DynamicSerializeElement
private int fontId = -1; private int fontId = -1;
@ -73,13 +87,40 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
@DynamicSerializeElement @DynamicSerializeElement
private VerticalAlignment verticalAlignment; 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 @DynamicSerializeElement
private Map<TextStyle, RGB> textStyleColorMap;
/**
* @deprecated Once backwards compatibility is not needed switch to
* {@link #textStyleColorMap}
* @see DrawStringEvent#SUPPORT_STYLE_COLORS
*/
@DynamicSerializeElement
@Deprecated
private EnumSet<TextStyle> textStyles; private EnumSet<TextStyle> textStyles;
/**
* @deprecated Once backwards compatibility is not needed switch to
* {@link #textStyleColorMap}
* @see DrawStringEvent#SUPPORT_STYLE_COLORS
*/
@DynamicSerializeElement @DynamicSerializeElement
@Deprecated
private RGB boxColor; private RGB boxColor;
/**
* @deprecated Once backwards compatibility is not needed switch to
* {@link #textStyleColorMap}
*/
@DynamicSerializeElement @DynamicSerializeElement
@Deprecated
private RGB shadowColor; private RGB shadowColor;
@DynamicSerializeElement @DynamicSerializeElement
@ -131,6 +172,9 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
if (!textStyles.equals(diffEvent.textStyles)) { if (!textStyles.equals(diffEvent.textStyles)) {
diffObject.textStyles = diffEvent.textStyles; diffObject.textStyles = diffEvent.textStyles;
} }
if (diffEvent.textStyleColorMap != null) {
diffObject.textStyleColorMap = diffEvent.textStyleColorMap;
}
return diffObject; return diffObject;
} }
@ -169,18 +213,19 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
if (diffObject.textStyles != null) { if (diffObject.textStyles != null) {
textStyles = diffObject.textStyles; textStyles = diffObject.textStyles;
} }
if (diffObject.textStyleColorMap != null) {
textStyleColorMap = diffObject.textStyleColorMap;
}
} }
public void setDrawableString(DrawableString string) { public void setDrawableString(DrawableString string) {
this.text = string.getText(); this.text = string.getText();
this.colors = string.getColors(); this.colors = string.getColors();
this.alpha = string.basics.alpha; this.alpha = string.basics.alpha;
this.boxColor = string.boxColor;
this.shadowColor = string.shadowColor;
this.xOrColors = string.basics.xOrColors; this.xOrColors = string.basics.xOrColors;
this.horizontalAlignment = string.horizontalAlignment; this.horizontalAlignment = string.horizontalAlignment;
this.verticalAlignment = string.verticallAlignment; this.verticalAlignment = string.verticallAlignment;
this.textStyles = string.getTextStyles();
this.magnification = string.magnification; this.magnification = string.magnification;
this.point = new double[] { string.basics.x, string.basics.y, this.point = new double[] { string.basics.x, string.basics.y,
string.basics.z }; string.basics.z };
@ -188,22 +233,53 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
if (string.font instanceof DispatchingFont) { if (string.font instanceof DispatchingFont) {
fontId = ((DispatchingFont) string.font).getObjectId(); fontId = ((DispatchingFont) string.font).getObjectId();
} }
Map<TextStyle, RGB> 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() { public DrawableString getDrawableString() {
DrawableString ds = new DrawableString(text, colors); DrawableString ds = new DrawableString(text, colors);
ds.basics.alpha = alpha; ds.basics.alpha = alpha;
ds.basics.xOrColors = xOrColors; ds.basics.xOrColors = xOrColors;
ds.boxColor = boxColor;
ds.shadowColor = shadowColor;
ds.horizontalAlignment = horizontalAlignment; ds.horizontalAlignment = horizontalAlignment;
ds.verticallAlignment = verticalAlignment; ds.verticallAlignment = verticalAlignment;
for (TextStyle textStyle : textStyles) {
ds.addTextStyle(textStyle);
}
ds.magnification = magnification; ds.magnification = magnification;
ds.setCoordinates(point[0], point[1], point[2]); ds.setCoordinates(point[0], point[1], point[2]);
ds.rotation = rotation; ds.rotation = rotation;
if (textStyleColorMap != null) {
for (Entry<TextStyle, RGB> 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; return ds;
} }
@ -304,6 +380,14 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
return textStyles; return textStyles;
} }
public Map<TextStyle, RGB> getTextStyleColorMap() {
return textStyleColorMap;
}
public void setTextStyleColorMap(Map<TextStyle, RGB> textStyleColorMap) {
this.textStyleColorMap = textStyleColorMap;
}
/** /**
* @param textStyles * @param textStyles
* the textStyles to set * the textStyles to set
@ -402,11 +486,42 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
this.xOrColors = xOrColors; this.xOrColors = xOrColors;
} }
/* @Override
* (non-Javadoc) public int hashCode() {
* final int prime = 31;
* @see java.lang.Object#equals(java.lang.Object) 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
@ -437,9 +552,22 @@ public class DrawStringEvent extends AbstractRemoteGraphicsRenderEvent {
if (Double.doubleToLongBits(rotation) != Double if (Double.doubleToLongBits(rotation) != Double
.doubleToLongBits(other.rotation)) .doubleToLongBits(other.rotation))
return false; 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)) if (!Arrays.equals(text, other.text))
return false; 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; return false;
if (verticalAlignment != other.verticalAlignment) if (verticalAlignment != other.verticalAlignment)
return false; return false;