📄 csvlinkhandler.java
字号:
* for each property should be the raw property name (without a * prefix) with a value that is a String that describes what the * property key represents, along with any other information about * the property that would be helpful (range, default value, * etc.). This method takes care of the basic LocationHandler * parameters, so any LocationHandlers that extend the * AbstractLocationHandler should call this method, too, before * adding any specific properties. * * @param list a Properties object to load the PropertyConsumer * properties into. If getList equals null, then a new * Properties object should be created. * @return Properties object containing PropertyConsumer property * values. If getList was not null, this should equal * getList. Otherwise, it should be the Properties object * created by the PropertyConsumer. */ public Properties getPropertyInfo(Properties list) { list = super.getPropertyInfo(list); list.remove(LatIndexProperty); list.remove(LonIndexProperty); list.put(Lat1IndexProperty, "The column index, in the location file, of the first node latitude."); list.put(Lon1IndexProperty, "The column index, in the location file, of the first node longitude."); list.put(Lat2IndexProperty, "The column index, in the location file, of the second node latitude."); list.put(Lon2IndexProperty, "The column index, in the location file, of the second node longitude."); list.put(DashIndexProperty, "The column index, in the location file, of the true/false dash indicator."); list.put(ColorIndexProperty, "The column index, in the location file, of the color string."); list.put(ThicknessIndexProperty, "The column index, in the location file, of the pixel thickness of the link."); list.put(GeoStyleIndexProperty, "The column index, in the location file, of the render type of the link."); return list; } protected boolean checkIndexSettings() { if (lat1Index == -1 || lon1Index == -1 || lat2Index == -1 || lon2Index == -1) { Debug.error("CSVLocationHandler: createData(): Index properties for Lat/Lon/Name are not set properly! lat index:" + latIndex + ", lon index:" + lonIndex); return false; } if (Debug.debugging("csvlocation")) { Debug.output("CSVLinkHandler: Reading File:" + locationFile + " lat1Index: " + lat1Index + " lon1Index: " + lon1Index + " lat2Index: " + lat2Index + " lon2Index: " + lon2Index + " geoStyleIndex: " + geoStyleIndex // + " linkTypeIndex: " + linkTypeIndex + " dashIndex: " + dashIndex + " colorIndex: " + colorIndex + " thicknessIndex: " + thicknessIndex); } return true; } protected TokenDecoder getTokenDecoder() { return new LinkDecoder(); } /** * Provides the palette widgets to control the options of showing * maps, or attribute text. * <P> * In this case, the palette widget only contains one button, * which reloads the data files for the layer. * <p> * * @return Component object representing the palette widgets. */ public Component getGUI() { JButton rereadFilesButton; JCheckBox showCSVLinkCheck; showCSVLinkCheck = new JCheckBox("Show Links", isShowLocations()); showCSVLinkCheck.setActionCommand(showLocationsCommand); showCSVLinkCheck.addActionListener(this); rereadFilesButton = new JButton("Re-Read Data File"); rereadFilesButton.setActionCommand(readDataCommand); rereadFilesButton.addActionListener(this); Box box = Box.createVerticalBox(); box.add(showCSVLinkCheck); box.add(rereadFilesButton); return box; } /* Utility functions */ /** * This gets a line-type from a token, and translates it into one * of LINETYPE_STRAIGHT, LINETYPE_GREATCIRCLE, or LINETYPE_RHUMB. * * @param token the token read from the CSV file. * @return one of LINETYPE_STRAIGHT, LINETYPE_GREATCIRCLE, or * LINETYPE_RHUMB */ protected int getLineTypeFromToken(Object token) { int default_lintetype = OMGraphic.LINETYPE_STRAIGHT; String tokstring = ((String) token).trim().toLowerCase(); if (Debug.debugging("csvlocation")) { Debug.output("CSVLinkHandler:getLineTypeFromToken(" + tokstring + ")"); } if (tokstring.startsWith("s")) return OMGraphic.LINETYPE_STRAIGHT; else if (tokstring.startsWith("g")) return OMGraphic.LINETYPE_GREATCIRCLE; else if (tokstring.startsWith("r")) return OMGraphic.LINETYPE_RHUMB; else { Debug.error("Don't understand Linetype " + tokstring + ", using default (STRAIGHT)"); return default_lintetype; } } /** * This interprets a color value from a token. The color can be * one of the standard colors in the java.awt.Color class, or it * can be a hexadecimal representation of any other displayable * color. * <p> * * @param token the token read from the CSV file. * <p> * @return the java.awt.Color described by that token, or * Color.black (if the token cannot be translated into a * proper color). */ protected Color getColorFromToken(Object token) { String tokstring = (String) token; if (Debug.debugging("csvlocation")) { Debug.output("CSVLinkHandler: getColorFromToken(" + tokstring + ")"); } Color c = ColorFactory.getNamedColor(tokstring, null); if (c == null) { // decode a hex color string. c = Color.decode(tokstring); if (c == null) { c = Color.BLACK; } } if (Debug.debugging("csvlocation")) { Debug.output("CSVLinkHandler: getColorFromToken returns (" + c + ")"); } return c; } public class LinkDecoder implements TokenDecoder { float lat1; float lon1; float lat2; float lon2; int linetype; Color color; boolean dashed; float thickness; public LinkDecoder() { reset(); } public void reset() { lat1 = 0; lon1 = 0; lat2 = 0; lon2 = 0; linetype = OMGraphic.LINETYPE_GREATCIRCLE; color = (Color) getLocationDrawingAttributes().getLinePaint(); dashed = false; thickness = 1f; } public void handleToken(Object token, int i) { try { if (i == lat1Index) lat1 = ((Double) token).floatValue(); else if (i == lon1Index) lon1 = ((Double) token).floatValue(); else if (i == lat2Index) lat2 = ((Double) token).floatValue(); else if (i == lon2Index) lon2 = ((Double) token).floatValue(); else if (i == geoStyleIndex) linetype = getLineTypeFromToken(token); // These are going to go away... else if (i == colorIndex) color = getColorFromToken(token); else if (i == thicknessIndex) thickness = ((Double) token).floatValue(); else if (i == dashIndex) dashed = Boolean.valueOf((String) token).booleanValue(); } catch (NumberFormatException nfe) { } } public void createAndAddObjectFromTokens(DataOrganizer organizer) { // Original Lines added to this else block to fix // reading a data file with a header in it. Link link = new Link(lat1, lon1, lat2, lon2, "No details", color, dashed, thickness, linetype); link.setLocationHandler(CSVLinkHandler.this); // What we really want to do is get the // locationDrawingAttributes and set them on the link. Debug.message("csvlocation", "CSVLinkHandler: " + link.getDetails()); organizer.put(lat1, lon1, link); organizer.put(lat2, lon2, link); reset(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -