linkproperties.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 454 行 · 第 1/2 页
JAVA
454 行
// **********************************************************************// // <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/LinkProperties.java,v $// $RCSfile: LinkProperties.java,v $// $Revision: 1.4.2.4 $// $Date: 2008/02/26 17:39:25 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Rectangle;import java.awt.Stroke;import java.awt.TexturePaint;import java.awt.geom.Line2D;import java.awt.image.BufferedImage;import java.io.DataInput;import java.io.DataOutputStream;import java.io.IOException;import java.util.Enumeration;import java.util.Hashtable;import java.util.Map;import java.util.Properties;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.util.ColorFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;/** * A LinkProperties object is a set of key-value strings that are going to be * sent over the link. In java-land, they are handled with the Properties * object. In link-land, they are handled like an array of strings. Requests * have a properties section, and graphic objects have them as well. */public class LinkProperties extends Properties implements LinkPropertiesConstants, LinkGraphicConstants { /** * Used by the graphics if no properties were sent with it. No properties * can be set on this LinkProperties object. */ public static final LinkProperties EMPTY_PROPERTIES = new LinkProperties() { public Object put(Object obj1, Object obj2) { return null; } public void putAll(Map map) {} }; protected Boolean reuseProperties; public LinkProperties() { super(); } public LinkProperties(LinkProperties settings) { super(settings); } /** * Create a LinkProperties object with it's first pair. * * @param keyString the key for the pair. * @param valueString the value for the pair. */ public LinkProperties(String keyString, String valueString) { super(); setProperty(keyString, valueString); } /** * Create a LinkProperties, and read it's contents off a link. Assumes the * properties are the next thing to be read, starting with the string count. * * @param link the Link to read properties from * @throws IOException. */ public LinkProperties(Link link) throws IOException { super(); read(link.dis); } /** * Create a LinkProperties, and read it's contents off a link. * * @param dis DataInput to read from. * @throws IOException. */ public LinkProperties(DataInput dis) throws IOException { read(dis); } public Boolean getReuseProperties() { return reuseProperties; } /** * A flag that controls how LinkProperties are managed. Setting this object * to Boolean.TRUE will indicate that the LinkProperties object decoded * previously should be reused, with any properties currently set in this * object overwriting the same property previously received. Setting it to * Boolean.FALSE, or setting it to null, will indicate than any buffered * LinkProperty object should be cleared before these properties are read. * * @param reuseProperties */ public void setReuseProperties(Boolean reuseProperties) { this.reuseProperties = reuseProperties; } /** * Calls the hashtable method <code>put</code>. Provided to provide a * similar interface in jdk1.1.x or jdk1.2.x, enforcing that only strings * can be in properties files. */ public synchronized Object setProperty(String key, String value) { return put(key, value); } /** * Write the properties as several strings. There is a string count (Key * count + value count), and then for each key and value string, a character * count, and the characters. * * @param link the link to write to. */ public void write(Link link) throws IOException { write(link.dos); } /** * Write the properties as several strings. There is a string count (Key * count + value count), and then for each key and value string, a character * count, and the characters. * * @param dos the DataOutputStream to write to. */ public void write(DataOutputStream dos) throws IOException { dos.writeInt((size() + 1) * 2); dos.writeInt(LPC_PROPERY_MANAGEMENT_POLICY.length()); dos.writeChars(LPC_PROPERY_MANAGEMENT_POLICY); if (reuseProperties == Boolean.TRUE) { dos.writeInt(LPC_REUSE_PROPERTIES.length()); dos.writeChars(LPC_REUSE_PROPERTIES); } else { dos.writeInt(LPC_CLEAR_PROPERTIES.length()); dos.writeChars(LPC_CLEAR_PROPERTIES); } for (Enumeration e = propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = getProperty(key); dos.writeInt(key.length()); dos.writeChars(key); dos.writeInt(value.length()); dos.writeChars(value); } } /** * Read the link to create the properties object. Assumes the properties are * the next thing to be read, starting with the string count. * * @param dis DataInput to read from. * @throws IOException. */ public void read(DataInput dis) throws IOException { int numArgs = dis.readInt(); if (numArgs > 0) { readArgs(numArgs, dis); } } /** * Read the link to fetch properties for this LinkProperties object. Assumes * the property count has been read and is being provided to this method * * @param numArgs the number of key + value strings to read. * @param dis DataInput to read from. * @throws IOException. */ public void readArgs(int numArgs, DataInput dis) throws IOException { String[] argStrings = new String[numArgs]; for (int i = 0; i < numArgs; i += 2) { int argLength = dis.readInt(); if (i == 0 && argLength == 1 && dis.readChar() == LPC_PROPERY_MANAGEMENT_POLICY_CHAR) { argLength = dis.readInt(); if (argLength == 1 && dis.readChar() == LPC_CLEAR_PROPERTIES_CHAR) { clear(); } continue; } argStrings[i] = LinkUtil.readString(dis, argLength); argLength = dis.readInt(); argStrings[i + 1] = LinkUtil.readString(dis, argLength); put(argStrings[i], argStrings[i + 1]); } if (Debug.debugging("linkdetail")) { System.out.println("LinkProperties | Read: " + this);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?