?? earthquakelayer.java
字號:
} try { quakefinger.close(); } catch (IOException e) { Debug.error("EarthquakeLayer.getEarthquakeData(): " + "error closing socket: " + e); } } // int nQuakes = linesOfData.size(); // for (int i=0; i<nQuakes; i++) { // Debug.output((String)linesOfData.elementAt(i)); // } return linesOfData; } // This is the USGS's date problem, not ours (of course when they // change their format, we'll have to update this). // Note that also this could just be a bogus line (not a dataline) // beginning with a number, so we've got to deal with it here. private String hackY2K(String date) { StringTokenizer tok = new StringTokenizer(date, "/"); String year, month, day; try { year = tok.nextToken(); month = tok.nextToken(); day = tok.nextToken(); } catch (NoSuchElementException e) { Debug.error("EarthquakeLayer: unparsable date: " + date); return null; } if (year.length() == 2) { int y; try { y = Integer.parseInt(year); } catch (NumberFormatException e) { Debug.error("EarthquakeLayer: invalid year: " + year); return null; } // Sliding window technique... if (y > 70) { date = "19"; } else { date = "20"; } } else if (year.length() != 4) { Debug.error("EarthquakeLayer: unparsable year: " + year); return null; } date = date + year + "/" + month + "/" + day; return date; } /** * Gets the gui controls associated with the layer. * * @return Component */ public Component getGUI() { JPanel p; if (gui == null) { gui = PaletteHelper.createVerticalPanel("Earthquakes"); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); gui.setLayout(gridbag); constraints.fill = GridBagConstraints.HORIZONTAL; // fill // horizontally constraints.gridwidth = GridBagConstraints.REMAINDER; //another // row constraints.anchor = GridBagConstraints.EAST; // tack to // the left // edge ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { int index = Integer.parseInt(e.getActionCommand(), 10); activeSites[index] = !activeSites[index]; } }; p = PaletteHelper.createCheckbox("Sites", fingerSites, activeSites, al); gridbag.setConstraints(p, constraints); gui.add(p); JButton b = new JButton("Query Now"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // force refetch of data lastDataFetchTime = 0; doPrepare(); } }); gridbag.setConstraints(p, constraints); gui.add(b); } return gui; } /** * Returns the MapMouseListener object that handles the mouse * events. * * @return the MapMouseListener for the layer, or null if none */ public MapMouseListener getMapMouseListener() { return this; } //---------------------------------------------------------------- // MapMouseListener interface methods //---------------------------------------------------------------- /** * Return a list of the modes that are interesting to the * MapMouseListener. The source MouseEvents will only get sent to * the MapMouseListener if the mode is set to one that the * listener is interested in. Layers interested in receiving * events should register for receiving events in "select" mode: * <code> * <pre> * return new String[] { SelectMouseMode.modeID }; * </pre> * <code> * @return String[] of modeID's * @see com.bbn.openmap.event.NavMouseMode#modeID * @see com.bbn.openmap.event.SelectMouseMode#modeID * @see com.bbn.openmap.event.NullMouseMode#modeID */ public String[] getMouseModeServiceList() { return new String[] { com.bbn.openmap.event.SelectMouseMode.modeID }; } /** * Invoked when a mouse button has been pressed on a component. * * @param e MouseEvent * @return true if the listener was able to process the event. */ public boolean mousePressed(MouseEvent e) { return false; } /** * Invoked when a mouse button has been released on a component. * * @param e MouseEvent * @return true if the listener was able to process the event. */ public boolean mouseReleased(MouseEvent e) { OMGraphicList omgraphics = getList(); if (omgraphics != null && drillData != null) { OMGraphic obj = omgraphics.findClosest(e.getX(), e.getY(), 4); if (obj != null) { int id = ((Integer) obj.getAppObject()).intValue(); fireRequestInfoLine(drillData[id]); showingInfoLine = true; return true; } } return false; } /** * Invoked when the mouse has been clicked on a component. The * listener will receive this event if it successfully processed * <code>mousePressed()</code>, or if no other listener * processes the event. If the listener successfully processes * mouseClicked(), then it will receive the next mouseClicked() * notifications that have a click count greater than one. * * @param e MouseEvent * @return true if the listener was able to process the event. */ public boolean mouseClicked(MouseEvent e) { return false; } /** * Invoked when the mouse enters a component. * * @param e MouseEvent */ public void mouseEntered(MouseEvent e) {} /** * Invoked when the mouse exits a component. * * @param e MouseEvent */ public void mouseExited(MouseEvent e) {} /** * Invoked when a mouse button is pressed on a component and then * dragged. The listener will receive these events if it * successfully processes mousePressed(), or if no other listener * processes the event. * * @param e MouseEvent * @return true if the listener was able to process the event. */ public boolean mouseDragged(MouseEvent e) { return false; } /** * Invoked when the mouse button has been moved on a component * (with no buttons down). * * @param e MouseEvent * @return true if the listener was able to process the event. */ public boolean mouseMoved(MouseEvent e) { // clean up display if (showingInfoLine) { showingInfoLine = false; fireRequestInfoLine(""); } return false; } /** * Handle a mouse cursor moving without the button being pressed. * This event is intended to tell the listener that there was a * mouse movement, but that the event was consumed by another * layer. This will allow a mouse listener to clean up actions * that might have happened because of another motion event * response. */ public void mouseMoved() {} //---------------------------------------------------------------- // PropertyConsumer Interface //---------------------------------------------------------------- /** * Set the properties of the EarthquakeLayer. * * @param prefix String * @param props Properties */ public void setProperties(String prefix, Properties props) { super.setProperties(prefix, props); prefix = PropUtils.getScopedPropertyPrefix(prefix); // list of sites String sites = props.getProperty(prefix + fingerSitesProperty); if (sites != null) { Vector v = new Vector(); String str; StringTokenizer tok = new StringTokenizer(sites); while (tok.hasMoreTokens()) { str = tok.nextToken(); v.addElement(str); } int len = v.size(); fingerSites = new String[len]; activeSites = new boolean[len]; activeSites[0] = true; for (int i = 0; i < len; i++) { fingerSites[i] = (String) v.elementAt(i); } } fetchIntervalMillis = PropUtils.intFromProperties(props, prefix + queryIntervalProperty, 300) * 1000; } /** * Get the associated properties object. */ public Properties getProperties(Properties props) { props = super.getProperties(props); return getProperties(propertyPrefix, props); } /** * Get the associated properties object. This method creates a * Properties object if necessary and fills it with the relevant * data for this layer. Relevant properties for EarthquakeLayers * are the sites to retrieve earth quake data from, and the * interval in milliseconds (see class description.) */ public Properties getProperties(String prefix, Properties props) { props = super.getProperties(props); prefix = PropUtils.getScopedPropertyPrefix(prefix); StringBuffer sitesToFinger = new StringBuffer(""); for (int i = 0; i < fingerSites.length; ++i) { sitesToFinger.append(fingerSites[i]); sitesToFinger.append(" "); } sitesToFinger.deleteCharAt(sitesToFinger.length() - 1); props.put(prefix + fingerSitesProperty, sitesToFinger.toString()); props.put(prefix + queryIntervalProperty, Long.toString(fetchIntervalMillis)); return props; } /** * Supplies the propertiesInfo object associated with this * EarthquakeLayer object. Contains the human readable * describtions of the properties and the * <code>initPropertiesProperty</code> (see Inspector class.) */ public Properties getPropertyInfo(Properties info) { info = super.getPropertyInfo(info); info.put(fingerSitesProperty, "WWW sites to finger"); info.put(queryIntervalProperty, "Query interval in seconds"); return info; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -