Skip to content
Snippets Groups Projects
Commit e311198b authored by helene ortiz's avatar helene ortiz
Browse files

Connected users functionnality in progress...

parent 466e53de
No related branches found
No related tags found
No related merge requests found
......@@ -328,6 +328,7 @@ closeChatMessage=Close chat
openChatMessage=Open chat
chatSendMessageLabel=Send a message
chatShellTitle=Online chat
usersShellTitle=Connected users
incomingChatMessage=You have a new message!
authorizedRemoteControlToolTip=Forbid remote control to Nomad
forbiddenRemoteControlToolTip=Allow remote control to Nomad
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.client.control.users;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.bridge.ControllerManager;
import fr.ill.ics.client.control.MainWindow;
import fr.ill.ics.client.view.users.ConnectedUsers;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.PropertyManager;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
import fr.ill.ics.util.exception.ControllerNotFoundException;
import fr.ill.ics.util.exception.PropertyNotFoundException;
/**
*
* @author ortizh
*
*/
public class ConnectedUsersManager {
private static ConnectedUsersManager instance = null;
private static final Logger LOGGER = Logger.getLogger(ConnectedUsersManager.class.getName());
private Controller controller;
private Property usersProperty;
private String usersControllerType = "connectedUsers";
private String usersPropertyName = "users";
private boolean configOK = false;
private ConnectedUsersManager() {
init();
}
public static ConnectedUsersManager getInstance() {
if (instance == null) {
instance = new ConnectedUsersManager();
}
return instance;
}
private void init() {
try {
Set<String> controllers = ControllerManager.getInstance().getControllersOfType(usersControllerType, true);
if (controllers != null && !controllers.isEmpty()) {
controller = ControllerManager.getInstance().getController((String)controllers.toArray()[0]);
if (controller != null) {
usersProperty = PropertyManager.getInstance().getProperty(controller, usersPropertyName, PluginType.GENERAL);
configOK = true;
} else {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "constructor", "Controller of type " + usersControllerType + " not found.");
}
} else {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "constructor", "Cannot find any controller of type " + usersControllerType);
}
} catch (PropertyNotFoundException e) {
MainWindow.getInstance().onPropertyNotFoundException(e);
} catch (ControllerNotFoundException e) {
MainWindow.getInstance().onControllerNotFoundException(e);
}
}
public void addListener(ConnectedUsers connectedUsers) {
if (configOK) {
usersProperty.addPropertyChangeListener(connectedUsers);
}
}
public void removeListener(ConnectedUsers connectedUsers) {
if (configOK) {
usersProperty.removePropertyChangeListener(connectedUsers);
}
}
public boolean configOK() {
return configOK;
}
public String getUsers() {
if (configOK) {
return usersProperty.getValue();
}
return null;
}
}
......@@ -62,6 +62,9 @@ public abstract class ColorFactory {
public static final int[] chatOwn = new int[] {176, 242, 182};
public static final int[] chatHeader = new int[] {64, 64, 64};
public static final int[] usersHeader = new int[] {128, 128, 128};
public static final int[] startupBackground = {0, 108, 151};
protected static ColorFactory instance = null;
......
......@@ -125,6 +125,8 @@ public class SWTColorFactory extends ColorFactory {
private static RGB chatHeaderRGB = createRGB(chatHeader[0], chatHeader[1], chatHeader[2]);
private static RGB chatOwnMessagesRGB = createRGB(chatOwn[0], chatOwn[1], chatOwn[2]);
private static RGB usersHeaderRGB = createRGB(usersHeader[0], usersHeader[1], usersHeader[2]);
private static RGB startupBackgroundRGB = createRGB(startupBackground[0], startupBackground[1], startupBackground[2]);
private SWTColorFactory() {
......@@ -509,6 +511,10 @@ public class SWTColorFactory extends ColorFactory {
return getColor(chatHeaderRGB);
}
public static Color getUsersHeaderColor() {
return getColor(usersHeaderRGB);
}
public static Color getStartupBackground() {
return getColor(startupBackgroundRGB);
}
......
......@@ -41,6 +41,7 @@ import fr.ill.ics.client.view.factory.swt.SWTImageFactory;
import fr.ill.ics.client.view.factory.swt.SWTWidgetFactory;
import fr.ill.ics.client.view.magnifier.Magnifier;
import fr.ill.ics.client.view.token.TokenWidget;
import fr.ill.ics.client.view.users.ConnectedUsers;
import fr.ill.ics.client.view.users.swt.SWTConnectedUsers;
import fr.ill.ics.client.view.util.swt.SWTImageUtils;
import fr.ill.ics.client.view.widget.swt.SWTAnimatedImage;
......@@ -175,7 +176,8 @@ public class SWTTokenWidget extends TokenWidget {
public void mouseDown(MouseEvent e) {
onUsersClick();
}
}); */
});
*/
}
......@@ -310,7 +312,7 @@ public class SWTTokenWidget extends TokenWidget {
public Point getUsersOpeningPoint() {
Point parentBottomRightCorner = new Point(parent.toDisplay(1,1).x + parent.getBounds().width, parent.toDisplay(1,1).y + parent.getBounds().height);
Point openingPoint = new Point(parentBottomRightCorner.x - Magnifier.getScaledValue(Chat.CHAT_WIDTH), parentBottomRightCorner.y - Magnifier.getScaledValue(Chat.CHAT_HEIGHT)-5);
Point openingPoint = new Point(parentBottomRightCorner.x - Magnifier.getScaledValue(ConnectedUsers.USERS_WIDTH), parentBottomRightCorner.y - Magnifier.getScaledValue(Chat.CHAT_HEIGHT) - Magnifier.getScaledValue(ConnectedUsers.USERS_HEIGHT)-5);
return openingPoint;
}
......
......@@ -17,24 +17,42 @@
*/
package fr.ill.ics.client.view.users;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import fr.ill.ics.client.control.users.ConnectedUsersManager;
import fr.ill.ics.client.view.token.TokenWidget;
import fr.ill.ics.client.view.widget.NomadWidget;
import fr.ill.ics.core.property.IPropertyChangeListener;
import fr.ill.ics.core.property.Property;
/**
*
* @author ortizh
*
*/
public abstract class ConnectedUsers {
public abstract class ConnectedUsers implements IPropertyChangeListener {
private final static String JSON_USERS = "users";
private final static String JSON_NAME = "name";
private final static String JSON_IP = "ip";
public final static int USERS_WIDTH = 300;
public final static int USERS_HEIGHT = 200;
public final static int MARGIN = 27;
protected TokenWidget tokenWidget;
protected Vector<NomadWidget> widgets;
private boolean isOpen = false;
protected int openingX;
protected int openingY;
public ConnectedUsers(TokenWidget tokenWidget) {
widgets = new Vector<NomadWidget>();
......@@ -42,8 +60,16 @@ public abstract class ConnectedUsers {
init();
}
protected void init() {
//onPropertyChanged(ConnectedUsersManager.getInstance().getUsers());
onPropertyChanged("{\"users\":[{\"name\":\"Ringo\", \"ip\":\"197.12.14.187\"},{\"name\":\"Paul\", \"ip\":\"172.24.17.145\"},{\"name\":\"John\", \"ip\":\"236.17.25.321\"},{\"name\":\"George\", \"ip\":\"188.29.37.214\"},{\"name\":\"Mick\", \"ip\":\"197.12.14.187\"},{\"name\":\"Keith\", \"ip\":\"172.24.17.145\"},{\"name\":\"Ronnie\", \"ip\":\"236.17.25.321\"},{\"name\":\"Brian\", \"ip\":\"188.29.37.214\"},{\"name\":\"Keren\", \"ip\":\"188.29.37.214\"},{\"name\":\"Siobhan\", \"ip\":\"188.29.37.214\"},{\"name\":\"Jacquie\", \"ip\":\"188.29.37.214\"},{\"name\":\"Paolo\", \"ip\":\"188.29.37.214\"},{\"name\":\"Franck\", \"ip\":\"188.29.37.214\"},{\"name\":\"Jérome\", \"ip\":\"188.29.37.214\"},{\"name\":\"Ali\", \"ip\":\"188.29.37.214\"},{\"name\":\"Yannick\", \"ip\":\"188.29.37.214\"},{\"name\":\"Guanghan\", \"ip\":\"188.29.37.214\"}]}");
}
public void open(int x, int y) {
ConnectedUsersManager.getInstance().addListener(this);
isOpen = true;
this.openingX = x;
this.openingY = y;
......@@ -51,6 +77,7 @@ public abstract class ConnectedUsers {
public void close() {
ConnectedUsersManager.getInstance().removeListener(this);
for (NomadWidget widget : widgets) {
widget.dispose();
widget = null;
......@@ -62,8 +89,58 @@ public abstract class ConnectedUsers {
public boolean isOpen() {
return isOpen;
}
public final void propertyChanged(Property property) {
onPropertyChanged(property.getValue());
}
private void onPropertyChanged(String users) {
Set<User> usersSet = new HashSet<User>();
try {
JSONParser parser = new JSONParser();
users.replaceAll("'", "\"");
JSONObject object = (JSONObject)parser.parse(users);
JSONArray array = (JSONArray)object.get(JSON_USERS);
if (array != null) {
for (int i = 0; i < array.size(); i++) {
JSONObject user = (JSONObject)array.get(i);
String name = (String)user.get(JSON_NAME);
String ip = (String)user.get(JSON_IP);
usersSet.add(new User(name, ip));
}
}
} catch (ParseException e) {
System.out.println("ParseException while parsing string " + users);
}
updateList(usersSet);
}
protected abstract void init();
protected class User {
private String name;
private String ip;
public User(String name, String ip) {
this.name = name;
this.ip = ip;
}
public String getName() {
return name;
}
public String getIp() {
return ip;
}
public String toString() {
return name + " / " + ip;
}
}
public abstract void clear();
protected abstract void updateList(Set<User> users);
}
......@@ -17,6 +17,8 @@
*/
package fr.ill.ics.client.view.users.swt;
import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.MouseAdapter;
......@@ -25,18 +27,23 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import fr.ill.ics.client.view.factory.FontFactory;
import fr.ill.ics.client.view.factory.ImageFactory;
import fr.ill.ics.client.view.factory.PWidgetFactory;
import fr.ill.ics.client.view.factory.swt.SWTColorFactory;
import fr.ill.ics.client.view.factory.swt.SWTImageFactory;
import fr.ill.ics.client.view.factory.swt.SWTPWidgetFactory;
import fr.ill.ics.client.view.factory.swt.SWTWidgetFactory;
import fr.ill.ics.client.view.magnifier.Magnifier;
import fr.ill.ics.client.view.swt.SWTMainWindowPeer;
......@@ -44,6 +51,9 @@ import fr.ill.ics.client.view.token.TokenWidget;
import fr.ill.ics.client.view.users.ConnectedUsers;
import fr.ill.ics.client.view.util.MoveListener;
import fr.ill.ics.client.view.util.swt.SWTImageUtils;
import fr.ill.ics.client.view.widget.PContainer;
import fr.ill.ics.client.view.widget.SimpleImage;
import fr.ill.ics.client.view.widget.swt.SWTSimpleImage;
import fr.ill.ics.util.ConfigManager;
/**
......@@ -52,8 +62,6 @@ import fr.ill.ics.util.ConfigManager;
*
*/
public class SWTConnectedUsers extends ConnectedUsers {
public final static int CHAT_WIDTH = 230;
public final static int CHAT_HEIGHT = 380;
protected Shell usersShell;
private Composite usersComposite;
......@@ -74,7 +82,7 @@ public class SWTConnectedUsers extends ConnectedUsers {
protected void init() {
usersShell = SWTWidgetFactory.getInstance().createShell(((SWTMainWindowPeer)SWTMainWindowPeer.getInstance()).getShell(), SWT.NO_TRIM | SWT.ON_TOP);
usersShell.setLayout(SWTWidgetFactory.getInstance().getNoMarginsGridLayout(1));
usersShell.setBackground(SWTColorFactory.getLoginBackgroundColor());
usersShell.setBackground(SWTColorFactory.getTextForegroundColor());
// Remove escape default listener so that specific code from MyKeyListener is executed.
usersShell.addListener(SWT.Traverse, new Listener() {
public void handleEvent(Event e) {
......@@ -99,6 +107,8 @@ public class SWTConnectedUsers extends ConnectedUsers {
setHeaderLayoutData();
headerCanvas.setLayout(new FormLayout());
initTitleArea();
initCloseButton();
initUsersArea();
......@@ -113,6 +123,7 @@ public class SWTConnectedUsers extends ConnectedUsers {
child.addListener(SWT.MouseUp, moveListener);
child.addListener(SWT.MouseMove, moveListener);
}
super.init();
}
private void setHeaderLayoutData() {
......@@ -121,6 +132,21 @@ public class SWTConnectedUsers extends ConnectedUsers {
}
private void initTitleArea() {
Label titleLabel = SWTWidgetFactory.getInstance().createCenterLabel(headerCanvas, "", FontFactory.titleFontDataHeight-1, FontFactory.BOLD_STYLE);
titleLabel.setForeground(SWTColorFactory.getTabButtonTextColor());
titleLabel.setText(ConfigManager.getInstance().getString("usersShellTitle"));
// Set the position and size of the title area composite
FormData titleFormData = new FormData();
titleFormData.left = new FormAttachment(headerCanvas, Magnifier.getScaledValue(MARGIN), SWT.CENTER);
titleFormData.top = new FormAttachment(headerCanvas, Magnifier.getScaledValue(9), SWT.CENTER);
titleFormData.height = Magnifier.getScaledValue(headerImage.getBounds().width);
titleFormData.width = Magnifier.getScaledValue(USERS_WIDTH - 2 * MARGIN);
titleLabel.setLayoutData(titleFormData);
titleLabel.setBackground(SWTColorFactory.getUsersHeaderColor());
}
private void initCloseButton() {
closeCanvas = SWTWidgetFactory.getInstance().createCanvas(headerCanvas, SWT.NONE, true);
closeImage = SWTImageFactory.getImage(ImageFactory.USERS_CLOSE);
......@@ -145,11 +171,11 @@ public class SWTConnectedUsers extends ConnectedUsers {
scroller = SWTWidgetFactory.getInstance().createScrolledComposite(usersComposite, SWT.V_SCROLL);
scroller.setLayoutData(SWTWidgetFactory.getInstance().getGridData());
usersListComposite = SWTWidgetFactory.getInstance().createComposite(scroller, SWT.BORDER);
usersListComposite = SWTWidgetFactory.getInstance().createComposite(scroller, SWT.NONE);
usersListComposite.setLayoutData(SWTWidgetFactory.getInstance().getGridData());
GridLayout gridLayout = SWTWidgetFactory.getInstance().getNoMarginsGridLayout(1);
GridLayout gridLayout = SWTWidgetFactory.getInstance().getInsideGridLayout(1);
usersListComposite.setLayout(gridLayout);
usersListComposite.setBackground(SWTColorFactory.getLightGrayColor());
usersListComposite.setBackground(SWTColorFactory.getTextForegroundColor());
scroller.setContent(usersListComposite);
scroller.setMinSize(usersListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
......@@ -169,12 +195,10 @@ public class SWTConnectedUsers extends ConnectedUsers {
@Override
public final void open(int x, int y) {
super.open(x, y);
usersShell.setSize(Magnifier.getScaledValue(CHAT_WIDTH), Magnifier.getScaledValue(CHAT_HEIGHT));
usersShell.setSize(Magnifier.getScaledValue(USERS_WIDTH), Magnifier.getScaledValue(USERS_HEIGHT));
usersShell.setLocation(x, y);
usersShell.open();
//fill(ChatFileManager.getInstance().getChat(ExperimentData.getInstance().getProposalId()));
// Necessary to make Shell be blocking
Display display = usersShell.getDisplay();
while (usersShell != null && !usersShell.isDisposed()) {
......@@ -198,4 +222,44 @@ public class SWTConnectedUsers extends ConnectedUsers {
control.dispose();
}
}
@Override
protected void updateList(Set<User> users) {
for (Control control : usersListComposite.getChildren()) {
control.dispose();
}
Composite composite = SWTWidgetFactory.getInstance().createComposite(usersListComposite, SWT.NONE);
composite.setLayoutData(SWTWidgetFactory.getInstance().getLabelGridData());
composite.setLayout(SWTWidgetFactory.getInstance().getInsideGridLayoutWithVerticalSpacing(3));
composite.setBackground(SWTColorFactory.getTextForegroundColor());
for (User user : users) {
Label labelName = SWTWidgetFactory.getInstance().createLabel(composite, "", 11, FontFactory.STANDARD_STYLE);
labelName.setText(user.getName());
labelName.setLayoutData(SWTWidgetFactory.getInstance().getLabelGridData());
labelName.setBackground(SWTColorFactory.getTextForegroundColor());
labelName.setForeground(SWTColorFactory.getBackgroundColor());
Label labelIp = SWTWidgetFactory.getInstance().createLabel(composite, "", 11, FontFactory.STANDARD_STYLE);
labelIp.setText(user.getIp());
GridData gridData = SWTWidgetFactory.getInstance().getLabelGridData();
if (!hasToken(user.getName())) {
gridData.horizontalSpan = 2;
}
labelIp.setLayoutData(gridData);
labelIp.setBackground(SWTColorFactory.getTextForegroundColor());
labelIp.setForeground(SWTColorFactory.getBackgroundColor());
if (hasToken(user.getName())) {
PContainer container = ((SWTPWidgetFactory)(PWidgetFactory.getInstance())).convertToPContainer(composite);
SimpleImage image = PWidgetFactory.getInstance().createSimpleImage(container, "TOKEN_OWNED_BY_ME", 20);
((SWTSimpleImage)image).getCanvas().setLayoutData(SWTWidgetFactory.getInstance().getImageGridData(20, 20, false));
((SWTSimpleImage)image).getCanvas().setBackground(SWTColorFactory.getTextForegroundColor());
}
}
scroller.setMinSize(usersListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
usersShell.layout(true, true);
}
private boolean hasToken(String name) {
return name.equals("Ali");
}
}
src/main/resources/img/multiclient/usersHeader.png

2.41 KiB | W: | H:

src/main/resources/img/multiclient/usersHeader.png

1.18 KiB | W: | H:

src/main/resources/img/multiclient/usersHeader.png
src/main/resources/img/multiclient/usersHeader.png
src/main/resources/img/multiclient/usersHeader.png
src/main/resources/img/multiclient/usersHeader.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment