Merge "Omaha #3709 unify collaboration color management" into omaha_14.4.1

Former-commit-id: fa93fe561ae1ad49979ab657b4a537dc7731af8e
This commit is contained in:
Nate Jensen 2015-01-14 14:05:18 -06:00 committed by Gerrit Code Review
commit 7c61d2c06d
25 changed files with 829 additions and 922 deletions

View file

@ -38,6 +38,7 @@ import org.jivesoftware.smackx.muc.Occupant;
* Jan 30, 2014 2698 bclement reworked convertFromRoom for venue participants
* Feb 3, 2014 2699 bclement fixed room id parsing when handle has special characters
* Feb 13, 2014 2751 bclement VenueParticipant refactor
* Jan 13, 2015 3709 bclement added convertFromRoom that doesn't reference MUC
*
* </pre>
*
@ -72,6 +73,24 @@ public class IDConverter {
* @return
*/
public static VenueParticipant convertFromRoom(MultiUserChat room, String id) {
VenueParticipant rval = convertFromRoom(id);
Occupant occupant;
if (room != null && (occupant = room.getOccupant(id)) != null) {
if (occupant.getJid() != null) {
// get actual user name
rval.setUserid(convertFrom(occupant.getJid()));
}
}
return rval;
}
/**
* Parse userId from room id string "room@host/handle".
*
* @param id
* @return
*/
public static VenueParticipant convertFromRoom(String id) {
String handle = StringUtils.parseResource(id);
if (handle == null || handle.trim().isEmpty()) {
throw new IllegalArgumentException(
@ -81,13 +100,6 @@ public class IDConverter {
String host = StringUtils.parseServer(cleanId);
String roomName = StringUtils.parseName(id);
VenueParticipant rval = new VenueParticipant(roomName, host, handle);
Occupant occupant;
if (room != null && (occupant = room.getOccupant(id)) != null) {
if (occupant.getJid() != null) {
// get actual user name
rval.setUserid(convertFrom(occupant.getJid()));
}
}
return rval;
}

View file

@ -17,19 +17,15 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui.colors;
package com.raytheon.uf.viz.collaboration.display.data;
import java.util.Map;
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.SWT;
import org.eclipse.swt.graphics.RGB;
/**
* Contains foreground and background chat colors for a list of users or sites
*
@ -43,6 +39,8 @@ import org.eclipse.swt.graphics.RGB;
* Nov 26, 2014 3709 mapeters Renamed from UserColorInformation, added fgSet getter.
* Dec 08, 2014 3709 mapeters Removed fgSet and individual colors' getters/setters,
* set foreground and background together.
* Jan 13, 2015 3709 bclement moved from collaboration.ui to collaboration.display
* moved ColorInfo class to UserColorInfo
*
* </pre>
*
@ -54,12 +52,25 @@ import org.eclipse.swt.graphics.RGB;
public class ColorInfoMap {
@XmlElement
private Map<String, ColorInfo> colors;
private Map<String, UserColorInfo> colors;
/**
*
*/
public ColorInfoMap() {
}
/**
* @param colors
*/
public ColorInfoMap(Map<String, UserColorInfo> colors) {
this.colors = colors;
}
/**
* @return the colors
*/
public Map<String, ColorInfo> getColors() {
public Map<String, UserColorInfo> getColors() {
return colors;
}
@ -67,58 +78,8 @@ public class ColorInfoMap {
* @param colors
* the colors to set
*/
public void setColors(Map<String, ColorInfo> colors) {
public void setColors(Map<String, UserColorInfo> colors) {
this.colors = colors;
}
@XmlAccessorType(XmlAccessType.NONE)
public static class ColorInfo {
@XmlAttribute
private int fgRed;
@XmlAttribute
private int fgGreen;
@XmlAttribute
private int fgBlue;
@XmlAttribute
private int bgRed;
@XmlAttribute
private int bgGreen;
@XmlAttribute
private int bgBlue;
public ColorInfo() {
}
/**
* @param type
* @return the RGB color of the given type
*/
public RGB getColor(int type) {
if (type == SWT.FOREGROUND) {
return new RGB(fgRed, fgGreen, fgBlue);
} else {
return new RGB(bgRed, bgGreen, bgBlue);
}
}
/**
* @param fg
* @param bg
*/
public void setColors(RGB fg, RGB bg) {
fgRed = fg.red;
fgGreen = fg.green;
fgBlue = fg.blue;
bgRed = bg.red;
bgGreen = bg.green;
bgBlue = bg.blue;
}
}
}

View file

@ -17,16 +17,13 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui.colors;
package com.raytheon.uf.viz.collaboration.display.data;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
/**
* Interface for color configuration managers to keep track of custom color
* settings for users. Colors are tracked by a string key which could be the
* user name or attribute (eg site name).
* Interface for color managers that keep track of color settings for users in a
* session or chat.
*
* <pre>
*
@ -34,35 +31,39 @@ import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 08, 2015 3709 bclement Initial creation
* Jan 13, 2015 3709 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public interface IColorConfigManager {
public interface IColorManager<T extends IUser> {
/**
* Set display colors
* Get assigned color for user
*
* @param key
* @param foreground
* @param background
*/
public void setColors(String key, RGB foreground, RGB background);
/**
* Get display colors
*
* @param key
* @param user
* @return
*/
public ColorInfo getColor(String key);
public UserColorInfo getColorForUser(T user);
/**
* Assign color to user
*
* @param user
* @param color
*/
public void setColorForUser(T user, UserColorInfo color);
/**
* Clear color assignments
*/
public void clearColors();
/**
* @return human readable description of color management
*/
public String getDescription(String key);
public String getDescription(T user);
}

View file

@ -21,6 +21,7 @@ package com.raytheon.uf.viz.collaboration.display.data;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.swt.graphics.RGB;
@ -46,6 +47,7 @@ import com.raytheon.viz.core.ColorUtil;
* Mar 06, 2014 2848 bclement synchronized color access
* Jul 02, 2014 1255 bclement collaboration specific RGB presets
* falls back to ColorUtil resource color presets
* Jan 13, 2015 3709 bclement implements IColorManager, uses UserColorInfo
*
* </pre>
*
@ -53,94 +55,129 @@ import com.raytheon.viz.core.ColorUtil;
* @version 1.0
*/
public class SessionColorManager {
public class SessionColorManager implements IColorManager<VenueParticipant> {
public static final String SESSION_COLOR_PREFERENCE_KEY = "collaborationParticipantColor";
private final Map<VenueParticipant, RGB> colors = new HashMap<VenueParticipant, RGB>();
protected final Map<VenueParticipant, UserColorInfo> colors = new HashMap<>();
private static final RGB[] rgbPresets;
private static final RGB[] foregroundPresets;
static {
HierarchicalPreferenceStore prefs = (HierarchicalPreferenceStore) Activator
.getDefault().getPreferenceStore();
String[] names = prefs.getStringArray(SESSION_COLOR_PREFERENCE_KEY);
if (names.length > 0) {
rgbPresets = new RGB[names.length];
foregroundPresets = new RGB[names.length];
int i = 0;
for (String name : names) {
rgbPresets[i++] = RGBColors.getRGBColor(name);
foregroundPresets[i++] = RGBColors.getRGBColor(name);
}
} else {
rgbPresets = ColorUtil.getResourceColorPresets();
foregroundPresets = ColorUtil.getResourceColorPresets();
}
}
/**
* Get a map of venue participants to their assigned colors used for
* Get a map of venue participants to their assigned foreground colors
*
* @return
*/
public Map<VenueParticipant, RGB> getColors() {
public Map<VenueParticipant, RGB> getForegroundColors() {
/*
* TODO the foreground specific methods are required since the shared
* display protocol doesn't support changing the background color as
* this would cause compatibility issues.
*/
Map<VenueParticipant, RGB> rval;
synchronized (colors) {
rval = new HashMap<VenueParticipant, RGB>(colors);
rval = new HashMap<VenueParticipant, RGB>(colors.size());
for (Entry<VenueParticipant, UserColorInfo> entry : colors
.entrySet()) {
rval.put(entry.getKey(), entry.getValue().getForeground());
}
}
return rval;
}
/**
* Clear color assignments and repopulate with supplied map
* Reassign foreground colors specified by map
*
* @param map
*/
public void setColors(Map<VenueParticipant, RGB> map) {
public void setForegroundColors(Map<VenueParticipant, RGB> map) {
synchronized (colors) {
colors.clear();
colors.putAll(map);
for (Entry<VenueParticipant, RGB> entry : map.entrySet()) {
VenueParticipant participant = entry.getKey();
UserColorInfo colorInfo = getColorInternal(participant);
RGB foreground = entry.getValue();
if (colorInfo != null) {
colorInfo.setForeground(foreground);
} else {
setColorInternal(participant, new UserColorInfo(foreground));
}
}
}
}
/**
* Get participant's assigned color
*
* @param user
* @return
*/
public RGB getColorForUser(VenueParticipant user) {
RGB rval;
synchronized (colors) {
rval = colors.get(user);
if (rval == null) {
@Override
public UserColorInfo getColorForUser(VenueParticipant user) {
UserColorInfo rval;
rval = getColorInternal(user);
if (rval == null) {
synchronized (colors) {
int count = colors.size();
if (rgbPresets.length <= count) {
count = count % rgbPresets.length;
if (foregroundPresets.length <= count) {
count = count % foregroundPresets.length;
}
rval = rgbPresets[count];
colors.put(user, rval);
rval = new UserColorInfo(foregroundPresets[count]);
setColorInternal(user, rval);
}
}
return rval;
}
/**
* Assign color to participant
*
* @param id
* @param rgb
* @param user
* @return null if user isn't found
*/
public void setColorForUser(VenueParticipant id, RGB rgb) {
synchronized (colors) {
colors.put(id, rgb);
protected UserColorInfo getColorInternal(VenueParticipant user) {
UserColorInfo rval = null;
if (user != null) {
synchronized (colors) {
rval = colors.get(user);
}
}
return rval;
}
/**
* Clear color assignments
* @param user
* @param color
*/
protected void setColorInternal(VenueParticipant user, UserColorInfo color) {
synchronized (colors) {
colors.put(user, color);
}
}
@Override
public void setColorForUser(VenueParticipant user, UserColorInfo color) {
setColorInternal(user, color);
}
@Override
public void clearColors() {
synchronized (colors) {
colors.clear();
}
}
@Override
public String getDescription(VenueParticipant user) {
return "Color changes will apply to the user " + user.getName()
+ " only in the " + user.getRoom() + " room. "
+ "\nColor changes will be discarded when you leave the room.";
}
}

View file

@ -54,6 +54,7 @@ import com.raytheon.uf.viz.core.VizApp;
* Feb 11, 2014 2751 njensen Added leaderChanged() and listeners
* Mar 07, 2014 2848 bclement made colorManager final, added modifyColors() listeners
* Mar 18, 2014 2895 njensen Improved javadoc
* Jan 13, 2015 3709 bclement SessionColorManager API changes
*
* </pre>
*
@ -72,7 +73,13 @@ public class SessionContainer {
/** subscribes to events related to the session based on role **/
private IRoleEventController roleEventController;
private final SessionColorManager colorManager = new SessionColorManager();
private final SessionColorManager colorManager = new SessionColorManager() {
@Override
public String getDescription(VenueParticipant user) {
return super.getDescription(user)
+ "\nColor changes will be seen by all participants in the session.";
}
};
private IRemoteDisplayContainer displayContainer;
@ -178,12 +185,13 @@ public class SessionContainer {
@Subscribe
public void modifyColors(ColorPopulator populator) {
colorManager.setColors(populator.getColors());
colorManager.setForegroundColors(populator.getColors());
}
@Subscribe
public void modifyColors(ColorChangeEvent event) {
colorManager.setColorForUser(event.getUserName(), event.getColor());
UserColorInfo color = new UserColorInfo(event.getColor());
colorManager.setColorForUser(event.getUserName(), color);
}
/**

View file

@ -0,0 +1,126 @@
/**
* 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.display.data;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import org.eclipse.swt.graphics.RGB;
/**
* Color information for a collaboration user which is used when styling text
* and telestration
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 12, 2015 3709 bclement Initial creation, moved from ColorInfoMap
*
* </pre>
*
* @author bclement
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
public class UserColorInfo {
@XmlAttribute
private int fgRed;
@XmlAttribute
private int fgGreen;
@XmlAttribute
private int fgBlue;
@XmlAttribute
private int bgRed;
@XmlAttribute
private int bgGreen;
@XmlAttribute
private int bgBlue;
/**
*
*/
public UserColorInfo() {
}
/**
* @param foreground
*/
public UserColorInfo(RGB foreground) {
this(foreground, new RGB(255, 255, 255));
}
/**
* @param foreground
* @param background
*/
public UserColorInfo(RGB foreground, RGB background) {
setForeground(foreground);
setBackground(background);
}
/**
* @return the background
*/
public RGB getBackground() {
return new RGB(bgRed, bgGreen, bgBlue);
}
/**
* @param background
* the background to set
*/
public void setBackground(RGB background) {
if (background != null) {
this.bgRed = background.red;
this.bgGreen = background.green;
this.bgBlue = background.blue;
}
}
/**
* @return the foreground
*/
public RGB getForeground() {
return new RGB(fgRed, fgGreen, fgBlue);
}
/**
* @param foreground
* the foreground to set
*/
public void setForeground(RGB foreground) {
if (foreground != null) {
this.fgRed = foreground.red;
this.fgGreen = foreground.green;
this.fgBlue = foreground.blue;
}
}
}

View file

@ -19,8 +19,6 @@
**/
package com.raytheon.uf.viz.collaboration.display.roles;
import org.eclipse.swt.graphics.RGB;
import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -33,6 +31,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.invite.ColorPopulator;
import com.raytheon.uf.viz.collaboration.display.data.ColorChangeEvent;
import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.display.editor.ActivateRemoteDisplay;
import com.raytheon.uf.viz.collaboration.display.roles.dataprovider.SharedEditorsManager;
import com.raytheon.uf.viz.core.IDisplayPane;
@ -56,6 +55,7 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
* Feb 13, 2014 2751 bclement VenueParticipant refactor
* Feb 13, 2014 2751 njensen Renamed container to displayContainer
* Mar 06, 2014 2848 bclement removed check for self from participantChanged
* Jan 13, 2015 3709 bclement SessionColorManager API changes
*
* </pre>
*
@ -98,12 +98,13 @@ public class DataProviderEventController extends
SessionColorManager scm = SharedDisplaySessionMgr
.getSessionContainer(session.getSessionId())
.getColorManager();
RGB color = scm.getColorForUser(event.getParticipant());
UserColorInfo color = scm.getColorForUser(event
.getParticipant());
ColorChangeEvent cce = new ColorChangeEvent(
event.getParticipant(), color);
event.getParticipant(), color.getForeground());
session.sendObjectToPeer(event.getParticipant(),
new ColorPopulator(scm.getColors()));
new ColorPopulator(scm.getForegroundColors()));
session.sendObjectToVenue(cce);
} catch (CollaborationException e) {
statusHandler.handle(Priority.PROBLEM,

View file

@ -29,6 +29,7 @@ import com.raytheon.uf.viz.collaboration.display.Activator;
import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.SessionContainer;
import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.display.editor.ReprojectRemoteDisplay;
import com.raytheon.uf.viz.core.DrawableString;
import com.raytheon.uf.viz.core.IExtent;
@ -60,6 +61,7 @@ import com.raytheon.uf.viz.remote.graphics.DispatchGraphicsTarget;
* Mar 06, 2014 2848 bclement get subject dynamically from session
* May 16, 2014 3163 bsteffen Remove references to deprecated
* {@link DrawableString} field.
* Jan 13, 2015 3709 bclement SessionColorManager API changes
*
* </pre>
*
@ -103,10 +105,12 @@ public class DataProviderRsc extends
}
target.clearClippingPlane();
IExtent extent = paintProps.getView().getExtent();
RGB color = colorManager.getColorForUser(session.getUserID());
target.drawRect(extent, color, 3.0f, 1.0f);
UserColorInfo colors = colorManager
.getColorForUser(session.getUserID());
RGB foreground = colors.getForeground();
target.drawRect(extent, foreground, 3.0f, 1.0f);
DrawableString string = new DrawableString(getName(), color);
DrawableString string = new DrawableString(getName(), foreground);
string.horizontalAlignment = HorizontalAlignment.CENTER;
string.verticallAlignment = VerticalAlignment.BOTTOM;
string.setCoordinates(extent.getMinX() + extent.getWidth() / 2,

View file

@ -36,6 +36,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
import com.raytheon.uf.viz.collaboration.display.Activator;
import com.raytheon.uf.viz.collaboration.display.data.SessionContainer;
import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.display.rsc.telestrator.CollaborationDrawingEvent.CollaborationEventType;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.IGraphicsTarget.LineStyle;
@ -70,6 +71,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* May 05, 2014 3076 bclement old CLEAR_ALL is now DISPOSE_ALL,
* added clearLayers() and getAllDrawingLayers()
* Jun 30, 2014 1798 bclement added getManager()
* Jan 13, 2015 3709 bclement SessionColorManager API changes
*
* </pre>
*
@ -180,8 +182,9 @@ public class CollaborationDrawingResource extends
layer.setEraserWidth(16); // Configure?
layer.setLineStyle(outline.getLineStyle());
layer.setLineWidth(outline.getOutlineWidth());
layer.setColor(container.getColorManager().getColorForUser(
user));
UserColorInfo colorInfo = container.getColorManager()
.getColorForUser(user);
layer.setColor(colorInfo.getForeground());
layer.paint(target, paintProps);
}
}

View file

@ -59,7 +59,6 @@ import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -89,6 +88,7 @@ import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IRosterChangeEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.event.RosterChangeType;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.comm.provider.connection.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.event.BookmarkEvent;
import com.raytheon.uf.viz.collaboration.comm.provider.event.UserPresenceChangedEvent;
@ -170,6 +170,7 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
* Dec 08, 2014 3709 mapeters Added MB3 change user text color actions to contacts list.
* Dec 12, 2014 3709 mapeters Store {@link ChangeTextColorAction}s in map, dispose them.
* Jan 09, 2015 3709 bclement color config manager API changes
* Jan 13, 2015 3709 bclement ChangeTextColorAction API changes
*
* </pre>
*
@ -210,7 +211,7 @@ public class CollaborationGroupView extends CaveFloatingView implements
private Action roomSearchAction;
private Map<String, ChangeTextColorAction> userColorActions;
private Map<String, ChangeTextColorAction<?>> userColorActions;
/**
* @param parent
@ -287,7 +288,8 @@ public class CollaborationGroupView extends CaveFloatingView implements
activeImage.dispose();
pressedImage.dispose();
for (ChangeTextColorAction userColorAction : userColorActions.values()) {
for (ChangeTextColorAction<?> userColorAction : userColorActions
.values()) {
userColorAction.dispose();
}
}
@ -479,13 +481,11 @@ public class CollaborationGroupView extends CaveFloatingView implements
manager.add(new AddNotifierAction(this));
manager.add(new Separator());
String colorActionKey = user.getFQName();
ChangeTextColorAction userColorAction = userColorActions
ChangeTextColorAction<?> userColorAction = userColorActions
.get(colorActionKey);
if (userColorAction == null) {
userColorAction = ChangeTextColorAction
.createChangeUserTextColorAction(user, false, false,
new RGB(0, 0, 255),
UserColorConfigManager.getInstance());
userColorAction = new ChangeTextColorAction<IUser>(user, false,
false, false, UserColorConfigManager.getInstance());
userColorActions.put(colorActionKey, userColorAction);
}
manager.add(userColorAction);
@ -498,13 +498,12 @@ public class CollaborationGroupView extends CaveFloatingView implements
if (me.isSameUser(user)) {
createMenu(manager);
String colorActionKey = user.getFQName();
ChangeTextColorAction userColorAction = userColorActions
ChangeTextColorAction<?> userColorAction = userColorActions
.get(colorActionKey);
if (userColorAction == null) {
userColorAction = ChangeTextColorAction
.createChangeUserTextColorAction(user, true, true,
new RGB(0, 0, 255),
UserColorConfigManager.getInstance());
userColorAction = new ChangeTextColorAction<IUser>(user,
true, true, false,
UserColorConfigManager.getInstance());
userColorActions.put(colorActionKey, userColorAction);
}
manager.insertBefore("afterFont", userColorAction);

View file

@ -22,22 +22,19 @@ package com.raytheon.uf.viz.collaboration.ui.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.comm.provider.connection.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.ui.colors.FeedColorConfigManager;
import com.raytheon.uf.viz.collaboration.display.data.IColorManager;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.ui.colors.ForegroundBackgroundColorDlg;
import com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager;
import com.raytheon.uf.viz.collaboration.ui.colors.ForegroundColorDlg;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
/**
@ -57,40 +54,47 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* current foreground and background colors.
* Jan 05, 2015 3709 mapeters Added getTextColors(), added me param to createChangeUserTextColorAction().
* Jan 09, 2015 3709 bclement color change manager API changes
* Jan 12, 2015 3709 bclement removed event handler for icon changes, added ChangeTextColorCallback
* Jan 13, 2015 3709 bclement unified color management, simplified construction, added foregroundOnly mode
*
* </pre>
*
* @author mapeters
* @version 1.0
*/
public class ChangeTextColorAction extends Action {
public class ChangeTextColorAction<T extends IUser> extends Action {
private final String key;
private final T user;
private RGB defaultForeground;
private IColorManager<T> colorManager;
private IColorConfigManager colorConfigManager;
private boolean foregroundOnly;
private Image icon;
/**
* Create and return new action for changing user colors.
* Callback that receives new color information when the action results in a
* new color selection for a user
*/
public static interface ChangeTextColorCallback {
public void newColor(IUser user, UserColorInfo colors);
}
private ChangeTextColorCallback actionCallback = null;
/**
* Generate display text string according to provided options
*
* @param user
* the user whose colors may be changed by this action
* @param me
* whether the selected user is the current user
* true if user represents the currently logged in user
* @param displayName
* whether to display the user's name or simply "User"
* @param defaultForeground
* the foreground color to use if none is stored
* @param colorConfigManager
* manager to store/retrieve user colors
* true if the user's name should be used or false if a generic
* display text should be used
* @return
*/
public static ChangeTextColorAction createChangeUserTextColorAction(
IUser user, boolean me, boolean displayName,
RGB defaultForeground, IColorConfigManager colorConfigManager) {
public static String getDisplayText(IUser user, boolean me,
boolean displayName) {
String name = user.getName();
String text = "Change ";
if (displayName) {
@ -100,47 +104,43 @@ public class ChangeTextColorAction extends Action {
}
text += " Text Colors...";
return new ChangeTextColorAction(text, user.getFQName(),
defaultForeground, colorConfigManager);
return text;
}
/**
* Create and return new action for changing site colors.
*
* @param site
* the site whose colors may be changed by this action
* @param defaultForeground
* the foreground color to use if none is stored
* @param user
* @param me
* true if user represents the currently logged in user
* @param displayName
* true if the user's name should be used or false if a generic
* display text should be used
* @param foregroundOnly
* true if only the option to change the foreground should be
* provided
* @param colorConfigManager
* manager to store/retrieve site colors
* @return
*/
public static ChangeTextColorAction createChangeSiteTextColorAction(
String site, RGB defaultForeground,
FeedColorConfigManager colorConfigManager) {
return new ChangeTextColorAction("Change Site Text Colors...", site,
defaultForeground, colorConfigManager);
}
private ChangeTextColorAction(String text, String key,
RGB defaultForeground, IColorConfigManager colorConfigManager) {
super(text);
this.key = key;
this.defaultForeground = defaultForeground;
this.colorConfigManager = colorConfigManager;
RGB[] colors = getTextColors();
setIconColors(colors[0], colors[1]);
CollaborationConnection.getConnection().registerEventHandler(this);
public ChangeTextColorAction(T user, boolean me, boolean displayName,
boolean foregroundOnly, IColorManager<T> colorConfigManager) {
super(getDisplayText(user, me, displayName));
this.user = user;
this.colorManager = colorConfigManager;
this.foregroundOnly = foregroundOnly;
UserColorInfo colors = getTextColors();
setIconColors(colors);
}
@Override
public void run() {
RGB[] colors = getTextColors();
ForegroundBackgroundColorDlg dialog = new ForegroundBackgroundColorDlg(
Display.getCurrent().getActiveShell(),
colorConfigManager.getDescription(key), colors[0], colors[1]);
UserColorInfo colors = getTextColors();
ForegroundColorDlg dialog;
Shell shell = Display.getCurrent().getActiveShell();
String desc = colorManager.getDescription(user);
if (foregroundOnly) {
dialog = new ForegroundColorDlg(shell, desc, colors.getForeground());
} else {
dialog = new ForegroundBackgroundColorDlg(shell, desc,
colors.getForeground(), colors.getBackground());
}
dialog.setCloseCallback(new ICloseCallback() {
@ -150,13 +150,13 @@ public class ChangeTextColorAction extends Action {
return;
}
if (returnValue instanceof RGB[]) {
RGB[] colors = (RGB[]) returnValue;
colorConfigManager.setColors(key, colors[0], colors[1]);
CollaborationConnection connection = CollaborationConnection
.getConnection();
connection.postEvent(new ChangeIconEvent(key, colors[0],
colors[1]));
if (returnValue instanceof UserColorInfo) {
UserColorInfo colors = (UserColorInfo) returnValue;
colorManager.setColorForUser(user, colors);
setIconColors(colors);
if (actionCallback != null) {
actionCallback.newColor(user, colors);
}
}
}
});
@ -164,36 +164,24 @@ public class ChangeTextColorAction extends Action {
}
/**
* Get the stored colors (or default colors) of this action's user/site
* Get the stored colors (or default colors) of this action's user
*
* @return RGB array of length 2 with foreground color in index 0 and
* background color in index 1
* @return color selected by color manager or default color if none found
*/
private RGB[] getTextColors() {
ColorInfo colorInfo = colorConfigManager.getColor(key);
RGB foreground;
RGB background;
if (colorInfo != null) {
foreground = colorInfo.getColor(SWT.FOREGROUND);
background = colorInfo.getColor(SWT.BACKGROUND);
} else {
foreground = defaultForeground;
background = new RGB(255, 255, 255);
}
return new RGB[] { foreground, background };
private UserColorInfo getTextColors() {
return colorManager.getColorForUser(user);
}
@Subscribe
public void changeIcon(ChangeIconEvent event) {
if (event.key.equals(this.key)) {
setIconColors(event.foreground, event.background);
}
}
private void setIconColors(RGB foreground, RGB background) {
/**
* Change colors in menu icon which represents the user's text color
* settings
*
* @param colors
*/
private void setIconColors(UserColorInfo colors) {
Device device = Display.getCurrent();
Color fg = new Color(device, foreground);
Color bg = new Color(device, background);
Color fg = new Color(device, colors.getForeground());
Color bg = new Color(device, colors.getBackground());
Image oldIcon = icon;
icon = new Image(device, 15, 15);
@ -215,31 +203,18 @@ public class ChangeTextColorAction extends Action {
}
}
private class ChangeIconEvent {
private String key;
private RGB foreground;
private RGB background;
private ChangeIconEvent(String key, RGB foreground, RGB background) {
this.key = key;
this.foreground = foreground;
this.background = background;
}
}
public void dispose() {
CollaborationConnection connection = CollaborationConnection
.getConnection();
if (connection != null) {
connection.unregisterEventHandler(this);
}
if (icon != null) {
icon.dispose();
}
}
}
/**
* @param actionCallback
* the actionCallback to set
*/
public void setActionCallback(ChangeTextColorCallback actionCallback) {
this.actionCallback = actionCallback;
}
}

View file

@ -1,101 +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.colors;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.viz.collaboration.ui.colors.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 PersistentColorConfigManager},
* renamed from SiteColorConfigManager.
* Dec 08, 2014 3709 mapeters Set foreground and background colors together.
* Jan 09, 2015 3709 bclement made into a true singleton, moved colorInfoMap to super
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class FeedColorConfigManager extends PersistentColorConfigManager {
private static final String FILE_PATH = CONFIG_DIR_NAME
+ IPathManager.SEPARATOR + "siteColorInfo.xml";
private static FeedColorConfigManager instance;
public static synchronized FeedColorConfigManager getInstance() {
if (instance == null) {
instance = new FeedColorConfigManager();
}
return instance;
}
protected FeedColorConfigManager() {
}
/**
* Set and store the given colors for the given site.
*
* @param site
* @param foreground
* @param background
*/
@Override
public synchronized void setColors(String site, RGB foreground,
RGB background) {
super.setColors(site, foreground, background, 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);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager#
* getDescription()
*/
@Override
public String getDescription(String key) {
return "Color changes will apply to all users from site " + key
+ " in the feed room.";
}
}

View file

@ -33,6 +33,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
/**
* A dialog that displays a label with settable foreground and background colors
* using a color control.
@ -43,8 +45,9 @@ import org.eclipse.swt.widgets.Shell;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 04, 2014 3709 lvenable Initial creation
* Dec 04, 2014 3709 lvenable Initial creation
* Jan 09, 2015 3709 bclement moved primary logic to new super class
* Jan 13, 2015 3709 bclement return UserColorInfo instead of RGB[]
*
* </pre>
*
@ -156,9 +159,9 @@ public class ForegroundBackgroundColorDlg extends ForegroundColorDlg {
@Override
protected void collectReturnValue() {
RGB[] rgbArray = new RGB[] { foregroundClr.getRGB(),
backgroundClr.getRGB() };
setReturnValue(rgbArray);
UserColorInfo colors = new UserColorInfo(foregroundClr.getRGB(),
backgroundClr.getRGB());
setReturnValue(colors);
}
@Override

View file

@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.colordialog.ColorWheelComp;
import com.raytheon.viz.ui.dialogs.colordialog.IColorWheelChange;
@ -49,6 +50,7 @@ import com.raytheon.viz.ui.dialogs.colordialog.IColorWheelChange;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 09, 2015 3709 bclement Initial creation, logic from ForegroundBackgroundColorDlg
* Jan 13, 2015 3709 bclement return UserColorInfo instead of RGB
*
* </pre>
*
@ -225,7 +227,7 @@ public class ForegroundColorDlg extends CaveSWTDialog implements
* button.
*/
protected void collectReturnValue() {
setReturnValue(foregroundClr.getRGB());
setReturnValue(new UserColorInfo(foregroundClr.getRGB()));
}
/**

View file

@ -1,136 +0,0 @@
package com.raytheon.uf.viz.collaboration.ui.colors;
import java.util.HashMap;
import java.util.Map;
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.Activator;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
/**
* Abstract class for collaboration chat coloring configuration managers
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 13, 2014 3709 mapeters Initial creation.
* Dec 09, 2014 3709 mapeters setColors() sets foreground and background together.
* Jan 09, 2015 3709 bclement renamed from AbstractColorConfigManager
* moved colorInfoMap from subclasses to here
*
* </pre>
*
* @author mapeters
* @version 1.0
*/
public abstract class PersistentColorConfigManager implements
IColorConfigManager {
protected static final String CONFIG_DIR_NAME = "collaboration";
private static final SingleTypeJAXBManager<ColorInfoMap> jaxb = SingleTypeJAXBManager
.createWithoutException(ColorInfoMap.class);
private ColorInfoMap colorInfoMap;
/**
* Set and store the given foreground and background colors for the given
* user/site at the given file location.
*
* @param key
* @param foreground
* @param background
* @param filePath
*/
protected void setColors(String key, RGB foreground, RGB background,
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 = new ColorInfo();
colors.put(key, colorInfo);
}
colorInfo.setColors(foreground, background);
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;
}
protected ColorInfoMap getColorInfoMap() {
return colorInfoMap;
}
protected void setColorInfoMap(ColorInfoMap colorInfo) {
this.colorInfoMap = colorInfo;
}
}

View file

@ -0,0 +1,148 @@
package com.raytheon.uf.viz.collaboration.ui.colors;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
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.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.display.data.ColorInfoMap;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.ui.Activator;
/**
* Abstract class for persisting user color configuration to localization
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 13, 2014 3709 mapeters Initial creation.
* Dec 09, 2014 3709 mapeters setColors() sets foreground and background together.
* Jan 09, 2015 3709 bclement renamed from AbstractColorConfigManager
* moved colorInfoMap from subclasses to here
* Jan 13, 2015 3709 bclement renamed to PersistentColorConfigStorage, now a utility
*
* </pre>
*
* @author mapeters
* @version 1.0
*/
public abstract class PersistentColorConfigStorage<T extends IUser> {
protected static final String CONFIG_DIR_NAME = "collaboration";
private static final SingleTypeJAXBManager<ColorInfoMap> jaxb = SingleTypeJAXBManager
.createWithoutException(ColorInfoMap.class);
/**
* Persist color mapping configuration to localization file
*
* @param colorInfoMap
* @param filePath
*/
public void persistColors(Map<T, UserColorInfo> map, String filePath) {
IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext lContext = pathMgr.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
LocalizationFile file = pathMgr.getLocalizationFile(lContext, filePath);
try {
jaxb.marshalToXmlFile(createStorageMap(map), file.getFile()
.getPath());
file.save();
} catch (Exception e) {
Activator.statusHandler.error(
"Unable to write color information to file: "
+ file.getName() + " in context " + lContext, e);
}
}
/**
* Convert runtime map to a map that can be serialized to storage
*
* @param colorInfoMap
* @return
*/
protected ColorInfoMap createStorageMap(Map<T, UserColorInfo> colorInfoMap) {
Map<String, UserColorInfo> rval = new HashMap<>(colorInfoMap.size());
for (Entry<T, UserColorInfo> entry : colorInfoMap.entrySet()) {
rval.put(convert(entry.getKey()), entry.getValue());
}
return new ColorInfoMap(rval);
}
/**
* Convert map from storage to runtime map
*
* @param persisted
* @return
*/
public Map<T, UserColorInfo> unpackStorageMap(
Map<String, UserColorInfo> persisted) {
Map<T, UserColorInfo> rval = new HashMap<>(persisted.size());
for (Entry<String, UserColorInfo> entry : persisted.entrySet()) {
rval.put(convert(entry.getKey()), entry.getValue());
}
return rval;
}
/**
* Convert user object to string key for storage
*
* @param user
* @return
*/
protected String convert(T user) {
return user.getClientIndependentId();
}
/**
* Convert persisted key to user object
*
* @param persisted
* @return
*/
protected abstract T convert(String persisted);
/**
* Get the color mapping configuration from localization
*
* @param filePath
* @return empty map if file does not exists in localization
*/
public Map<T, UserColorInfo> getColors(String filePath) {
IPathManager pm = (PathManager) PathManagerFactory.getPathManager();
LocalizationContext locContext = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
LocalizationFile file = pm.getLocalizationFile(locContext, filePath);
Map<String, UserColorInfo> rval = null;
if (file != null && file.exists()) {
try {
ColorInfoMap map = jaxb.unmarshalFromXmlFile(file.getFile());
if (map != null) {
rval = map.getColors();
}
} catch (SerializationException e) {
Activator.statusHandler.error(
"Unable to read color information from file: "
+ file.getName() + " in level "
+ LocalizationLevel.USER, e);
}
}
if (rval == null) {
rval = new HashMap<>();
}
return unpackStorageMap(rval);
}
}

View file

@ -19,17 +19,16 @@
**/
package com.raytheon.uf.viz.collaboration.ui.colors;
import org.eclipse.swt.graphics.RGB;
import java.util.Map;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueId;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
/**
* Keeps track of custom user color configurations for users in a particular
* chat room
* Session color manager that persists colors to localization
*
* <pre>
*
@ -37,20 +36,24 @@ import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 08, 2015 3709 bclement Initial creation
* Jan 13, 2015 3709 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class RoomSpecificColorConfigManager extends
PersistentColorConfigManager {
public class PersistentSessionColorManager extends SessionColorManager {
private static final String ROOM_CONFIG_DIR = CONFIG_DIR_NAME
private static final String ROOM_CONFIG_DIR = PersistentColorConfigStorage.CONFIG_DIR_NAME
+ IPathManager.SEPARATOR + "roomColors";
private final String roomId;
private final PersistentColorConfigStorage<VenueParticipant> storage = new PersistentColorConfigStorage<VenueParticipant>() {
@Override
protected VenueParticipant convert(String persisted) {
return IDConverter.convertFromRoom(persisted);
}
};
private final String configFilePath;
@ -58,62 +61,46 @@ public class RoomSpecificColorConfigManager extends
* @param roomId
* @return
*/
public static RoomSpecificColorConfigManager getManagerForRoom(String roomId) {
public static PersistentSessionColorManager getManagerForRoom(String roomId) {
/*
* if multiple managers are created for the same room, it could cause
* concurrency issues with writing to localization. This could be solved
* with a soft reference cache here. However, since there *should* only
* be one of these per room id, it might be overkill
*/
return new RoomSpecificColorConfigManager(roomId);
return new PersistentSessionColorManager(roomId);
}
/**
* @param roomId
*/
protected RoomSpecificColorConfigManager(String roomId) {
this.roomId = roomId;
protected PersistentSessionColorManager(String roomId) {
this.configFilePath = ROOM_CONFIG_DIR + IPathManager.SEPARATOR + roomId;
Map<VenueParticipant, UserColorInfo> persistedColors = storage
.getColors(configFilePath);
colors.putAll(persistedColors);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.AbstractColorConfigManager#setColors
* (java.lang.String, org.eclipse.swt.graphics.RGB,
* org.eclipse.swt.graphics.RGB)
*/
@Override
public synchronized void setColors(String participant, RGB foreground,
RGB background) {
super.setColors(participant, foreground, background, configFilePath);
public String getDescription(VenueParticipant participant) {
return "Color changes will apply to the user " + participant.getName()
+ " only in the " + participant.getRoom() + " room.";
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.AbstractColorConfigManager#getColor
* (java.lang.String)
*/
@Override
public synchronized ColorInfo getColor(String participant) {
return super.getColor(participant, configFilePath);
protected void setColorInternal(VenueParticipant user, UserColorInfo color) {
synchronized (storage) {
super.setColorInternal(user, color);
storage.persistColors(colors, configFilePath);
}
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager#
* getDescription()
*/
@Override
public String getDescription(String key) {
VenueParticipant id = IDConverter.convertFromRoom(null, key);
VenueId venue = VenueId.fromString(roomId);
return "Color changes will apply to the user " + id.getName()
+ " only in the " + venue.getName() + " room.";
public void clearColors() {
synchronized (storage) {
super.clearColors();
storage.persistColors(colors, configFilePath);
}
}
}

View file

@ -1,103 +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.colors;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueId;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
/**
* Non-persistent color configuration manager
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 08, 2015 3709 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class TemporaryColorConfigManager implements IColorConfigManager {
private final Map<String, ColorInfo> map = new HashMap<String, ColorInfoMap.ColorInfo>();
private final String roomId;
/**
*
*/
public TemporaryColorConfigManager(String roomId) {
this.roomId = roomId;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager#setColors
* (java.lang.String, org.eclipse.swt.graphics.RGB,
* org.eclipse.swt.graphics.RGB)
*/
@Override
public void setColors(String key, RGB foreground, RGB background) {
ColorInfo info = new ColorInfo();
info.setColors(foreground, background);
map.put(key, info);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager#getColor
* (java.lang.String)
*/
@Override
public ColorInfo getColor(String key) {
return map.get(key);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager#
* getDescription()
*/
@Override
public String getDescription(String key) {
VenueParticipant id = IDConverter.convertFromRoom(null, key);
VenueId venue = VenueId.fromString(roomId);
return "Color changes will apply to the user " + id.getName()
+ " only in the " + venue.getName() + " room. "
+ "\nColor changes will be discarded when you leave the room.";
}
}

View file

@ -19,12 +19,16 @@
**/
package com.raytheon.uf.viz.collaboration.ui.colors;
import java.util.Map;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.comm.provider.connection.CollaborationConnection;
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.display.data.IColorManager;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
/**
* Custom user coloring configuration manager for use where the user's true
@ -37,20 +41,29 @@ import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 13, 2014 3709 mapeters Initial creation.
* Nov 26, 2014 3709 mapeters Abstracted out code to {@link PersistentColorConfigManager}.
* Nov 26, 2014 3709 mapeters Abstracted out code to {@link PersistentColorConfigStorage}.
* Dec 08, 2014 3709 mapeters Set foreground and background colors together.
* Jan 09, 2015 3709 bclement made into a true singleton, moved colorInfoMap to super
* Jan 13, 2015 3709 bclement refactored to use PersistentColorConfigStorage utility
*
* </pre>
*
* @author mapeters
* @version 1.0
*/
public class UserColorConfigManager extends PersistentColorConfigManager {
public class UserColorConfigManager implements IColorManager<IUser> {
private static final String FILE_PATH = CONFIG_DIR_NAME
private static final String FILE_PATH = PersistentColorConfigStorage.CONFIG_DIR_NAME
+ IPathManager.SEPARATOR + "userColorInfo.xml";
/* dark blue */
private static final UserColorInfo DEFAULT_USER_COLORS = new UserColorInfo(
new RGB(0, 0, 191));
/* red */
private static final UserColorInfo DEFAULT_PEER_COLORS = new UserColorInfo(
new RGB(255, 0, 0));
private static UserColorConfigManager instance;
public static synchronized UserColorConfigManager getInstance() {
@ -60,44 +73,70 @@ public class UserColorConfigManager extends PersistentColorConfigManager {
return instance;
}
private final PersistentColorConfigStorage<IUser> storage = new PersistentColorConfigStorage<IUser>() {
@Override
protected IUser convert(String persisted) {
return IDConverter.convertFrom(persisted);
}
};
private Map<IUser, UserColorInfo> _colors;
protected UserColorConfigManager() {
}
/**
* Set and store the given colors for the given user.
*
* @param user
* @param foreground
* @param background
*/
@Override
public synchronized void setColors(String user, RGB foreground,
RGB background) {
super.setColors(user, foreground, background, FILE_PATH);
public String getDescription(IUser user) {
return "Color changes will apply to one-on-one chat sessions with user "
+ user.getName() + ".";
}
@Override
public UserColorInfo getColorForUser(IUser user) {
Map<IUser, UserColorInfo> colorMap = getColorMap();
UserColorInfo rval = colorMap.get(user);
if (rval == null) {
CollaborationConnection conn = CollaborationConnection
.getConnection();
if (conn.getUser().isSameUser(user)) {
rval = DEFAULT_USER_COLORS;
} else {
rval = DEFAULT_PEER_COLORS;
}
}
return rval;
}
/**
* Get the {@link ColorInfo} for the given user from memory.
* Get color mappings, goes to storage if not initialized
*
* @param user
* @return
*/
@Override
public synchronized ColorInfo getColor(String user) {
return super.getColor(user, FILE_PATH);
private Map<IUser, UserColorInfo> getColorMap() {
synchronized (storage) {
if (_colors == null) {
_colors = storage.getColors(FILE_PATH);
}
}
return _colors;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager#
* getDescription()
*/
@Override
public String getDescription(String key) {
UserId id = IDConverter.convertFrom(key);
return "Color changes will apply to one-on-one chat sessions with user "
+ id.getName() + ".";
public void setColorForUser(IUser user, UserColorInfo color) {
synchronized (storage) {
Map<IUser, UserColorInfo> colorMap = getColorMap();
colorMap.put(user, color);
storage.persistColors(colorMap, FILE_PATH);
}
}
@Override
public void clearColors() {
synchronized (storage) {
Map<IUser, UserColorInfo> colorMap = getColorMap();
colorMap.clear();
storage.persistColors(colorMap, FILE_PATH);
}
}
}

View file

@ -99,6 +99,7 @@ import com.raytheon.viz.ui.views.CaveFloatingView;
* implemented here, added messagesTextMenuMgr.
* Nov 26, 2014 3709 mapeters Added {@link #getColorFromRGB()}.
* Dec 08, 2014 3709 mapeters Removed messagesTextMenuMgr.
* Jan 13, 2015 3709 bclement styleAndAppendText() takes foreground and background
* </pre>
*
* @author rferrel
@ -366,8 +367,8 @@ public abstract class AbstractSessionView<T extends IUser> extends
sb.append("(").append(time).append(") ");
int offset = sb.length();
boolean newLine = Activator.getDefault()
.getPreferenceStore().getBoolean("chatLines");
boolean newLine = Activator.getDefault().getPreferenceStore()
.getBoolean("chatLines");
String displayPreference = newLine ? ("\n ") : (": ");
sb.append(name).append(displayPreference).append(body);
@ -470,7 +471,8 @@ public abstract class AbstractSessionView<T extends IUser> extends
String name, T userId, String subject, List<StyleRange> ranges);
protected abstract void styleAndAppendText(StringBuilder sb, int offset,
String name, T userId, List<StyleRange> ranges, Color color);
String name, T userId, List<StyleRange> ranges, Color foreground,
Color background);
/**
* Find keys words in body of message starting at offset.
@ -586,7 +588,7 @@ public abstract class AbstractSessionView<T extends IUser> extends
oldFont.dispose();
}
}
public void setAlertWords(List<AlertWord> words) {
alertWords = words;
}
@ -636,14 +638,17 @@ public abstract class AbstractSessionView<T extends IUser> extends
builder.insert(0, "\n");
}
Color color = Display.getCurrent().getSystemColor(swtColor);
Color foreground = Display.getCurrent().getSystemColor(
swtColor);
Color background = Display.getCurrent().getSystemColor(
SWT.COLOR_WHITE);
StyleRange range = new StyleRange(messagesText
.getCharCount(), builder.length(), color, null,
SWT.BOLD);
.getCharCount(), builder.length(), foreground,
null, SWT.BOLD);
List<StyleRange> ranges = new ArrayList<StyleRange>();
ranges.add(range);
styleAndAppendText(builder, 0, builder.toString(), null,
ranges, color);
ranges, foreground, background);
}
// Archive the message

View file

@ -33,10 +33,8 @@ import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IPartListener;
@ -53,6 +51,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession;
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
import com.raytheon.uf.viz.collaboration.comm.identity.invite.ColorPopulator;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.comm.identity.user.SharedDisplayRole;
import com.raytheon.uf.viz.collaboration.comm.provider.event.LeaderChangeEvent;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
@ -64,6 +63,7 @@ import com.raytheon.uf.viz.collaboration.display.data.ColorChangeEvent;
import com.raytheon.uf.viz.collaboration.display.data.SessionContainer;
import com.raytheon.uf.viz.collaboration.display.data.SessionContainer.IDisplayContainerChangedListener;
import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.display.rsc.SelfAddingSystemResourceListener;
import com.raytheon.uf.viz.collaboration.display.rsc.telestrator.CollaborationDrawingEvent;
import com.raytheon.uf.viz.collaboration.display.rsc.telestrator.CollaborationDrawingEvent.CollaborationEventType;
@ -72,7 +72,8 @@ import com.raytheon.uf.viz.collaboration.display.rsc.telestrator.CollaborationDr
import com.raytheon.uf.viz.collaboration.display.rsc.telestrator.CollaborationDrawingToolLayer;
import com.raytheon.uf.viz.collaboration.display.rsc.telestrator.CollaborationDrawingUIManager;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.colors.ForegroundColorDlg;
import com.raytheon.uf.viz.collaboration.ui.actions.ChangeTextColorAction;
import com.raytheon.uf.viz.collaboration.ui.actions.ChangeTextColorAction.ChangeTextColorCallback;
import com.raytheon.uf.viz.core.ContextManager;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
@ -82,7 +83,6 @@ import com.raytheon.uf.viz.core.rsc.IResourceDataChanged;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.drawing.DrawingToolLayer;
import com.raytheon.uf.viz.drawing.DrawingToolLayer.DrawMode;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.input.EditableManager;
/**
@ -109,6 +109,7 @@ import com.raytheon.viz.ui.input.EditableManager;
* Jun 30, 2014 1798 bclement added disableCurrentLayer()
* Dev 02, 2014 3709 mapeters added {@link #initComponents()} override
* Jan 09, 2015 3709 bclement now uses ForegroundColorDlg for consistency
* Jan 13, 2015 3709 bclement now uses ChangeTextColorAction for consistency
*
* </pre>
*
@ -132,8 +133,6 @@ public class CollaborationSessionView extends SessionView implements
}
};
private Action colorChangeAction;
private Action leaderChangeAction;
private ActionContributionItem drawAction;
@ -237,58 +236,10 @@ public class CollaborationSessionView extends SessionView implements
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.session.SessionView#initComponents
* (org.eclipse.swt.widgets.Composite)
*/
@Override
protected void initComponents(Composite parent) {
enableUserColors = false;
super.initComponents(parent);
}
/**
* Callback used in the change color action. Gets the new color from the
* dialog and sends a color change event to the session
*/
private final ICloseCallback colorChangeCallback = new ICloseCallback() {
public void dialogClosed(Object returnValue) {
if (returnValue != null && returnValue instanceof RGB) {
RGB rgb = (RGB) returnValue;
IStructuredSelection selection = (IStructuredSelection) usersTable
.getSelection();
VenueParticipant entry = (VenueParticipant) selection
.getFirstElement();
ColorChangeEvent event = new ColorChangeEvent(entry, rgb);
try {
session.sendObjectToVenue(event);
} catch (CollaborationException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to send color change to venue", e);
}
}
}
};
@Override
protected void createActions() {
super.createActions();
Bundle bundle = Activator.getDefault().getBundle();
colorChangeAction = new Action("Change Color...",
IconUtil.getImageDescriptor(bundle, "change_color.gif")) {
@Override
public void run() {
ForegroundColorDlg dlg = new ForegroundColorDlg(Display
.getCurrent().getActiveShell(),
"Color changes will be seen by all participants of the "
+ session.getVenueName() + " session.");
dlg.setCloseCallback(colorChangeCallback);
dlg.open();
}
};
leaderChangeAction = new Action("Transfer Leadership",
IconUtil.getImageDescriptor(bundle, "leader_transfer.gif")) {
@ -623,7 +574,7 @@ public class CollaborationSessionView extends SessionView implements
|| session.hasRole(SharedDisplayRole.SESSION_LEADER)) {
if (session.hasRole(SharedDisplayRole.SESSION_LEADER)) {
manager.add(new Separator());
manager.add(colorChangeAction);
IStructuredSelection selection = (IStructuredSelection) usersTable
.getSelection();
VenueParticipant entry = (VenueParticipant) selection
@ -636,6 +587,55 @@ public class CollaborationSessionView extends SessionView implements
}
}
/**
* Callback used in the change color action. Gets the new color from the
* dialog and sends a color change event to the session
*/
private final ChangeTextColorCallback sendColorEventCallback = new ChangeTextColorCallback() {
@Override
public void newColor(IUser user, UserColorInfo colors) {
IStructuredSelection selection = (IStructuredSelection) usersTable
.getSelection();
VenueParticipant entry = (VenueParticipant) selection
.getFirstElement();
ColorChangeEvent event = new ColorChangeEvent(entry,
colors.getForeground());
try {
session.sendObjectToVenue(event);
} catch (CollaborationException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to send color change to venue", e);
}
}
};
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.session.SessionView#addColorAction
* (org.eclipse.jface.action.IMenuManager,
* com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant,
* boolean)
*/
@Override
protected void addColorAction(IMenuManager manager, VenueParticipant user,
boolean me) {
if (session.hasRole(SharedDisplayRole.SESSION_LEADER)) {
String colorActionKey = user.getFQName();
ChangeTextColorAction<VenueParticipant> userColorAction = userColorActions
.get(colorActionKey);
if (userColorAction == null) {
userColorAction = new ChangeTextColorAction<VenueParticipant>(
user, me, me, true, colorManager);
userColorAction.setActionCallback(sendColorEventCallback);
userColorActions.put(colorActionKey, userColorAction);
}
manager.add(userColorAction);
}
}
@Subscribe
public void modifyColors(ColorPopulator populator) {
VizApp.runAsync(new Runnable() {

View file

@ -38,6 +38,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.SharedDisplaySess
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.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.ui.AbstractUserLabelProvider;
import com.raytheon.uf.viz.collaboration.ui.SiteConfigurationManager;
@ -58,6 +59,7 @@ import com.raytheon.uf.viz.collaboration.ui.SiteConfigurationManager;
* Feb 13, 2014 2751 njensen Added leader icons
* Feb 18, 2014 2751 bclement changed tooltip from JID to UserId
* Oct 10, 2014 3708 bclement SiteConfigurationManager changes, added actingSite
* Jan 13, 2015 3709 bclement added support for foreground and background colors
*
* </pre>
*
@ -71,10 +73,13 @@ public class ParticipantsLabelProvider extends
protected String sessionId = null;
private String actingSite;
private static final RGB DEFAULT_FOREGROUND = new RGB(0,0,0);
private static final RGB DEFAULT_BACKGROUND = new RGB(255,255,255);
protected Map<RGB, Color> colors = new HashMap<RGB, Color>();
private SessionColorManager manager;
private SessionColorManager sessionColorManager;
private Font boldFont;
@ -160,9 +165,34 @@ public class ParticipantsLabelProvider extends
return null;
}
VenueParticipant user = ((VenueParticipant) element);
RGB rgb = manager.getColorForUser(user);
UserColorInfo colors = sessionColorManager.getColorForUser(user);
RGB rgb = colors.getForeground();
return getTextColor(rgb, DEFAULT_FOREGROUND);
}
@Override
public Color getBackground(Object element) {
if (!(element instanceof VenueParticipant)) {
return null;
}
VenueParticipant user = ((VenueParticipant) element);
UserColorInfo colors = sessionColorManager.getColorForUser(user);
RGB rgb = colors.getBackground();
return getTextColor(rgb, DEFAULT_BACKGROUND);
}
/**
* Gets text coloring for participant.
*
* @param rgb
* @param defaultColor
* @return default if rgb is null
*/
private Color getTextColor(RGB rgb, RGB defaultColor) {
if (rgb == null) {
rgb = new RGB(0, 0, 0);
rgb = defaultColor;
}
Color color = colors.get(rgb);
if (color == null) {
@ -252,8 +282,8 @@ public class ParticipantsLabelProvider extends
* @param manager
* the manager to set
*/
public void setManager(SessionColorManager manager) {
this.manager = manager;
public void setSessionColorManager(SessionColorManager manager) {
this.sessionColorManager = manager;
}
@Override

View file

@ -32,7 +32,6 @@ import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.jivesoftware.smack.packet.Presence.Type;
@ -49,9 +48,9 @@ import com.raytheon.uf.viz.collaboration.comm.provider.connection.CollaborationC
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.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.ui.actions.ChangeTextColorAction;
import com.raytheon.uf.viz.collaboration.ui.actions.PrintLogActionContributionItem;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.ui.colors.UserColorConfigManager;
import com.raytheon.uf.viz.collaboration.ui.notifier.NotifierTask;
import com.raytheon.uf.viz.collaboration.ui.notifier.NotifierTools;
@ -78,6 +77,7 @@ import com.raytheon.uf.viz.core.sounds.SoundUtil;
* Dec 12, 2014 3709 mapeters Store {@link ChangeTextColorAction}s as fields,
* dispose them.
* Jan 09, 2015 3709 bclement color config manager API changes
* Jan 13, 2015 3709 bclement ChangeTextColorAction API changes
*
* </pre>
*
@ -93,24 +93,21 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
public static final String ID = "com.raytheon.uf.viz.collaboration.PeerToPeerView";
private static final Color DEFAULT_USER_FOREGROUND_COLOR = Display
.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE);
private static final Color DEFAULT_PEER_FOREGROUND_COLOR = Display
.getCurrent().getSystemColor(SWT.COLOR_RED);
private static final Color BLACK = Display.getCurrent().getSystemColor(
SWT.COLOR_BLACK);
private static final Color WHITE = Display.getCurrent().getSystemColor(
SWT.COLOR_WHITE);
private IUser peer;
private boolean online = true;
private static UserColorConfigManager colorConfigManager;
private static UserColorConfigManager colorManager;
private ChangeTextColorAction userColorAction;
private ChangeTextColorAction<IUser> userColorAction;
private ChangeTextColorAction peerColorAction;
private ChangeTextColorAction<IUser> peerColorAction;
public PeerToPeerView() {
super();
@ -222,48 +219,40 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
if (connection == null) {
return;
}
Color color = null;
Color foreground;
Color background;
if (userId == null) {
color = BLACK;
} else if (!userId.equals(connection.getUser())) {
color = DEFAULT_PEER_FOREGROUND_COLOR;
foreground = BLACK;
background = WHITE;
} else {
color = DEFAULT_USER_FOREGROUND_COLOR;
UserColorInfo colors = colorManager.getColorForUser(userId);
foreground = getColorFromRGB(colors.getForeground());
background = getColorFromRGB(colors.getBackground());
}
styleAndAppendText(sb, offset, name, userId, ranges, color);
styleAndAppendText(sb, offset, name, userId, ranges, foreground,
background);
};
@Override
public void styleAndAppendText(StringBuilder sb, int offset, String name,
IUser userId, List<StyleRange> ranges, Color color) {
Color fgColor = color;
Color bgColor = null;
if (userId != null) {
// get user colors from config manager
ColorInfo userColor = colorConfigManager.getColor(userId
.getFQName());
if (userColor != null) {
fgColor = getColorFromRGB(userColor.getColor(SWT.FOREGROUND));
bgColor = getColorFromRGB(userColor.getColor(SWT.BACKGROUND));
}
}
IUser userId, List<StyleRange> ranges, Color foreground,
Color background) {
StyleRange range = new StyleRange(messagesText.getCharCount(),
sb.length(), fgColor, null, SWT.NORMAL);
sb.length(), foreground, null, SWT.NORMAL);
ranges.add(range);
range = new StyleRange(messagesText.getCharCount() + offset,
(userId != null ? name.length() + 1 : sb.length() - offset),
fgColor, null, SWT.BOLD);
foreground, null, SWT.BOLD);
ranges.add(range);
messagesText.append(sb.toString());
for (StyleRange newRange : ranges) {
messagesText.setStyleRange(newRange);
}
int lineNumber = messagesText.getLineCount() - 1;
messagesText.setLineBackground(lineNumber, 1, bgColor);
messagesText.setLineBackground(lineNumber, 1, background);
messagesText.setTopIndex(lineNumber);
}
@ -330,7 +319,7 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
@Override
protected void initComponents(Composite parent) {
super.initComponents(parent);
colorConfigManager = UserColorConfigManager.getInstance();
colorManager = UserColorConfigManager.getInstance();
// unfortunately this code cannot be a part of createToolbarButton
// because I cannot instantiate the ACI until after the messagesText
@ -400,10 +389,8 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
private void createDropDownMenu() {
IMenuManager mgr = getViewSite().getActionBars().getMenuManager();
UserId myUser = CollaborationConnection.getConnection().getUser();
RGB defaultUserForeground = DEFAULT_USER_FOREGROUND_COLOR.getRGB();
userColorAction = ChangeTextColorAction
.createChangeUserTextColorAction(myUser, true, true,
defaultUserForeground, colorConfigManager);
userColorAction = new ChangeTextColorAction<IUser>(myUser, true, true,
false, colorManager);
mgr.add(userColorAction);
}
@ -412,10 +399,8 @@ public class PeerToPeerView extends AbstractSessionView<IUser> implements
*/
public void addChangePeerColorAction() {
IMenuManager mgr = getViewSite().getActionBars().getMenuManager();
RGB defaultPeerForeground = DEFAULT_PEER_FOREGROUND_COLOR.getRGB();
peerColorAction = ChangeTextColorAction
.createChangeUserTextColorAction(peer, false, true,
defaultPeerForeground, colorConfigManager);
peerColorAction = new ChangeTextColorAction<IUser>(peer, false, true,
false, colorManager);
mgr.add(peerColorAction);
}
}

View file

@ -19,9 +19,6 @@
**/
package com.raytheon.uf.viz.collaboration.ui.session;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jface.action.Action;
@ -31,9 +28,6 @@ import org.eclipse.jface.util.IPropertyChangeListener;
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.Composite;
import org.jivesoftware.smack.packet.Presence;
@ -45,8 +39,6 @@ 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.SiteConfigurationManager;
import com.raytheon.uf.viz.collaboration.ui.actions.ChangeTextColorAction;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.ui.colors.FeedColorConfigManager;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
/**
@ -80,6 +72,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
* Dec 12, 2014 3709 mapeters Store {@link ChangeTextColorAction}s in map, dispose them.
* Jan 05, 2015 3709 mapeters Use both site and user name as key in siteColorActions map.
* Jan 09, 2015 3709 bclement color config manager API changes
* Jan 12, 2015 3709 bclement use parent object's session color manager, colors now based on user, not site
*
* </pre>
*
@ -97,8 +90,6 @@ public class SessionFeedView extends SessionView {
private Action userRemoveSiteAction;
private static FeedColorConfigManager colorConfigManager;
private String actingSite;
/**
@ -108,16 +99,13 @@ public class SessionFeedView extends SessionView {
private volatile boolean initialized = false;
private Map<String, ChangeTextColorAction> siteColorActions;
/**
*
*/
public SessionFeedView() {
super();
actingSite = CollaborationConnection.getConnection()
.getPresence().getProperty(SiteConfigInformation.SITE_NAME)
.toString();
actingSite = CollaborationConnection.getConnection().getPresence()
.getProperty(SiteConfigInformation.SITE_NAME).toString();
}
/*
@ -129,13 +117,8 @@ public class SessionFeedView extends SessionView {
*/
@Override
protected void initComponents(Composite parent) {
enableUserColors = false;
super.initComponents(parent);
colorConfigManager = FeedColorConfigManager.getInstance();
usersTable.refresh();
siteColorActions = new HashMap<>();
}
@Subscribe
@ -208,17 +191,6 @@ public class SessionFeedView extends SessionView {
protected void fillContextMenu(IMenuManager manager) {
super.fillContextMenu(manager);
String site = getSelectedSite();
VenueParticipant user = getSelectedParticipant();
String mapKey = site + " " + user.getName();
RGB defaultForeground = colorManager.getColorForUser(user);
ChangeTextColorAction siteColorAction = siteColorActions.get(mapKey);
if (siteColorAction == null) {
siteColorAction = ChangeTextColorAction
.createChangeSiteTextColorAction(site, defaultForeground,
colorConfigManager);
siteColorActions.put(mapKey, siteColorAction);
}
manager.add(siteColorAction);
if (!SiteConfigurationManager.isVisible(actingSite, site)) {
userAddSiteAction
.setText("Show Messages from " + getSelectedSite());
@ -272,50 +244,12 @@ public class SessionFeedView extends SessionView {
// should we append?
if (site == null
|| SiteConfigurationManager
.isVisible(actingSite, site.toString())) {
|| SiteConfigurationManager.isVisible(actingSite,
site.toString())) {
appendMessage(msg);
}
}
/**
* 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, List<StyleRange> ranges,
Color fgColor, Color bgColor, String subject) {
String site = null;
if (subject != null) {
site = subject;
} else if (userId != null) {
Presence presence = session.getVenue().getPresence(userId);
if (presence != null) {
site = String.valueOf(presence
.getProperty(SiteConfigInformation.SITE_NAME));
}
}
if (site != null) {
ColorInfo siteColor = colorConfigManager.getColor(site);
if (siteColor != null) {
fgColor = getColorFromRGB(siteColor.getColor(SWT.FOREGROUND));
bgColor = getColorFromRGB(siteColor.getColor(SWT.BACKGROUND));
}
}
super.styleAndAppendText(sb, offset, name, userId, ranges, fgColor,
bgColor, subject);
}
/**
* Get the selected user
*
@ -488,12 +422,4 @@ public class SessionFeedView extends SessionView {
}
}
@Override
public void dispose() {
for (ChangeTextColorAction siteColorAction : siteColorActions.values()) {
siteColorAction.dispose();
}
super.dispose();
}
}

View file

@ -53,7 +53,6 @@ import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@ -82,14 +81,13 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.VenueSession;
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.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.display.data.UserColorInfo;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.actions.ChangeTextColorAction;
import com.raytheon.uf.viz.collaboration.ui.actions.ChangeTextColorAction.ChangeTextColorCallback;
import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction;
import com.raytheon.uf.viz.collaboration.ui.actions.PrintLogActionContributionItem;
import com.raytheon.uf.viz.collaboration.ui.colors.ColorInfoMap.ColorInfo;
import com.raytheon.uf.viz.collaboration.ui.colors.IColorConfigManager;
import com.raytheon.uf.viz.collaboration.ui.colors.RoomSpecificColorConfigManager;
import com.raytheon.uf.viz.collaboration.ui.colors.TemporaryColorConfigManager;
import com.raytheon.uf.viz.collaboration.ui.colors.PersistentSessionColorManager;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.sounds.SoundUtil;
@ -125,6 +123,7 @@ import com.raytheon.uf.viz.core.sounds.SoundUtil;
* Dec 02, 2014 3709 mapeters added color actions for group chats without shared display.
* Dec 12, 2014 3709 mapeters Store {@link ChangeTextColorAction}s in map, dispose them.
* Jan 09, 2015 3709 bclement color config manager API changes
* Jan 12, 2015 3709 bclement unified color management into SessionColorManager
*
* </pre>
*
@ -158,11 +157,17 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
protected SessionColorManager colorManager;
private IColorConfigManager colorConfigManager;
protected Map<String, ChangeTextColorAction<VenueParticipant>> userColorActions = new HashMap<>();
private Map<String, ChangeTextColorAction> userColorActions;
protected boolean enableUserColors = true;
/*
* callback used to refresh participant list when the user adds/changes a
* custom color configuration for a participant
*/
protected final ChangeTextColorCallback refreshCallback = new ChangeTextColorCallback() {
public void newColor(IUser user, UserColorInfo colors) {
refreshParticipantList();
}
};
public SessionView() {
super();
@ -185,17 +190,6 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
protected void initComponents(Composite parent) {
initColorManager();
super.initComponents(parent);
if (enableUserColors) {
IVenue venue = session.getVenue();
if (venue.isPersistent()) {
colorConfigManager = RoomSpecificColorConfigManager
.getManagerForRoom(venue.getId());
} else {
colorConfigManager = new TemporaryColorConfigManager(
venue.getId());
}
userColorActions = new HashMap<>();
}
// unfortunately this code cannot be a part of createToolbarButton
// because I cannot instantiate the ACI until after the messagesText
@ -249,20 +243,22 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
if (!me) {
manager.add(new PeerToPeerChatAction(entry));
}
if (enableUserColors) {
// add color actions if in group chat room without shared display
String colorActionKey = entry.getFQName();
RGB defaultForeground = colorManager.getColorForUser(entry);
ChangeTextColorAction userColorAction = userColorActions
.get(colorActionKey);
if (userColorAction == null) {
userColorAction = ChangeTextColorAction
.createChangeUserTextColorAction(entry, me, me,
defaultForeground, colorConfigManager);
userColorActions.put(colorActionKey, userColorAction);
}
manager.add(userColorAction);
addColorAction(manager, entry, me);
}
protected void addColorAction(IMenuManager manager, VenueParticipant user,
boolean me) {
String colorActionKey = user.getFQName();
ChangeTextColorAction<VenueParticipant> userColorAction = userColorActions
.get(colorActionKey);
if (userColorAction == null) {
userColorAction = new ChangeTextColorAction<VenueParticipant>(user,
me, me, false, colorManager);
userColorAction.setActionCallback(refreshCallback);
userColorActions.put(colorActionKey, userColorAction);
}
manager.add(userColorAction);
}
@Subscribe
@ -281,7 +277,13 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
}
protected void initColorManager() {
colorManager = new SessionColorManager();
IVenue venue = session.getVenue();
if (venue.isPersistent()) {
colorManager = PersistentSessionColorManager
.getManagerForRoom(venue.getId());
} else {
colorManager = new SessionColorManager();
}
}
protected void createUsersComp(final Composite parent) {
@ -383,7 +385,7 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
usersTable.getTable().setLayout(layout);
usersTable.getTable().setLayoutData(data);
ParticipantsLabelProvider labelProvider = new ParticipantsLabelProvider();
ParticipantsLabelProvider labelProvider = createParticipantsLabelProvider();
setParticipantValues(labelProvider);
usersTable.setContentProvider(ArrayContentProvider.getInstance());
@ -434,9 +436,13 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
((GridData) usersComp.getLayoutData()).exclude = true;
}
protected ParticipantsLabelProvider createParticipantsLabelProvider() {
return new ParticipantsLabelProvider();
}
protected void setParticipantValues(ParticipantsLabelProvider labelProvider) {
labelProvider.setSessionId(sessionId);
labelProvider.setManager(colorManager);
labelProvider.setSessionColorManager(colorManager);
}
@Override
@ -447,12 +453,8 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
disposeArrow(downArrow);
disposeArrow(rightArrow);
if (colorManager != null) {
colorManager.clearColors();
}
if (userColorActions != null) {
for (ChangeTextColorAction userColorAction : userColorActions
for (ChangeTextColorAction<?> userColorAction : userColorActions
.values()) {
userColorAction.dispose();
}
@ -510,9 +512,10 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
protected void styleAndAppendText(StringBuilder sb, int offset,
String name, VenueParticipant userId, String subject,
List<StyleRange> ranges) {
RGB rgb = colorManager.getColorForUser(userId);
UserColorInfo colors = colorManager.getColorForUser(userId);
styleAndAppendText(sb, offset, name, userId, ranges,
getColorFromRGB(rgb), null, subject);
getColorFromRGB(colors.getForeground()),
getColorFromRGB(colors.getBackground()), subject);
}
/*
@ -526,22 +529,14 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
@Override
protected void styleAndAppendText(StringBuilder sb, int offset,
String name, VenueParticipant userId, List<StyleRange> ranges,
Color color) {
styleAndAppendText(sb, offset, name, userId, ranges, color, null, null);
Color foreground, Color background) {
styleAndAppendText(sb, offset, name, userId, ranges, foreground,
background, null);
}
protected void styleAndAppendText(StringBuilder sb, int offset,
String name, VenueParticipant userId, List<StyleRange> ranges,
Color fgColor, Color bgColor, String subject) {
if (enableUserColors && userId != null) {
// Color text by user if in group chat room without shared display
ColorInfo userColor = colorConfigManager.getColor(userId
.getFQName());
if (userColor != null) {
fgColor = getColorFromRGB(userColor.getColor(SWT.FOREGROUND));
bgColor = getColorFromRGB(userColor.getColor(SWT.BACKGROUND));
}
}
StyleRange range = new StyleRange(messagesText.getCharCount(),
sb.length(), fgColor, null, SWT.NORMAL);
ranges.add(range);