📄 locationlayer.java
字号:
return dataHandlerNames; } /** * Called when the LocationHandlers are reset, or their names are reset, to * refresh the palette with the new information. */ protected void resetPalette() { box = null; super.resetPalette(); } /** * Overridden from Layer because we are placing our own scroll pane around * the LocationHandler GUIs. */ protected WindowSupport createWindowSupport() { return new WindowSupport(getGUI(), getName()); } // ---------------------------------------------------------------------- // GUI // ---------------------------------------------------------------------- protected Box box = null; /** * Provides the palette widgets to control the options of showing maps, or * attribute text. * * @return Component object representing the palette widgets. */ public java.awt.Component getGUI() { if (box == null) { box = Box.createVerticalBox(); int nHandlers = 0; if (dataHandlers != null) { nHandlers = dataHandlers.length; } JPanel[] panels = new JPanel[nHandlers]; Box box2 = Box.createVerticalBox(); for (int i = 0; i < nHandlers; i++) { String handlerName; if (dataHandlerNames != null && i < dataHandlerNames.length) { handlerName = dataHandlerNames[i]; } else { handlerName = ""; } panels[i] = PaletteHelper.createPaletteJPanel(handlerName); panels[i].add(dataHandlers[i].getGUI()); // box.add(panels[i]); box2.add(panels[i]); } JScrollPane scrollPane = new JScrollPane(box2, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT); scrollPane.setAlignmentY(java.awt.Component.TOP_ALIGNMENT); box.add(scrollPane); if (declutterMatrix != null) { JPanel dbp = new JPanel(new GridLayout(0, 1)); JCheckBox declutterButton = new JCheckBox(i18n.get(LocationLayer.class, "declutterNames", "Declutter Names"), useDeclutterMatrix); declutterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JCheckBox jcb = (JCheckBox) ae.getSource(); useDeclutterMatrix = jcb.isSelected(); if (isVisible()) { doPrepare(); } } }); declutterButton.setToolTipText(i18n.get(LocationLayer.class, "declutterNames", I18n.TOOLTIP, "<HTML><BODY>Move location names so they don't overlap.<br>This may take awhile if you are zoomed out.</BODY></HTML>")); dbp.add(declutterButton); box.add(dbp); } } return box; } // ------------------------------------------------------------ // MapMouseListener implementation // ------------------------------------------------------------ /** Given a mouse event, find the closest location on the screen. */ public Location findClosestLocation(MouseEvent evt) { Vector graphics = getGraphicList(); if (graphics != null) { int x = evt.getX(); int y = evt.getY(); float limit = 4.0f; Location ret = null; Location loc; float closestDistance = Float.MAX_VALUE; float currentDistance; int i; int size = graphics.size(); for (i = 0; i < size; i++) { loc = (Location) graphics.elementAt(i); currentDistance = loc.distance(x, y); if (currentDistance < closestDistance) { ret = loc; closestDistance = currentDistance; } } if (closestDistance <= limit) return ret; } return null; } public String[] getMouseModeServiceList() { String[] services = { SelectMouseMode.modeID }; return services; } protected void showMapPopup(MouseEvent evt, MapBean map) { if (backgroundMenu == null) { backgroundMenu = new LocationPopupMenu(); backgroundMenu.add(new LocationMenuItem(recenter, backgroundMenu, this)); backgroundMenu.add(new LocationMenuItem(cancel, backgroundMenu, this)); backgroundMenu.setMap(map); } backgroundMenu.setEvent(evt); backgroundMenu.show(this, evt.getX(), evt.getY()); } protected void showLocationPopup(MouseEvent evt, Location loc, MapBean map) { if (locMenu == null) { locMenu = new LocationPopupMenu(); locMenu.setMap(map); } locMenu.removeAll(); locMenu.setEvent(evt); locMenu.setLoc(loc); locMenu.add(new LocationMenuItem(LocationLayer.recenter, locMenu, this)); locMenu.add(new LocationMenuItem(LocationLayer.cancel, locMenu, this)); locMenu.addSeparator(); LocationHandler lh = loc.getLocationHandler(); if (lh != null) { lh.fillLocationPopUpMenu(locMenu); } locMenu.show(this, evt.getX(), evt.getY()); } public boolean mousePressed(MouseEvent evt) { if (!isVisible()) return false; Location loc = findClosestLocation(evt); if (map == null) { try { map = (MapBean) SwingUtilities.getAncestorOfClass(Class.forName("com.bbn.openmap.MapBean"), this); } catch (java.lang.ClassNotFoundException e) { Debug.error("LocationLayer: Whatza MapBean??"); } } if (loc == null) { // user clicked on map Debug.message("location", "Clicked on background"); showMapPopup(evt, map); } else { // user clicked on rate center Debug.message("location", "Clicked on location"); showLocationPopup(evt, loc, map); } return true; } public boolean mouseReleased(MouseEvent e) { return false; } public boolean mouseClicked(MouseEvent evt) { return false; } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public boolean mouseDragged(MouseEvent e) { return false; } boolean setNameOnLine = false; public boolean mouseMoved(MouseEvent evt) { if (!isVisible()) return false; Location loc = findClosestLocation(evt); if (loc == null) { if (setNameOnLine) { // only do this once. fireRequestInfoLine(""); setNameOnLine = false; } return false; // pass through!! } else { fireRequestInfoLine(loc.getName()); setNameOnLine = true; return true; } } public void mouseMoved() { // fireRequestInfoLine(""); } /** * PropertyConsumer method, to fill in a Properties object, reflecting the * current values of the layer. If the layer has a propertyPrefix set, the * property keys should have that prefix plus a separating '.' prepended to * each propery key it uses for configuration. * * @param props a Properties object to load the PropertyConsumer properties * into. If props 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 getProperties(Properties props) { props = super.getProperties(props); String prefix = PropUtils.getScopedPropertyPrefix(this); props.put(prefix + UseDeclutterMatrixProperty, new Boolean(useDeclutterMatrix).toString()); if (declutterMatrix != null) { props.put(prefix + DeclutterMatrixClassProperty, declutterMatrix.getClass().getName()); props.put(prefix + AllowPartialsProperty, new Boolean(declutterMatrix.isAllowPartials()).toString()); } StringBuffer handlerList = new StringBuffer(); // Need to hand this off to the location handlers, and build a // list of marker names to use in the LocationLayer property // list. if (dataHandlers != null) { for (int i = 0; i < dataHandlers.length; i++) { String pp = dataHandlers[i].getPropertyPrefix(); handlerList.append(" " + pp); props.put(pp + ".prettyName", dataHandlerNames[i]); dataHandlers[i].getProperties(props); } } props.put(prefix + LocationHandlerListProperty, handlerList.toString()); return props; } /** * Method to fill in a Properties object with values reflecting the * properties able to be set on this PropertyConsumer. The key 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.). For Layer, this method should at least * return the 'prettyName' property. * * @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); PropUtils.setI18NPropertyInfo(i18n, list, LocationLayer.class, UseDeclutterMatrixProperty, "Use Declutter Matrix", "Flag for using the declutter matrix.", "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor"); PropUtils.setI18NPropertyInfo(i18n, list, LocationLayer.class, DeclutterMatrixClassProperty, "Declutter Matrix Class", "Class name of the declutter matrix to use (com.bbn.openmap.layer.DeclutterMatrix).", null); PropUtils.setI18NPropertyInfo(i18n, list, LocationLayer.class, AllowPartialsProperty, "Allow partials", "Flag to allow labels to run off the edge of the map.", "com.bbn.openmap.util.propertyEditor.YesNoPropertyEditor"); PropUtils.setI18NPropertyInfo(i18n, list, LocationLayer.class, LocationHandlerListProperty, "Location Handlers", "Space-separated list of unique names to use to scope the LocationHandler property definitions.", null); if (dataHandlers != null) { for (int i = 0; i < dataHandlers.length; i++) { dataHandlers[i].getPropertyInfo(list); } } return list; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -