- Timestamp:
- 2013-04-13T14:19:56+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java
r5844 r5845 6 6 import java.awt.Color; 7 7 import java.awt.Component; 8 import java.awt.Dimension;9 8 import java.awt.Font; 10 9 import java.awt.GridBagLayout; 11 10 import java.awt.event.ActionEvent; 12 11 import java.awt.event.KeyEvent; 12 import java.awt.event.MouseEvent; 13 13 import java.util.Collection; 14 import java.util.HashMap; 14 15 import javax.swing.AbstractAction; 15 import javax.swing.DefaultCellEditor;16 16 17 17 import javax.swing.JPanel; 18 18 import javax.swing.JTable; 19 import javax.swing.JTextField;20 19 import javax.swing.KeyStroke; 20 import javax.swing.event.CellEditorListener; 21 import javax.swing.event.ChangeEvent; 21 22 import javax.swing.table.DefaultTableModel; 22 23 import javax.swing.table.TableCellEditor; … … 30 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 32 import org.openstreetmap.josm.gui.ExtendedDialog; 32 import org.openstreetmap.josm.gui.util.TableCellEditorSupport;33 33 import org.openstreetmap.josm.gui.util.TableHelper; 34 34 import org.openstreetmap.josm.tools.GBC; … … 50 50 int[] count; 51 51 52 /** 53 * Class for displaying "delete from ... objects" in the table 54 */ 52 55 static class DeleteTagMarker { 53 56 int num; … … 60 63 } 61 64 65 /** 66 * Class for displaying list of existing tag values in the table 67 */ 68 static class ExistingValues { 69 String tag; 70 HashMap<String, Integer> valueCount; 71 public ExistingValues(String tag) { 72 this.tag=tag; valueCount=new HashMap<String, Integer>(); 73 } 74 75 int addValue(String val) { 76 Integer c = valueCount.get(val); 77 int r = c==null? 1 : (c.intValue()+1); 78 valueCount.put(val, r); 79 return r; 80 } 81 82 @Override 83 public String toString() { 84 StringBuilder sb=new StringBuilder(); 85 for (String k: valueCount.keySet()) { 86 if (sb.length()>0) sb.append(", "); 87 sb.append(k); 88 } 89 return sb.toString(); 90 } 91 92 private String getToolTip() { 93 StringBuilder sb=new StringBuilder(); 94 sb.append("<html>"); 95 sb.append(tr("Old values of")); 96 sb.append(" <b>"); 97 sb.append(tag); 98 sb.append("</b><br/>"); 99 for (String k: valueCount.keySet()) { 100 sb.append("<b>"); 101 sb.append(valueCount.get(k)); 102 sb.append(" x </b>"); 103 sb.append(k); 104 sb.append("<br/>"); 105 } 106 sb.append("</html>"); 107 return sb.toString(); 108 109 } 110 } 62 111 63 112 public AddTagsDialog(String[][] tags) { … … 70 119 71 120 72 DefaultTableModel tm = new DefaultTableModel(new String[] {tr("Assume"), tr("Key"), tr("Value")}, tags.length) {73 final Class<?> types[] = {Boolean.class, String.class, Object.class };121 final DefaultTableModel tm = new DefaultTableModel(new String[] {tr("Assume"), tr("Key"), tr("Value"), tr("Existing values")}, tags.length) { 122 final Class<?> types[] = {Boolean.class, String.class, Object.class, ExistingValues.class}; 74 123 @Override 75 124 public Class getColumnClass(int c) { … … 85 134 count[i] = 0; 86 135 String key = tags[i][0]; 87 String value = tags[i][1] ;136 String value = tags[i][1], oldValue; 88 137 Boolean b = Boolean.TRUE; 138 ExistingValues old = new ExistingValues(key); 89 139 for (OsmPrimitive osm : sel) { 90 if (osm.keySet().contains(key) && !osm.get(key).equals(value)) { 91 b = Boolean.FALSE; 92 count[i]++; 93 break; 140 oldValue = osm.get(key); 141 if (oldValue!=null) { 142 old.addValue(oldValue); 143 if (!oldValue.equals(value)) { 144 b = Boolean.FALSE; 145 count[i]++; 146 } 94 147 } 95 148 } … … 97 150 tm.setValueAt(tags[i][0], i, 1); 98 151 tm.setValueAt(tags[i][1].isEmpty() ? new DeleteTagMarker(count[i]) : tags[i][1], i, 2); 99 } 100 152 tm.setValueAt(old , i, 3); 153 } 154 101 155 propertyTable = new JTable(tm) { 102 156 … … 120 174 public TableCellEditor getCellEditor(int row, int column) { 121 175 Object value = getValueAt(row,column); 122 System.out.println(value);123 176 if (value instanceof DeleteTagMarker) return null; 177 if (value instanceof ExistingValues) return null; 124 178 return getDefaultEditor(value.getClass()); 125 179 } 180 181 @Override 182 public String getToolTipText(MouseEvent event) { 183 int r = rowAtPoint(event.getPoint()); 184 int c = columnAtPoint(event.getPoint()); 185 Object o = getValueAt(r, c); 186 if (c==1 || c==2) return o.toString(); 187 if (c==3) return ((ExistingValues)o).getToolTip(); 188 return tr("Enable the checkbox to accept the value"); 189 } 190 126 191 }; 127 192 … … 129 194 // a checkbox has a size of 15 px 130 195 propertyTable.getColumnModel().getColumn(0).setMaxWidth(15); 131 TableHelper.adjustColumnWidth(propertyTable, 1, 200); 132 TableHelper.adjustColumnWidth(propertyTable, 2, 700); 196 TableHelper.adjustColumnWidth(propertyTable, 1, 150); 197 TableHelper.adjustColumnWidth(propertyTable, 2, 400); 198 TableHelper.adjustColumnWidth(propertyTable, 3, 300); 133 199 // get edit results if the table looses the focus, for example if a user clicks "add tags" 134 200 propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); … … 139 205 } 140 206 }); 141 207 142 208 // set the content of this AddTagsDialog consisting of the tableHeader and the table itself. 143 209 JPanel tablePanel = new JPanel(); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r5844 r5845 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Point; 6 7 import java.util.HashMap; 7 8 import org.openstreetmap.josm.Main; … … 10 11 import org.openstreetmap.josm.data.coor.LatLon; 11 12 import org.openstreetmap.josm.data.osm.Node; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 14 import org.openstreetmap.josm.gui.util.GuiHelper; 13 15 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; … … 64 66 // Create a new node 65 67 LatLon ll = new LatLon(lat, lon); 66 Node nnew = new Node(ll);67 68 68 // Now execute the commands to add this node. 69 Main.main.undoRedo.add(new AddCommand(nnew)); 70 Main.main.getCurrentDataSet().setSelected(nnew); 69 Node nd = null; 70 71 if (Main.map != null && Main.map.mapView != null) { 72 Point p = Main.map.mapView.getPoint(ll); 73 nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate); 74 if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remotecontrol.tolerance", 0.1)) { 75 nd = null; // node is too far 76 } 77 } 78 79 if (nd==null) { 80 nd = new Node(ll); 81 // Now execute the commands to add this node. 82 Main.main.undoRedo.add(new AddCommand(nd)); 83 } 84 85 Main.main.getCurrentDataSet().setSelected(nd); 71 86 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 72 87 AutoScaleAction.autoScale("selection"); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r5844 r5845 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Point; 5 6 import java.util.ArrayList; 6 7 import java.util.Arrays; 8 import java.util.HashMap; 7 9 import java.util.LinkedList; 8 10 import java.util.List; … … 15 17 import org.openstreetmap.josm.data.coor.LatLon; 16 18 import org.openstreetmap.josm.data.osm.Node; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 20 import org.openstreetmap.josm.data.osm.Way; 18 21 import org.openstreetmap.josm.gui.util.GuiHelper; … … 31 34 32 35 private final List<LatLon> allCoordinates = new ArrayList<LatLon>(); 36 37 /** 38 * The place to remeber already added nodes (they are reused if needed @since 5845 39 */ 40 HashMap<LatLon, Node> addedNodes; 33 41 34 42 @Override … … 84 92 } 85 93 } 94 95 /** 96 * Find the node with almost the same ccords in dataset or in already added nodes 97 * @since 5845 98 **/ 99 Node findOrCreateNode(LatLon ll, List<Command> commands) { 100 Node nd = null; 101 102 if (Main.map != null && Main.map.mapView != null) { 103 Point p = Main.map.mapView.getPoint(ll); 104 nd = Main.map.mapView.getNearestNode(p, OsmPrimitive.isUsablePredicate); 105 if (nd!=null && nd.getCoor().greatCircleDistance(ll) > Main.pref.getDouble("remote.tolerance", 0.1)) { 106 nd = null; // node is too far 107 } 108 } 109 110 Node prev = null; 111 for (LatLon lOld: addedNodes.keySet()) { 112 if (lOld.greatCircleDistance(ll) < Main.pref.getDouble("remotecontrol.tolerance", 0.1)) { 113 prev = addedNodes.get(lOld); 114 break; 115 } 116 } 86 117 118 if (prev!=null) { 119 nd = prev; 120 } else if (nd==null) { 121 nd = new Node(ll); 122 // Now execute the commands to add this node. 123 commands.add(new AddCommand(nd)); 124 addedNodes.put(ll, nd); 125 } 126 return nd; 127 } 128 87 129 /* 88 130 * This function creates the way with given coordinates of nodes 89 131 */ 90 132 private void addWay() { 133 addedNodes = new HashMap<LatLon, Node>(); 91 134 Way way = new Way(); 92 135 List<Command> commands = new LinkedList<Command>(); 93 136 for (LatLon ll : allCoordinates) { 94 Node node = new Node(ll);137 Node node = findOrCreateNode(ll, commands); 95 138 way.addNode(node); 96 commands.add(new AddCommand(node));97 139 } 98 140 allCoordinates.clear();
Note:
See TracChangeset
for help on using the changeset viewer.