From 5ad0cde96b5b30d59795f349001e4e42237b8c06 Mon Sep 17 00:00:00 2001 From: Mark Peters Date: Tue, 2 Dec 2014 11:24:01 -0600 Subject: [PATCH] Omaha #3709 Support foreground/background colors by site for nws-collaborate room Change-Id: Id090446cf3ee5e9755039c228a0924fa3756add0 Former-commit-id: 999feecc3880c10f5d19a2829d7552fa49595bd5 --- .../ui/AbstractColorConfigManager.java | 135 ++++++++++ ...olorInformation.java => ColorInfoMap.java} | 23 +- .../ui/FeedColorConfigManager.java | 89 +++++++ .../ui/SiteColorConfigManager.java | 159 ------------ .../ui/SiteColorInformation.java | 173 ------------- .../ui/UserColorConfigManager.java | 114 ++------- .../ui/session/AbstractSessionView.java | 32 ++- .../ui/session/PeerToPeerView.java | 74 ++---- .../ui/session/SessionFeedView.java | 234 ++++++++---------- .../collaboration/ui/session/SessionView.java | 43 ++-- 10 files changed, 432 insertions(+), 644 deletions(-) create mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/AbstractColorConfigManager.java rename cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/{UserColorInformation.java => ColorInfoMap.java} (90%) create mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/FeedColorConfigManager.java delete mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorConfigManager.java delete mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorInformation.java diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/AbstractColorConfigManager.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/AbstractColorConfigManager.java new file mode 100644 index 0000000000..f6429b114c --- /dev/null +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/AbstractColorConfigManager.java @@ -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 + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 13, 2014 3709       mapeters    Initial creation.
+ * 
+ * 
+ * + * @author mapeters + * @version 1.0 + */ +public abstract class AbstractColorConfigManager { + + private static final SingleTypeJAXBManager 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 colors = colorInfoMap.getColors(); + if (colors == null) { + colorInfoMap.setColors(new HashMap()); + 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 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); +} diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorInformation.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ColorInfoMap.java similarity index 90% rename from cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorInformation.java rename to cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ColorInfoMap.java index 1cf9a07e0b..a1100f1eec 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorInformation.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ColorInfoMap.java @@ -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 * *
  * 
@@ -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.
  * 
  * 
* @@ -48,15 +49,15 @@ import org.eclipse.swt.graphics.RGB; */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class UserColorInformation { +public class ColorInfoMap { @XmlElement - private Map colors; + private Map colors; /** * @return the colors */ - public Map getColors() { + public Map getColors() { return colors; } @@ -64,12 +65,12 @@ public class UserColorInformation { * @param colors * the colors to set */ - public void setColors(Map colors) { + public void setColors(Map 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; + } } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/FeedColorConfigManager.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/FeedColorConfigManager.java new file mode 100644 index 0000000000..d052c95a95 --- /dev/null +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/FeedColorConfigManager.java @@ -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 + * + *
+ * 
+ * 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.
+ * 
+ * 
+ * + * @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; + } +} diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorConfigManager.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorConfigManager.java deleted file mode 100644 index bb6e35b9d5..0000000000 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorConfigManager.java +++ /dev/null @@ -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 - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Oct 10, 2014 3708       bclement    Moved color methods from SiteConfigurationManager
- * 
- * 
- * - * @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 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 getSiteColors() { - SiteColorInformation colorInfo = getSiteColorInformation(); - if (colorInfo != null) { - return getSiteColorInformation().getColors(); - } else { - return null; - } - } - -} diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorInformation.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorInformation.java deleted file mode 100644 index 742dd3052e..0000000000 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/SiteColorInformation.java +++ /dev/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 - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Jul 16, 2012            mnash     Initial creation
- * 
- * 
- * - * @author mnash - * @version 1.0 - */ -@XmlRootElement -@XmlAccessorType(XmlAccessType.NONE) -public class SiteColorInformation { - - @XmlElement - List colors; - - /** - * @return the colors - */ - public List getColors() { - return colors; - } - - /** - * @param colors - * the colors to set - */ - public void setColors(List 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()); - } - } - } -} diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorConfigManager.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorConfigManager.java index af306f86cc..e4994e4815 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorConfigManager.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/UserColorConfigManager.java @@ -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}. * * * * @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 colors = colorInfo.getColors(); - if (colors == null) { - colorInfo.setColors(new HashMap()); - 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 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; } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java index d6e661d3b4..b8b8f506f6 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java @@ -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()}. * * * @author rferrel @@ -151,9 +152,9 @@ public abstract class AbstractSessionView extends protected abstract void setMessageLabel(Composite comp); public AbstractSessionView() { - imageMap = new HashMap(); - fonts = new HashMap(); - colors = new HashMap(); + imageMap = new HashMap<>(); + fonts = new HashMap<>(); + colors = new HashMap<>(); } protected void initComponents(Composite parent) { @@ -402,15 +403,10 @@ public abstract class AbstractSessionView 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 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; + } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/PeerToPeerView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/PeerToPeerView.java index cf6ff5b9b8..e272d85a1f 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/PeerToPeerView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/PeerToPeerView.java @@ -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 * * * @@ -103,12 +102,12 @@ public class PeerToPeerView extends AbstractSessionView implements private static final Color BLACK = Display.getCurrent().getSystemColor( SWT.COLOR_BLACK); - private Map 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 implements conn.unregisterEventHandler(this); } super.dispose(); - - for (Color color : rgbToColor.values()) { - color.dispose(); - } } /* @@ -238,7 +233,7 @@ public class PeerToPeerView extends AbstractSessionView 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 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 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 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 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); } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionFeedView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionFeedView.java index 4ca7347914..66cd5e692e 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionFeedView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionFeedView.java @@ -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 * * * @@ -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 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(); - } + + 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 ranges) { + String name, VenueParticipant userId, List 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(); + } } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java index af6bcda30b..1eb0f0c91f 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java @@ -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. * * * @@ -148,8 +148,6 @@ public class SessionView extends AbstractSessionView protected SessionColorManager colorManager; - protected Map mappedColors; - public SessionView() { super(); } @@ -159,7 +157,6 @@ public class SessionView extends AbstractSessionView super.createPartControl(parent); createActions(); createContextMenu(); - mappedColors = new HashMap(); } /* @@ -408,12 +405,6 @@ public class SessionView extends AbstractSessionView 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 String name, VenueParticipant userId, String subject, List 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 protected void styleAndAppendText(StringBuilder sb, int offset, String name, VenueParticipant userId, List 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 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() {