📄 linklayer.java
字号:
e); if (!tellServer) { repaint(); return true; } // needRepaint = true; // Why? At this point, we // should wait to see what the server wants us to do, // we should only repaint if a graphic update comes // back. descriptor = LinkUtil.setMask(descriptor, GRAPHIC_ID_MASK); id = ((LinkProperties) gesGraphic.getAppObject()).getProperty(LPC_GRAPHICID); } else { // 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); } // Send the query LinkActionRequest.write(descriptor, e, llpoint.getLatitude(), llpoint.getLongitude(), args, l); ///////////////////////////////////////////////////// // With asynchronous behavior, we don't listen to the // reply // now. The LinkListener will handle it. // // Read the response // l.readAndParse(getProjection(), currentGenerator, // this); // lal = l.getActionList(); // lar = l.getActionRequest(); // if (id != null) { // args.remove(LPC_GRAPHICID); // } ///////////////////////////////////////////////////// } linkManager.finLink(); ///////////////////////////////////////////////////// // With asynchronous behavior, we don't listen to the // reply // now. The LinkListener will handle it. // handleLinkActionRequest(lar); // // If nothing else was returned concerning the gesture // query // if (lal == null) { // return false; // } // handleLinkActionList(lal); // return lal.consumedGesture(); ///////////////////////////////////////////////////// // I don't know what to answer here, we really don't know // at this point. There may be something we can do to set // up some lag circle to start returning true if we need // to, but if we're not listening in this thread, we just // don't know if the gesture is consumed here and we can't // hold up the event thread to find out. return false; } catch (IOException ioe) { System.err.println("LinkLayer: IOException contacting server during gesture handling!"); System.err.println(ioe); linkManager.resetLink(); return false; } } // DrawingToolRequestor method public void drawingComplete(OMGraphic omg, OMAction action) { ////////////// send the new graphic, along with instructions //on what to do with it, to the server. String id = null; // unknown Object obj = omg.getAppObject(); LinkProperties lp = null; if (obj != null && obj instanceof LinkProperties) { lp = (LinkProperties) obj; id = lp.getProperty(LPC_GRAPHICID); } if (id == null) { // Doesn't look like it was a modified graphic already // recieved from the server, so we should tell the server // to add it to its list. action.setMask(OMAction.ADD_GRAPHIC_MASK); } try { // We do want the link object here... If another thread is // using the link, wait. ClientLink l = linkManager.getLink(true); if (l == null) { System.err.println("LinkLayer.drawingComplete: unable to get link."); return; } synchronized (l) { LinkActionList lal = new LinkActionList(l, new LinkProperties()); if (action.isMask(OMAction.ADD_GRAPHIC_MASK) || action.isMask(OMAction.UPDATE_GRAPHIC_MASK)) { lal.writeGraphicGestureHeader(action.getValue()); LinkGraphic.write(omg, l); } else { // This shouldn't ever get called with a null lp // properties object. If the object is new or // doesn't have an ID, the upper paragraph will // get called. lal.modifyGraphic(action.getValue(), lp); } lal.end(Link.END_TOTAL); } ///////////////////////////////////////////////////// // With asynchronous behavior, we don't listen to the // reply // now. The LinkListener will handle it. // l.readAndParse(getProjection(), currentGenerator); ///////////////////////////////////////////////////// linkManager.finLink(); } catch (UnknownHostException uhe) { Debug.error("LinkLayer: unknown host!"); return; } catch (java.io.IOException ioe) { Debug.error("LinkLayer: Communication error between " + getName() + " layer\nand Link Server: Host: " + host + ", Port: " + port + "LinkLayer: IOException contacting server!\n" + ioe.getMessage()); linkManager.resetLink(); if (!quiet) { fireRequestMessage("Communication error between " + getName() + " layer\nand Link Server: Host: " + host + ", Port: " + port); } return; } } /** * Set the search distance limit pixel distance for graphics * searches. When the graphics list is checked for a graphic that * is closest to a mouse event, this is the pixel limit within * hits are considered. * * @param limit the pixel limit to consider something "closest". */ public void setDistanceLimit(int limit) { if (limit < 0) { distanceLimit = 0; } else { distanceLimit = limit; } } /** * Get the search distance limit pixel distance for graphics * searches. */ public int getDistanceLimit() { return distanceLimit; } /** * Looks at a properties object, and checks for map updates. * * @param props LinkProperties containing map parameters. */ public void updateMap(LinkProperties props) { Proj projection = (Proj) getProjection(); float latitude = PropUtils.floatFromProperties(props, LPC_CENTER_LAT, projection.getCenter().getLatitude()); float longitude = PropUtils.floatFromProperties(props, LPC_CENTER_LONG, projection.getCenter().getLongitude()); float scale = PropUtils.floatFromProperties(props, LPC_SCALE, projection.getScale()); int width = PropUtils.intFromProperties(props, LPC_WIDTH, projection.getWidth()); int height = PropUtils.intFromProperties(props, LPC_HEIGHT, projection.getHeight()); String projType = props.getProperty(LPC_PROJECTION); float latmin = PropUtils.floatFromProperties(props, LPC_LATMIN, -1000.f); float latmax = PropUtils.floatFromProperties(props, LPC_LATMAX, -1000.f); float lonmin = PropUtils.floatFromProperties(props, LPC_LONMIN, -1000.f); float lonmax = PropUtils.floatFromProperties(props, LPC_LONMAX, -1000.f); if (latmin >= -90.f && latmax <= 90.f && lonmin >= -180.f && lonmax <= 180.f && latmin <= latmax && lonmin <= lonmax) { // Calculate center point float dist = 0.5f * GreatCircle.spherical_distance(ProjMath.degToRad(latmax), ProjMath.degToRad(lonmin), ProjMath.degToRad(latmin), ProjMath.degToRad(lonmax)); float azimuth = GreatCircle.spherical_azimuth(ProjMath.degToRad(latmax), ProjMath.degToRad(lonmin), ProjMath.degToRad(latmin), ProjMath.degToRad(lonmax)); LatLonPoint center = GreatCircle.spherical_between(ProjMath.degToRad(latmax), ProjMath.degToRad(lonmin), dist, azimuth); latitude = center.getLatitude(); longitude = center.getLongitude(); } MapHandler mapHandler = (MapHandler) getBeanContext(); if (mapHandler == null) { Debug.message("link", "Warning...mapHandler = null"); } else { MapBean mapBean = (MapBean) mapHandler.get("com.bbn.openmap.MapBean"); if (mapBean == null) { Debug.message("link", "Warning...mapBean = null"); } else { if (projType != null) { Class projClass = ProjectionFactory.getProjClassForName(projType); if (projClass == null) { projClass = Mercator.class; } projection = (Proj) ProjectionFactory.makeProjection(projClass, latitude, longitude, scale, width, height); } else { projection = (Proj) mapBean.getProjection(); projection.setCenter(latitude, longitude); projection.setScale(scale); projection.setWidth(width); projection.setHeight(height); } if (latmin >= -90.f && latmax <= 90.f && lonmin >= -180.f && lonmax <= 180.f && latmin <= latmax && lonmin <= lonmax) { LatLonPoint upperLeft = new LatLonPoint(latmax, lonmin); LatLonPoint lowerRight = new LatLonPoint(latmin, lonmax); scale = ProjMath.getScale(upperLeft, lowerRight, projection); projection.setScale(scale); LatLonPoint ul = projection.getUpperLeft(); LatLonPoint lr = projection.getLowerRight(); float factor1 = (latmax - latmin) / (ul.getLatitude() - lr.getLatitude()); float factor2 = (lonmax - lonmin) / (lr.getLongitude() - ul.getLongitude()); if (factor2 > factor1) factor1 = factor2; if (factor1 > 1.0) { scale *= factor1; projection.setScale(scale); } } mapBean.setProjection(projection); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -