Changeset 30419 in osm for applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap
- Timestamp:
- 2014-04-27T16:28:56+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java
r30384 r30419 2 2 package org.openstreetmap.josm.plugins.utilsplugin2; 3 3 4 import java.awt.event.MouseAdapter; 5 import java.awt.event.MouseEvent; 6 import java.awt.event.MouseListener; 4 7 import javax.swing.JMenu; 5 8 import javax.swing.JMenuItem; 9 import javax.swing.SwingUtilities; 6 10 7 11 import org.openstreetmap.josm.Main; 8 12 import org.openstreetmap.josm.actions.search.SearchCompiler; 13 import org.openstreetmap.josm.data.coor.EastNorth; 9 14 import org.openstreetmap.josm.gui.MainMenu; 10 15 import org.openstreetmap.josm.gui.MapFrame; … … 127 132 SearchCompiler.addMatchFactory(new UtilsSimpleMatchFactory()); 128 133 } 129 134 135 MouseListener mouseListener = new MouseAdapter() { 136 @Override 137 public void mouseReleased(final MouseEvent e) { 138 if (e.getButton()==MouseEvent.BUTTON1 && 139 e.getClickCount() > 1 && Main.isDisplayingMapView() && Main.map.mapMode == Main.map.mapModeSelect && 140 (0 == (e.getModifiersEx() & (MouseEvent.ALT_DOWN_MASK + MouseEvent.CTRL_DOWN_MASK + MouseEvent.SHIFT_DOWN_MASK) ))) { 141 SwingUtilities.invokeLater(new Runnable() { 142 @Override 143 public void run() { 144 EastNorth en = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 145 SelectBoundaryAction.selectByInternalPoint(en); 146 } 147 }); 148 } 149 } 150 }; 151 130 152 @Override 131 153 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { … … 160 182 drawArc.setEnabled(enabled); 161 183 multiTag.setEnabled(enabled); 184 if (oldFrame!=null && oldFrame.mapView!=null) oldFrame.mapView.removeMouseListener(mouseListener); 185 if (newFrame!=null && newFrame.mapView!=null && Main.pref.getBoolean(UtilsPluginPreferences.PREF_DOUBLECLICK, true)) 186 newFrame.mapView.addMouseListener(mouseListener); 162 187 } 163 188 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/UtilsPluginPreferences.java
r30002 r30419 14 14 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 15 15 import java.awt.event.ActionListener; 16 import javax.swing.JCheckBox; 16 17 import javax.swing.JPanel; 17 18 import javax.swing.ListSelectionModel; 18 19 import javax.swing.event.TableModelListener; 19 20 import javax.swing.table.DefaultTableModel; 21 import org.openstreetmap.josm.Main; 20 22 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; 21 23 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; … … 30 32 JButton loadButton; 31 33 JButton saveButton; 34 JCheckBox dblClick = new JCheckBox(tr("Double click selects object by its internal point")); 35 public static final String PREF_DOUBLECLICK = "utilsplugin2.doubleclick"; 32 36 33 37 public UtilsPluginPreferences() { 34 super("utils", tr("Utilsplugin2 settings [TESTING]"), tr("Here you can change some preferences of Utilsplugin2 functions"));38 super("utils", tr("Utilsplugin2 settings"), tr("Here you can change some preferences of Utilsplugin2 functions")); 35 39 } 36 40 … … 38 42 public void addGui(PreferenceTabbedPane gui) { 39 43 JPanel all = new JPanel(new GridBagLayout()); 40 41 // FIXME: get rid of hardcoded URLS42 44 43 45 URLList.getSelectedURL(); … … 79 81 + " Your can manually load settings from file <b>customurl.txt</b> in JOSM folder")); 80 82 83 dblClick.setSelected(Main.pref.getBoolean(PREF_DOUBLECLICK, true)); 84 all.add(dblClick, GBC.std().insets(5,10,0,0)); 85 81 86 all.add(new JLabel(tr("Custom URL configuration")),GBC.std().insets(5,10,0,0)); 82 87 all.add(resetButton,GBC.std().insets(25,10,0,0)); … … 129 134 List<String> lst = readItemsFromTable(); 130 135 URLList.updateURLList(lst); 131 136 Main.pref.put(PREF_DOUBLECLICK, dblClick.isSelected()); 132 137 return false; 133 138 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagDialog.java
r30389 r30419 1 1 package org.openstreetmap.josm.plugins.utilsplugin2.multitagger; 2 2 3 import java.awt.Color; 3 4 import java.awt.Component; 4 5 import java.awt.Dimension; … … 20 21 import static javax.swing.Action.SHORT_DESCRIPTION; 21 22 import javax.swing.BoxLayout; 23 import javax.swing.DefaultCellEditor; 22 24 import javax.swing.JButton; 23 25 import javax.swing.JComponent; … … 49 51 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 50 52 import org.openstreetmap.josm.tools.GBC; 53 import static org.openstreetmap.josm.tools.I18n.marktr; 51 54 import static org.openstreetmap.josm.tools.I18n.tr; 52 55 import org.openstreetmap.josm.tools.ImageProvider; 56 import org.openstreetmap.josm.tools.Shortcut; 53 57 import org.openstreetmap.josm.tools.WindowGeometry; 54 58 … … 116 120 t.setColumnSelectionAllowed(true); 117 121 t.setDefaultRenderer(OsmPrimitiveType.class, new PrimitiveTypeIconRenderer()); 122 t.setDefaultRenderer(String.class, new ColoredRenderer()); 118 123 t.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 119 124 t.getSelectionModel().addListSelectionListener(selectionListener); … … 346 351 initAutocompletion(); 347 352 tableModel.fireTableDataChanged(); 348 } 353 } 354 355 class ColoredRenderer extends DefaultTableCellRenderer { 356 private final Color highlightColor = 357 Main.pref.getColor( marktr("Multitag Background: highlight"), 358 new Color(255,255,200)); 359 @Override 360 public Component getTableCellRendererComponent(JTable table, Object value, boolean 361 isSelected, boolean hasFocus, int row, int column) { 362 int row1 = tbl.convertRowIndexToModel(row); 363 JLabel label = (JLabel) super.getTableCellRendererComponent( 364 table, value, isSelected, hasFocus, row, column); 365 if (tbl.isRowSelected(row1) && !tbl.isColumnSelected(column)) { 366 label.setBackground(highlightColor); 367 } else { 368 if (isSelected) { 369 label.setBackground(Main.pref.getUIColor("Table.selectionBackground")); 370 } else { 371 label.setBackground(Main.pref.getUIColor("Table.background")); 372 } 373 } 374 return label; 375 } 376 } 349 377 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r30200 r30419 176 176 int s = newNodes.size(); 177 177 for (Way w: initWays) { 178 178 newNodes.addAll(w.getNodes()); 179 179 } 180 180 return newNodes.size()-s; … … 182 182 183 183 public static void addWaysIntersectingWaysRecursively 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 184 (Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { 185 Set<Way> foundWays = new HashSet<Way>(); 186 foundWays.addAll(initWays); 187 newWays.addAll(initWays); 188 Set<Way> newFoundWays; 189 190 int level=0,c; 191 do { 192 c=0; 193 newFoundWays = new HashSet<Way>(); 194 for (Way w : foundWays){ 195 c+=addWaysIntersectingWay(allWays, w, newFoundWays,newWays); 196 } 197 foundWays = newFoundWays; 198 newWays.addAll(newFoundWays); 199 level++; 200 200 // System.out.printf("%d: %d ways added to selection intersectiong\n",level,c); 201 202 203 204 205 206 207 201 if (c>maxWays1) { 202 new Notification( 203 tr("Too many ways are added: {0}!",c) 204 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 205 return; 206 } 207 } while ( c >0 && level < maxLevel ); 208 208 } 209 209 … … 211 211 (Collection<Way> initWays, Set<Way> newWays) 212 212 { 213 214 215 216 217 218 219 220 221 222 223 213 //long t = System.currentTimeMillis(); 214 int level=0,c; 215 newWays.addAll(initWays); 216 do { 217 c=0; 218 Set<Way> foundWays = new HashSet<Way>(); 219 foundWays.addAll(newWays); 220 for (Way w : foundWays){ 221 c+=addWaysConnectedToWay(w, newWays); 222 } 223 level++; 224 224 // System.out.printf("%d: %d ways added to selection\n",level,c); 225 226 227 228 229 230 231 232 225 if (c>maxWays) { 226 new Notification( 227 tr("Too many ways are added: {0}!",c) 228 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 229 return; 230 } 231 } while ( c >0 && level < maxLevel ); 232 // System.out.println("time = "+(System.currentTimeMillis()-t)+" ways = "+newWays.size()); 233 233 } 234 234 … … 344 344 } 345 345 } 346 346 347 static boolean isPointInsideMultipolygon(EastNorth p, Relation rel) { 348 Set<Way> usedWays = OsmPrimitive.getFilteredSet(rel.getMemberPrimitives(), Way.class); 349 return isPointInsidePolygon(p, buildPointList(usedWays)); 350 } 351 347 352 static void addAllInsideMultipolygon(DataSet data, Relation rel, Set<Way> newWays, Set<Node> newNodes) { 348 353 if (!rel.isMultipolygon()) return; 349 354 BBox box = rel.getBBox(); 350 Set<Way> usedWays = OsmPrimitive.getFilteredSet(rel.getMemberPrimitives(), Way.class); 351 List<EastNorth> polyPoints = new ArrayList<EastNorth>(10000); 352 353 for (Way way: usedWays) { 354 List<Node> polyNodes = way.getNodes(); 355 // converts all points to EastNorth 356 for (Node n: polyNodes) polyPoints.add(n.getEastNorth()); 357 polyPoints.add(null); // next segment indicator 358 } 359 360 355 Collection<Way> usedWays = rel.getMemberPrimitives(Way.class); 356 List<EastNorth> polyPoints = buildPointList(usedWays); 357 361 358 List<Node> searchNodes = data.searchNodes(box); 362 359 Set<Node> newestNodes = new HashSet<Node>(); … … 387 384 if (!way.isClosed()) return; 388 385 BBox box = way.getBBox(); 389 List<Node> polyNodes = way.getNodes(); 390 List<EastNorth> polyPoints = new ArrayList<EastNorth>(polyNodes.size()+5); 391 392 // converts all points to EastNorth 393 for (Node n: polyNodes) polyPoints.add(n.getEastNorth()); 386 Iterable<EastNorth> polyPoints = getWayPoints(way); 394 387 395 388 List<Node> searchNodes = data.searchNodes(box); … … 414 407 } 415 408 416 public static boolean isPointInsidePolygon(EastNorth point, List<EastNorth> polygonPoints) {409 public static boolean isPointInsidePolygon(EastNorth point, Iterable<EastNorth> polygonPoints) { 417 410 int n = getRayIntersectionsCount(point, polygonPoints); 418 411 if (n<0) return true; // we are near node or near edge 419 412 return (n%2==1); 420 413 } 421 414 422 415 /** 416 * @param point - point to start an OX-parallel ray 417 * @param polygonPoints - poits forming bundary, use null to split unconnected segmants 423 418 * @return 0 = not inside polygon, 1 = strictly inside, 2 = near edge, 3 = near vertex 424 419 */ 425 public static int getRayIntersectionsCount(EastNorth point, List<EastNorth> polygonPoints) {420 public static int getRayIntersectionsCount(EastNorth point, Iterable<EastNorth> polygonPoints) { 426 421 if (point==null) return 0; 427 422 EastNorth oldPoint = null; … … 512 507 } 513 508 514 515 509 private static List<EastNorth> buildPointList(Iterable<Way> ways) { 510 ArrayList<EastNorth> points = new ArrayList<EastNorth>(1000); 511 for (Way way: ways) { 512 for (EastNorth en: getWayPoints(way)) points.add(en); 513 points.add(null); // next segment indicator 514 } 515 return points; 516 } 517 518 public static Iterable<EastNorth> getWayPoints(final Way w) { 519 return new Iterable<EastNorth>() { 520 @Override 521 public Iterator<EastNorth> iterator() { 522 return new Iterator<EastNorth>() { 523 int idx = 0; 524 @Override public boolean hasNext() { 525 return idx < w.getNodesCount(); 526 } 527 @Override public EastNorth next() { 528 return w.getNode(idx++).getEastNorth(); 529 } 530 }; 531 } 532 }; 533 } 534 516 535 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectBoundaryAction.java
r30177 r30419 2 2 package org.openstreetmap.josm.plugins.utilsplugin2.selection; 3 3 4 import java.awt.Point; 4 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; … … 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.KeyEvent; 9 import java.util.ArrayList;10 import java.util.Arrays;11 10 import java.util.Collection; 11 import java.util.Collections; 12 12 import java.util.HashSet; 13 import java.util.List;14 13 import java.util.Set; 14 import java.util.TreeMap; 15 15 16 16 import javax.swing.JOptionPane; 17 import org.openstreetmap.josm.Main; 17 18 18 import org.openstreetmap.josm.Main;19 19 import org.openstreetmap.josm.actions.JosmAction; 20 import org.openstreetmap.josm.data.coor.EastNorth; 21 import org.openstreetmap.josm.data.osm.BBox; 20 22 import org.openstreetmap.josm.data.osm.Node; 21 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 24 import org.openstreetmap.josm.data.osm.Relation; 25 import org.openstreetmap.josm.data.osm.RelationMember; 23 26 import org.openstreetmap.josm.data.osm.Way; 24 27 import org.openstreetmap.josm.gui.Notification; 28 import org.openstreetmap.josm.tools.Geometry; 25 29 26 30 import org.openstreetmap.josm.tools.Shortcut; … … 39 43 putValue("help", ht("/Action/SelectAreaBoundary")); 40 44 } 41 45 46 public static void selectByInternalPoint(EastNorth e) { 47 //Node n= new Node(e); 48 TreeMap<Double, OsmPrimitive> found = new TreeMap<>(); 49 for (Way w: getCurrentDataSet().getWays()) { 50 if (w.isUsable() && w.isClosed() ) { 51 //if (Geometry.nodeInsidePolygon(n, w.getNodes())) { 52 if (NodeWayUtils.isPointInsidePolygon(e, NodeWayUtils.getWayPoints(w))) { 53 found.put(Geometry.closedWayArea(w), w); 54 } 55 } 56 } 57 for (Relation r: getCurrentDataSet().getRelations()) { 58 if (r.isUsable() && r.isMultipolygon()) { 59 //if (Geometry.isNodeInsideMultiPolygon(n, r, null)) { 60 if (NodeWayUtils.isPointInsideMultipolygon(e, r)) { 61 for (RelationMember m: r.getMembers()) { 62 if (m.isWay() && m.getWay().isClosed()) { 63 found.values().remove(m.getWay()); 64 } 65 } 66 // estimate multipolygon size by its bounding box area 67 BBox bBox = r.getBBox(); 68 EastNorth en1 = Main.map.mapView.getProjection().latlon2eastNorth(bBox.getTopLeft()); 69 EastNorth en2 = Main.map.mapView.getProjection().latlon2eastNorth(bBox.getBottomRight()); 70 double s = Math.abs((en1.east()-en2.east())*(en1.north()-en2.north())); 71 if (s==0) s=1e8; 72 found.put(s, r); 73 } 74 } 75 } 76 77 if (!found.isEmpty()) { 78 getCurrentDataSet().setSelected(Collections.singletonList( 79 found.firstEntry().getValue())); 80 } 81 } 82 42 83 @Override 43 84 public void actionPerformed(ActionEvent e) { … … 45 86 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Node.class); 46 87 47 Set<Way> newWays = new HashSet< Way>();88 Set<Way> newWays = new HashSet<>(); 48 89 49 90 Way w=null; … … 53 94 for (OsmPrimitive p : selectedNodes.iterator().next().getReferrers()) { 54 95 if (p instanceof Way && p.isSelectable()) { 55 //if (w!=null) return; // ifwe want only one way 96 //if (w!=null) return; // if we want only one way 56 97 w=(Way) p; 57 98 break; 58 99 } 59 100 } 101 } else { 102 Point p = Main.map.mapView.getMousePosition(); 103 selectByInternalPoint(Main.map.mapView.getEastNorth(p.x, p.y)); 104 return; 60 105 } 61 106 } else if (selectedWays.size()==1) { … … 95 140 setEnabled(false); 96 141 } else { 97 updateEnabledState(getCurrentDataSet().getSelected()); 142 setEnabled(true); 143 // updateEnabledState(getCurrentDataSet().getSelected()); 98 144 } 99 145 } … … 102 148 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 103 149 if (selection == null) { 104 setEnabled(false); 150 // setEnabled(false); 105 151 return; 106 152 } 107 setEnabled(!selection.isEmpty()); 153 setEnabled(true); 154 //setEnabled(!selection.isEmpty()); 108 155 } 109 156 }
Note:
See TracChangeset
for help on using the changeset viewer.