graphics = new LinkOMGraphicList();
setGraphicList(graphics);
}
Debug.message("link", "DrawLinkLayer mouseClicked");
OMGraphic gesGraphic = null;
LinkOMGraphicList selectableList = new LinkOMGraphicList();
OMGraphic g;
Properties p;
String selectable;
for (Iterator it = graphics.iterator(); it.hasNext();) {
g = (OMGraphic) it.next();
p = (Properties) g.getAppObject();
selectable = p.getProperty(LPC_SELECTABLE);
if (selectable.equals("true")) {
selectableList.add(g);
}
}
gesGraphic = selectableList.findClosest(e.getX(),
e.getY(),
distanceLimit);
try {
if (e == null) {
graphics.deselectAll();
return false;
}
String id = null;
// If there was a graphic, set the mask to indicate that,
// and keep track of the graphic and the list index of the
// graphic for the response. If a graphic modify command
// comes back without an ID, then we'll assume the server
// was refering to this graphic.
if (gesGraphic != null) {
Debug.message("link", "LinkLayer: found gesture graphic");
boolean tellServer = graphicGestureReaction(gesGraphic,
descriptor,
e);
if (!tellServer) {
repaint();
return true;
}
descriptor = LinkUtil.setMask(descriptor, GRAPHIC_ID_MASK);
id = ((LinkProperties) gesGraphic.getAppObject()).getProperty(LPC_GRAPHICID);
} else {
Debug.message("link", "LinkLayer: gesture graphic NOT FOUND");
// clear out info line
fireRequestInfoLine("");
}
// server inform
if (!LinkUtil.isMask(getGestureDescriptor(),
SERVER_NOTIFICATION_MASK)) {
return false;
}
// Get the lat/lon point of the event
LatLonPoint llpoint = getProjection().inverse(e.getX(), e.getY());
// Don't need these anymore, look below for explaination
// for asynchronous operation.
// LinkActionList lal;
// LinkActionRequest lar;
ClientLink l = linkManager.getLink(false);
// We'll check this here because we don't want to wait if
// it is not available - it could be used for another
// graphics or gui fetch.
if (l == null) {
Debug.message("link",
"LinkLayer: unable to get link in handleGesture().");
return false;
}
// Using the link - carefully prevent others from using it
// too!
synchronized (l) {
if (id != null) {
args.setProperty(LPC_GRAPHICID, id);
} else {
// Reset this to prevent sending the id of a graphic
// that is not being clicked on.
args.remove(LPC_GRAPHICID);
}
// Send the query
LinkActionRequest.write(descriptor,
e,
llpoint.getLatitude(),
llpoint.getLongitude(),
args,
l);
}
linkManager.finLink();
} catch (IOException ioe) {
System.err.println("LinkLayer: IOException contacting server during gesture handling!");
System.err.println(ioe);
linkManager.resetLink();
return false;
}
OMDrawingTool dt = getDrawingTool();
if (dt != null) {
// Stop editing any graphic currently being edited
dt.setMask(OMDrawingTool.DEACTIVATE_ASAP_BEHAVIOR_MASK);
EditableOMGraphic egraphic = dt.getCurrentEditable();
if (egraphic != null) {
OMGraphic graphic = egraphic.getGraphic();
OMAction action = new OMAction(UPDATE_GRAPHIC_MASK);
drawingComplete(graphic, action);
dt.setCurrentEditable(null);
}
}
// FIXME - we could operate on a subset of graphics by either having
// multiple graphics lists or by filtering the graphics list
// to only detect/edit the graphics we want.
if (gesGraphic != null && drawingTool != null) {
OMGraphic graphic = null;
if (dt != null) {
Properties prop = (Properties) gesGraphic.getAppObject();
String editable = prop.getProperty(LPC_EDITABLE);
Debug.message("link", "DrawLinkLayer: editable: " + editable);