Changeset 36081 in osm for applications/editors
- Timestamp:
- 2023-05-12T14:34:31+02:00 (20 months ago)
- Location:
- applications/editors/josm/plugins/buildings_tools
- Files:
-
- 9 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/AdvancedSettingsDialog.java
r35669 r36081 14 14 import org.openstreetmap.josm.tools.GBC; 15 15 16 /** 17 * A dialog for users to set "advanced" settings for the tool 18 */ 16 19 public class AdvancedSettingsDialog extends MyDialog { 17 20 private final TagEditorModel tagsModel = new TagEditorModel(); … … 20 23 private final JCheckBox cSoftCur = new JCheckBox(tr("Rotate crosshair")); 21 24 private final JCheckBox cNoClickDrag = new JCheckBox(tr("Disable click+drag")); 25 private final JCheckBox cToggleMapMode = new JCheckBox(tr("Switch between circle and rectangle modes")); 22 26 27 /** 28 * Create a new advanced settings dialog 29 */ 23 30 public AdvancedSettingsDialog() { 24 31 super(tr("Advanced settings")); … … 34 41 panel.add(cSoftCur, GBC.eol().fill(GBC.HORIZONTAL)); 35 42 panel.add(cNoClickDrag, GBC.eol().fill(GBC.HORIZONTAL)); 43 panel.add(cToggleMapMode, GBC.eol().fill(GBC.HORIZONTAL)); 36 44 37 45 cBigMode.setSelected(ToolSettings.isBBMode()); 38 46 cSoftCur.setSelected(ToolSettings.isSoftCursor()); 39 47 cNoClickDrag.setSelected(ToolSettings.isNoClickAndDrag()); 48 cToggleMapMode.setSelected(ToolSettings.isTogglingBuildingTypeOnRepeatedKeyPress()); 49 50 cToggleMapMode.setToolTipText(tr("This is similar to the select action toggling between lasso and rectangle select modes")); 40 51 41 52 setupDialog(); … … 43 54 } 44 55 56 /** 57 * Save the settings 58 */ 45 59 public final void saveSettings() { 46 60 ToolSettings.saveTags(tagsModel.getTags()); … … 48 62 ToolSettings.setSoftCursor(cSoftCur.isSelected()); 49 63 ToolSettings.setNoClickAndDrag(cNoClickDrag.isSelected()); 64 ToolSettings.setTogglingBuildingTypeOnRepeatedKeyPress(cToggleMapMode.isSelected()); 50 65 } 51 66 } -
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/BuildingsToolsPlugin.java
r35978 r36081 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.buildings_tools; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import javax.swing.JMenu; … … 15 17 import org.openstreetmap.josm.plugins.Plugin; 16 18 import org.openstreetmap.josm.plugins.PluginInformation; 19 import org.openstreetmap.josm.tools.ImageProvider; 17 20 21 /** 22 * The entry point for the buildings tools plugin 23 */ 18 24 public class BuildingsToolsPlugin extends Plugin { 19 25 public static final Projection MERCATOR = Projections.getProjectionByCode("EPSG:3857"); // Mercator 20 26 27 /** 28 * Convert a latlon to east north 29 * @param p The latlon to convert 30 * @return The east-north ({@link #MERCATOR}) 31 */ 21 32 public static EastNorth latlon2eastNorth(ILatLon p) { 22 33 return MERCATOR.latlon2eastNorth(p); 23 34 } 24 35 36 /** 37 * Convert an east-north to a latlon 38 * @param p The east north to convert (from {@link #MERCATOR}) 39 * @return The latlon 40 */ 25 41 public static LatLon eastNorth2latlon(EastNorth p) { 26 42 return MERCATOR.eastNorth2latlon(p); … … 29 45 public BuildingsToolsPlugin(PluginInformation info) { 30 46 super(info); 31 JMenu dataMenu = MainApplication.getMenu().dataMenu; 32 MainMenu.add(dataMenu, new BuildingSizeAction()); 33 MainMenu.add(dataMenu, new BuildingCircleAction()); 34 MainMenu.add(dataMenu, new BuildingRectangleAction()); 35 MainMenu.add(dataMenu, new MergeAddrPointsAction()); 47 JMenu moreToolsMenu = MainApplication.getMenu().moreToolsMenu; 48 if (moreToolsMenu.getMenuComponentCount() > 0) { 49 moreToolsMenu.addSeparator(); 50 } 51 MainMenu.add(moreToolsMenu, new DrawBuildingAction()); 52 JMenu optionMenu = new JMenu(tr("Draw buildings modes")); 53 optionMenu.setIcon(ImageProvider.get("preference_small", ImageProvider.ImageSizes.MENU)); 54 moreToolsMenu.add(optionMenu); 55 MainMenu.add(optionMenu, new BuildingSizeAction()); 56 MainMenu.add(optionMenu, new BuildingCircleAction()); 57 MainMenu.add(optionMenu, new BuildingRectangleAction()); 58 MainMenu.add(optionMenu, new MergeAddrPointsAction()); 36 59 } 37 60 … … 39 62 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 40 63 if (oldFrame == null && newFrame != null) { 41 MainApplication.getMap().addMapMode(new IconToggleButton(new DrawBuildingAction()));64 newFrame.addMapMode(new IconToggleButton(new DrawBuildingAction())); 42 65 } 43 66 } -
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/DrawBuildingAction.java
r35997 r36081 23 23 import org.openstreetmap.josm.tools.Geometry; 24 24 import org.openstreetmap.josm.tools.ImageProvider; 25 import org.openstreetmap.josm.tools.Logging;26 25 import org.openstreetmap.josm.tools.Shortcut; 27 26 … … 45 44 import static org.openstreetmap.josm.tools.I18n.tr; 46 45 46 /** 47 * The action for drawing the building 48 */ 47 49 public class DrawBuildingAction extends MapMode implements MapViewPaintable, DataSelectionListener, 48 50 KeyPressReleaseListener, ModifierExListener { 51 private static final long serialVersionUID = -3515263157730927711L; 49 52 // We need to avoid opening many file descriptors on Linux under Wayland -- see JOSM #21929. This will probably also 50 53 // improve performance, since we aren't creating cursors all the time. … … 73 76 private final PreferenceChangedListener shapeChangeListener = event -> updCursor(); 74 77 78 /** 79 * Create a new {@link DrawBuildingAction} object 80 */ 75 81 public DrawBuildingAction() { 76 82 super(tr("Draw buildings"), "building", tr("Draw buildings"), … … 88 94 89 95 private static Cursor getCursor() { 90 try { 91 if (ToolSettings.Shape.CIRCLE == ToolSettings.getShape()) { 96 switch (ToolSettings.getShape()) { 97 case RECTANGLE: 98 return CURSOR_BUILDING; 99 case CIRCLE: 92 100 return CURSOR_SILO; 93 } else { 94 return CURSOR_BUILDING; 95 } 96 } catch (Exception e) { 97 Logging.error(e); 98 } 99 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 101 default: 102 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 103 } 100 104 } 101 105 … … 161 165 } 162 166 167 /** 168 * Cancel the drawing of a building 169 */ 163 170 public final void cancelDrawing() { 164 171 mode = Mode.None; … … 194 201 cancelDrawing(); 195 202 } 203 if (!ToolSettings.isTogglingBuildingTypeOnRepeatedKeyPress() 204 || !MainApplication.isDisplayingMapView() || !getShortcut().isEvent(e)) { 205 return; 206 } 207 e.consume(); 208 switch (ToolSettings.getShape()) { 209 case CIRCLE: 210 ToolSettings.saveShape(ToolSettings.Shape.RECTANGLE); 211 break; 212 case RECTANGLE: 213 ToolSettings.saveShape(ToolSettings.Shape.CIRCLE); 214 } 196 215 } 197 216 198 217 @Override 199 218 public void doKeyReleased(KeyEvent e) { 219 // Do nothing 200 220 } 201 221 … … 437 457 } 438 458 459 /** 460 * Update the snap for drawing 461 * @param newSelection The selection to use 462 */ 439 463 public final void updateSnap(Collection<? extends OsmPrimitive> newSelection) { 440 464 building.clearAngleSnap(); -
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/ToolSettings.java
r35978 r36081 5 5 import java.util.Arrays; 6 6 import java.util.Collection; 7 import java.util.Collections; 7 8 import java.util.HashMap; 8 9 import java.util.Iterator; … … 14 15 import org.openstreetmap.josm.tools.Logging; 15 16 17 /** 18 * A holder for plugin settings 19 */ 16 20 public final class ToolSettings { 17 21 … … 22 26 public static final BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", false); 23 27 28 /** 29 * The shapes that users can create 30 */ 24 31 public enum Shape { 25 32 CIRCLE, RECTANGLE … … 32 39 private static final Map<String, String> TAGS = new HashMap<>(); 33 40 41 /** 42 * Get the current shape that will be created 43 * @return The shape 44 */ 34 45 public static Shape getShape() { 35 46 loadShape(); … … 37 48 } 38 49 50 /** 51 * Set whether to use the address dialog 52 * @param useAddr {@code true} if the address dialog should be used 53 */ 39 54 public static void setAddrDialog(boolean useAddr) { 40 55 ToolSettings.useAddr = useAddr; 41 56 } 42 57 58 /** 59 * Set some constraints for new buildings 60 * @param newwidth The max width ({@link Shape#RECTANGLE}) or max diameter ({@link Shape#CIRCLE}) 61 * @param newlenstep The step sizes to use when setting the length of a {@link Shape#RECTANGLE} 62 */ 43 63 public static void setSizes(double newwidth, double newlenstep) { 44 64 width = newwidth; … … 46 66 } 47 67 68 /** 69 * Get the width/diameter 70 * @return The max width ({@link Shape#RECTANGLE}) or max diameter ({@link Shape#CIRCLE}) 71 */ 48 72 public static double getWidth() { 49 73 return width; 50 74 } 51 75 76 /** 77 * Get the step length for {@link Shape#RECTANGLE} 78 * @return The amount to increase the length of a {@link Shape#RECTANGLE}. 79 */ 52 80 public static double getLenStep() { 53 81 return lenstep; 54 82 } 55 83 84 /** 85 * Check if we want to show the user an address dialog 86 * @return {@code true} if the user should be shown the address dialog 87 */ 56 88 public static boolean isUsingAddr() { 57 89 return useAddr; 58 90 } 59 91 92 /** 93 * Get the tags that the user wants to set on all new objects 94 * @return The tag map 95 */ 60 96 public static Map<String, String> getTags() { 61 97 loadTags(); 62 return TAGS; 63 } 64 98 return Collections.unmodifiableMap(TAGS); 99 } 100 101 /** 102 * Set the tags to put on all new objects 103 * @param tags The tags to set 104 */ 65 105 public static void saveTags(Map<String, String> tags) { 66 106 TAGS.clear(); … … 74 114 } 75 115 116 /** 117 * Load tags from preferences 118 */ 76 119 private static void loadTags() { 77 120 TAGS.clear(); … … 87 130 } 88 131 132 /** 133 * Set the shape to use 134 * @param shape The shape 135 */ 89 136 public static void saveShape(Shape shape) { 90 137 Config.getPref().put("buildings_tool.shape", shape.name()); 91 138 } 92 139 140 /** 141 * Load the shape to use from preferences 142 * @return The shape to use 143 */ 93 144 private static Shape loadShape() { 94 145 String shape = Config.getPref().get("buildings_tool.shape"); … … 102 153 } 103 154 155 /** 156 * Set the Big buildings mode 157 * @param bbmode {@code true} if big building mode should be used 158 */ 104 159 public static void setBBMode(boolean bbmode) { 105 160 Config.getPref().putBoolean("buildings_tools.bbmode", bbmode); 106 161 } 107 162 163 /** 164 * Get the Big buildings mode 165 * @return {@code true} if big building mode should be used 166 */ 108 167 public static boolean isBBMode() { 109 168 return Config.getPref().getBoolean("buildings_tools.bbmode", false); … … 134 193 } 135 194 195 /** 196 * Check if we are toggling between {@link Shape} types if the user toggles the mapmode with a keypress 197 * @return {@code true} if we want to change the shape type 198 */ 199 public static boolean isTogglingBuildingTypeOnRepeatedKeyPress() { 200 return Config.getPref().getBoolean("buildings_tools.toggle_building_type", false); 201 } 202 203 /** 204 * Set whether or not we are toggling between {@link Shape} types if the user toggles the mapmode with a keypress 205 * @param toggle {@code true} if we want to change the shape type 206 */ 207 public static void setTogglingBuildingTypeOnRepeatedKeyPress(boolean toggle) { 208 Config.getPref().putBoolean("buildings_tools.toggle_building_type", toggle); 209 } 210 136 211 public static boolean isNoClickAndDrag() { 137 212 return Config.getPref().getBoolean("buildings_tools.noclickdrag", false);
Note:
See TracChangeset
for help on using the changeset viewer.