linkactionlist.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,646 行 · 第 1/5 页
JAVA
1,646 行
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/link/LinkActionList.java,v $// $RCSfile: LinkActionList.java,v $// $Revision: 1.4.2.5 $// $Date: 2008/01/25 17:44:27 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;import com.bbn.openmap.Layer;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGrid;import com.bbn.openmap.omGraphics.grid.OMGridGenerator;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import java.awt.Color;import java.awt.Image;import java.io.EOFException;import java.io.IOException;import java.util.Vector;import javax.swing.ImageIcon;/** * The LinkActionList carries information about actions that the client should * perform in response to a gesture query. The possible actions include URLs and * HTML text to display in a browser, information to display in a pop-up window * or status display, or changes to make to graphics. */public class LinkActionList implements LinkActionConstants, LinkPropertiesConstants { /** Link used for the transmission/reception of actions. */ protected Link link = null; /** The terminator of the gesture section when receiving actions. */ protected String linkStatus = Link.END_TOTAL; /** */ protected boolean reacted = false; /** * This flag tells whether properties have been received that note how to * update the map. */ protected boolean mapUpdate = false; /** Use these properties to set the map */ protected LinkProperties mapProperties; /** * Instead of allocating a new empty vector for each gesture response, even * if there isn't a graphic update, use this to return an empty vector. */ protected static Vector emptyGraphicUpdates = new Vector(); /** Graphics list received. */ protected Vector updates = null; /** Version Number of request format. */ protected static float version = Link.LINK_VERSION; /** The properties returned for this list. */ protected LinkProperties properties; /** * Write a gesture response section to the link, from the server side. * * @param link the Link to write to. * @throws IOException */ public LinkActionList(Link link, LinkProperties properties) throws IOException { this.link = link; link.start(Link.ACTIONS_HEADER); link.dos.writeFloat(version); properties.write(link); } /** * Read the gesture section off the link, from the client. * * @param link the link to read from. * @param layer the client layer. * @param proj the projection to use on graphic updates. * @param generator an OMGridGenerator that knows how to render grid * objects. * @throws IOException * @throws EOFException */ public LinkActionList(Link link, Layer layer, Projection proj, OMGridGenerator generator) throws IOException, EOFException { this.link = link; linkStatus = readGestureResponses(layer, proj, generator); } /** * After reading the gesture response, this returns the section ending * string terminating the gesture section, either Link.END_TOTAL or * Link.END_SECTION. * * @return either Link.END_TOTAL or Link.END_SECTION. */ public String getLinkStatus() { return linkStatus; } /** * Get the properties for the LinkActionList. Any information messages can * be picked up from within the properties - html, URL, messages, text and * information lines. * * @return properties */ public LinkProperties getProperties() { return properties; } /** * Get the properties for the map update. * * @return mapProperties */ public LinkProperties getMapProperties() { return mapProperties; } /** * Return all the graphic updates that came across the link, in the form of * a Vector of LinkActionList.GraphicUpdate objects. * * @return Vector of GraphicUpdate objects. */ public Vector getGraphicUpdates() { if (updates == null) { return emptyGraphicUpdates; } else { return updates; } } /** * The server method that needs to be called at the end of sending a gesture * response. This will tell the link what type of teminator to put on the * end of the gesture response section, and also tell the link to fluxh the * output stream.. * * @param endType use Link.END_SECTION if you want to add more types of * responses. Use Link.END_TOTAL at the end of the total * transmission. * @throws IOException */ public void end(String endType) throws IOException { link.end(endType); } /** * If a ACTIONS_HEADER has been encountered coming off the link, then this * method should be called to read the string of gesture that follows. The * gestures are read and reacted to directly - the responses that involve * the Information Delegator are handled here, and all graphic updates are * stored in the graphicUpdates Vector. Assumes the ACTIONS_HEADER has been * read. * * @param layer the layer that wants the gesture results.. * @param proj If you want the gesture graphic to be projected as it comes * off the wire, add a projection here. Otherwise, use null. * @param generator an OMGridGenerator that knows how to render grid * objects. * @return Link.END_TOTAL or Link.END_SECTION, depending on how the section * ends. * @throws IOException * @throws EOFException */ protected String readGestureResponses(Layer layer, Projection proj, OMGridGenerator generator) throws IOException, EOFException { long startTime = System.currentTimeMillis(); String header = null; int gestureType; float ver = link.dis.readFloat(); if (ver != version) { if (ver == .1) {// Big difference.... throw new IOException("LinkActionList: Versions do not match! DANGER!"); } else { Debug.message("link", "LinkActionList: Versions do not match"); } } if (properties != null) { properties.clear(); } properties = LinkProperties.read(link.dis, properties); LinkProperties graphicProperties = new LinkProperties(); Debug.message("link", "LinkActionList: reading actions:"); while (true) { // Just consume the header, don't create a useless // string object. header = link.readDelimiter(false); if (header == Link.END_TOTAL || header == Link.END_SECTION) { long endTime = System.currentTimeMillis(); if (Debug.debugging("link")) { Debug.output("LinkActionList: received in " + (float) (endTime - startTime) / 1000.0f + " seconds"); } return header; } gestureType = link.dis.readByte(); switch (gestureType) { case ACTION_GRAPHICS: int graphicAction = link.dis.readInt(); if (updates == null) { updates = new Vector(); } if (LinkUtil.isMask(graphicAction, UPDATE_ADD_GRAPHIC_MASK) || LinkUtil.isMask(graphicAction, UPDATE_GRAPHIC_MASK)) { updates.addElement(readGraphic(graphicAction, graphicProperties, proj, generator)); } else { graphicProperties = LinkProperties.read(link.dis, graphicProperties); updates.addElement(new GraphicUpdate(graphicAction, graphicProperties.getProperty(LPC_GRAPHICID))); } reacted = true; break; case ACTION_GUI: break; case ACTION_MAP: mapUpdate = true; if (mapProperties != null) { mapProperties.clear(); } mapProperties = LinkProperties.read(link.dis, mapProperties); break; default: System.err.println("LinkActionList: received unknown gesture type."); } } } /** * Read a graphic's particulars, for upates and additions. Assumes that the * gesture type and graphic action has been read. * * @param graphicAction the action to take on the graphic. * @param proj the projection to apply to the graphic. * @param generator an OMGridGenerator that knows how to render grid * objects. * @throws IOException. */ protected GraphicUpdate readGraphic(int graphicAction, LinkProperties graphicProperties, Projection proj, OMGridGenerator generator) throws IOException { OMGraphic graphic = null; String header = link.readDelimiter(false); // Sanity check if (header == Link.END_TOTAL || header == Link.END_SECTION) { return null; } int graphicType = link.dis.readByte(); switch (graphicType) { case LinkGraphicList.GRAPHICTYPE_LINE: graphic = LinkLine.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_POLY: graphic = LinkPoly.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_RECTANGLE: graphic = LinkRectangle.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_POINT: graphic = LinkPoint.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_CIRCLE: graphic = LinkCircle.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_ELLIPSE: graphic = LinkEllipse.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_RASTER: graphic = LinkRaster.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_BITMAP: graphic = LinkBitmap.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_TEXT: graphic = LinkText.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_GRID: graphic = LinkGrid.read(link.dis, graphicProperties); break; case LinkGraphicList.GRAPHICTYPE_ARC: graphic = LinkArc.read(link.dis, graphicProperties); break; default: System.err.println("LinkActionList: received unknown graphic type."); } if (graphic != null && proj != null) { if (graphic instanceof OMGrid) { ((OMGrid) graphic).setGenerator(generator); } graphic.generate(proj); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?