/** * This function would return a Color object for string such as red, green,.. (all that are * available from java.awt.color class). It can also return a specific color represented by HEX or * Octal number like 0xffeeffee */ protected Color GetColorFromString(String token) { String tokstring = (String) token; Color result = Color.black; if (Debug.debugging("areas")) { Debug.output("AreaHandler: GetColorFromString(" + tokstring + ")"); } // Thank the heavens for Emacs macros! if (tokstring.equals("black")) result = Color.black; else if (tokstring.equals("blue")) result = Color.blue; else if (tokstring.equals("cyan")) result = Color.cyan; else if (tokstring.equals("darkGray")) result = Color.darkGray; else if (tokstring.equals("gray")) result = Color.gray; else if (tokstring.equals("green")) result = Color.green; else if (tokstring.equals("lightGray")) result = Color.lightGray; else if (tokstring.equals("magenta")) result = Color.magenta; else if (tokstring.equals("orange")) result = Color.orange; else if (tokstring.equals("pink")) result = Color.pink; else if (tokstring.equals("red")) result = Color.red; else if (tokstring.equals("white")) result = Color.white; else if (tokstring.equals("yellow")) result = Color.yellow; else // decode a hex color string. result = Color.decode(tokstring); if (Debug.debugging("areas")) { Debug.output("AreaHandler.GetColorFromToken returns (" + result + ")"); } return result; }
/** * Initializes this object from the given properties * * @param props the <code>Properties</code> holding settings for this object */ public void setProperties(String prefix, Properties props) { if (Debug.debugging("areas")) { Debug.output("AreaHandler: setting properties"); } setPropertyPrefix(prefix); originalProperties = props; // These will get initialized when someone asks for it. // Otherwise, it delays the startup of the map. politicalAreas = null; String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); String transClassName = props.getProperty(realPrefix + ShapeLayer.TransformProperty); if (transClassName != null) { try { coordTransform = (GeoCoordTransformation) ComponentFactory.create( transClassName, realPrefix + ShapeLayer.TransformProperty, props); } catch (ClassCastException cce) { } } }
/** * Add content to this Group. The OMGraphicHandler layers that are part of the map with have their * graphics may be added with a small separation between the layers, depending on the value of * layerSeparation. * * @param mapHandler Description of the Parameter */ protected void createMap(MapHandler mapHandler) { double baselineHeight = layerSeparation; LayerHandler lh = (LayerHandler) mapHandler.get("com.bbn.openmap.LayerHandler"); if (lh != null) { Debug.message("3d", "LayerMapContent: putting layer graphics on the map."); Layer[] layers = lh.getLayers(); // Back to front makes the sea in the back, and keeps // first layers on top, to go with the OpenMap paradigm. for (int i = layers.length - 1; i >= 0; i--) { Layer layer = layers[i]; if (layer.isVisible()) { if (layer instanceof ScaleFilterLayer) { ScaleFilterLayer sfl = (ScaleFilterLayer) layer; layer = sfl.getAppropriateLayer(); } if (layer instanceof OMGraphicHandlerLayer) { addContent(this, (OMGraphicHandlerLayer) layer, baselineHeight += layerSeparation); } else { Debug.message("3d", "LayerMapContent: skipping layer " + layer.getName()); } } } } addSea(this, mapHandler); }
/** * The method needs more information from the properties than the CodePosition version of this * method provides, like getting the base symbol code for the scheme and the hierarchy addition. */ public CodePosition addPositionChoice(int index, String entry, String prefix, Properties props) { CodeScheme cs = (CodeScheme) super.addPositionChoice(index, entry, prefix, props); prefix = PropUtils.getScopedPropertyPrefix(prefix) + entry + "."; String next = props.getProperty(prefix + NextProperty); if (next != null) { String nextClassName = props.getProperty(next + ".class"); if (nextClassName != null) { CodePosition cp = (CodePosition) ComponentFactory.create(nextClassName); if (DEBUG) { Debug.output("CodeScheme created next class(" + next + "), " + nextClassName); } if (cp != null) { cs.nextPosition = cp; cp.parsePositions(next, props); } } else { if (DEBUG) { Debug.output("CodeScheme couldn't create next class(" + next + "), " + nextClassName); } } } cs.defaultSymbolCode = props.getProperty(prefix + DefaultSymbolCodeProperty); cs.hierarchyAddition = props.getProperty(prefix + HierarchyCodeAdditionProperty, ""); // Don't need to add to choices, already done in super class // method. return cs; }
/** * Create and set the graphic within the state machine. The GraphicAttributes describe the type of * poly to create. */ public void createGraphic(GraphicAttributes ga) { init(); stateMachine.setUndefined(); int renderType = OMGraphic.RENDERTYPE_LATLON; int lineType = OMGraphic.LINETYPE_GREATCIRCLE; if (ga != null) { renderType = ga.getRenderType(); lineType = ga.getLineType(); } if (Debug.debugging("eomg")) { Debug.output("EditableOMDistance.createGraphic(): rendertype = " + renderType); } if (lineType == OMGraphic.LINETYPE_UNKNOWN) { lineType = OMGraphic.LINETYPE_GREATCIRCLE; ga.setLineType(OMGraphic.LINETYPE_GREATCIRCLE); } this.poly = (OMDistance) createGraphic(renderType, lineType); if (ga != null) { ga.setRenderType(poly.getRenderType()); ga.setTo(poly, true); } }
public void finalize() { if (getGraphic() != null) { getGraphic().setVisible(true); } if (Debug.debugging("gc")) { Debug.output("EditableOMGraphic gone."); } }
/** * DeterminePoliticalAreas goes over a list of omgraphics, and spits out a hashtable that holds * PoliticalArea objects for every area key. * * @param graphicList the list of graphics. The top level graphic entries on the list represent * areas. */ public Hashtable determinePoliticalAreas(OMGraphicList graphicList) { if (Debug.debugging("areas")) { Debug.output("AreaHandler: Determining political areas from OMGraphicList"); } Hashtable poli_areas = new Hashtable(); return determinePoliticalAreas(graphicList, poli_areas); }
/** * Parse the hierarchy properties to create SymbolParts for those parts under a particular scheme * represented by this instance of CodeScheme. * * @param hCode the hierarchy code of this scheme, used to grow the tree for subsequent * generations. * @param props the hierarchy properties. * @param parent the SymbolPart parent that the new SymbolPart tree falls under. */ public void parseHierarchy(String hCode, Properties props, SymbolPart parent) { List codePositionList = null; if (nextPosition != null) { codePositionList = nextPosition.getPositionChoices(); } if (codePositionList == null || codePositionList.isEmpty()) { Debug.output(prettyName + ".parseHierarchy(): codePositionList.size = 0"); return; } List parentList = null; for (Iterator it = codePositionList.iterator(); it.hasNext(); ) { CodePosition cp = (CodePosition) it.next(); String newHCode = hCode + "." + cp.getHierarchyNumber(); if (DEBUG) { Debug.output("CodeScheme.parse: " + newHCode + " with " + cp.getPrettyName()); } String entry = props.getProperty(newHCode); if (entry != null) { SymbolPart sp = new SymbolPart(cp, entry, props, parent); if (parentList == null) { parentList = parent.getSubs(); if (parentList == null) { parentList = new ArrayList(); parent.setSubs(parentList); } } if (DEBUG) { Debug.output( "CodeScheme.parse: adding " + sp.getPrettyName() + " to " + parent.getPrettyName()); } parentList.add(sp); if (DEBUG) { Debug.output( "CodeScheme.parse: handling " + cp.getPrettyName() + " children for " + sp.getPrettyName()); } cp.parseHierarchy(newHCode, props, sp); } else { if (DEBUG) { Debug.output("CodeScheme.parse: no entry found for " + newHCode); } } } }
/** * Send a Paint event to all registered listeners. * * @param graphics PaintEvent */ public void paint(Graphics graphics) { if (isEmpty()) return; for (PaintListener target : this) { if (Debug.debugging("paint")) { Debug.output("PaintListenerSupport.paint(): target is: " + target); } target.listenerPaint(getSource(), graphics); } }
/** * Takes a name of a file, and checks to see if it reflects an entry in a jar file. (Check the * filename and see if it looks like "jarfile!jarfileentry".) If it is, it separates the path, and * set the inputReader to a JarInputReader and returns true. If not, it returns false. */ protected boolean setJarInputReader(final String name) throws IOException { try { final int index = name.indexOf("!"); if (index != -1) { // Used to be this, modified by Erik Sanders to work // with jdk 1.4 plugin // String jarFileName = // name.substring(name.indexOf(":") + 1, index); // changed to this... String jarFileName; if (name.startsWith("file:")) { // java-plugin 1.3 returns local file: strip file: // from string jarFileName = name.substring(name.indexOf(":") + 1, index); } else { // java-plugin 1.4 returns reference to server, so // leave http:// part // Used to start the substring from 1, but changed // to 0 thanks to DGK jarFileName = name.substring(0, index); } // skip !/ " final String jarEntryName = name.substring(index + 2); if (Debug.debugging("binaryfile")) { Debug.output(" got: \n" + jarFileName + "\n" + jarEntryName); } // If the jar doesn't exist, should return something // that indicates this. Should check the performance // impllications of this call, though, at some point. // DGK added final File f = new File(jarFileName); if (f.exists() == false) { return false; } setInputReader(new JarInputReader(jarFileName, jarEntryName)); return true; } } catch (final java.security.AccessControlException ace) { if (Debug.debugging("binaryfile")) { Debug.output("BinaryFile.setJarInputFile: AccessControlException for " + name); } } return false; }
/** * Filters the OMGraphicHandler graphic list so that graphics inside or outside the given shape * will be visible. Returns an OMGraphicList with those visible shapes. The returned list should * not be assumed to be the same OMGraphicList object that is maintained inside the * OMGraphicHandler. * * @param shapeBoundary java.awt.Shape object defining a boundary. * @param getInsideBoundary if true, the filter will look for shapes inside and contacting the * boundary. If false, the filter will look for shapes outside the boundary. * @return OMGraphicList containing OMGraphics that are within the Shape. */ public OMGraphicList filter(Shape shapeBoundary, boolean getInsideBoundary) { Area area = null; if (shapeBoundary != null) { area = new Area(shapeBoundary); } if (Debug.debugging("filtersupportdetail")) { Debug.output(getList().getDescription()); } return filterList(getList(), area, getInsideBoundary); }
/** Read a cache of OMGraphics */ public OMGraphicList readCachedGraphics(URL url) throws java.io.IOException { if (Debug.debugging("areas")) { Debug.output("Reading cached graphics"); } OMGraphicList omgraphics = new OMGraphicList(); if (url != null) { omgraphics.readGraphics(url); } return omgraphics; }
/** From the Runnable interface. The thread starts here... */ public void run() { try { handleClient(); } catch (IOException ioe) { link.cleanUp(); link = null; if (com.bbn.openmap.util.Debug.debugging("link")) { System.err.println(ioe); } com.bbn.openmap.util.Debug.output("LinkServer: Client disconnected"); System.gc(); } }
/** * This main function basically reads in the data sources (the shape file and the csv information * file, and creates a serialized graphics file that will act like a cache later. */ public static void main(String[] argv) { String propertiesFile = null; String prefix = null; String outputFile = null; Debug.init(); if (argv.length < 6) printUsage(); for (int i = 0; i < argv.length; i++) { if (argv[i].equalsIgnoreCase("-props")) { propertiesFile = argv[++i]; } else if (argv[i].equalsIgnoreCase("-prefix")) { prefix = argv[++i]; } else if (argv[i].equalsIgnoreCase("-file")) { outputFile = argv[++i]; } } if (propertiesFile == null || prefix == null || outputFile == null) { printUsage(); } try { Properties properties = new Properties(); // Read in the properties. URL propertiesURL = new URL(propertiesFile); InputStream is = propertiesURL.openStream(); properties.load(is); // Let's make a file ShapeLayer sl = new ShapeLayer(); sl.setProperties(prefix, properties); AreaHandler ah = new AreaHandler(sl.getSpatialIndex(), sl.getDrawingAttributes()); // Set the properties in the handler. ah.setProperties(prefix, properties); // Write the saved graphics. ah.getGraphics().writeGraphics(outputFile); } catch (java.net.MalformedURLException murle) { Debug.error("Bad URL for properties file : " + propertiesFile); printUsage(); } catch (java.io.IOException ioe) { Debug.error("IOException creating cached graphics file: " + outputFile); printUsage(); } }
/** * Method to set the properties in the PropertyConsumer. The prefix is a string that should be * prepended to each property key (in addition to a separating '.') in order for the * PropertyConsumer to uniquely identify properties meant for it, in the midst of Properties meant * for several objects. * * @param prefix a String used by the PropertyConsumer to prepend to each property value it wants * to look up - setList.getProperty(prefix.propertyKey). If the prefix had already been set, * then the prefix passed in should replace that previous value. * @param setList a Properties object that the PropertyConsumer can use to retrieve expected * properties it can use for configuration. */ public void setProperties(String prefix, Properties setList) { super.setProperties(prefix, setList); prefix = PropUtils.getScopedPropertyPrefix(prefix); wmsServer = setList.getProperty(prefix + WMSServerProperty); if (wmsServer == null) { Debug.error("WMSPlugIn needs a WMS server."); } queryHeader = wmsServer; setImageFormat(setList.getProperty(prefix + ImageFormatProperty, getImageFormat())); setTransparent(setList.getProperty(prefix + TransparentProperty, getTransparent())); setBackgroundColor(setList.getProperty(prefix + BackgroundColorProperty, getBackgroundColor())); setWmsVersion(setList.getProperty(prefix + WMSVersionProperty, getWmsVersion())); layers = setList.getProperty(prefix + LayersProperty); styles = setList.getProperty(prefix + StylesProperty); /** Include for vendor specific parameters */ setVendorSpecificNames( setList.getProperty(prefix + VendorSpecificNamesProperty, getVendorSpecificNames())); setVendorSpecificValues( setList.getProperty(prefix + VendorSpecificValuesProperty, getVendorSpecificValues())); } // end setProperties
/** * Called when some fundamental parameters change. * * <p>Each projection will decide how to respond to this change. For instance, they may need to * recalculate "constant" parameters used in the forward() and inverse() calls. * * <p> */ protected void computeParameters() { Debug.message("proj", "Gnomonic.computeParameters()"); super.computeParameters(); // maxscale = scale at which a world hemisphere fits in the // window maxscale = (width < height) ? (float) (planetPixelRadius * 2 * hPrime) / (float) width : (float) (planetPixelRadius * 2 * hPrime) / (float) height; if (maxscale < minscale) { maxscale = minscale; } if (scale > maxscale) { scale = maxscale; } scaled_radius = planetPixelRadius / scale; // width of the world in pixels at current scale. We see only // one hemisphere. world.x = (int) ((planetPixelRadius * 2 * hPrime) / scale); // do some precomputation of stuff cosCtrLat = Math.cos(centerY); sinCtrLat = Math.sin(centerY); // compute the offsets hy = height / 2; wx = width / 2; }
/** Write an OMPoint to the Link. */ public static void write(OMPoint point, Link link, LinkProperties props) throws IOException { props.setProperty(LinkPoint.LPC_POINT_OVAL, point.isOval() ? "true" : "false"); switch (point.getRenderType()) { case OMPoint.RENDERTYPE_LATLON: LinkPoint.write( (float) point.getLat(), (float) point.getLon(), point.getRadius(), props, link.dos); break; case OMPoint.RENDERTYPE_XY: LinkPoint.write(point.getX(), point.getY(), point.getRadius(), props, link.dos); break; case OMPoint.RENDERTYPE_OFFSET: LinkPoint.write( (float) point.getLat(), (float) point.getLon(), point.getX(), point.getY(), point.getRadius(), props, link.dos); break; default: Debug.error("LinkPoint.write: point rendertype unknown."); } }
public void actionPerformed(ActionEvent ae) { if (map != null) { Proj proj = (Proj) map.getProjection(); DataBounds bounds = provider.getDataBounds(); if (bounds != null) { java.awt.geom.Point2D center = bounds.getCenter(); if (center != null) { proj.setCenter((float) center.getY(), (float) center.getX()); LatLonPoint llp1 = new LatLonPoint(bounds.getMax().getY(), bounds.getMin().getX()); LatLonPoint llp2 = new LatLonPoint(bounds.getMin().getY(), bounds.getMax().getX()); // 1.1 buffers the edges for viewing a little, a // little zommed out. proj.setScale(ProjMath.getScale(llp1, llp2, proj) * 1.1f); map.setProjection(proj); } } else { String complaint = "Can't move map over data: " + provider.getName() + " isn't ready. Add to map?"; if (infoDelegator != null) { infoDelegator.displayMessage("Go Over Data", complaint); } else { Debug.error(complaint); } } } }
/** * This function takes an OMGraphicList and loads each one with the array representing the records * in the dbf file. Each graphics stores the graphic in its object slot. */ public void loadDbfModelIntoGraphics(OMGraphicList list) { if (list != null && dbfModel.getRowCount() > 0) { int numgraphics = list.size(); for (int i = 0; i < numgraphics; i++) { try { OMGraphic omg = list.getOMGraphicAt(i); Integer recnum = (Integer) (omg.getAttribute(ShapeConstants.SHAPE_INDEX_ATTRIBUTE)); // OFF BY ONE!!! The shape record numbers // assigned to the records start with 0, while // everything else we do starts with 0. The DbfTableModel // follows java convention and starts at 0. The integer // stored in the OMG should know it too. Object inforec = dbfModel.getRecord(recnum.intValue()); omg.putAttribute(ShapeConstants.SHAPE_DBF_INFO_ATTRIBUTE, inforec); } catch (ClassCastException cce) { if (Debug.debugging("shape")) { cce.printStackTrace(); } } catch (NullPointerException npe) { npe.printStackTrace(); } } } }
/** * Inverse project x,y coordinates into a LatLonPoint. * * @param x integer x coordinate * @param y integer y coordinate * @param llp LatLonPoint * @return LatLonPoint llp * @see Proj#inverse(Point2D) */ public <T extends Point2D> T inverse(double x, double y, T llp) { if (llp == null) { llp = (T) new LatLonPoint.Double(); } // convert from screen to world coordinates x -= wx; y = hy - y; // Debug.output("Gnomonic.inverse: x,y=" + x + "," + y); double rho = Math.sqrt(x * x + y * y); if (rho == 0) { Debug.message("proj", "Gnomonic.inverse: center!"); llp.setLocation(ProjMath.radToDeg(centerX), ProjMath.radToDeg(centerY)); return llp; } double c = Math.atan2(rho, scaled_radius); double cosC = Math.cos(c); double sinC = Math.sin(c); // calculate latitude double lat = Math.asin(cosC * sinCtrLat + (y * sinC * (cosCtrLat / rho))); // calculate longitude double lon = centerX + Math.atan2((x * sinC), (rho * cosCtrLat * cosC - y * sinCtrLat * sinC)); // Debug.output("Gnomonic.inverse: lat,lon=" + // ProjMath.radToDeg(lat) + "," + // ProjMath.radToDeg(lon)); // check if point in outer space // if (MoreMath.approximately_equal(lat, ctrLat) && // MoreMath.approximately_equal(lon, ctrLon) && // (Math.abs(x-(width/2))<2) && // (Math.abs(y-(height/2))<2)) if (Double.isNaN(lat) || Double.isNaN(lon)) { Debug.message("proj", "Gnomonic.inverse(): outer space!"); lat = centerY; lon = centerX; } llp.setLocation(Math.toDegrees(wrapLongitude(lon)), Math.toDegrees(normalizeLatitude(lat))); return llp; }
/** Set the OMGraphicList within this OMGraphicHandler. Works if canSetGraphicList == true. */ public synchronized void setList(OMGraphicList omgl) { if (DEBUG) { Debug.output( "FilterSupport.setList() with " + (omgl != null ? omgl.size() + " graphics." : "null list.")); } list = omgl; }
/** * Return the graphic list currently being used by the OMGraphicHandler. If filters have been * applied, then the OMGraphics that have made it through the filter are visible. List may be * null, if it hasn't been set. * * @see OMGraphic#isVisible(). */ public synchronized OMGraphicList getList() { if (DEBUG) { Debug.output( "FilterSupport.getList() with " + (list != null ? list.size() + " graphics." : "null list.")); } return list; }
/** * Use the current projection to place the graphics on the screen. Has to be called to at least * assure the graphics that they are ready for rendering. Called when the graphic position * changes. * * @param proj com.bbn.openmap.proj.Projection * @return true */ public boolean generate(Projection proj) { Debug.message("eomg", "EditableOMPoly.generate()"); if (poly != null) { poly.generate(proj); } generateGrabPoints(proj); return true; }
/** * Paints the layer. * * @param g the Graphics context for painting */ public void paint(java.awt.Graphics g) { Debug.message("dted", getName() + "|DTEDLayer.paint()"); super.paint(g); if (location != null) location.render(g); location = null; }
/** Get all the graphics from the shapefile, colored appropriately. */ public OMGraphicList getGraphics() { if (omgraphics == null) { omgraphics = new OMGraphicList(); try { spatialIndex.getOMGraphics( -180, -90, 180, 90, omgraphics, drawingAttributes, (Projection) null, coordTransform); updateDrawingParameters(omgraphics); } catch (IOException ioe) { Debug.error(ioe.getMessage()); } catch (FormatException fe) { Debug.error(fe.getMessage()); } } return omgraphics; }
/** * Given a new projection, the grab points may need to be repositioned off the current position of * the graphic. Called when the projection changes. */ public void regenerate(Projection proj) { Debug.message("eomg", "EditableOMPoly.regenerate()"); if (poly != null) { poly.generate(proj); setGrabPoints(poly); } generateGrabPoints(proj); }
/** * Draw the EditableOMPoly parts into the java.awt.Graphics object. The grab points are only * rendered if the poly machine state is PolySelectedState.POLY_SELECTED. * * @param graphics java.awt.Graphics. */ public void render(java.awt.Graphics graphics) { Debug.message("eomg", "EditableOMPoly.render()"); State state = getStateMachine().getState(); if (poly != null && !(state instanceof PolyUndefinedState)) { poly.setVisible(true); poly.render(graphics); poly.setVisible(false); } else { Debug.message("eomg", "EditableOMPoly.render: null or undefined poly."); return; } // Render the points actually on the polygon if (state instanceof GraphicSelectedState || state instanceof PolyAddNodeState || state instanceof PolyDeleteNodeState) { for (GrabPoint gb : polyGrabPoints) { if (gb != null) { gb.setVisible(true); gb.render(graphics); gb.setVisible(false); } } } // In certain conditions, render the offset grab point. if (state instanceof GraphicSelectedState || state instanceof GraphicEditState /* * || * state * instanceof * PolySetOffsetState */) { if (gpo != null && poly.getRenderType() == OMGraphic.RENDERTYPE_OFFSET) { gpo.setVisible(true); gpo.render(graphics); gpo.setVisible(false); } } }
protected void addSubfield(DDFSubfield ddfs) { if (Debug.debugging("iso8211")) { Debug.output("DDFField(" + getFieldDefn().getName() + ").addSubfield(" + ddfs + ")"); } String sfName = ddfs.getDefn().getName().trim().intern(); Object sf = subfields.get(sfName); if (sf == null) { subfields.put(sfName, ddfs); } else { if (sf instanceof List) { ((List) sf).add(ddfs); } else { Vector subList = new Vector(); subList.add(sf); subList.add(ddfs); subfields.put(sfName, subList); } } }
/** * Prints a VPF Library * * @param prefix lines get printed with this prefix * @param cat the CoverageAttributeTable (Library) to print */ public static void printLibrary(String prefix, CoverageAttributeTable cat) { StringBuffer printedlayers = new StringBuffer(); String printedlayername = null; if (cat == null) { System.err.println(prefix + "Library doesn't exist"); return; } String[] coverages = cat.getCoverageNames(); if (Debug.debugging("vpf")) { Debug.output(prefix + "uses " + (cat.isTiledData() ? "tiled" : "untiled") + " data"); } for (int i = 0; i < coverages.length; i++) { printedlayername = printCoverageProperties(prefix, cat, coverages[i]); if (printedlayername != null) { printedlayers.append(" " + printedlayername); } } println("# Summary:" + printedlayers); }
public void setCacheSize(int cs) { if (cs > 0) { cacheSize = cs; } else { Debug.output( "DTEDLayer (" + getName() + ") being told to set cache size to invalid value (" + cs + ")."); } }