📄 linkgraphiclist.java
字号:
// **********************************************************************// // <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/LinkGraphicList.java,v $// $RCSfile: LinkGraphicList.java,v $// $Revision: 1.5.2.2 $// $Date: 2005/08/09 18:10:44 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;import java.awt.Color;import java.awt.Image;import java.io.EOFException;import java.io.IOException;import javax.swing.ImageIcon;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;/** * The LinkGraphicList is an object that describes a list of graphics. * This object can be used to write the graphics to the link, and read * the graphics response section from the link. * <P> * * To use it to write to the link, create the LinkGraphicList with the * constructor that takes a link as its only argument, and then use * the write methods to add graphics. When all the graphics are * written to the link, close the section by calling end() with the * approproate symbol. * <P> * * To use it to read from a link, use the constructor that takes a * link and a LinkOMGraphicsList (and a projection, if you want to * generate the graphics as you read them). Call getGraphics() to get * the updated list. */public class LinkGraphicList implements LinkGraphicConstants { /** Link used for the transmission/reception of graphics. */ protected Link link = null; /** Graphics list received. */ protected LinkOMGraphicList graphics = null; /** The terminator of the graphics section when receiving graphics. */ protected String linkStatus = Link.END_TOTAL; /** Version Number of request format. */ protected static float version = Link.LINK_VERSION; /** The properties returned for this list. */ protected LinkProperties properties; /** Write a graphics section to the link. */ public LinkGraphicList(Link link, LinkProperties properties) throws IOException { this.link = link; link.start(Link.GRAPHICS_HEADER); link.dos.writeFloat(version); properties.write(link); } /** * Read the graphics section off the link. * * @param link the link to read the response from. * @param graphicList the list to add graphics to. * @throws IOException * @throws EOFException */ public LinkGraphicList(Link link, LinkOMGraphicList graphicList) throws IOException, EOFException { this(link, graphicList, (Projection) null, (OMGridGenerator) null); } /** * Read the graphics section off the link, if you want the * graphics to be projected as they come off the link. * * @param link the link to read graphics from. * @param graphicList the list to add graphics to. * @param proj the projection to use for generating graphics. * @param generator an OMGridGenerator that knows how to render * grid objects. * @throws IOException * @throws EOFException */ public LinkGraphicList(Link link, LinkOMGraphicList graphicList, Projection proj, OMGridGenerator generator) throws IOException, EOFException { this.link = link; graphics = graphicList; if (graphics == null) { graphics = new LinkOMGraphicList(); } linkStatus = readGraphics(graphics, proj, generator); } /** * After a readAndParse() has been called on a link, this can be * called to retrieve graphics in an LinkOMGraphicList, if any * graphics were sent. * * @return LinkOMGraphicList containing the graphics read off the * link. If no graphics were sent the list will be empty. */ public LinkOMGraphicList getGraphics() { return graphics; } /** * After reading the graphics response, this returns the section * ending string terminating the graphics 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 LinkGraphicList. 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; } /** * The server method that needs to be called at the end of sending * a graphics response. This will tell the link what type of * teminator to put on the end of the graphics 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 response sections. 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 GRAPHICS_RESPONSE_HEADER has been encountered coming off * the link, then this method should be called to read the string * of graphics that follows. The graphics are read and added to * the LinkOMGraphicList provided. * * @param graphics the LinkOMGraphicList to add the link graphics * too. This method assumes that this is never null. * @param proj If you want the graphics to be projected as they * come off the wire, add a projection here. Otherwise, use * null. * @param generator an OMGridGenerator that knows how to render * grid objects. * @throws IOException * @throws EOFException */ protected String readGraphics(LinkOMGraphicList graphics, Projection proj, OMGridGenerator generator) throws IOException, EOFException { OMGraphic graphic; long startTime = System.currentTimeMillis(); String header = null; int graphicType; // This is important, it's checked by the LinkLayer to see if // it needs to generate the LinkOMGraphicList to see if the // contents need to be generated. graphics.setNeedToRegenerate(proj == null); // doing nothing with the version number. float ver = link.dis.readFloat(); if (ver != version) { if (ver == .1) {// Big difference.... throw new IOException("LinkGraphicList: Versions do not match! DANGER!"); } else { Debug.message("link", "LinkGraphicList: Versions do not match."); } } properties = new LinkProperties(link); Debug.message("link", "LinkGraphicList: reading graphics:"); while (true) { graphic = null; // 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(); Debug.message("link", "LinkGraphicList: received " + graphics.size() + " graphics in " + (float) (endTime - startTime) / 1000.0f + " seconds"); return header; } graphicType = link.dis.readInt(); switch (graphicType) { case GRAPHICTYPE_LINE: graphic = LinkLine.read(link.dis); break; case GRAPHICTYPE_POLY: graphic = LinkPoly.read(link.dis); break; case GRAPHICTYPE_RECTANGLE: graphic = LinkRectangle.read(link.dis); break; case GRAPHICTYPE_POINT: graphic = LinkPoint.read(link.dis); break; case GRAPHICTYPE_CIRCLE: graphic = LinkCircle.read(link.dis); break; case GRAPHICTYPE_RASTER: graphic = LinkRaster.read(link.dis); break; case GRAPHICTYPE_BITMAP: graphic = LinkBitmap.read(link.dis); break; case GRAPHICTYPE_TEXT: graphic = LinkText.read(link.dis); break; case GRAPHICTYPE_GRID: graphic = LinkGrid.read(link.dis); break; default: throw new IOException("LinkGraphicList: received unknown graphic type."); } if (graphic != null) { if (graphic instanceof OMGrid) { ((OMGrid) graphic).setGenerator(generator); } if (proj != null) { graphic.generate(proj); } graphics.add(graphic); } } } /** * Write an arc with lat/lon placement. * * @param latPoint latitude of center point, decimal degrees * @param lonPoint longitude of center point, decimal degrees * @param w horizontal diameter of arc, pixels * @param h vertical diameter of arc, pixels * @param s starting angle of arc, decimal degrees * @param e angular extent of arc, decimal degrees * @param properties attributes for the arc. * @throws IOException */ public void addArc(float latPoint, float lonPoint, int w, int h, float s, float e, LinkProperties properties) throws IOException { LinkArc.write(latPoint, lonPoint, 0, 0, w, h, s, e, properties, link.dos); } /** * Write an arc with x/y placement. * * @param x1 window position of center point from left of window, * in pixels * @param y1 window position of center point from top of window, * in pixels * @param w horizontal diameter of arc, pixels * @param h vertical diameter of arc, pixels * @param s starting angle of arc, decimal degrees * @param e angular extent of arc, decimal degrees * @param properties attributes for the arc. * @throws IOException */ public void addArc(int x1, int y1, int w, int h, float s, float e, LinkProperties properties) throws IOException { LinkArc.write(x1, y1, w, h, s, e, properties, link.dos); } /** * Writing an arc at a x, y, offset to a Lat/Lon location. * * @param latPoint latitude of center of arc. * @param lonPoint longitude of center of arc. * @param offset_x1 # pixels to the right the center will be moved * from lonPoint. * @param offset_y1 # pixels down that the center will be moved * from latPoint. * @param w horizontal diameter of arc, pixels. * @param h vertical diameter of arc, pixels. * @param s starting angle of arc, decimal degrees * @param e angular extent of arc, decimal degrees * @param properties attributes for the arc. * @throws IOException */ public void addArc(float latPoint, float lonPoint, int offset_x1, int offset_y1, int w, int h, float s, float e, LinkProperties properties) throws IOException { LinkArc.write(latPoint, lonPoint, offset_x1, offset_y1, w, h, s, e, properties, link.dos); } /** * Write an arc with a certain radius at a Lat/Lon location. * Assumes the radius is in decimal degrees. * * @param latPoint latitude of center point, decimal degrees * @param lonPoint longitude of center point, decimal degrees * @param radius distance in decimal degrees * @param s starting angle of arc, decimal degrees * @param e angular extent of arc, decimal degrees * @param properties attributes for the arc. * @throws IOException */ public void addArc(float latPoint, float lonPoint, float radius, float s, float e, LinkProperties properties) throws IOException { LinkArc.write(latPoint, lonPoint, radius, -1, -1, s, e, properties, link.dos); } /** * Write an arc with a certain radius at a Lat/Lon location, and * allows you to specify units of the radius. * * @param latPoint latitude of center of arc in decimal degrees * @param lonPoint longitude of center of arc in decimal degrees * @param radius distance * @param units integer value for units for distance - KM, MILES, * NMILES. If < 0, assume decimal degrees. * @param s starting angle of arc, decimal degrees * @param e angular extent of arc, decimal degrees * @param properties attributes for the arc. * @throws IOException */ public void addArc(float latPoint, float lonPoint, float radius, int units, float s, float e, LinkProperties properties) throws IOException { LinkArc.write(latPoint, lonPoint, radius, units, -1, s, e, properties, link.dos); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -