Issue #429 drawing additions, code cleanup, toolbar fixes

Former-commit-id: 8e83184569 [formerly fa78aa2f7f4738770b37beb6b02fe5adbb074fae]
Former-commit-id: b707408a0a
This commit is contained in:
Matt Nash 2012-04-11 16:44:23 -05:00
parent 9f05fd9905
commit c6d7a5a69b
23 changed files with 801 additions and 487 deletions

View file

@ -98,6 +98,7 @@ import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
import com.raytheon.uf.viz.collaboration.ui.session.SessionView;
import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.drawing.PathToolbar;
/**
* This class is the main view to display the user's information and allow the
@ -166,6 +167,8 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
private Action changePasswordAction;
private Action drawToolbarAction;
// private Action refreshActiveSessionsAction;
private Action collapseAllAction;
@ -407,6 +410,16 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
public void run() {
};
};
drawToolbarAction = new Action("Drawing Toolbar") {
@Override
public void run() {
PathToolbar.getToolbar().open();
}
};
drawToolbarAction.setImageDescriptor(IconUtil.getImageDescriptor(
com.raytheon.uf.viz.drawing.Activator.getDefault().getBundle(),
"draw.gif"));
}
private void changePassword() {
@ -570,6 +583,10 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
mgr.add(changeStatusAction);
mgr.add(changeStatusMessageAction);
mgr.add(changePasswordAction);
mgr.add(new Separator());
mgr.add(drawToolbarAction);
mgr.add(new Separator());
if (CollaborationDataManager.getInstance().isConnected()) {
mgr.add(logoutAction);
@ -762,9 +779,8 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
builder.append("ID: ").append(node.getId());
if (node instanceof CollaborationUser) {
CollaborationUser user = (CollaborationUser) node;
builder.append("\nMode: ")
.append(user.getMode()).append("\n");
builder.append("Type: ").append(user.getType())
builder.append("\nStatus: ")
.append(user.getMode().getMode())
.append("\n");
builder.append("Message: \"").append(
user.getStatusMessage() + "\"");
@ -902,7 +918,8 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
addGroupAction.setEnabled(false);
addUserAction.setEnabled(false);
selectGroups.setEnabled(false);
changeStatusMessageAction.setEnabled(false);
changeStatusAction.setEnabled(false);
drawToolbarAction.setEnabled(false);
changePasswordAction.setEnabled(false);
return;
}
@ -910,7 +927,7 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
addUserAction.setEnabled(true);
selectGroups.setEnabled(true);
changeStatusAction.setEnabled(true);
changeStatusMessageAction.setEnabled(true);
drawToolbarAction.setEnabled(true);
changePasswordAction.setEnabled(true);
LoginUser user = new LoginUser(manager.getLoginId());

View file

@ -0,0 +1,154 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IDisplayEvent;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 11, 2012 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
@DynamicSerialize
public class ColorChangeEvent implements IDisplayEvent {
@DynamicSerializeElement
private String userName;
@DynamicSerializeElement
private Integer red;
@DynamicSerializeElement
private Integer green;
@DynamicSerializeElement
private Integer blue;
public ColorChangeEvent() {
}
public ColorChangeEvent(String user, RGB color) {
this.userName = user;
if (color != null) {
red = color.red;
green = color.green;
blue = color.blue;
}
}
/**
* @param userName
* the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param color
* the color to set
*/
public void setColor(RGB color) {
if (color != null) {
red = color.red;
green = color.green;
blue = color.blue;
}
}
/**
* @return the color
*/
public RGB getColor() {
RGB color = null;
if (red != null && green != null && blue != null) {
color = new RGB(red, green, blue);
}
return color;
}
/**
* @return the red
*/
public Integer getRed() {
return red;
}
/**
* @param red
* the red to set
*/
public void setRed(Integer red) {
this.red = red;
}
/**
* @return the green
*/
public Integer getGreen() {
return green;
}
/**
* @param green
* the green to set
*/
public void setGreen(Integer green) {
this.green = green;
}
/**
* @return the blue
*/
public Integer getBlue() {
return blue;
}
/**
* @param blue
* the blue to set
*/
public void setBlue(Integer blue) {
this.blue = blue;
}
}

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.collaboration.ui.telestrator;
package com.raytheon.uf.viz.collaboration.ui;
import java.util.HashMap;
import java.util.Map;
@ -27,7 +27,7 @@ import org.eclipse.swt.graphics.RGB;
import com.raytheon.viz.core.ColorUtil;
/**
* TODO Add Description
*
*
* <pre>
*
@ -43,17 +43,18 @@ import com.raytheon.viz.core.ColorUtil;
* @version 1.0
*/
public class TelestratorColorManager {
// TODO make so this supports multiple sessions
public class SessionColorManager {
private Map<String, RGB> colors;
private static TelestratorColorManager colorManager = null;
private static SessionColorManager colorManager = null;
private static RGB[] rgbPresets = null;
public static TelestratorColorManager getColorManager() {
public static SessionColorManager getColorManager() {
if (colorManager == null) {
colorManager = new TelestratorColorManager();
colorManager = new SessionColorManager();
rgbPresets = ColorUtil.getResourceColorPresets();
}
return colorManager;
@ -62,7 +63,7 @@ public class TelestratorColorManager {
/**
*
*/
private TelestratorColorManager() {
private SessionColorManager() {
if (colors == null) {
colors = new HashMap<String, RGB>();
}
@ -80,19 +81,23 @@ public class TelestratorColorManager {
*
* @param user
*/
public void addUser(String user) {
private RGB addUser(String user) {
int count = colors.size();
if (rgbPresets.length <= colors.size()) {
count = rgbPresets.length % colors.size();
}
colors.put(user, rgbPresets[count]);
return rgbPresets[count];
}
public RGB getColorFromUser(String user) {
if (colors.get(user) == null) {
addUser(user);
}
// if (colors.get(user) == null) {
addUser(user);
// }
return colors.get(user);
}
public void clearColors() {
colors.clear();
}
}

View file

@ -19,7 +19,13 @@
**/
package com.raytheon.uf.viz.collaboration.ui.role;
import org.eclipse.swt.graphics.RGB;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.ui.ColorChangeEvent;
import com.raytheon.uf.viz.collaboration.ui.SessionColorManager;
import com.raytheon.uf.viz.collaboration.ui.telestrator.CollaborationPathDrawingTool;
import com.raytheon.uf.viz.collaboration.ui.telestrator.CollaborationPathToolbar;
import com.raytheon.uf.viz.core.VizApp;
@ -49,6 +55,8 @@ public abstract class AbstractRoleEventController implements
protected ISharedDisplaySession session;
private PathDrawingTool tool;
protected AbstractRoleEventController(ISharedDisplaySession session) {
this.session = session;
}
@ -67,10 +75,27 @@ public abstract class AbstractRoleEventController implements
VizApp.runAsync(new Runnable() {
@Override
public void run() {
try {
// assign a color that everyone will receive
String user = CollaborationDataManager.getInstance()
.getLoginId();
RGB color = SessionColorManager.getColorManager()
.getColorFromUser(user);
System.out.println("color for " + user + " is : "
+ color.toString());
ColorChangeEvent cce = new ColorChangeEvent(user, color);
session.sendObjectToVenue(cce);
} catch (CollaborationException e) {
e.printStackTrace();
}
// activate the drawing tool by default for the session leader
PathDrawingTool tool = new CollaborationPathDrawingTool();
tool = new CollaborationPathDrawingTool();
((CollaborationPathDrawingTool) tool).setSession(session
.getSessionId());
tool.activate();
session.registerEventHandler(tool);
// open the path drawing toolbar
PathToolbar toolbar = CollaborationPathToolbar.getToolbar();
toolbar.open();
@ -81,6 +106,8 @@ public abstract class AbstractRoleEventController implements
protected void deactivateTelestrator() {
// TODO this must be handled better
PathToolbar.getToolbar().close();
tool.deactivate();
session.unRegisterEventHandler(tool);
}
}

View file

@ -50,6 +50,7 @@ import com.raytheon.uf.viz.remote.graphics.AbstractRemoteGraphicsEvent;
import com.raytheon.uf.viz.remote.graphics.Dispatcher;
import com.raytheon.uf.viz.remote.graphics.DispatcherFactory;
import com.raytheon.uf.viz.remote.graphics.DispatchingGraphicsFactory;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
/**
@ -84,8 +85,10 @@ public class DataProviderEventController extends AbstractRoleEventController {
if (event.getEventType().equals(ParticipantEventType.ARRIVED)) {
// TODO this seems to trigger when you create the room, in which
// case you don't need to send it for yourself
AbstractEditor editor = CollaborationDataManager.getInstance()
.getActivelySharedEditors(session.getSessionId()).get(0);
// TODO instead of going to active editor, should get ones
// specifically shared with this session
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
SharedEditor se = EditorSetup.extractSharedEditor(editor);
try {
session.sendObjectToPeer(event.getParticipant()
@ -315,6 +318,7 @@ public class DataProviderEventController extends AbstractRoleEventController {
@Override
public void shutdown() {
super.shutdown();
super.deactivateTelestrator();
}
}

View file

@ -34,6 +34,7 @@ import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Color;
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;
@ -46,8 +47,8 @@ import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.SessionColorManager;
import com.raytheon.uf.viz.core.icon.IconUtil;
/**
@ -86,6 +87,8 @@ public abstract class AbstractSessionView extends ViewPart implements
private StyledText composeText;
protected Map<String, Color> colors;
// protected Action chatAction;
protected abstract String getSessionImageName();
@ -100,6 +103,12 @@ public abstract class AbstractSessionView extends ViewPart implements
public AbstractSessionView() {
imageMap = new HashMap<String, Image>();
colors = new HashMap<String, Color>();
Map<String, RGB> rgbs = SessionColorManager.getColorManager()
.getColors();
for (String user : rgbs.keySet()) {
colors.put(user, new Color(Display.getCurrent(), rgbs.get(user)));
}
}
private void initComponents(Composite parent) {
@ -245,7 +254,6 @@ public abstract class AbstractSessionView extends ViewPart implements
int offset = sb.length();
sb.append(name).append(": ").append(body);
// here is the place to put the font and color changes for keywords
// read in localization file once and then don't read in again, per
// chat room?
@ -265,19 +273,14 @@ public abstract class AbstractSessionView extends ViewPart implements
}
}
ParticipantRole[] roles = getRoles(fqName);
Color color = SessionColorAdvisor.getColor(roles, fqName
.equals(CollaborationDataManager.getInstance().getLoginId()));
StyleRange range = new StyleRange(messagesText.getCharCount() + offset,
name.length() + 1, color, null, SWT.BOLD);
name.length() + 1, colors.get(fqName), null, SWT.BOLD);
messagesText.append(sb.toString());
messagesText.setStyleRange(range);
for (StyleRange newRange : ranges) {
messagesText.setStyleRange(newRange);
}
messagesText.setTopIndex(messagesText.getLineCount() - 1);
// room for other fun things here, such as sounds and such
executeSightsSounds();
}
@ -347,6 +350,10 @@ public abstract class AbstractSessionView extends ViewPart implements
getViewSite().getWorkbenchWindow().getPartService()
.removePartListener(this);
}
for (Color color : colors.values()) {
color.dispose();
}
SessionColorManager.getColorManager().clearColors();
}
/*

View file

@ -232,7 +232,10 @@ public class CollaborationSessionView extends SessionView {
super.fillContextMenu(manager);
// check if data provider
// check if session leader
manager.add(switchToAction);
if (!CollaborationDataManager.getInstance().getSession(sessionId)
.hasRole(ParticipantRole.SESSION_LEADER)) {
manager.add(switchToAction);
}
}
/*

View file

@ -1,84 +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.session;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 6, 2012 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
public class SessionColorAdvisor {
private static Map<ParticipantRole, Color> colors = null;
public static Color getColor(ParticipantRole[] type, boolean isSelf) {
if (colors == null) {
colors = new HashMap<ParticipantRole, Color>();
colors.put(ParticipantRole.SESSION_LEADER, Display.getCurrent()
.getSystemColor(SWT.COLOR_BLUE));
colors.put(ParticipantRole.DATA_PROVIDER, Display.getCurrent()
.getSystemColor(SWT.COLOR_RED));
colors.put(ParticipantRole.PARTICIPANT, Display.getCurrent()
.getSystemColor(SWT.COLOR_DARK_GREEN));
}
if (isSelf) {
return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
}
ParticipantRole rType = null;
if (type == null || type.length == 0) {
rType = ParticipantRole.PARTICIPANT;
} else if (type.length == 1) {
rType = type[0];
} else {
rType = ParticipantRole.PARTICIPANT;
for (ParticipantRole rt : type) {
if (rt == ParticipantRole.DATA_PROVIDER) {
rType = rt;
break;
}
if (rt == ParticipantRole.SESSION_LEADER) {
rType = rt;
}
}
}
return colors.get(rType);
}
}

View file

@ -346,19 +346,21 @@ public class SessionView extends AbstractSessionView {
if (item != null) {
CollaborationUser user = (CollaborationUser) item.getData();
StringBuilder builder = new StringBuilder();
builder.append("mode: ").append(user.getMode())
.append("\n");
builder.append("type: ").append(user.getType())
.append("\n");
builder.append("message: \"")
builder.append("Status : ")
.append(user.getMode().getMode()).append("\n");
builder.append("Message : \"")
.append(user.getStatusMessage()).append("\"\n");
builder.append("-- Roles --");
for (ParticipantRole type : user.getRoles()) {
// TODO fake XXX take this out
// if (type == ParticipantRole.UNKNOWN) {
// continue;
// }
builder.append("\n" + type.toString());
// TODO, this might not work at this point?
if (CollaborationDataManager.getInstance()
.getSession(sessionId)
.hasRole(ParticipantRole.SESSION_LEADER)) {
builder.append("\nSession Leader");
}
if (CollaborationDataManager.getInstance()
.getSession(sessionId)
.hasRole(ParticipantRole.DATA_PROVIDER)) {
builder.append("\nData Provider");
}
usersTable.getTable().setToolTipText(builder.toString());
} else {

View file

@ -29,17 +29,19 @@ import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
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.event.IDisplayEvent;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.ClearDrawingEvent;
import com.raytheon.uf.viz.collaboration.ui.ColorChangeEvent;
import com.raytheon.uf.viz.collaboration.ui.SessionColorManager;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.CollaborationDrawingEvent;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.RedoDrawingEvent;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.UndoDrawingEvent;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.CollaborationDrawingEvent.CollaborationEventType;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.RGBColors;
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
import com.raytheon.uf.viz.core.drawables.PaintProperties;
import com.raytheon.uf.viz.core.exception.VizException;
@ -52,6 +54,8 @@ import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.TopologyException;
/**
* A layer that extends Drawing Layer but allows other users to have things
@ -73,13 +77,18 @@ import com.vividsolutions.jts.geom.LineString;
public class CollaborationDrawingLayer extends DrawingLayer {
protected static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(CollaborationDrawingLayer.class);
private Multimap<String, ShapeContainer> collaboratorShapes;
private Multimap<String, ShapeContainer> deletedCollaboratorShapes;
private Map<String, RGB> colors;
private IWireframeShape tempRemoteShape = null;
private RGB officialColor = null;
private boolean allowDraw = false;
/**
* @param data
@ -92,10 +101,8 @@ public class CollaborationDrawingLayer extends DrawingLayer {
.getActiveEditorAs(AbstractEditor.class);
CollaborationDataManager mgr = CollaborationDataManager.getInstance();
for (String str : mgr.getSessions().keySet()) {
// if (editor.equals(mgr.getEditor(str))) {
mgr.getSession(str).registerEventHandler(this);
break;
// }
}
}
@ -120,11 +127,7 @@ public class CollaborationDrawingLayer extends DrawingLayer {
this.deletedCollaboratorShapes = LinkedHashMultimap.create();
this.deletedCollaboratorShapes = Multimaps
.synchronizedMultimap(this.deletedCollaboratorShapes);
TelestratorColorManager colorManager = TelestratorColorManager
.getColorManager();
officialColor = colorManager.getColorFromUser(CollaborationDataManager
.getInstance().getLoginId());
colors = SessionColorManager.getColorManager().getColors();
}
/*
@ -150,8 +153,13 @@ public class CollaborationDrawingLayer extends DrawingLayer {
for (String userName : collaboratorShapes.keySet()) {
for (ShapeContainer sh : collaboratorShapes.get(userName)) {
if (sh != null) {
RGB color = RGBColors.getRGBColor(sh.rgb);
target.drawWireframeShape(sh.shape, color,
sh.getShape().clearLabels();
RGB color = SessionColorManager.getColorManager()
.getColors().get(userName);
if (color == null) {
color = new RGB(255, 0, 0);
}
target.drawWireframeShape(sh.getShape(), color,
outline.getOutlineWidth(),
outline.getLineStyle());
}
@ -161,18 +169,26 @@ public class CollaborationDrawingLayer extends DrawingLayer {
}
@Subscribe
public void handle(IDisplayEvent event) {
if (event instanceof ClearDrawingEvent) {
resetTemp();
clearSelfShapes(((ClearDrawingEvent) event).getUserName());
// TODO check if session leader, otherwise only remove my wireframe
// shapes
if (/* if session leader */false) {
disposeInternal();
}
issueRefresh();
} else if (event instanceof UndoDrawingEvent) {
String userName = ((UndoDrawingEvent) event).getUserName();
public void setColorEvent(ColorChangeEvent event) {
if (CollaborationDataManager.getInstance().getLoginId()
.equals(event.getUserName())) {
this.color = event.getColor();
}
colors.put(event.getUserName(), event.getColor());
issueRefresh();
}
@Subscribe
public void handle(CollaborationDrawingEvent event) {
switch (event.getType()) {
case DRAW:
addCollaborationShape(event.getUserName(), event.getContainer());
break;
case DISABLE:
allowDraw = !allowDraw;
getEventBus().post(event);
case UNDO:
String userName = event.getUserName();
Collection<ShapeContainer> container = collaboratorShapes
.get(userName);
Iterator<ShapeContainer> itr = container.iterator();
@ -185,13 +201,12 @@ public class CollaborationDrawingLayer extends DrawingLayer {
}
deletedCollaboratorShapes.put(userName, lastElement);
collaboratorShapes.get(userName).remove(lastElement);
issueRefresh();
} else if (event instanceof RedoDrawingEvent) {
String userName = ((RedoDrawingEvent) event).getUserName();
Collection<ShapeContainer> container = deletedCollaboratorShapes
.get(userName);
Iterator<ShapeContainer> itr = container.iterator();
ShapeContainer lastElement = null;
break;
case REDO:
userName = event.getUserName();
container = deletedCollaboratorShapes.get(userName);
itr = container.iterator();
lastElement = null;
if (itr.hasNext()) {
lastElement = itr.next();
}
@ -200,13 +215,54 @@ public class CollaborationDrawingLayer extends DrawingLayer {
}
collaboratorShapes.put(userName, lastElement);
deletedCollaboratorShapes.get(userName).remove(lastElement);
issueRefresh();
} else if (event instanceof CollaborationDrawingEvent) {
CollaborationDrawingEvent collEvent = (CollaborationDrawingEvent) event;
addCollaborationShape(collEvent.getUserName(),
collEvent.getContainer());
issueRefresh();
break;
case CLEAR:
resetTemp();
clearSelfShapes(event.getUserName());
// TODO check if session leader, otherwise only remove my wireframe
// shapes
if (/* if session leader */false) {
disposeInternal();
}
break;
case ERASE:
userName = event.getUserName();
double extentPercentageX = paintProps.getView().getExtent()
.getWidth()
/ (double) paintProps.getCanvasBounds().width;
double cursorSize = 16;
double size = extentPercentageX * cursorSize;
synchronized (collaboratorShapes) {
for (ShapeContainer cont : collaboratorShapes.get(userName)) {
Geometry line = event.getContainer().getGeom();
if (line.buffer(size / 2).intersects(cont.getGeom())) {
Geometry intersection = line.buffer(size / 2)
.intersection(cont.getGeom());
Geometry finalGeom = null;
try {
finalGeom = cont.getGeom().difference(intersection);
} catch (TopologyException e) {
continue;
}
if (finalGeom instanceof MultiLineString) {
Geometry lString = (MultiLineString) finalGeom;
for (int j = 0; j < lString.getNumGeometries(); j++) {
LineString lineString = (LineString) lString
.getGeometryN(j);
drawTempLinePrimitive(lineString,
eraseWireframeShape);
ShapeContainer shCont = new ShapeContainer();
shCont.setGeom(lString);
shCont.setShape(eraseWireframeShape);
collaboratorShapes.get(userName).add(shCont);
}
}
}
}
}
break;
}
issueRefresh();
}
/**
@ -214,7 +270,7 @@ public class CollaborationDrawingLayer extends DrawingLayer {
*/
private void clearSelfShapes(String userName) {
for (ShapeContainer cont : collaboratorShapes.get(userName)) {
cont.shape.dispose();
cont.getShape().dispose();
}
collaboratorShapes.removeAll(userName);
}
@ -233,6 +289,19 @@ public class CollaborationDrawingLayer extends DrawingLayer {
// sendDrawEvent(line);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.drawing.DrawingLayer#addTempEraseLine(com.vividsolutions
* .jts.geom.LineString)
*/
@Override
public void addTempEraseLine(LineString line) {
super.addTempEraseLine(line);
sendEraseEvent(line);
}
/*
* (non-Javadoc)
*
@ -244,7 +313,11 @@ public class CollaborationDrawingLayer extends DrawingLayer {
public void finalizeLine(LineString line, String uuid) {
super.finalizeLine(line, uuid);
// for showing the line only after the artist lets up on the mouse
sendDrawEvent(line);
if (state == LayerState.DRAWING) {
sendDrawEvent(line);
} else if (state == LayerState.ERASING) {
sendEraseEvent(line);
}
}
/*
@ -255,7 +328,8 @@ public class CollaborationDrawingLayer extends DrawingLayer {
@Override
public void undoAdd() {
super.undoAdd();
UndoDrawingEvent event = new UndoDrawingEvent();
CollaborationDrawingEvent event = new CollaborationDrawingEvent();
event.setType(CollaborationEventType.UNDO);
event.setUserName(CollaborationDataManager.getInstance().getLoginId());
sendGenericEvent(event);
}
@ -268,17 +342,33 @@ public class CollaborationDrawingLayer extends DrawingLayer {
@Override
public void redoAdd() {
super.redoAdd();
RedoDrawingEvent event = new RedoDrawingEvent();
CollaborationDrawingEvent event = new CollaborationDrawingEvent();
event.setType(CollaborationEventType.REDO);
event.setUserName(CollaborationDataManager.getInstance().getLoginId());
sendGenericEvent(event);
}
public void sendDisableOthers() {
CollaborationDrawingEvent event = new CollaborationDrawingEvent();
event.setType(CollaborationEventType.DISABLE);
sendGenericEvent(event);
}
private void sendEraseEvent(LineString line) {
ShapeContainer container = new ShapeContainer();
container.setGeom(line);
CollaborationDrawingEvent eObject = new CollaborationDrawingEvent();
eObject.setType(CollaborationEventType.ERASE);
eObject.setContainer(container);
eObject.setUserName(CollaborationDataManager.getInstance().getLoginId());
sendGenericEvent(eObject);
}
private void sendDrawEvent(LineString line) {
ShapeContainer container = new ShapeContainer();
String color = RGBColors.getColorName(officialColor);
container.setRgb(color);
container.setGeom(line);
CollaborationDrawingEvent tObject = new CollaborationDrawingEvent();
tObject.setType(CollaborationEventType.DRAW);
tObject.setContainer(container);
tObject.setUserName(CollaborationDataManager.getInstance().getLoginId());
sendGenericEvent(tObject);
@ -292,7 +382,8 @@ public class CollaborationDrawingLayer extends DrawingLayer {
@Override
public void reset() {
super.reset();
ClearDrawingEvent event = new ClearDrawingEvent();
CollaborationDrawingEvent event = new CollaborationDrawingEvent();
event.setType(CollaborationEventType.CLEAR);
event.setUserName(CollaborationDataManager.getInstance().getLoginId());
sendGenericEvent(event);
}
@ -304,7 +395,7 @@ public class CollaborationDrawingLayer extends DrawingLayer {
try {
((ISharedDisplaySession) sessions.get(str)).sendEvent(event);
} catch (CollaborationException e) {
e.printStackTrace();
statusHandler.handle(Priority.ERROR, "Unable to send event", e);
}
}
}
@ -314,7 +405,7 @@ public class CollaborationDrawingLayer extends DrawingLayer {
tempRemoteShape = target.createWireframeShape(false, getDescriptor());
// }
drawTempLinePrimitive(container.getGeom(), tempRemoteShape);
container.shape = tempRemoteShape;
container.setShape(tempRemoteShape);
synchronized (collaboratorShapes) {
collaboratorShapes.put(userName, container);
}
@ -327,6 +418,17 @@ public class CollaborationDrawingLayer extends DrawingLayer {
// }
}
public void addColor(String userName, RGB color) {
colors.put(userName, color);
}
/**
* @return the allowDraw
*/
public boolean isAllowDraw() {
return allowDraw;
}
/*
* (non-Javadoc)
*
@ -343,11 +445,11 @@ public class CollaborationDrawingLayer extends DrawingLayer {
// }
for (ShapeContainer cont : collaboratorShapes.values()) {
cont.shape.dispose();
cont.getShape().dispose();
}
for (ShapeContainer cont : deletedCollaboratorShapes.values()) {
cont.shape.dispose();
cont.getShape().dispose();
}
collaboratorShapes.clear();

View file

@ -48,6 +48,9 @@ import com.raytheon.uf.viz.drawing.PathDrawingResourceData;
@XmlAccessorType(XmlAccessType.NONE)
public class CollaborationPathDrawingResourceData extends
PathDrawingResourceData {
private String sessionId;
/*
* (non-Javadoc)
*
@ -85,6 +88,20 @@ public class CollaborationPathDrawingResourceData extends
*/
@Override
public void setClassT(String classT) {
System.out.println("setClassT");
}
/**
* @param sessionId
* the sessionId to set
*/
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
/**
* @return the sessionId
*/
public String getSessionId() {
return sessionId;
}
}

View file

@ -19,7 +19,10 @@
**/
package com.raytheon.uf.viz.collaboration.ui.telestrator;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.drawing.tools.PathDrawingTool;
/**
@ -40,6 +43,9 @@ import com.raytheon.uf.viz.drawing.tools.PathDrawingTool;
*/
public class CollaborationPathDrawingTool extends PathDrawingTool {
private String session;
/*
* (non-Javadoc)
*
@ -48,6 +54,107 @@ public class CollaborationPathDrawingTool extends PathDrawingTool {
@Override
public AbstractResourceData constructData() {
CollaborationPathDrawingResourceData data = new CollaborationPathDrawingResourceData();
session = data.getSessionId();
System.out.println("session : " + session);
return data;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.drawing.AbstractDrawingTool#activateTool()
*/
@Override
protected void activateTool() {
super.activateTool();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.drawing.tools.PathDrawingTool#getMouseHandler()
*/
@Override
public IInputHandler getMouseHandler() {
if (theHandler == null) {
theHandler = new CollaborationPathDrawingHandler();
}
return theHandler;
}
public class CollaborationPathDrawingHandler extends PathDrawingHandler {
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.input.IInputHandler#handleMouseDown(int,
* int, int)
*/
@Override
public boolean handleMouseDown(int anX, int aY, int button) {
boolean allowDraw = ((CollaborationDrawingLayer) theDrawingLayer)
.isAllowDraw();
boolean isSessionLeader = CollaborationDataManager.getInstance()
.getSession(session)
.hasRole(ParticipantRole.SESSION_LEADER);
if (allowDraw && !isSessionLeader) {
return false;
}
return super.handleMouseDown(anX, aY, button);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.input.IInputHandler#handleMouseDownMove(int,
* int, int)
*/
@Override
public boolean handleMouseDownMove(int x, int y, int button) {
boolean allowDraw = ((CollaborationDrawingLayer) theDrawingLayer)
.isAllowDraw();
boolean isSessionLeader = CollaborationDataManager.getInstance()
.getSession(session)
.hasRole(ParticipantRole.SESSION_LEADER);
if (allowDraw && !isSessionLeader) {
return false;
}
return super.handleMouseDownMove(x, y, button);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.input.IInputHandler#handleMouseUp(int, int,
* int)
*/
@Override
public boolean handleMouseUp(int anX, int aY, int button) {
boolean allowDraw = ((CollaborationDrawingLayer) theDrawingLayer)
.isAllowDraw();
boolean isSessionLeader = CollaborationDataManager.getInstance()
.getSession(session)
.hasRole(ParticipantRole.SESSION_LEADER);
if (allowDraw && !isSessionLeader) {
return false;
}
return super.handleMouseUp(anX, aY, button);
}
}
/**
* @param session
* the session to set
*/
public void setSession(String session) {
this.session = session;
}
/**
* @return the session
*/
public String getSession() {
return session;
}
}

View file

@ -19,12 +19,24 @@
**/
package com.raytheon.uf.viz.collaboration.ui.telestrator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolItem;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.CollaborationDrawingEvent;
import com.raytheon.uf.viz.collaboration.ui.telestrator.event.CollaborationDrawingEvent.CollaborationEventType;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.drawing.DrawingLayer;
import com.raytheon.uf.viz.drawing.PathToolbar;
import com.raytheon.uf.viz.drawing.events.DrawingEvent;
import com.raytheon.uf.viz.drawing.events.DrawingEventBus;
import com.raytheon.uf.viz.drawing.tools.PathDrawingTool;
/**
* TODO Add Description
@ -44,6 +56,7 @@ import com.raytheon.uf.viz.drawing.tools.PathDrawingTool;
*/
public class CollaborationPathToolbar extends PathToolbar {
private ToolItem leaderOnly;
/**
* @param parentShell
@ -52,17 +65,6 @@ public class CollaborationPathToolbar extends PathToolbar {
super(parentShell);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.drawing.PathToolbar#startTool()
*/
@Override
protected void startTool() {
PathDrawingTool tool = new CollaborationPathDrawingTool();
tool.activate();
}
public static PathToolbar getToolbar() {
if (pathToolbar == null) {
pathToolbar = new CollaborationPathToolbar(new Shell(
@ -84,26 +86,23 @@ public class CollaborationPathToolbar extends PathToolbar {
// allows for subclasses to add more items to the toolbar, in this case
// allowing the user to turn off other collaborator drawings
super.initializeComponents(shell);
// ToolItem allowOthersItem = new ToolItem(toolbar, SWT.CHECK);
// allowOthersItem.setText("Leader Only");
// allowOthersItem.setImage(IconUtil.getImageDescriptor(
// Activator.getDefault().getBundle(), "multiple_draw.gif")
// .createImage());
// allowOthersItem.setSelection(true);
// allowOthersItem.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// AbstractEditor editor = EditorUtil
// .getActiveEditorAs(AbstractEditor.class);
// IDescriptor desc = editor.getActiveDisplayPane()
// .getDescriptor();
// for (ResourcePair pair : desc.getResourceList()) {
// if (pair.getResource() instanceof CollaborationDrawingLayer) {
// System.out.println("collaborating");
// }
// }
// }
// });
createLeaderItem();
}
@Override
public void handleMessage(final DrawingEvent event) {
VizApp.runAsync(new Runnable() {
@Override
public void run() {
if (event instanceof CollaborationDrawingEvent) {
CollaborationDrawingEvent cde = (CollaborationDrawingEvent) event;
if (cde.getType() == CollaborationEventType.DISABLE) {
disableAll();
}
}
CollaborationPathToolbar.super.handleMessage(event);
}
});
}
/*
@ -114,5 +113,39 @@ public class CollaborationPathToolbar extends PathToolbar {
@Override
public void updateToolbar() {
super.updateToolbar();
// for non-leaders, need to disable/remove the leaderOnly button
DrawingLayer resource = getDrawingResource();
if (resource.getResourceData() instanceof CollaborationPathDrawingResourceData) {
String sessionId = ((CollaborationPathDrawingResourceData) resource
.getResourceData()).getSessionId();
if (!CollaborationDataManager.getInstance().getSession(sessionId)
.hasRole(ParticipantRole.SESSION_LEADER)
&& leaderOnly != null) {
leaderOnly.setEnabled(false);
}
}
}
private void createLeaderItem() {
leaderOnly = new ToolItem(toolbar, SWT.CHECK);
leaderOnly.setText("Lock Collaborators");
leaderOnly.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "multiple_draw.gif")
.createImage());
leaderOnly.setSelection(false);
leaderOnly.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DrawingLayer layer = getDrawingResource();
CollaborationDrawingLayer dLayer = (CollaborationDrawingLayer) layer;
dLayer.sendDisableOthers();
}
});
}
public void disableAll() {
toolbar.setEnabled(!toolbar.getEnabled());
}
}

View file

@ -44,14 +44,7 @@ import com.vividsolutions.jts.geom.Geometry;
@DynamicSerialize
public class ShapeContainer {
public IWireframeShape shape;
@DynamicSerializeElement
public String rgb;
// public LineStyle lineStyle;
// public float lineWidth;
private IWireframeShape shape;
@DynamicSerializeElement
private Geometry geom;
@ -74,21 +67,6 @@ public class ShapeContainer {
this.shape = shape;
}
/**
* @return the rgb
*/
public String getRgb() {
return rgb;
}
/**
* @param rgb
* the rgb to set
*/
public void setRgb(String rgb) {
this.rgb = rgb;
}
/**
* @return the geom
*/

View file

@ -1,64 +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.telestrator.event;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IDisplayEvent;
import com.raytheon.uf.viz.drawing.events.DrawingEvent;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 4, 2012 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
@DynamicSerialize
public class ClearDrawingEvent extends DrawingEvent implements IDisplayEvent {
@DynamicSerializeElement
private String userName;
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName
* the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
}

View file

@ -46,14 +46,20 @@ import com.raytheon.uf.viz.drawing.events.DrawingEvent;
public class CollaborationDrawingEvent extends DrawingEvent implements
IDisplayEvent {
public static enum CollaborationEventType {
DRAW, ERASE, REDO, UNDO, CLEAR, DISABLE;
}
@DynamicSerializeElement
private ShapeContainer container;
@DynamicSerializeElement
protected String userName;
private String userName;
@DynamicSerializeElement
private CollaborationEventType type;
public CollaborationDrawingEvent() {
}
public CollaborationDrawingEvent(ShapeContainer cont) {
@ -89,4 +95,19 @@ public class CollaborationDrawingEvent extends DrawingEvent implements
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the type
*/
public CollaborationEventType getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(CollaborationEventType type) {
this.type = type;
}
}

View file

@ -1,44 +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.telestrator.event;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 4, 2012 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
@DynamicSerialize
public class RedoDrawingEvent extends CollaborationDrawingEvent {
}

View file

@ -1,43 +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.telestrator.event;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 4, 2012 mnash Initial creation
*
* </pre>
*
* @author mnash
* @version 1.0
*/
@DynamicSerialize
public class UndoDrawingEvent extends CollaborationDrawingEvent {
}

View file

@ -20,6 +20,9 @@
package com.raytheon.uf.viz.drawing;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.exception.VizException;
@ -43,6 +46,9 @@ import com.raytheon.viz.ui.tools.AbstractModalTool;
*/
public abstract class AbstractDrawingTool extends AbstractModalTool {
protected static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(AbstractDrawingTool.class);
/** The drawing layer */
protected DrawingLayer theDrawingLayer;
@ -78,7 +84,8 @@ public abstract class AbstractDrawingTool extends AbstractModalTool {
theDrawingLayer = (DrawingLayer) constructData().construct(
new LoadProperties(), desc);
} catch (VizException e1) {
e1.printStackTrace();
statusHandler.handle(Priority.ERROR,
"Unable to construct the drawing layer", e1);
}
try {
desc.getResourceList().add(theDrawingLayer);

View file

@ -38,11 +38,11 @@ import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability;
import com.raytheon.uf.viz.drawing.events.DrawingEvent;
import com.raytheon.uf.viz.drawing.events.DrawingEventBus;
import com.raytheon.uf.viz.drawing.events.DrawingListener;
import com.raytheon.viz.ui.input.EditableManager;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
@ -59,6 +59,9 @@ import com.vividsolutions.jts.geom.TopologyException;
*/
public class DrawingLayer extends
AbstractVizResource<AbstractResourceData, MapDescriptor> {
public static enum LayerState {
DRAWING, ERASING, NONE;
}
protected List<Geometry> tempGeometries;
@ -72,9 +75,13 @@ public class DrawingLayer extends
protected IGraphicsTarget target;
protected boolean erase = false;
protected LayerState state;
private PaintProperties paintProps = null;
// protected boolean erase = false;
//
// private boolean draw = true;
protected PaintProperties paintProps = null;
private boolean needsRefresh = false;
@ -113,6 +120,7 @@ public class DrawingLayer extends
*/
@Override
protected void initInternal(IGraphicsTarget target) throws VizException {
EditableManager.makeEditable(this, true);
this.tempGeometries = new ArrayList<Geometry>();
this.wireframeShapes = new LinkedHashMap<Geometry, IWireframeShape>();
this.deletedShapes = new LinkedHashMap<Geometry, IWireframeShape>();
@ -120,7 +128,6 @@ public class DrawingLayer extends
this.target = target;
outline = getCapability(OutlineCapability.class);
color = getCapability(ColorableCapability.class).getColor();
getCapability(EditableCapability.class);
}
/*
@ -143,7 +150,6 @@ public class DrawingLayer extends
}
outline = getCapability(OutlineCapability.class);
color = getCapability(ColorableCapability.class).getColor();
for (IWireframeShape sh : wireframeShapes.values()) {
target.drawWireframeShape(sh, color,
@ -205,16 +211,17 @@ public class DrawingLayer extends
* Finalize a temporary line by putting it in the map of all the drawn
* shapes
*
* UUID is optional, and generally should be null
* UUID is optional, an generally should be null
*
* @param line
* @param isFinal
* @param uuid
*/
public void finalizeLine(LineString line, String uuid) {
tempWireframeShape.compile();
wireframeShapes.put(line, tempWireframeShape);
if (state == LayerState.DRAWING) {
tempWireframeShape.compile();
wireframeShapes.put(line, tempWireframeShape);
}
// this will update the toolbar if necessary
DrawingEvent event = new DrawingEvent();
eventBus.post(event);
@ -336,21 +343,6 @@ public class DrawingLayer extends
}
}
/**
* @return are you currently erasing
*/
public boolean isErase() {
return erase;
}
/**
* @param erase
* to erase or not to erase
*/
public void setErase(boolean erase) {
this.erase = erase;
}
/**
* @return the deletedShapes, these shapes will get disposed when the clear
* button is selected
@ -380,4 +372,39 @@ public class DrawingLayer extends
public DrawingListener getEventListener() {
return eventListener;
}
/**
* @return the state
*/
public LayerState getState() {
return state;
}
/**
* @param state
* the state to set
*/
public void setState(LayerState state) {
this.state = state;
}
// /*
// * (non-Javadoc)
// *
// * @see
// * com.raytheon.uf.viz.core.rsc.AbstractVizResource#project(org.opengis.
// * referencing.crs.CoordinateReferenceSystem)
// */
// @Override
// public void project(CoordinateReferenceSystem crs) throws VizException {
// super.project(crs);
// for (Geometry geom : wireframeShapes.keySet()) {
// IWireframeShape shape = target.createWireframeShape(true,
// getDescriptor());
// for (int i = 0; i < geom.getNumGeometries(); i++) {
// Geometry ls = convertPixels((LineString) geom.getGeometryN(i));
// drawTempLinePrimitive(ls, shape);
// }
// wireframeShapes.put(geom, shape);
// }
// }
}

View file

@ -39,10 +39,13 @@ import org.eclipse.ui.contexts.IContextService;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.uf.viz.drawing.DrawingLayer.LayerState;
import com.raytheon.uf.viz.drawing.actions.ClearDrawingAction;
import com.raytheon.uf.viz.drawing.actions.EraseObjectsAction;
import com.raytheon.uf.viz.drawing.actions.RedoAddAction;
@ -53,6 +56,8 @@ import com.raytheon.uf.viz.drawing.tools.PathDrawingTool;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.raytheon.viz.ui.perspectives.VizPerspectiveListener;
import com.raytheon.viz.ui.tools.AbstractModalTool;
/**
* TODO Add Description
@ -72,20 +77,24 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
*/
public class PathToolbar extends CaveSWTDialog {
protected static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PathToolbar.class);
private static final String EDIT_TOOL_CATEGY = "com.raytheon.viz.ui.modalTool.nav";
protected static AbstractModalTool lastTool = null;
protected static PathToolbar pathToolbar;
// private Map<AbstractEditor, ResourcePair> layers;
protected ToolBar toolbar;
private ToolItem drawItem;
protected ToolItem drawItem;
private ToolItem eraserItem;
protected ToolItem eraserItem;
private ToolItem undoItem;
protected ToolItem undoItem;
private ToolItem redoItem;
protected ToolItem redoItem;
protected ToolItem clearItem;
@ -96,6 +105,9 @@ public class PathToolbar extends CaveSWTDialog {
pathToolbar = new PathToolbar(new Shell(Display.getCurrent()));
DrawingEventBus.register(PathToolbar.getToolbar());
}
lastTool = VizPerspectiveListener.getCurrentPerspectiveManager()
.getToolManager().getSelectedModalTool(EDIT_TOOL_CATEGY);
return pathToolbar;
}
@ -108,14 +120,6 @@ public class PathToolbar extends CaveSWTDialog {
setText("Drawing");
}
/**
* @param args
*/
public static void main(String[] args) {
PathToolbar bar = new PathToolbar(new Shell());
bar.open();
}
/*
* (non-Javadoc)
*
@ -154,33 +158,32 @@ public class PathToolbar extends CaveSWTDialog {
toolbar.setLayout(layout);
toolbar.setLayoutData(data);
drawItem = new ToolItem(toolbar, SWT.NONE);
drawItem = new ToolItem(toolbar, SWT.CHECK);
drawItem.setText("Draw");
drawItem.setImage(IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "draw.gif").createImage());
getDrawingResource().setState(LayerState.NONE);
drawItem.setSelection(false);
drawItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
IDescriptor desc = editor.getActiveDisplayPane()
.getDescriptor();
for (ResourcePair pair : desc.getResourceList()) {
if (pair.getResource() instanceof DrawingLayer) {
((DrawingLayer) pair.getResource()).erase = false;
eraserItem.setSelection(false);
}
DrawingLayer layer = getDrawingResource();
switch (layer.getState()) {
case DRAWING:
lastTool.activate();
layer.setState(LayerState.NONE);
break;
case ERASING:
layer.setState(LayerState.DRAWING);
eraserItem.setSelection(false);
break;
case NONE:
layer.setState(LayerState.DRAWING);
break;
}
startTool();
// ((VizMultiPaneEditor) editor)
// .addSelectedPaneChangedListener(PathToolbar
// .getToolbar());
updateToolbar();
}
});
undoItem = new ToolItem(toolbar, SWT.FLAT);
undoItem.setText("Undo");
undoItem.setImage(IconUtil.getImageDescriptor(
@ -233,6 +236,19 @@ public class PathToolbar extends CaveSWTDialog {
eraserItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DrawingLayer layer = getDrawingResource();
// reactivate the last tool
if (layer.getState() == LayerState.ERASING) {
lastTool.activate();
} else {
lastTool.deactivate();
}
// uncheck the draw item
drawItem.setSelection(false);
// execute the EraseObjectsAction
EraseObjectsAction action = new EraseObjectsAction();
executeAction(action);
}
@ -253,7 +269,7 @@ public class PathToolbar extends CaveSWTDialog {
try {
action.execute(null);
} catch (ExecutionException e) {
e.printStackTrace();
statusHandler.handle(Priority.ERROR, "Unable to execute action", e);
}
}
@ -267,42 +283,46 @@ public class PathToolbar extends CaveSWTDialog {
if (this.isDisposed()) {
return;
}
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
ResourceList list = editor.getActiveDisplayPane().getDescriptor()
.getResourceList();
for (ResourcePair pair : list) {
if (pair.getResource() instanceof DrawingLayer) {
if (toolbar != null && !toolbar.isDisposed()) {
DrawingLayer layer = (DrawingLayer) pair.getResource();
if (layer.getDeletedShapes().isEmpty()
&& layer.getWireframeShapes().isEmpty()) {
undoItem.setEnabled(false);
redoItem.setEnabled(false);
clearItem.setEnabled(false);
} else {
clearItem.setEnabled(true);
if (layer.getDeletedShapes().isEmpty()) {
redoItem.setEnabled(false);
} else {
redoItem.setEnabled(true);
}
if (layer.getWireframeShapes().isEmpty()) {
undoItem.setEnabled(false);
} else {
undoItem.setEnabled(true);
}
}
DrawingLayer layer = getDrawingResource();
if (toolbar != null && !toolbar.isDisposed()) {
if (layer.getDeletedShapes().isEmpty()
&& layer.getWireframeShapes().isEmpty()) {
undoItem.setEnabled(false);
redoItem.setEnabled(false);
clearItem.setEnabled(false);
} else {
clearItem.setEnabled(true);
if (layer.getDeletedShapes().isEmpty()) {
redoItem.setEnabled(false);
} else {
redoItem.setEnabled(true);
}
if (layer.getWireframeShapes().isEmpty()) {
undoItem.setEnabled(false);
} else {
undoItem.setEnabled(true);
}
}
}
}
/**
*
*/
protected void startTool() {
PathDrawingTool tool = new PathDrawingTool();
tool.activate();
protected DrawingLayer getDrawingResource() {
AbstractEditor editor = EditorUtil
.getActiveEditorAs(AbstractEditor.class);
IDescriptor desc = editor.getActiveDisplayPane().getDescriptor();
DrawingLayer layer = null;
for (ResourcePair pair : desc.getResourceList()) {
if (pair.getResource() instanceof DrawingLayer) {
layer = (DrawingLayer) pair.getResource();
break;
}
}
if (layer == null) {
PathDrawingTool tool = new PathDrawingTool();
tool.activate();
lastTool.deactivate();
layer = getDrawingResource();
}
return layer;
}
}

View file

@ -26,6 +26,7 @@ import org.eclipse.core.commands.ExecutionException;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.uf.viz.drawing.DrawingLayer;
import com.raytheon.uf.viz.drawing.DrawingLayer.LayerState;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
@ -55,9 +56,12 @@ public class EraseObjectsAction extends AbstractHandler {
.getActiveDisplayPane().getDescriptor().getResourceList();
for (ResourcePair pair : list) {
if (pair.getResource() instanceof DrawingLayer) {
((DrawingLayer) pair.getResource())
.setErase(!((DrawingLayer) pair.getResource())
.isErase());
DrawingLayer layer = (DrawingLayer) pair.getResource();
if (layer.getState() == LayerState.ERASING) {
layer.setState(LayerState.NONE);
} else {
layer.setState(LayerState.ERASING);
}
break;
}
}

View file

@ -23,6 +23,8 @@ package com.raytheon.uf.viz.drawing.tools;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.commands.HandlerEvent;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.ImageData;
@ -34,7 +36,9 @@ import com.raytheon.uf.viz.core.rsc.IInputHandler;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.drawing.AbstractDrawingTool;
import com.raytheon.uf.viz.drawing.Activator;
import com.raytheon.uf.viz.drawing.DrawingLayer.LayerState;
import com.raytheon.uf.viz.drawing.PathDrawingResourceData;
import com.raytheon.viz.ui.input.EditableManager;
import com.raytheon.viz.ui.input.InputAdapter;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
@ -86,12 +90,13 @@ public class PathDrawingTool extends AbstractDrawingTool {
@Override
public boolean handleMouseDown(int anX, int aY, int button) {
if (button != 1
|| theDrawingLayer.getState() == LayerState.NONE
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable())
.isEditable()) {
return false;
}
Cursor cursor = null;
if (theDrawingLayer.isErase()) {
if (theDrawingLayer.getState() == LayerState.ERASING) {
ImageData data = IconUtil.getImageDescriptor(
Activator.getDefault().getBundle(), "eraser_box.gif")
.getImageData();
@ -125,9 +130,11 @@ public class PathDrawingTool extends AbstractDrawingTool {
@Override
public boolean handleMouseDownMove(int x, int y, int button) {
if (button != 1
|| theDrawingLayer.getState() == LayerState.NONE
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable())
.isEditable()) {
return false;
}
Coordinate p1 = editor.translateClick(theLastMouseX, theLastMouseY);
Coordinate p2 = editor.translateClick(x, y);
@ -140,7 +147,7 @@ public class PathDrawingTool extends AbstractDrawingTool {
LineString ls = gf.createLineString(new Coordinate[] { p1, p2 });
ls = theDrawingLayer.convertPixels(ls);
if (theDrawingLayer.isErase()) {
if (theDrawingLayer.getState() == LayerState.ERASING) {
theDrawingLayer.addTempEraseLine(ls);
} else {
theDrawingLayer.addTempDrawLine(ls);
@ -160,6 +167,7 @@ public class PathDrawingTool extends AbstractDrawingTool {
@Override
public boolean handleMouseUp(int anX, int aY, int button) {
if (button != 1
|| theDrawingLayer.getState() == LayerState.NONE
|| !theDrawingLayer.getCapability(EditableCapability.class)
.isEditable()) {
return false;
@ -176,15 +184,11 @@ public class PathDrawingTool extends AbstractDrawingTool {
if (coords.length > 1) {
LineString ls = gf.createLineString(coords);
ls = theDrawingLayer.convertPixels(ls);
if (!theDrawingLayer.isErase()) {
if (theDrawingLayer.getState() == LayerState.DRAWING) {
theDrawingLayer.finalizeLine(ls, null);
}
}
// this probably should be put elsewhere or genericized in some
// manner
// PathToolbar.getToolbar().updateToolbar();
editor.refresh();
return true;
}
@ -198,8 +202,16 @@ public class PathDrawingTool extends AbstractDrawingTool {
@Override
public void activate() {
super.activate();
theDrawingLayer.getCapability(EditableCapability.class).setEditable(
true);
editor.registerMouseHandler(getMouseHandler());
EditableManager.makeEditable(theDrawingLayer, theDrawingLayer
.getCapability(EditableCapability.class).isEditable());
addHandlerListener(new IHandlerListener() {
@Override
public void handlerChanged(HandlerEvent handlerEvent) {
// TODO Auto-generated method stub
System.out.println("changed");
}
});
theDrawingLayer.issueRefresh();
}
@ -212,9 +224,11 @@ public class PathDrawingTool extends AbstractDrawingTool {
public void deactivate() {
super.deactivate();
editor.unregisterMouseHandler(getMouseHandler());
// change the cursor back
Cursor cursor = new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW);
Display.getCurrent().getActiveShell().setCursor(cursor);
cursor.dispose();
theDrawingLayer = null;
}
}