?? crfpclient.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/corba/com/bbn/openmap/layer/rpf/corba/CRFPClient.java,v $// $RCSfile: CRFPClient.java,v $// $Revision: 1.3.2.2 $// $Date: 2005/08/09 21:17:59 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.rpf.corba;import java.awt.Point;import java.awt.image.BufferedImage;import java.io.ByteArrayInputStream;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import java.util.Vector;import com.bbn.openmap.Environment;import com.bbn.openmap.layer.rpf.RpfCoverageBox;import com.bbn.openmap.layer.rpf.RpfFrameProvider;import com.bbn.openmap.layer.rpf.RpfIndexedImageData;import com.bbn.openmap.layer.rpf.RpfViewAttributes;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.CRFPCADRGProjection;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.CRFPCoverageBox;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.CRFPViewAttributes;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.LLPoint;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.RawImage;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.Server;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.ServerHelper;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.proj.CADRG;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGImageDecoder;/** * An implementation of the RpfFrameProvider interface that uses CORBA * to get the subframe data via a server. The image data is * transmitted in jpeg format. This class requires the sunw package * that handles jpeg encoding/decoding. * <P> * * The client can connect to the server in two different ways. The * client can locate the server using an IOR file that the server has * written. This IOR file is read using an URL. The server can also be * located using the CORBA naming service. The name should be in a * three part fomat <ROOT name>/ <PART2>/ <PART3>. The root name has * to be known by the nameserver and the entire string has to be used * by the server on startup. If both the IOR and name string are set, * the IOR is the thing that gets used. */public class CRFPClient implements RpfFrameProvider { /** The property specifying the IOR URL. */ public static final String iorUrlProperty = "ior"; /** The name of the server, using the name service. */ public static final String nameProperty = "name"; /** The property specifying the initial JPEG quality. */ public static final String JPEGQualityProperty = "jpegQuality"; /** The CRFPServer. */ protected transient Server server = null; /** The string used for the CORBA naming service. */ protected String naming = null; /** The URL used for the IOR, to connect to the server that way. */ protected URL iorURL = null; private String clientID = Environment.generateUniqueString(); /** * The compression quality of the images. Lower quality images are * smaller. */ public float jpegQuality = .8f; /** * We'll set up the connection to the server when it's needed, but * not here. */ public CRFPClient() {} /** * Set the JPEG quality parameter for subframe transfer. * * @param jq number between 0 and 1, should be between .4 and .8. * Anything else is a waste. */ public void setJpegQuality(float jq) { jpegQuality = jq; } /** * Get the quality setting for JPEG subframe retrieval. * * @return float reflecting JPEG quality. */ public float getJpegQuality() { return jpegQuality; } /** * Set the name used for the CORBA naming service. */ public void setNaming(String CORBAName) { naming = CORBAName; } /** * Get the name used for the CORBA naming service. */ public String getNaming() { return naming; } /** * If you want to connect to the server using an ior, set the URL * where it is located. */ public void setIorURL(URL iorurl) { iorURL = iorurl; } /** * Get the URL for the ior. */ public URL getIorURL() { return iorURL; } /** * Get the clientID string that is used by the server to keep * track of clients. This string in internally generated. */ public String getClientID() { return clientID; } /** * Set all the RPF properties from a properties object. */ public void setProperties(String prefix, java.util.Properties properties) { prefix = PropUtils.getScopedPropertyPrefix(prefix); jpegQuality = PropUtils.floatFromProperties(properties, prefix + JPEGQualityProperty, .8f); String url = properties.getProperty(prefix + iorUrlProperty); if (url != null) { try { iorURL = PropUtils.getResourceOrFileOrURL(url); } catch (MalformedURLException e) { throw new IllegalArgumentException("\"" + url + "\"" + " is malformed."); } } naming = properties.getProperty(prefix + nameProperty); } /** * When the client is deleted, it should sign off from the server, * so that it can free up it's cache for it. */ protected void finalize() { if (Debug.debugging("crfp")) { Debug.output("CRFPClient.finalize(): calling shutdown"); } try { if (server != null) { server.signoff(clientID); } server = null; } catch (org.omg.CORBA.SystemException e) { Debug.error("CRFPClient.finalize(): " + e); } catch (Throwable t) { Debug.error("CRFPClient.finalize(): " + t); } } /** * Returns true because the view attributes should be set if they * change at the RpfCacheHandler/RpfCacheManager. */ public boolean needViewAttributeUpdates() { return true; } /** * Set the RpfViewAttribute object parameters, which describes * alot about what you'll be asking for later. * * @param rva the view attributes. */ public void setViewAttributes(RpfViewAttributes rva) { Server serv = getServer(); if (serv == null || rva == null) { return; } try { serv.setViewAttributes(new CRFPViewAttributes((short) rva.numberOfColors, (short) rva.opaqueness, rva.scaleImages, rva.imageScaleFactor, rva.chartSeries), clientID); Debug.message("crfp", "CRFPClient: setting attributes."); } catch (org.omg.CORBA.SystemException e) { handleCORBAError(e); } } /** * Given a projection that describes a map or geographical area, * return RpfCoverageBoxes that let you know how to locate and ask * for RpfSubframes. * * @param ullat NW latitude. * @param ullon NW longitude * @param lrlat SE latitude * @param lrlon SE longitude * @param p a CADRG projection */ public Vector getCoverage(float ullat, float ullon, float lrlat, float lrlon, CADRG p) { CRFPCoverageBox[] boxes; Server serv = getServer(); if (serv == null) return new Vector(); LLPoint llpoint = new LLPoint(p.getCenter().getLatitude(), p.getCenter() .getLongitude()); CRFPCADRGProjection proj = new CRFPCADRGProjection(llpoint, (short) p.getHeight(), (short) p.getWidth(), p.getScale(), (short) p.getZone()); Debug.message("crfp", "CRFPClient: getting coverage from server."); try { boxes = serv.getCoverage(ullat, ullon, lrlat, lrlon, proj, clientID); return translateCRFPCoverageBoxes(boxes); } catch (org.omg.CORBA.SystemException e) { handleCORBAError(e); } return new Vector(); } /** * Given a projection that describes a map or geographical area, * return RpfCoverageBoxes that let you know what bounding boxes * of data are available. * * @param ullat NW latitude. * @param ullon NW longitude * @param lrlat SE latitude * @param lrlon SE longitude * @param p a CADRG projection */ public Vector getCatalogCoverage(float ullat, float ullon, float lrlat, float lrlon, CADRG p, String chartSeriesCode) { CRFPCoverageBox[] boxes; Server serv = getServer(); if (serv == null) return new Vector(); LLPoint llpoint = new LLPoint(p.getCenter().getLatitude(), p.getCenter() .getLongitude()); CRFPCADRGProjection proj = new CRFPCADRGProjection(llpoint, (short) p.getHeight(), (short) p.getWidth(), p.getScale(), (short) p.getZone()); Debug.message("crfp", "CRFPClient: getting catalog coverage from server."); try { boxes = serv.getCatalogCoverage(ullat, ullon, lrlat, lrlon, proj, chartSeriesCode, clientID); return translateCRFPCoverageBoxes(boxes); } catch (org.omg.CORBA.SystemException e) { handleCORBAError(e); } return new Vector(); } /** * Given an area and a two-letter chart series code, find the * percentage of coverage on the map that that chart series can * offer. If you want specific coverage information, use the * getCatalogCoverage call. * * @see #getCatalogCoverage(float ullat, float ullon, float lrlat, * float lrlon, CADRG p, String chartSeriesCode) */ public float getCalculatedCoverage(float ullat, float ullon, float lrlat, float lrlon, CADRG p, String chartSeries) { if (chartSeries.equalsIgnoreCase(RpfViewAttributes.ANY)) { return 0f; } Vector results = getCatalogCoverage(ullat, ullon, lrlat,
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -