Merge "Omaha #3709 Support foreground/background colors by site for nws-collaborate room" into omaha_14.4.1
Former-commit-id: f2751d48244d29af3f047d49da5ae117ce14a86b
This commit is contained in:
commit
370a090480
10 changed files with 432 additions and 644 deletions
|
@ -0,0 +1,135 @@
|
|||
package com.raytheon.uf.viz.collaboration.ui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManager;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
import com.raytheon.uf.common.serialization.SingleTypeJAXBManager;
|
||||
import com.raytheon.uf.viz.collaboration.ui.ColorInfoMap.ColorInfo;
|
||||
|
||||
/**
|
||||
* Abstract class collaboration chat coloring configuration managers
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 13, 2014 3709 mapeters Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mapeters
|
||||
* @version 1.0
|
||||
*/
|
||||
public abstract class AbstractColorConfigManager {
|
||||
|
||||
private static final SingleTypeJAXBManager<ColorInfoMap> jaxb = SingleTypeJAXBManager
|
||||
.createWithoutException(ColorInfoMap.class);
|
||||
|
||||
/**
|
||||
* Set and store the color type of the given user/site to be the given rgb
|
||||
* at the given file location. If creating new {@link ColorInfo} and setting
|
||||
* background, set foreground to defaultForeground to prevent it from
|
||||
* incorrectly defaulting.
|
||||
*
|
||||
* @param key
|
||||
* @param type
|
||||
* @param rgb
|
||||
* @param defaultForeground
|
||||
* @param filePath
|
||||
*/
|
||||
protected void setColor(String key, ColorType type, RGB rgb,
|
||||
RGB defaultForeground, String filePath) {
|
||||
ColorInfoMap colorInfoMap = this.getColorInfoMap();
|
||||
if (colorInfoMap == null) {
|
||||
colorInfoMap = new ColorInfoMap();
|
||||
this.setColorInfoMap(colorInfoMap);
|
||||
}
|
||||
Map<String, ColorInfo> colors = colorInfoMap.getColors();
|
||||
if (colors == null) {
|
||||
colorInfoMap.setColors(new HashMap<String, ColorInfo>());
|
||||
colors = colorInfoMap.getColors();
|
||||
}
|
||||
|
||||
ColorInfo colorInfo = colors.get(key);
|
||||
if (colorInfo != null) {
|
||||
colorInfo.setColor(type, rgb, defaultForeground);
|
||||
} else {
|
||||
ColorInfo color = new ColorInfo();
|
||||
color.setColor(type, rgb, defaultForeground);
|
||||
colors.put(key, color);
|
||||
}
|
||||
|
||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lContext = pathMgr.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
LocalizationFile file = pathMgr.getLocalizationFile(lContext, filePath);
|
||||
try {
|
||||
jaxb.marshalToXmlFile(colorInfoMap, file.getFile().getPath());
|
||||
file.save();
|
||||
} catch (Exception e) {
|
||||
Activator.statusHandler.error(
|
||||
"Unable to write color information to file: "
|
||||
+ file.getName() + " in context " + lContext, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ColorInfo} for the given user/site from memory.
|
||||
*
|
||||
* @param key
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
protected ColorInfo getColor(String key, String filePath) {
|
||||
ColorInfoMap colorInfoMap = this.getColorInfoMap();
|
||||
if (colorInfoMap == null) {
|
||||
IPathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
||||
LocalizationContext locContext = pm.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
LocalizationFile file = pm
|
||||
.getLocalizationFile(locContext, filePath);
|
||||
|
||||
if (file != null && file.exists()) {
|
||||
try {
|
||||
colorInfoMap = jaxb.unmarshalFromXmlFile(file.getFile());
|
||||
this.setColorInfoMap(colorInfoMap);
|
||||
} catch (SerializationException e) {
|
||||
Activator.statusHandler.error(
|
||||
"Unable to read color information from file: "
|
||||
+ file.getName() + " in level "
|
||||
+ LocalizationLevel.USER, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (colorInfoMap != null) {
|
||||
Map<String, ColorInfo> colors = colorInfoMap.getColors();
|
||||
if (colors != null) {
|
||||
return colors.get(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void setColor(String key, ColorType type, RGB rgb,
|
||||
RGB defaultForeground);
|
||||
|
||||
public abstract ColorInfo getColor(String key);
|
||||
|
||||
protected abstract ColorInfoMap getColorInfoMap();
|
||||
|
||||
protected abstract void setColorInfoMap(ColorInfoMap colorInfo);
|
||||
}
|
|
@ -31,7 +31,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
/**
|
||||
* Contains foreground and background chat colors for a list of users
|
||||
* Contains foreground and background chat colors for a list of users or sites
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -40,6 +40,7 @@ import org.eclipse.swt.graphics.RGB;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 13, 2014 3709 mapeters Initial creation.
|
||||
* Nov 26, 2014 3709 mapeters Renamed from UserColorInformation, added fgSet getter.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -48,15 +49,15 @@ import org.eclipse.swt.graphics.RGB;
|
|||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class UserColorInformation {
|
||||
public class ColorInfoMap {
|
||||
|
||||
@XmlElement
|
||||
private Map<String, UserColor> colors;
|
||||
private Map<String, ColorInfo> colors;
|
||||
|
||||
/**
|
||||
* @return the colors
|
||||
*/
|
||||
public Map<String, UserColor> getColors() {
|
||||
public Map<String, ColorInfo> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
|
@ -64,12 +65,12 @@ public class UserColorInformation {
|
|||
* @param colors
|
||||
* the colors to set
|
||||
*/
|
||||
public void setColors(Map<String, UserColor> colors) {
|
||||
public void setColors(Map<String, ColorInfo> colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public static class UserColor {
|
||||
public static class ColorInfo {
|
||||
|
||||
/**
|
||||
* tells {@link #setColor()} when to use defaultForeground
|
||||
|
@ -98,7 +99,7 @@ public class UserColorInformation {
|
|||
@XmlAttribute
|
||||
private int bgBlue = 255;
|
||||
|
||||
public UserColor() {
|
||||
public ColorInfo() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,8 +200,16 @@ public class UserColorInformation {
|
|||
* foreground color, otherwise it defaults to black
|
||||
*/
|
||||
setColor(ColorType.FOREGROUND, defaultForeground, null);
|
||||
fgSet = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the foreground has been set
|
||||
*/
|
||||
public boolean isForegroundSet() {
|
||||
return fgSet;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.viz.collaboration.ui;
|
||||
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.viz.collaboration.ui.ColorInfoMap.ColorInfo;
|
||||
|
||||
/**
|
||||
* Configuration manager for reading/writing colors for each site to/from a
|
||||
* user-localized file
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 10, 2014 3708 bclement Moved color methods from SiteConfigurationManager
|
||||
* Nov 26, 2014 3709 mapeters Abstracted out code to {@link AbstractColorConfigManager},
|
||||
* renamed from SiteColorConfigManager.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bclement
|
||||
* @version 1.0
|
||||
*/
|
||||
public class FeedColorConfigManager extends AbstractColorConfigManager {
|
||||
|
||||
private static final String FILE_PATH = "collaboration"
|
||||
+ IPathManager.SEPARATOR + "siteColorInfo.xml";
|
||||
|
||||
private static ColorInfoMap colorInfoMap;
|
||||
|
||||
/**
|
||||
* Set and store the color type of the given site to be the given rgb.
|
||||
*
|
||||
* @param site
|
||||
* @param type
|
||||
* @param rgb
|
||||
* @param defaultForeground
|
||||
*/
|
||||
@Override
|
||||
public synchronized void setColor(String site,
|
||||
ColorType type, RGB rgb, RGB defaultForeground) {
|
||||
super.setColor(site, type, rgb, defaultForeground, FILE_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ColorInfo} for the given site from memory.
|
||||
*
|
||||
* @param site
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public synchronized ColorInfo getColor(String site) {
|
||||
return super.getColor(site, FILE_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ColorInfoMap getColorInfoMap() {
|
||||
return colorInfoMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setColorInfoMap(ColorInfoMap colorInfoMap) {
|
||||
FeedColorConfigManager.colorInfoMap = colorInfoMap;
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.viz.collaboration.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManager;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
|
||||
|
||||
/**
|
||||
* Site coloring configuration manager
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 10, 2014 3708 bclement Moved color methods from SiteConfigurationManager
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bclement
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SiteColorConfigManager {
|
||||
|
||||
private static SiteColorInformation colorInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private SiteColorConfigManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the colorInfo.xml file out to user localization so that the user
|
||||
* can retrieve it on CAVE restart
|
||||
*
|
||||
* @param information
|
||||
*/
|
||||
public static void writeSiteColorInformation(
|
||||
SiteColorInformation information) {
|
||||
colorInfo = information;
|
||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lContext = pathMgr.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
LocalizationFile file = pathMgr.getLocalizationFile(lContext,
|
||||
"collaboration" + File.separator + "colorInfo.xml");
|
||||
try {
|
||||
JAXBContext context = JAXBContext
|
||||
.newInstance(SiteColorInformation.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
|
||||
new Boolean(true));
|
||||
marshaller.marshal(information, file.getFile());
|
||||
file.save();
|
||||
} catch (Exception e) {
|
||||
Activator.statusHandler.error(
|
||||
"Unable to write color information to file: "
|
||||
+ file.getName() + " in context " + lContext, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate the colorInfo object so that the colors can be read in from
|
||||
* the colorInfo.xml file and retrieved from localization
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static SiteColorInformation getSiteColorInformation() {
|
||||
if (colorInfo == null) {
|
||||
PathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
||||
Map<LocalizationLevel, LocalizationFile> files = pm
|
||||
.getTieredLocalizationFile(LocalizationType.CAVE_STATIC,
|
||||
"collaboration" + File.separator + "colorInfo.xml");
|
||||
LocalizationLevel[] levels = LocalizationLevel.values();
|
||||
|
||||
for (int i = levels.length - 1; i >= 0 && colorInfo == null; --i) {
|
||||
LocalizationLevel level = levels[i];
|
||||
if (level == LocalizationLevel.SITE
|
||||
|| level == LocalizationLevel.USER) {
|
||||
LocalizationFile file = files.get(level);
|
||||
if (file != null) {
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = file.openInputStream();
|
||||
JAXBContext context = JAXBContext
|
||||
.newInstance(SiteColorInformation.class);
|
||||
Unmarshaller unmarshaller = context
|
||||
.createUnmarshaller();
|
||||
colorInfo = (SiteColorInformation) unmarshaller
|
||||
.unmarshal(in);
|
||||
} catch (Exception e) {
|
||||
Activator.statusHandler.error(
|
||||
"Unable to read color information from file: "
|
||||
+ file.getName() + " in level "
|
||||
+ level, e);
|
||||
}
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
Activator.statusHandler.error(
|
||||
"Problem closing color information file: "
|
||||
+ file.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return colorInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of colors from site information config
|
||||
*/
|
||||
public static List<SiteColor> getSiteColors() {
|
||||
SiteColorInformation colorInfo = getSiteColorInformation();
|
||||
if (colorInfo != null) {
|
||||
return getSiteColorInformation().getColors();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.viz.collaboration.ui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 16, 2012 mnash Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mnash
|
||||
* @version 1.0
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class SiteColorInformation {
|
||||
|
||||
@XmlElement
|
||||
List<SiteColor> colors;
|
||||
|
||||
/**
|
||||
* @return the colors
|
||||
*/
|
||||
public List<SiteColor> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param colors
|
||||
* the colors to set
|
||||
*/
|
||||
public void setColors(List<SiteColor> colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public static class SiteColor {
|
||||
|
||||
@XmlAttribute
|
||||
private String site;
|
||||
|
||||
@XmlAttribute
|
||||
private int red;
|
||||
|
||||
@XmlAttribute
|
||||
private int green;
|
||||
|
||||
@XmlAttribute
|
||||
private int blue;
|
||||
|
||||
public SiteColor() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the site
|
||||
*/
|
||||
public String getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param site
|
||||
* the site to set
|
||||
*/
|
||||
public void setSite(String site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the red
|
||||
*/
|
||||
public int getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param red
|
||||
* the red to set
|
||||
*/
|
||||
public void setRed(int red) {
|
||||
this.red = red;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the green
|
||||
*/
|
||||
public int getGreen() {
|
||||
return green;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param green
|
||||
* the green to set
|
||||
*/
|
||||
public void setGreen(int green) {
|
||||
this.green = green;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blue
|
||||
*/
|
||||
public int getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blue
|
||||
* the blue to set
|
||||
*/
|
||||
public void setBlue(int blue) {
|
||||
this.blue = blue;
|
||||
}
|
||||
|
||||
public RGB getColor() {
|
||||
return new RGB(red, green, blue);
|
||||
}
|
||||
|
||||
public void setColor(RGB rgb) {
|
||||
red = rgb.red;
|
||||
green = rgb.green;
|
||||
blue = rgb.blue;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof SiteColor == false) {
|
||||
return false;
|
||||
} else {
|
||||
return this.getSite().equals(((SiteColor) obj).getSite());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,25 +19,12 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.collaboration.ui;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManager;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.viz.collaboration.ui.UserColorInformation.UserColor;
|
||||
import com.raytheon.uf.viz.collaboration.ui.ColorInfoMap.ColorInfo;
|
||||
|
||||
/**
|
||||
* User coloring configuration manager
|
||||
|
@ -48,106 +35,53 @@ import com.raytheon.uf.viz.collaboration.ui.UserColorInformation.UserColor;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 13, 2014 3709 mapeters Initial creation
|
||||
* Nov 13, 2014 3709 mapeters Initial creation.
|
||||
* Nov 26, 2014 3709 mapeters Abstracted out code to {@link AbstractColorConfigManager}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mapeters
|
||||
* @version 1.0
|
||||
*/
|
||||
public class UserColorConfigManager {
|
||||
public class UserColorConfigManager extends AbstractColorConfigManager {
|
||||
|
||||
private static UserColorInformation colorInfo;
|
||||
private static final String FILE_PATH = "collaboration"
|
||||
+ IPathManager.SEPARATOR + "userColorInfo.xml";
|
||||
|
||||
private UserColorConfigManager() {
|
||||
}
|
||||
private static ColorInfoMap colorInfoMap;
|
||||
|
||||
/**
|
||||
* Set and store the color type of the given user to be the given rgb. If
|
||||
* creating new {@link UserColor} and setting background, set foreground to
|
||||
* defaultForeground to prevent it from incorrectly defaulting.
|
||||
* Set and store the color type of the given user to be the given rgb.
|
||||
*
|
||||
* @param user
|
||||
* @param type
|
||||
* @param rgb
|
||||
* @param defaultForeground
|
||||
*/
|
||||
public synchronized static void setColorForUser(String user,
|
||||
@Override
|
||||
public synchronized void setColor(String user,
|
||||
ColorType type, RGB rgb, RGB defaultForeground) {
|
||||
if (colorInfo == null) {
|
||||
colorInfo = new UserColorInformation();
|
||||
}
|
||||
Map<String, UserColor> colors = colorInfo.getColors();
|
||||
if (colors == null) {
|
||||
colorInfo.setColors(new HashMap<String, UserColor>());
|
||||
colors = colorInfo.getColors();
|
||||
}
|
||||
|
||||
UserColor userColor = colors.get(user);
|
||||
if (userColor != null) {
|
||||
userColor.setColor(type, rgb, null);
|
||||
} else {
|
||||
UserColor color = new UserColor();
|
||||
color.setColor(type, rgb, defaultForeground);
|
||||
colors.put(user, color);
|
||||
}
|
||||
|
||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lContext = pathMgr.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
LocalizationFile file = pathMgr.getLocalizationFile(lContext,
|
||||
"collaboration" + IPathManager.SEPARATOR + "userColorInfo.xml");
|
||||
try {
|
||||
JAXBContext context = JAXBContext
|
||||
.newInstance(UserColorInformation.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
|
||||
new Boolean(true));
|
||||
marshaller.marshal(colorInfo, file.getFile());
|
||||
file.save();
|
||||
} catch (Exception e) {
|
||||
Activator.statusHandler.error(
|
||||
"Unable to write color information to file: "
|
||||
+ file.getName() + " in context " + lContext, e);
|
||||
}
|
||||
super.setColor(user, type, rgb, defaultForeground, FILE_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link UserColor} for the given user from memory.
|
||||
* Get the {@link ColorInfo} for the given user from memory.
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public synchronized static UserColor getColorForUser(String user) {
|
||||
if(colorInfo == null) {
|
||||
IPathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
||||
LocalizationContext locContext = pm.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
LocalizationFile file = pm.getLocalizationFile(locContext,
|
||||
"collaboration" + IPathManager.SEPARATOR
|
||||
+ "userColorInfo.xml");
|
||||
@Override
|
||||
public synchronized ColorInfo getColor(String user) {
|
||||
return super.getColor(user, FILE_PATH);
|
||||
}
|
||||
|
||||
if (file != null && file.exists()) {
|
||||
try (InputStream in = file.openInputStream()) {
|
||||
JAXBContext context = JAXBContext
|
||||
.newInstance(UserColorInformation.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
colorInfo = (UserColorInformation) unmarshaller
|
||||
.unmarshal(in);
|
||||
} catch (Exception e) {
|
||||
Activator.statusHandler.error(
|
||||
"Unable to read color information from file: "
|
||||
+ file.getName() + " in level "
|
||||
+ LocalizationLevel.USER, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(colorInfo != null) {
|
||||
Map<String, UserColor> colors = colorInfo.getColors();
|
||||
if (colors != null) {
|
||||
return colors.get(user);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@Override
|
||||
protected ColorInfoMap getColorInfoMap() {
|
||||
return colorInfoMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setColorInfoMap(ColorInfoMap colorInfoMap) {
|
||||
UserColorConfigManager.colorInfoMap = colorInfoMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ import com.raytheon.viz.ui.views.CaveFloatingView;
|
|||
* Oct 14, 2014 3709 mapeters Support changing foreground/background color.
|
||||
* Nov 14, 2014 3709 mapeters Changing foreground/background colors no longer
|
||||
* implemented here, added messagesTextMenuMgr.
|
||||
* Nov 26, 2014 3709 mapeters Added {@link #getColorFromRGB()}.
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
|
@ -151,9 +152,9 @@ public abstract class AbstractSessionView<T extends IUser> extends
|
|||
protected abstract void setMessageLabel(Composite comp);
|
||||
|
||||
public AbstractSessionView() {
|
||||
imageMap = new HashMap<String, Image>();
|
||||
fonts = new HashMap<String, Font>();
|
||||
colors = new HashMap<RGB, Color>();
|
||||
imageMap = new HashMap<>();
|
||||
fonts = new HashMap<>();
|
||||
colors = new HashMap<>();
|
||||
}
|
||||
|
||||
protected void initComponents(Composite parent) {
|
||||
|
@ -402,15 +403,10 @@ public abstract class AbstractSessionView<T extends IUser> extends
|
|||
|
||||
RGB rgb = new RGB(keyword.getRed(), keyword
|
||||
.getGreen(), keyword.getBlue());
|
||||
Color color = null;
|
||||
|
||||
// using the stored colors so we don't leak
|
||||
if (colors.containsKey(rgb)) {
|
||||
color = colors.get(rgb);
|
||||
} else {
|
||||
color = new Color(Display.getCurrent(),
|
||||
rgb);
|
||||
colors.put(rgb, color);
|
||||
}
|
||||
Color color = getColorFromRGB(rgb);
|
||||
|
||||
TextStyle style = new TextStyle(font,
|
||||
color, null);
|
||||
StyleRange keywordRange = new StyleRange(
|
||||
|
@ -664,4 +660,18 @@ public abstract class AbstractSessionView<T extends IUser> extends
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get corresponding Color from map using RGB
|
||||
*
|
||||
* @param rgb
|
||||
* @return
|
||||
*/
|
||||
protected Color getColorFromRGB(RGB rgb) {
|
||||
Color color = colors.get(rgb);
|
||||
if (color == null) {
|
||||
color = new Color(Display.getCurrent(), rgb);
|
||||
colors.put(rgb, color);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@ package com.raytheon.uf.viz.collaboration.ui.session;
|
|||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
|
||||
|
@ -55,8 +53,8 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.RosterItem;
|
|||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
|
||||
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
||||
import com.raytheon.uf.viz.collaboration.ui.ColorInfoMap.ColorInfo;
|
||||
import com.raytheon.uf.viz.collaboration.ui.UserColorConfigManager;
|
||||
import com.raytheon.uf.viz.collaboration.ui.UserColorInformation.UserColor;
|
||||
import com.raytheon.uf.viz.collaboration.ui.actions.PrintLogActionContributionItem;
|
||||
import com.raytheon.uf.viz.collaboration.ui.notifier.NotifierTask;
|
||||
import com.raytheon.uf.viz.collaboration.ui.notifier.NotifierTools;
|
||||
|
@ -79,6 +77,7 @@ import com.raytheon.uf.viz.core.sounds.SoundUtil;
|
|||
* Jun 17, 2014 3078 bclement changed peer type to IUser
|
||||
* Nov 14, 2014 3709 mapeters support foregound/background color
|
||||
* settings for each user
|
||||
* Nov 26, 2014 3709 mapeters add colorConfigManager, use parent's colors map
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -103,12 +102,12 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
private static final Color BLACK = Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_BLACK);
|
||||
|
||||
private Map<RGB, Color> rgbToColor = new HashMap<>();
|
||||
|
||||
private IUser peer;
|
||||
|
||||
private boolean online = true;
|
||||
|
||||
private static UserColorConfigManager colorConfigManager;
|
||||
|
||||
public PeerToPeerView() {
|
||||
super();
|
||||
CollaborationConnection.getConnection().registerEventHandler(this);
|
||||
|
@ -128,10 +127,6 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
conn.unregisterEventHandler(this);
|
||||
}
|
||||
super.dispose();
|
||||
|
||||
for (Color color : rgbToColor.values()) {
|
||||
color.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -238,7 +233,7 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
|
||||
if (userId != null) {
|
||||
// get user colors from config manager
|
||||
UserColor userColor = UserColorConfigManager.getColorForUser(userId
|
||||
ColorInfo userColor = colorConfigManager.getColor(userId
|
||||
.getName());
|
||||
if (userColor != null) {
|
||||
fgColor = getColorFromRGB(userColor
|
||||
|
@ -266,21 +261,6 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
messagesText.setTopIndex(lineNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get corresponding Color from map using RGB
|
||||
*
|
||||
* @param rgb
|
||||
* @return
|
||||
*/
|
||||
private Color getColorFromRGB(RGB rgb) {
|
||||
Color color = rgbToColor.get(rgb);
|
||||
if (color == null) {
|
||||
color = new Color(Display.getCurrent(), rgb);
|
||||
rgbToColor.put(rgb, color);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSessionImageName() {
|
||||
return PEER_TO_PEER_IMAGE_NAME;
|
||||
|
@ -344,6 +324,7 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
@Override
|
||||
protected void initComponents(Composite parent) {
|
||||
super.initComponents(parent);
|
||||
colorConfigManager = new UserColorConfigManager();
|
||||
|
||||
// unfortunately this code cannot be a part of createToolbarButton
|
||||
// because I cannot instantiate the ACI until after the messagesText
|
||||
|
@ -424,16 +405,18 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
*/
|
||||
private class ChangeUserColorAction extends Action {
|
||||
|
||||
ColorType type;
|
||||
private ColorType type;
|
||||
|
||||
String user;
|
||||
private String user;
|
||||
|
||||
boolean me;
|
||||
private boolean me;
|
||||
|
||||
public ChangeUserColorAction(ColorType type, String user, boolean me) {
|
||||
super("Change " + (me ? "Your " : (user + "'s ")) + type.toString()
|
||||
+ " Color...", IconUtil.getImageDescriptor(Activator
|
||||
.getDefault().getBundle(), "change_color.gif"));
|
||||
private ChangeUserColorAction(ColorType type, String user,
|
||||
boolean me) {
|
||||
super("Change " + (me ? "Your " : (user + "'s "))
|
||||
+ type.toString() + " Color...", IconUtil
|
||||
.getImageDescriptor(Activator.getDefault().getBundle(),
|
||||
"change_color.gif"));
|
||||
this.type = type;
|
||||
this.user = user;
|
||||
this.me = me;
|
||||
|
@ -443,24 +426,21 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
|
|||
public void run() {
|
||||
ColorDialog dialog = new ColorDialog(Display.getCurrent()
|
||||
.getActiveShell());
|
||||
RGB defaultForeground = null;
|
||||
UserColor userColor = UserColorConfigManager.getColorForUser(user);
|
||||
if (userColor != null) {
|
||||
dialog.setRGB(userColor.getColor(type));
|
||||
} else {
|
||||
defaultForeground = me ? DEFAULT_USER_FOREGROUND_COLOR.getRGB()
|
||||
: DEFAULT_PEER_FOREGROUND_COLOR.getRGB();
|
||||
if (type == ColorType.FOREGROUND) {
|
||||
/*
|
||||
* set the dialog to display default foreground color as
|
||||
* currently selected
|
||||
*/
|
||||
dialog.setRGB(defaultForeground);
|
||||
}
|
||||
RGB defaultForeground = me ? DEFAULT_USER_FOREGROUND_COLOR.getRGB()
|
||||
: DEFAULT_PEER_FOREGROUND_COLOR.getRGB();
|
||||
ColorInfo colorInfo = colorConfigManager.getColor(user);
|
||||
if (colorInfo != null) {
|
||||
dialog.setRGB(colorInfo.getColor(type));
|
||||
} else if (type == ColorType.FOREGROUND) {
|
||||
/*
|
||||
* set the dialog to display default foreground color as
|
||||
* currently selected
|
||||
*/
|
||||
dialog.setRGB(defaultForeground);
|
||||
}
|
||||
RGB rgb = dialog.open();
|
||||
if (rgb != null) {
|
||||
UserColorConfigManager.setColorForUser(user, type, rgb,
|
||||
colorConfigManager.setColor(user, type, rgb,
|
||||
defaultForeground);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.collaboration.ui.session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
|
@ -31,12 +32,12 @@ import org.eclipse.jface.util.PropertyChangeEvent;
|
|||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.ColorDialog;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
|
||||
|
@ -44,9 +45,8 @@ import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformatio
|
|||
import com.raytheon.uf.viz.collaboration.comm.provider.connection.CollaborationConnection;
|
||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
|
||||
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
||||
import com.raytheon.uf.viz.collaboration.ui.SiteColorConfigManager;
|
||||
import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation;
|
||||
import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
|
||||
import com.raytheon.uf.viz.collaboration.ui.ColorInfoMap.ColorInfo;
|
||||
import com.raytheon.uf.viz.collaboration.ui.FeedColorConfigManager;
|
||||
import com.raytheon.uf.viz.collaboration.ui.SiteConfigurationManager;
|
||||
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||
import com.raytheon.uf.viz.core.icon.IconUtil;
|
||||
|
@ -77,6 +77,7 @@ import com.raytheon.uf.viz.core.icon.IconUtil;
|
|||
* Apr 01, 2014 2938 mpduff Update logic for site and role changes.
|
||||
* Apr 22, 2014 3038 bclement added initialized flag to differentiate between roster population and new joins
|
||||
* Oct 10, 2014 3708 bclement SiteConfigurationManager refactor
|
||||
* Nov 26, 2014 3709 mapeters support foreground/background color preferences for each site
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -88,15 +89,17 @@ public class SessionFeedView extends SessionView {
|
|||
|
||||
public static final String ID = "com.raytheon.uf.viz.collaboration.SessionFeedView";
|
||||
|
||||
private Action colorChangeAction;
|
||||
|
||||
private Action autoJoinAction;
|
||||
|
||||
private Action userAddSiteAction;
|
||||
|
||||
private Action userRemoveSiteAction;
|
||||
|
||||
private List<SiteColor> colors;
|
||||
private Action bgColorChangeAction;
|
||||
|
||||
private Action fgColorChangeAction;
|
||||
|
||||
private static FeedColorConfigManager colorConfigManager;
|
||||
|
||||
private String actingSite;
|
||||
|
||||
|
@ -127,14 +130,8 @@ public class SessionFeedView extends SessionView {
|
|||
@Override
|
||||
protected void initComponents(Composite parent) {
|
||||
super.initComponents(parent);
|
||||
colors = SiteColorConfigManager.getSiteColors();
|
||||
if (colors != null) {
|
||||
for (VenueParticipant user : session.getVenue().getParticipants()) {
|
||||
setColorForSite(user);
|
||||
}
|
||||
} else {
|
||||
colors = new ArrayList<SiteColor>();
|
||||
}
|
||||
|
||||
colorConfigManager = new FeedColorConfigManager();
|
||||
usersTable.refresh();
|
||||
}
|
||||
|
||||
|
@ -152,37 +149,10 @@ public class SessionFeedView extends SessionView {
|
|||
@Override
|
||||
protected void createActions() {
|
||||
super.createActions();
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
colorChangeAction = new Action("Change Site Color...",
|
||||
IconUtil.getImageDescriptor(bundle, "change_color.gif")) {
|
||||
@Override
|
||||
public void run() {
|
||||
ColorDialog dlg = new ColorDialog(Display.getCurrent()
|
||||
.getActiveShell());
|
||||
RGB rgb = dlg.open();
|
||||
if (rgb != null) {
|
||||
/*
|
||||
* get the selected entry so we know what site to change the
|
||||
* color for
|
||||
*/
|
||||
String site = getSelectedSite();
|
||||
|
||||
replaceSiteColor(site.toString(), rgb);
|
||||
/*
|
||||
* loop through all the entries in the list so we can set
|
||||
* the color for all sites corresponding to "selectedSite"
|
||||
*/
|
||||
if (site != null) {
|
||||
for (VenueParticipant user : session.getVenue()
|
||||
.getParticipants()) {
|
||||
setColorForSite(user);
|
||||
}
|
||||
}
|
||||
bgColorChangeAction = new ChangeSiteColorAction(ColorType.BACKGROUND);
|
||||
|
||||
usersTable.refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
fgColorChangeAction = new ChangeSiteColorAction(ColorType.FOREGROUND);
|
||||
|
||||
autoJoinAction = new Action(CollabPrefConstants.AUTO_JOIN, SWT.TOGGLE) {
|
||||
@Override
|
||||
|
@ -238,7 +208,8 @@ public class SessionFeedView extends SessionView {
|
|||
@Override
|
||||
protected void fillContextMenu(IMenuManager manager) {
|
||||
super.fillContextMenu(manager);
|
||||
manager.add(colorChangeAction);
|
||||
manager.add(bgColorChangeAction);
|
||||
manager.add(fgColorChangeAction);
|
||||
String site = getSelectedSite();
|
||||
if (!SiteConfigurationManager.isVisible(actingSite, site)) {
|
||||
userAddSiteAction
|
||||
|
@ -299,14 +270,57 @@ public class SessionFeedView extends SessionView {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site's foreground/background colors from colorConfigManager to pass
|
||||
* to parent method.
|
||||
*
|
||||
* @param sb
|
||||
* @param offset
|
||||
* @param name
|
||||
* @param userId
|
||||
* @param ranges
|
||||
* @param fgColor
|
||||
* @param bgColor
|
||||
* @param subject
|
||||
*/
|
||||
@Override
|
||||
protected void styleAndAppendText(StringBuilder sb, int offset,
|
||||
String name, VenueParticipant userId, String subject,
|
||||
List<StyleRange> ranges) {
|
||||
String name, VenueParticipant userId, List<StyleRange> ranges,
|
||||
Color fgColor, Color bgColor, String subject) {
|
||||
String site = null;
|
||||
if (subject != null) {
|
||||
setColorForSite(userId, subject);
|
||||
site = subject;
|
||||
} else if (userId != null) {
|
||||
Presence presence = session.getVenue().getPresence(userId);
|
||||
if (presence != null) {
|
||||
site = String.valueOf(presence
|
||||
.getProperty(SiteConfigInformation.SITE_NAME));
|
||||
}
|
||||
}
|
||||
super.styleAndAppendText(sb, offset, name, userId, subject, ranges);
|
||||
if (site != null) {
|
||||
ColorInfo siteColor = colorConfigManager.getColor(site);
|
||||
if (siteColor != null) {
|
||||
if (siteColor.isForegroundSet()) {
|
||||
fgColor = getColorFromRGB(siteColor
|
||||
.getColor(ColorType.FOREGROUND));
|
||||
}
|
||||
bgColor = getColorFromRGB(siteColor
|
||||
.getColor(ColorType.BACKGROUND));
|
||||
}
|
||||
}
|
||||
super.styleAndAppendText(sb, offset, name, userId, ranges, fgColor,
|
||||
bgColor, subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected user
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private VenueParticipant getSelectedParticipant() {
|
||||
IStructuredSelection selection = (IStructuredSelection) usersTable
|
||||
.getSelection();
|
||||
return (VenueParticipant) selection.getFirstElement();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -316,77 +330,12 @@ public class SessionFeedView extends SessionView {
|
|||
* @return
|
||||
*/
|
||||
private String getSelectedSite() {
|
||||
IStructuredSelection selection = (IStructuredSelection) usersTable
|
||||
.getSelection();
|
||||
VenueParticipant selectedEntry = (VenueParticipant) selection
|
||||
.getFirstElement();
|
||||
VenueParticipant selectedEntry = getSelectedParticipant();
|
||||
Presence pres = session.getVenue().getPresence(selectedEntry);
|
||||
Object selectedSite = pres.getProperty(SiteConfigInformation.SITE_NAME);
|
||||
return selectedSite == null ? "" : selectedSite.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an IRosterEntry and sets their color in the SessionColorManager for
|
||||
* the site that they belong to, calls into
|
||||
* setColorForSite(UserId,IPresence)
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
private void setColorForSite(VenueParticipant user) {
|
||||
Presence presence = session.getVenue().getPresence(user);
|
||||
setColorForSite(user, presence);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the work for setting the color for each user that belongs to a site
|
||||
*
|
||||
* @param id
|
||||
* @param presence
|
||||
*/
|
||||
private void setColorForSite(VenueParticipant id, Presence presence) {
|
||||
if (presence == null) {
|
||||
return;
|
||||
}
|
||||
Object site = presence.getProperty(SiteConfigInformation.SITE_NAME);
|
||||
if (site != null) {
|
||||
setColorForSite(id, site.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void setColorForSite(VenueParticipant id, String site) {
|
||||
SiteColor siteColor = new SiteColor();
|
||||
siteColor.setSite(site.toString());
|
||||
int index = colors.indexOf(siteColor);
|
||||
if (index >= 0) {
|
||||
SiteColor actualColor = colors.get(index);
|
||||
colorManager.setColorForUser(id, actualColor.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the color from the map if the site exists in the list
|
||||
*
|
||||
* @param site
|
||||
* @param rgb
|
||||
*/
|
||||
private void replaceSiteColor(String site, RGB rgb) {
|
||||
// now that the users have their color set, we need to add
|
||||
// to the list that has the site color information
|
||||
SiteColor color = new SiteColor();
|
||||
color.setSite(site);
|
||||
color.setColor(rgb);
|
||||
boolean exists = false;
|
||||
for (SiteColor col : SessionFeedView.this.colors) {
|
||||
if (col.getSite().equals(site)) {
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
if (exists) {
|
||||
SessionFeedView.this.colors.remove(color);
|
||||
}
|
||||
SessionFeedView.this.colors.add(color);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -450,11 +399,6 @@ public class SessionFeedView extends SessionView {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Presence changed is triggered for participant's site being changed.
|
||||
* Need to set the color to handle this situation.
|
||||
*/
|
||||
setColorForSite(participant, presence);
|
||||
refreshParticipantList();
|
||||
}
|
||||
|
||||
|
@ -541,16 +485,44 @@ public class SessionFeedView extends SessionView {
|
|||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.collaboration.ui.session.SessionView#dispose()
|
||||
* action for changing foreground/background color for a selected site
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
SiteColorInformation information = new SiteColorInformation();
|
||||
information.setColors(this.colors);
|
||||
// TODO should color config be written more often?
|
||||
SiteColorConfigManager.writeSiteColorInformation(information);
|
||||
private class ChangeSiteColorAction extends Action {
|
||||
|
||||
private ColorType type;
|
||||
|
||||
private ChangeSiteColorAction(ColorType type) {
|
||||
super("Change Site " + type.toString() + " Color...", IconUtil
|
||||
.getImageDescriptor(Activator.getDefault().getBundle(),
|
||||
"change_color.gif"));
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ColorDialog dialog = new ColorDialog(Display.getCurrent()
|
||||
.getActiveShell());
|
||||
RGB defaultForeground = colorManager
|
||||
.getColorForUser(getSelectedParticipant());
|
||||
String site = getSelectedSite();
|
||||
ColorInfo colorInfo = colorConfigManager.getColor(site);
|
||||
if (colorInfo != null
|
||||
&& (type != ColorType.FOREGROUND || colorInfo.isForegroundSet())) {
|
||||
/*
|
||||
* don't set dialog from colorInfo if null or type is foreground
|
||||
* and foreground hasn't been set (use default)
|
||||
*/
|
||||
dialog.setRGB(colorInfo.getColor(type));
|
||||
} else if (type == ColorType.FOREGROUND) {
|
||||
dialog.setRGB(defaultForeground);
|
||||
}
|
||||
RGB rgb = dialog.open();
|
||||
if (rgb != null) {
|
||||
colorConfigManager.setColor(site, type, rgb,
|
||||
defaultForeground);
|
||||
}
|
||||
|
||||
usersTable.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,7 @@ package com.raytheon.uf.viz.collaboration.ui.session;
|
|||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.action.IContributionItem;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
|
@ -115,6 +113,8 @@ import com.raytheon.uf.viz.core.sounds.SoundUtil;
|
|||
* negative weights - set to zero if negative.
|
||||
* Jun 17, 2014 3078 bclement added private chat to menu and double click
|
||||
* Jul 03, 2014 3342 bclement added count to participants label
|
||||
* Nov 26, 2014 3709 mapeters added styleAndAppendText() taking fg and bg colors,
|
||||
* use parent's colors map.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -148,8 +148,6 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
|
|||
|
||||
protected SessionColorManager colorManager;
|
||||
|
||||
protected Map<RGB, Color> mappedColors;
|
||||
|
||||
public SessionView() {
|
||||
super();
|
||||
}
|
||||
|
@ -159,7 +157,6 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
|
|||
super.createPartControl(parent);
|
||||
createActions();
|
||||
createContextMenu();
|
||||
mappedColors = new HashMap<RGB, Color>();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -408,12 +405,6 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
|
|||
disposeArrow(downArrow);
|
||||
disposeArrow(rightArrow);
|
||||
|
||||
if (mappedColors != null) {
|
||||
for (Color col : mappedColors.values()) {
|
||||
col.dispose();
|
||||
}
|
||||
mappedColors.clear();
|
||||
}
|
||||
if (colorManager != null) {
|
||||
colorManager.clearColors();
|
||||
}
|
||||
|
@ -471,12 +462,8 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
|
|||
String name, VenueParticipant userId, String subject,
|
||||
List<StyleRange> ranges) {
|
||||
RGB rgb = colorManager.getColorForUser(userId);
|
||||
if (mappedColors.get(rgb) == null) {
|
||||
Color col = new Color(Display.getCurrent(), rgb);
|
||||
mappedColors.put(rgb, col);
|
||||
}
|
||||
styleAndAppendText(sb, offset, name, userId, ranges,
|
||||
mappedColors.get(rgb));
|
||||
getColorFromRGB(rgb), null, subject);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -491,22 +478,26 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
|
|||
protected void styleAndAppendText(StringBuilder sb, int offset,
|
||||
String name, VenueParticipant userId, List<StyleRange> ranges,
|
||||
Color color) {
|
||||
StyleRange range = new StyleRange(messagesText.getCharCount(), offset,
|
||||
color, null, SWT.NORMAL);
|
||||
styleAndAppendText(sb, offset, name, userId, ranges, color, null, null);
|
||||
}
|
||||
|
||||
protected void styleAndAppendText(StringBuilder sb, int offset,
|
||||
String name, VenueParticipant userId, List<StyleRange> ranges,
|
||||
Color fgColor, Color bgColor, String subject) {
|
||||
StyleRange range = new StyleRange(messagesText.getCharCount(),
|
||||
sb.length(), fgColor, null, SWT.NORMAL);
|
||||
ranges.add(range);
|
||||
if (userId != null) {
|
||||
range = new StyleRange(messagesText.getCharCount() + offset,
|
||||
name.length() + 1, color, null, SWT.BOLD);
|
||||
} else {
|
||||
range = new StyleRange(messagesText.getCharCount() + offset,
|
||||
sb.length() - offset, color, null, SWT.BOLD);
|
||||
}
|
||||
range = new StyleRange(messagesText.getCharCount() + offset,
|
||||
(userId != null ? name.length() + 1 : sb.length() - offset),
|
||||
fgColor, null, SWT.BOLD);
|
||||
ranges.add(range);
|
||||
messagesText.append(sb.toString());
|
||||
for (StyleRange newRange : ranges) {
|
||||
messagesText.setStyleRange(newRange);
|
||||
}
|
||||
messagesText.setTopIndex(messagesText.getLineCount() - 1);
|
||||
int lineNumber = messagesText.getLineCount() - 1;
|
||||
messagesText.setLineBackground(lineNumber, 1, bgColor);
|
||||
messagesText.setTopIndex(lineNumber);
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
|
|
Loading…
Add table
Reference in a new issue