Changeset 11885 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-04-10T23:49:54+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java
r11848 r11885 10 10 11 11 import javax.swing.DefaultListCellRenderer; 12 import javax.swing.Icon;13 12 import javax.swing.JLabel; 14 13 import javax.swing.JList; … … 24 23 import org.openstreetmap.josm.tools.Utils; 25 24 25 /** 26 * Abstract superclass of different "Merge" actions. 27 * @since 1890 28 */ 26 29 public abstract class AbstractMergeAction extends JosmAction { 27 30 28 31 /** 29 32 * the list cell renderer used to render layer list entries 30 *31 33 */ 32 34 public static class LayerListCellRenderer extends DefaultListCellRenderer { … … 36 38 Layer layer = (Layer) value; 37 39 JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected, cellHasFocus); 38 Icon icon = layer.getIcon(); 39 label.setIcon(icon); 40 label.setIcon(layer.getIcon()); 40 41 label.setToolTipText(layer.getToolTipText()); 41 42 return label; … … 45 46 /** 46 47 * Constructs a new {@code AbstractMergeAction}. 48 * @param name the action's text as displayed on the menu (if it is added to a menu) 49 * @param iconName the filename of the icon to use 50 * @param tooltip a longer description of the action that will be displayed in the tooltip. Please note 51 * that html is not supported for menu actions on some platforms. 52 * @param shortcut a ready-created shortcut object or null if you don't want a shortcut. But you always 53 * do want a shortcut, remember you can always register it with group=none, so you 54 * won't be assigned a shortcut unless the user configures one. If you pass null here, 55 * the user CANNOT configure a shortcut for your action. 56 * @param register register this action for the toolbar preferences? 47 57 */ 48 public AbstractMergeAction() {49 super();50 }51 52 58 public AbstractMergeAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register) { 53 59 super(name, iconName, tooltip, shortcut, register); 54 60 } 55 61 62 /** 63 * Constructs a new {@code AbstractMergeAction}. 64 * @param name the action's text as displayed on the menu (if it is added to a menu) 65 * @param iconName the filename of the icon to use 66 * @param tooltip a longer description of the action that will be displayed in the tooltip. Please note 67 * that html is not supported for menu actions on some platforms. 68 * @param shortcut a ready-created shortcut object or null if you don't want a shortcut. But you always 69 * do want a shortcut, remember you can always register it with group=none, so you 70 * won't be assigned a shortcut unless the user configures one. If you pass null here, 71 * the user CANNOT configure a shortcut for your action. 72 * @param register register this action for the toolbar preferences? 73 * @param toolbar identifier for the toolbar preferences. The iconName is used, if this parameter is null 74 * @param installAdapters false, if you don't want to install layer changed and selection changed adapters 75 */ 56 76 public AbstractMergeAction(String name, String iconName, String tooltip, Shortcut shortcut, 57 77 boolean register, String toolbar, boolean installAdapters) { … … 59 79 } 60 80 81 /** 82 * Ask user to choose the target layer. 83 * @param targetLayers list of candidate target layers. 84 * @return the chosen layer 85 */ 61 86 protected static Layer askTargetLayer(List<Layer> targetLayers) { 62 87 return askTargetLayer(targetLayers.toArray(new Layer[targetLayers.size()]), … … 99 124 } 100 125 126 /** 127 * Warns user when there no layers the source layer could be merged to. 128 * @param sourceLayer source layer 129 */ 101 130 protected void warnNoTargetLayersForSourceLayer(Layer sourceLayer) { 102 JOptionPane.showMessageDialog(Main.parent, 103 tr("<html>There are no layers the source layer<br>''{0}''<br>could be merged to.</html>", 104 Utils.escapeReservedCharactersHTML(sourceLayer.getName())), 105 tr("No target layers"), JOptionPane.WARNING_MESSAGE); 131 String message = tr("<html>There are no layers the source layer<br>''{0}''<br>could be merged to.</html>", 132 Utils.escapeReservedCharactersHTML(sourceLayer.getName())); 133 if (!GraphicsEnvironment.isHeadless()) { 134 JOptionPane.showMessageDialog(Main.parent, message, tr("No target layers"), JOptionPane.WARNING_MESSAGE); 135 } 106 136 } 107 137 } -
trunk/src/org/openstreetmap/josm/actions/MergeLayerAction.java
r11848 r11885 10 10 import java.util.Collections; 11 11 import java.util.List; 12 import java.util.concurrent.Future; 12 13 13 14 import org.openstreetmap.josm.Main; … … 38 39 } 39 40 40 protected void doMerge(List<Layer> targetLayers, final Collection<Layer> sourceLayers) { 41 /** 42 * Submits merge of layers. 43 * @param targetLayers possible target layers 44 * @param sourceLayers source layers 45 * @return a Future representing pending completion of the merge task, or {@code null} 46 * @since 11885 (return type) 47 */ 48 protected Future<?> doMerge(List<Layer> targetLayers, final Collection<Layer> sourceLayers) { 41 49 final Layer targetLayer = askTargetLayer(targetLayers); 42 50 if (targetLayer == null) 43 return ;51 return null; 44 52 final Object actionName = getValue(NAME); 45 Main.worker.submit(() -> {53 return Main.worker.submit(() -> { 46 54 final long start = System.currentTimeMillis(); 47 55 boolean layerMerged = false; … … 69 77 * Merges a list of layers together. 70 78 * @param sourceLayers The layers to merge 79 * @return a Future representing pending completion of the merge task, or {@code null} 80 * @since 11885 (return type) 71 81 */ 72 public voidmerge(List<Layer> sourceLayers) {73 doMerge(sourceLayers, sourceLayers);82 public Future<?> merge(List<Layer> sourceLayers) { 83 return doMerge(sourceLayers, sourceLayers); 74 84 } 75 85 … … 77 87 * Merges the given source layer with another one, determined at runtime. 78 88 * @param sourceLayer The source layer to merge 89 * @return a Future representing pending completion of the merge task, or {@code null} 90 * @since 11885 (return type) 79 91 */ 80 public voidmerge(Layer sourceLayer) {92 public Future<?> merge(Layer sourceLayer) { 81 93 if (sourceLayer == null) 82 return ;94 return null; 83 95 List<Layer> targetLayers = LayerListDialog.getInstance().getModel().getPossibleMergeTargets(sourceLayer); 84 96 if (targetLayers.isEmpty()) { 85 97 warnNoTargetLayersForSourceLayer(sourceLayer); 86 return ;98 return null; 87 99 } 88 doMerge(targetLayers, Collections.singleton(sourceLayer));100 return doMerge(targetLayers, Collections.singleton(sourceLayer)); 89 101 } 90 102 … … 112 124 } 113 125 126 /** 127 * Returns the source layer. 128 * @return the source layer 129 */ 114 130 protected Layer getSourceLayer() { 115 return Main. map != null ? Main.getLayerManager().getActiveLayer() : null;131 return Main.getLayerManager().getActiveLayer(); 116 132 } 117 133 -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r11713 r11885 243 243 244 244 // toolBarToggles, toggle dialog buttons 245 LayerListDialog.createInstance( this);245 LayerListDialog.createInstance(mapView.getLayerManager()); 246 246 propertiesDialog = new PropertiesDialog(); 247 247 selectionListDialog = new SelectionListDialog(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r11881 r11885 44 44 import org.openstreetmap.josm.actions.MergeLayerAction; 45 45 import org.openstreetmap.josm.data.preferences.AbstractProperty; 46 import org.openstreetmap.josm.gui.MapFrame;47 46 import org.openstreetmap.josm.gui.MapView; 48 47 import org.openstreetmap.josm.gui.SideButton; … … 90 89 91 90 /** 92 * Creates the instance of the dialog. It's connected to the map frame <code>mapFrame</code>91 * Creates the instance of the dialog. It's connected to the layer manager 93 92 * 94 * @param mapFrame the map frame 95 */ 96 public static void createInstance(MapFrame mapFrame) { 93 * @param layerManager the layer manager 94 * @since 11885 (signature) 95 */ 96 public static void createInstance(MainLayerManager layerManager) { 97 97 if (instance != null) 98 98 throw new IllegalStateException("Dialog was already created"); 99 instance = new LayerListDialog( mapFrame);99 instance = new LayerListDialog(layerManager); 100 100 } 101 101 … … 105 105 * @return the instance of the dialog 106 106 * @throws IllegalStateException if the dialog is not created yet 107 * @see #createInstance(Ma pFrame)107 * @see #createInstance(MainLayerManager) 108 108 */ 109 109 public static LayerListDialog getInstance() { … … 164 164 165 165 /** 166 * Creates a layer list and attach it to the given mapView. 167 * @param mapFrame map frame 168 */ 169 protected LayerListDialog(MapFrame mapFrame) { 170 this(mapFrame.mapView.getLayerManager()); 171 } 172 173 /** 174 * Creates a layer list and attach it to the given mapView. 166 * Creates a layer list and attach it to the given layer manager. 175 167 * @param layerManager The layer manager this list is for 176 168 * @since 10467 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r11538 r11885 265 265 */ 266 266 protected void registerInWindowMenu() { 267 windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu, 268 (JosmAction) getToggleAction(), 269 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG); 267 if (Main.main != null) { 268 windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu, 269 (JosmAction) getToggleAction(), 270 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG); 271 } 270 272 } 271 273 … … 329 331 // toggling the selected value in order to enforce PropertyChangeEvents 330 332 setIsShowing(true); 331 windowMenuItem.setState(true); 333 if (windowMenuItem != null) { 334 windowMenuItem.setState(true); 335 } 332 336 toggleAction.putValue("selected", Boolean.FALSE); 333 337 toggleAction.putValue("selected", Boolean.TRUE); … … 374 378 closeDetachedDialog(); 375 379 this.setVisible(false); 376 windowMenuItem.setState(false); 380 if (windowMenuItem != null) { 381 windowMenuItem.setState(false); 382 } 377 383 setIsShowing(false); 378 384 toggleAction.putValue("selected", Boolean.FALSE); … … 456 462 hideNotify(); 457 463 } 458 Main.main.menu.windowMenu.remove(windowMenuItem); 464 if (Main.main != null) { 465 Main.main.menu.windowMenu.remove(windowMenuItem); 466 } 459 467 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 460 468 Main.pref.removePreferenceChangeListener(this);
Note:
See TracChangeset
for help on using the changeset viewer.