📄 linklayer.java
字号:
currentGenerator = (OMGridGenerator) PropUtils.objectFromProperties(properties, realPrefix + GridGeneratorProperty); if (currentGenerator == null) { Debug.message("linkdetail", getName() + "|LinkLayer: no generator for grid objects."); } distanceLimit = PropUtils.intFromProperties(properties, realPrefix + DistanceLimitProperty, distanceLimit); // listener = new LinkListener(linkManager, this, // currentGenerator); } protected void setListener(LinkListener ll) { listener = ll; } protected LinkListener getListener() { return listener; } /** * Prepares the graphics for the layer. This is where the * getRectangle() method call is made on the link. * <p> * Occasionally it is necessary to abort a prepare call. When this * happens, the map will set the cancel bit in the LayerThread, * (the thread that is running the prepare). If this Layer needs * to do any cleanups during the abort, it should do so, but * return out of the prepare asap. * * @return a list of graphics. */ public synchronized OMGraphicList prepare() { OMGraphicList currentList = getList(); if (listener == null) { listener = new LinkListener(linkManager, this, currentGenerator); } if (listener != null && !listener.isListening()) { // Call LinkListener to launch SwingWorker to kick off a // thread for the listener. listener.startUp(); } if (Debug.debugging("link")) { Debug.output(getName() + "|LinkLayer.prepare(): Listener " + (listener == null ? "is null," : "is OK,") + " listening (" + (listener == null ? "nope" : "" + listener.isListening()) + ")"); } if (isCancelled()) { Debug.message("link", getName() + "|LinkLayer.prepare(): aborted."); return currentList; } Projection projection = getProjection(); if (projection == null) { Debug.error("Link Layer needs to be added to the MapBean before it can get graphics!"); return currentList; } else if (currentList != null) { // If the list isn't empty, it isn't being cleared when a // new projection is received, as dictated by the policy // of the layer. Should regenerate it here. If it's // understood that a new list will be sent by the server, // then a different ProjectionChangePolicy should be used. currentList.generate(projection); } Debug.message("basic", getName() + "|LinkLayer.prepare(): doing it"); // Setting the OMGraphicsList for this layer. Remember, the // LinkOMGraphicList is made up of OMGraphics, which are // generated // (projected) when the graphics are added to the list. So, // after this call, the list is ready for painting. // call getRectangle(); if (Debug.debugging("link")) { System.out.println(getName() + "|LinkLayer.prepare(): " + "calling getRectangle " + " with projection: " + projection + " ul = " + projection.getUpperLeft() + " lr = " + projection.getLowerRight()); } // LinkOMGraphicList omGraphicList; ////////////// Call getRectangle for server.... 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: unable to get link in prepare()."); return currentList; } synchronized (l) { // omGraphicList = getGraphics(l, projection); sendMapRequest(l, projection); } linkManager.finLink(); } catch (UnknownHostException uhe) { System.err.println("LinkLayer: unknown host!"); // return currentList; } catch (java.io.IOException ioe) { System.err.println("LinkLayer: IOException contacting server for map request!"); System.err.println(ioe); linkManager.resetLink(); if (!quiet) { fireRequestMessage("Communication error between " + getName() + " layer\nand Link Server: Host: " + host + ", Port: " + port); } System.err.println("LinkLayer: Communication error between " + getName() + " layer\nand Link Server: Host: " + host + ", Port: " + port); // return currentList; } ///////////////////////////////////////////////////// // With asynchronous behavior, we don't listen to the reply // now. The LinkListener will handle setting the new // OMGraphicList if one is needed as decided by the server. ///////////////////// // safe quit // int size = 0; // if (omGraphicList != null) { // size = omGraphicList.size(); // if (Debug.debugging("basic")) { // System.out.println(getName()+ // "|LinkLayer.prepare(): finished with "+ // size+" graphics"); // } // // omGraphicList.project(projection); // } // else // Debug.message("basic", getName()+ // "|LinkLayer.prepare(): finished with null graphics list"); return currentList; } /** * Creates the LinkMapRequest. * * @param link the link to communicate over. * @param proj the projection to give to the graphics. * @return LinkOMGraphicList containing graphics from the server. * @throws IOException */ protected void sendMapRequest(ClientLink link, Projection proj) throws IOException { LatLonPoint ul = proj.getUpperLeft(); LatLonPoint lr = proj.getLowerRight(); float ulLat = ul.getLatitude(); float ulLon = ul.getLongitude(); float lrLat = lr.getLatitude(); float lrLon = lr.getLongitude(); LinkBoundingPoly[] boundingPolys = null; if ((ulLon > lrLon) || MoreMath.approximately_equal(ulLon, lrLon, .001f)) { Debug.message("link", "Dateline is on screen"); float ymin = (float) Math.min(ulLat, lrLat); float ymax = (float) Math.max(ulLat, lrLat); // xmin, ymin, xmax, ymax boundingPolys = new LinkBoundingPoly[2]; boundingPolys[0] = new LinkBoundingPoly(ulLon, ymin, 180.0f, ymax); boundingPolys[1] = new LinkBoundingPoly(-180.0f, ymin, lrLon, ymax); } else { boundingPolys = new LinkBoundingPoly[1]; boundingPolys[0] = new LinkBoundingPoly(ulLon, lrLat, lrLon, ulLat); } LinkMapRequest.write(proj.getCenter().getLatitude(), proj.getCenter().getLongitude(), proj.getScale(), proj.getHeight(), proj.getWidth(), boundingPolys, args, link); ///////////////////////////////////////////////////// // With asynchronous behavior, we don't listen to the reply // now. The LinkListener will handle it. // link.readAndParse(proj, currentGenerator); // // While we are here, check for any change in gesture query // // requests. // LinkActionRequest lar = link.getActionRequest(); // if (lar != null) { // setGestureDescriptor(lar.getDescriptor()); // } // handleLinkGraphicList(link.getGraphicList()); ///////////////////////////////////////////////////// } public void handleLinkGraphicList(LinkGraphicList lgl) { Debug.message("link", "LinkLayer.handleLinkGraphicList()"); if (lgl != null) { //Deal with all the messaging.... handleMessages(lgl.getProperties()); LinkOMGraphicList lomgl = lgl.getGraphics(); setGraphicList(lomgl); // Do we need to regenerate? Projection proj = getProjection(); if (lomgl.getNeedToRegenerate(proj)) { // set to false in LinkGraphicList.readGraphics if the // projection was there when the LinkGraphicList was // created. If it wasn't there, we need to try to // project them before calling repaint(). Projection // will be null if the layer hasn't been added to the // map. lomgl.generate(proj); } repaint(); } } public void handleLinkActionList(LinkActionList lal) { Debug.message("link", "LinkLayer.handleLinkActionList()"); if (lal == null) { return; } handleMessages(lal.getProperties()); // The only thing we need to do is handle any gesture // changes... Vector updates = lal.getGraphicUpdates(); Enumeration items = updates.elements(); boolean needRepaint = false; LinkOMGraphicList graphics = getGraphicList(); Projection proj = getProjection(); if (graphics == null) { Debug.message("link", "LinkLayer.handleLinkActionList: null LinkOMGraphicList, making new one..."); // Why ignore what the server has to say, set the new // OMGraphicList and react accordingly. graphics = new LinkOMGraphicList(); setGraphicList(graphics); } while (items.hasMoreElements()) { needRepaint = true; // We do! GraphicUpdate gu = (GraphicUpdate) items.nextElement(); // Take care of this first..... if (LinkUtil.isMask(gu.action, MODIFY_DESELECTALL_GRAPHIC_MASK)) { Debug.message("link", "LinkLayer.handleLinkActionList: deselecting all graphics"); graphics.deselectAll(); } // Find the graphic that we are talking about - if the // ID is not "none", or if the id doesn't match the // gesGraphic LinkGraphicID, then look for the new // graphic. Otherwise, assume that the gesGraphic is // the one that the action refers to. // This code was moved from handleGesture to here, the // main difference being that in handleGesture any actual // OMGraphic that was gestured over was already known at // this point, and there was no sense looking for it if // you already had it. Since we moved the code, and this // method is being called from a different thread, we // don't have that luxury - we have to look up the // OMGraphic again... if (gu == null) { Debug.message("link", "LinkLayer.handleLinkActionList: null GraphicUpdate, skipping..."); continue; } OMGraphic gug = gu.graphic; OMGraphic reactionGraphic = null; int reactionGraphicIndex = Link.UNKNOWN; if (LinkUtil.isMask(gu.action, UPDATE_ADD_GRAPHIC_MASK)) { if (Debug.debugging("link")) { Debug.output("LinkLayer.handleLinkActionList: adding graphic, id:" + gu.id); } if (gug != null) { gug.generate(proj); graphics.add(gug); reactionGraphic = gug; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -