Changeset 1917 in josm
- Timestamp:
- 2009-08-06T10:51:28+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r1913 r1917 25 25 import javax.swing.DefaultListSelectionModel; 26 26 import javax.swing.Icon; 27 import javax.swing.JComponent; 27 28 import javax.swing.JLabel; 28 29 import javax.swing.JList; … … 30 31 import javax.swing.JPanel; 31 32 import javax.swing.JScrollPane; 33 import javax.swing.KeyStroke; 32 34 import javax.swing.ListModel; 33 35 import javax.swing.ListSelectionModel; … … 129 131 //-- delete layer action 130 132 DeleteLayerAction deleteLayerAction = new DeleteLayerAction(); 133 layerList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 134 KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),"deleteLayer" 135 ); 136 layerList.getActionMap().put("deleteLayer", deleteLayerAction); 131 137 adaptTo(deleteLayerAction, selectionModel); 132 138 buttonPanel.add(new SideButton(deleteLayerAction, "delete")); … … 136 142 137 143 /** 138 * Create an layer list and attach it to the given mapView.144 * Create an layer list and attach it to the given mapView. 139 145 */ 140 146 protected LayerListDialog(MapFrame mapFrame) { … … 186 192 } 187 193 194 /** 195 * Wires <code>listener</code> to <code>listSelectionModel</code> in such a way, that 196 * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()} 197 * on every {@see ListSelectionEvent}. 198 * 199 * @param listener the listener 200 * @param listSelectionModel the source emitting {@see ListSelectionEvent}s 201 */ 188 202 protected void adaptTo(final IEnabledStateUpdating listener, ListSelectionModel listSelectionModel) { 189 203 listSelectionModel.addListSelectionListener( … … 196 210 } 197 211 212 /** 213 * Wires <code>listener</code> to <code>listModel</code> in such a way, that 214 * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()} 215 * on every {@see ListDataEvent}. 216 * 217 * @param listener the listener 218 * @param listSelectionModel the source emitting {@see ListDataEvent}s 219 */ 198 220 protected void adaptTo(final IEnabledStateUpdating listener, ListModel listModel) { 199 221 listModel.addListDataListener( … … 213 235 ); 214 236 } 215 237 /** 238 * Wires <code>listener</code> to {@see MapView} in such a way, that 239 * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()} 240 * on every {@see LayerChangeListener}-event emitted by {@see MapView}. 241 * 242 * @param listener the listener 243 */ 216 244 protected void adaptToLayerChanges(final IEnabledStateUpdating listener) { 217 245 Layer.listeners.add( … … 374 402 if (this.layer == null) { 375 403 List<Layer> selectedLayers = getModel().getSelectedLayers(); 404 if (selectedLayers.isEmpty()) 405 return; 376 406 if (selectedLayers.size() == 1) { 377 407 deleteSingleLayer(selectedLayers.get(0)); … … 473 503 toActivate = model.getSelectedLayers().get(0); 474 504 } 475 getModel().activateLayer(toActivate); 505 // model is going to be updated via LayerChangeListener 506 // and PropertyChangeEvents 507 Main.map.mapView.setActiveLayer(toActivate); 508 toActivate.setVisible(true); 476 509 } 477 510 … … 662 695 /** 663 696 * The layer list model. The model manages a list of layers and provides methods for 664 * moving layers up and down, for toggling their visibili y,for activating a layer.697 * moving layers up and down, for toggling their visibility, and for activating a layer. 665 698 * 666 699 * The model is a {@see ListModel} and it provides a {@see ListSelectionModel}. It expectes … … 670 703 * The model manages a list of {@see LayerListModelListener} which are mainly notified if 671 704 * the model requires views to make a specific list entry visible. 705 * 706 * It also listens to {@see PropertyChangeEvent}s of every {@see Layer} it manages, in particular to 707 * the properties {@see Layer#VISIBLE_PROP} and {@see Layer#NAME_PROP}. 672 708 */ 673 709 public class LayerListModel extends DefaultListModel implements LayerChangeListener, PropertyChangeListener{ … … 811 847 if (layer == null) 812 848 return; 849 layer.removePropertyChangeListener(this); 813 850 int size = getSize(); 814 851 List<Integer> rows = getSelectedRows(); … … 829 866 layer.addPropertyChangeListener(this); 830 867 fireContentsChanged(this, 0, getSize()); 868 int idx = getLayers().indexOf(layer); 869 selectionModel.setSelectionInterval(idx, idx); 870 ensureSelectedIsVisible(); 831 871 } 832 872 … … 958 998 959 999 /** 960 * Activates the layer <code>layer</code>961 *962 * @param layer the layer963 */964 public void activateLayer(Layer layer) {965 if (layer == null)966 return;967 Main.map.mapView.setActiveLayer(layer);968 layer.setVisible(true);969 int idx = getLayers().indexOf(layer);970 selectionModel.setSelectionInterval(idx,idx);971 ensureSelectedIsVisible();972 }973 974 /**975 1000 * Replies the list of layers currently managed by {@see MapView}. 976 1001 * Never null, but can be empty. … … 983 1008 return Collections.<Layer>emptyList(); 984 1009 return Main.map.mapView.getAllLayersAsList(); 1010 } 1011 1012 /** 1013 * Ensures that at least one layer is selected in the layer dialog 1014 * 1015 */ 1016 protected void ensureActiveSelected() { 1017 if (getLayers().size() == 0) return; 1018 if (getActiveLayer() != null) { 1019 // there's an active layer - select it and make it 1020 // visible 1021 int idx = getLayers().indexOf(getActiveLayer()); 1022 selectionModel.setSelectionInterval(idx, idx); 1023 ensureSelectedIsVisible(); 1024 } else { 1025 // no active layer - select the first one and make 1026 // it visible 1027 selectionModel.setSelectionInterval(0, 0); 1028 ensureSelectedIsVisible(); 1029 } 1030 } 1031 1032 /** 1033 * Replies the active layer. null, if no active layer is available 1034 * 1035 * @return the active layer. null, if no active layer is available 1036 */ 1037 protected Layer getActiveLayer() { 1038 if (Main.map == null || Main.map.mapView == null) return null; 1039 return Main.map.mapView.getActiveLayer(); 985 1040 } 986 1041 … … 1017 1072 } 1018 1073 } 1074 ensureActiveSelected(); 1019 1075 } 1020 1076 … … 1058 1114 } 1059 1115 1116 /** 1117 * Creates a {@see ShowHideLayerAction} for <code>layer</code> in the 1118 * context of this {@see LayerListDialog}. 1119 * 1120 * @param layer the layer 1121 * @return the action 1122 */ 1060 1123 public ShowHideLayerAction createShowHideLayerAction(Layer layer) { 1061 1124 return new ShowHideLayerAction(layer); 1062 1125 } 1063 1126 1127 /** 1128 * Creates a {@see DeleteLayerAction} for <code>layer</code> in the 1129 * context of this {@see LayerListDialog}. 1130 * 1131 * @param layer the layer 1132 * @return the action 1133 */ 1064 1134 public DeleteLayerAction createDeleteLayerAction(Layer layer) { 1065 1135 return new DeleteLayerAction(layer); 1066 1136 } 1067 1137 1138 /** 1139 * Creates a {@see ActivateLayerAction} for <code>layer</code> in the 1140 * context of this {@see LayerListDialog}. 1141 * 1142 * @param layer the layer 1143 * @return the action 1144 */ 1068 1145 public ActivateLayerAction createActivateLayerAction(Layer layer) { 1069 1146 return new ActivateLayerAction(layer); 1070 1147 } 1071 1148 1149 /** 1150 * Creates a {@see MergeLayerAction} for <code>layer</code> in the 1151 * context of this {@see LayerListDialog}. 1152 * 1153 * @param layer the layer 1154 * @return the action 1155 */ 1072 1156 public MergeAction createMergeLayerAction(Layer layer) { 1073 1157 return new MergeAction(layer);
Note:
See TracChangeset
for help on using the changeset viewer.