📄 layerspanel.java
字号:
layerButton.setBorderPainted(false); // layerButton.setToolTipText("Layer Controls"); layerButton.setToolTipText(i18n.get(LayersPanel.class, "layerButton", I18n.TOOLTIP, "Layer Controls")); layerButton.setMargin(new Insets(0, 0, 0, 0)); layerButton.addActionListener(getActionListener()); } return layerButton; } /** * Get the ActionListener that triggers the LayersPanel. Useful to have to * provide an alternative way to bring up the LayersPanel. * * @return ActionListener */ public ActionListener getActionListener() { return new ActionListener() { public void actionPerformed(ActionEvent evt) { WindowSupport ws = getWindowSupport(); int w = 328; int h = 300; Dimension dim = ws.getComponentSize(); if (dim != null) { w = (int) dim.getWidth(); h = (int) dim.getHeight(); } int x = 10; int y = 10; Point loc = ws.getComponentLocation(); if (loc != null) { x = (int) loc.getX(); y = (int) loc.getY(); } MapHandler mh = (MapHandler) getBeanContext(); Frame frame = null; if (mh != null) { frame = (Frame) mh.get(java.awt.Frame.class); } ws.displayInWindow(frame, x, y, w, h); } }; } /** * Set the layers that are in the LayersPanel. Make sure that the layer[] is * the same as that passed to any other OpenMap component, like the * LayersMenu. This method checks to see if the layer[] has actually * changed, in order or in size. If it has, then createPanel() is called to * rebuild the LayersPanel. * * @param inLayers the array of layers. */ public void setLayers(Layer[] inLayers) { Layer[] layers = inLayers; if (inLayers == null) { layers = new Layer[0]; } if (Debug.debugging("layerspanel")) { Debug.output("LayersPanel.setLayers() with " + layers.length + " layers."); } LinkedList panes = getPanes(); int separatorOffset = 0; if (backgroundLayerSeparator != null && panes.contains(backgroundLayerSeparator)) { separatorOffset = 1; } if (panes.size() - separatorOffset != layers.length) { // if the panel hasn't been created yet, or if someone has // changed the layers on us, rebuild the panel. createPanel(layers); return; } int i = 0; Iterator it = panes.iterator(); while (it.hasNext() && i < layers.length) { LayerPane pane = (LayerPane) it.next(); if (pane == backgroundLayerSeparator) { continue; } if (pane.getLayer() != layers[i]) { // If the layer order sways at all, then we start over // and rebuild the panel createPanel(layers); return; } else { pane.updateLayerLabel(); } // Do this just in case someone has changed something // somewhere else... pane.setLayerOn(layers[i].isVisible()); i++; } // One last check for a mismatch... if (it.hasNext() || i < layers.length) { createPanel(layers); } // If we get here, it means that what we had is what we // wanted. } protected LinkedList getPanes() { if (panes == null) { panes = new LinkedList(); } return panes; } protected void setPanes(LinkedList lpa) { panes = lpa; } /** * Create the panel that shows the LayerPanes. This method creates the * on/off buttons, palette buttons, and layer labels, and adds them to the * scrollPane used to display all the layers. * * @param inLayers the Layer[] that reflects all possible layers that can be * added to the map. */ public void createPanel(Layer[] inLayers) { Debug.message("layerspanel", "LayersPanel.createPanel()"); if (scrollPane != null) { remove(scrollPane); } Layer[] layers = inLayers; if (layers == null) { layers = new Layer[0]; } if (panesPanel == null) { panesPanel = new JPanel(); panesPanel.setLayout(new BoxLayout(panesPanel, BoxLayout.Y_AXIS)); panesPanel.setAlignmentX(LEFT_ALIGNMENT); panesPanel.setAlignmentY(BOTTOM_ALIGNMENT); } else { ((BoxLayout) panesPanel.getLayout()).invalidateLayout(panesPanel); panesPanel.removeAll(); } if (bg == null) { bg = new ButtonGroup(); } LinkedList panes = new LinkedList(); LinkedList backgroundPanes = new LinkedList(); // populate the arrays of CheckBoxes and strings used to fill // the JPanel for the panes for (int i = 0; i < layers.length; i++) { Layer layer = layers[i]; if (layer == null) { Debug.output("LayersPanel caught null layer, " + i + " out of " + layers.length); continue; } LayerPane lpane = (LayerPane) paneLookUp.get(layer); if (lpane == null) { if (Debug.debugging("layercontrol")) { Debug.output("LayersPanel: Creating LayerPane for " + layer.getName()); } lpane = createLayerPaneForLayer(layer, layerHandler, bg); lpane.addPropertyChangeListener(LayerSelectedCmd, this); lpane.addPropertyChangeListener(LayerDeselectedCmd, this); paneLookUp.put(layer, lpane); } else { // In case this has been modified elsewhere... lpane.setLayerOn(layer.isVisible()); } if (layer.getAddAsBackground() && backgroundLayerSeparator != null) { backgroundPanes.add(lpane); } else { panes.add(lpane); panesPanel.add(lpane); } } if (backgroundPanes.size() != 0) { if (Debug.debugging("layerspanel")) { Debug.output("Adding BackgroundLayerSeparator"); } panes.add(backgroundLayerSeparator); panesPanel.add(backgroundLayerSeparator); panes.addAll(backgroundPanes); Iterator it = backgroundPanes.iterator(); while (it.hasNext()) { panesPanel.add((LayerPane) it.next()); } } else if (backgroundLayerSeparator != null) { if (Debug.debugging("layerspanel")) { Debug.output("No layers are background layers, adding separator"); } panes.add(backgroundLayerSeparator); panesPanel.add(backgroundLayerSeparator); } setPanes(panes); if (scrollPane != null) { remove(scrollPane); scrollPane.removeAll(); scrollPane = null; } scrollPane = new JScrollPane(panesPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); add(scrollPane, BorderLayout.CENTER); revalidate(); } /** * Called when a new LayerPane needs to be created for a layer. You can use * this to extend LayerPane and return something else that fits your GUI. */ protected LayerPane createLayerPaneForLayer(Layer layer, LayerHandler layerHandler, ButtonGroup bg) { if (showStatus) { return new LayerStatusPane(layer, layerHandler, bg); } else { return new LayerPane(layer, layerHandler, bg); } } public void deletePanes(LinkedList dpanes) { Debug.message("layerspanel", "LayersPanel.deletePanes()"); if (dpanes != null) { paneLookUp.clear(); Iterator it = dpanes.iterator(); while (it.hasNext()) { LayerPane pane = (LayerPane) it.next(); if (pane != null && pane != backgroundLayerSeparator) { pane.removePropertyChangeListener(this); pane.cleanup(bg); } } } // Shouldn't call this, but it's the only thing // that seems to make it work... if (Debug.debugging("helpgc")) { System.gc(); } } /** * Set up the buttons used to move layers up and down, or add/remove layers. * The button component should hook itself up to the LayersPanel, and assume * that the LayersPanel has a BorderLayout with the list in the center spot. */ protected void createControlButtons() { controls = new LayerControlButtonPanel(this); } /** * Should be called internally, when the LayersPanel creates the * LayerControlButtonPanel. If called from the LCBP, a loop will ensue. * * @param lcbp */ protected void setControlsAndNotify(LayerControlButtonPanel lcbp) { setControls(lcbp); if (lcbp != null) { lcbp.setLayersPanel(this); } } /** * Simply sets the controls. * * @param lcbp */ public void setControls(LayerControlButtonPanel lcbp) { controls = lcbp; } public LayerControlButtonPanel getControls() { return controls; } /** * Method associated with the ActionListener interface. This method listens * for action events meant to change the order of the layers, as fired by * the layer order buttons. * * @param e ActionEvent */ public void actionPerformed(java.awt.event.ActionEvent e) { String command = e.getActionCommand(); if (Debug.debugging("layerspanel")) { Debug.output("LayersPanel.actionPerformed(): " + command); } try { LayerPane pane = findSelectedPane(); if (pane != null) { moveLayer(pane, command); } } catch (NullPointerException npe) { } catch (ArrayIndexOutOfBoundsException aioobe) { } } /** * Change a layer's position. */ public void moveLayer(Layer layer, String command) { if (Debug.debugging("layercontrol")) { Debug.output("LayersPanel.moveLayer(): " + command + " for " + layer.getName()); } moveLayer((LayerPane) paneLookUp.get(layer), command); } /** * Change a layer's position, with the layer represented by a LayerPane. */ protected void moveLayer(LayerPane lp, String command) { if (lp == null) { if (Debug.debugging("layercontrol")) { Debug.output("LayersPanel.moveLayer(): LayerPane not represented on list"); } if (command == LayerRemoveCmd) { // OK, here's a hidden trick. If no layers are // selected // and the minus sign is clicked, then this is called. System.gc();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -