Changeset 23829 in osm for applications/editors/josm
- Timestamp:
- 2010-10-25T22:18:31+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit
- Files:
-
- 6 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/AddressEditAction.java
r23814 r23829 8 8 import java.util.Collection; 9 9 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.actions.JosmAction; 12 11 import org.openstreetmap.josm.data.SelectionChangedListener; 13 import org.openstreetmap.josm.data.osm.DataSet;14 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;16 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor.CancelListener; 17 14 import org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditDialog; … … 28 25 private AddressEditModel addressModel; 29 26 private boolean isCanceled = false; 27 private AddressEditContainer addressEditContainer; 30 28 31 29 public AddressEditAction() { … … 37 35 | InputEvent.SHIFT_DOWN_MASK), false); 38 36 setEnabled(false); 39 DataSet.addSelectionListener(this);37 40 38 } 41 39 … … 49 47 @Override 50 48 public void actionPerformed(ActionEvent arg0) { 51 collectAddressesAndStreets(Main.main.getCurrentDataSet() 52 .allPrimitives()); 53 54 if (addressModel != null) { 55 AddressEditDialog dlg = new AddressEditDialog(addressModel); 56 dlg.setVisible(true); 49 addressEditContainer = new AddressEditContainer(); 50 if (addressEditContainer != null) { 51 addressEditContainer.attachToDataSet(); 52 try { 53 AddressEditDialog dlg = new AddressEditDialog(addressEditContainer); 54 dlg.setVisible(true); 55 } finally { 56 addressEditContainer.detachFromDataSet(); 57 } 57 58 } 58 59 } … … 63 64 return; 64 65 65 final AddressVisitor addrVisitor = new AddressVisitor(); 66 67 //final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Prepare OSM data...")); 68 // int ticks = osmData.size(); 69 70 71 72 try { 73 for (OsmPrimitive osm : osmData) { 74 osm.visit(addrVisitor); 75 76 if (isCanceled) { 77 addrVisitor.clearData(); // free visitor data 78 return; 79 } 80 } 81 //monitor.worked(1); 82 83 // generateTagCode(addrVisitor); 84 //monitor.setCustomText(tr("Resolving addresses...")); 85 addrVisitor.resolveAddresses(); 86 //monitor.worked(1); 87 88 89 } finally { 90 //monitor.close(); 91 } 92 93 addressModel = new AddressEditModel( 94 addrVisitor.getStreetList(), 95 addrVisitor.getUnresolvedItems()); 66 96 67 } 97 68 … … 109 80 /* ----------------------------------------- */ 110 81 111 private void generateTagCode(Address Visitor addrVisitor) {82 private void generateTagCode(AddressEditContainer addrVisitor) { 112 83 /* This code is abused to generate tag utility code */ 113 84 for (String tag : addrVisitor.getTags()) { -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/AddressNode.java
r23816 r23829 112 112 cc = this.getCountry().compareTo(other.getCountry()); 113 113 if ( cc == 0) { 114 cc = this.getState().compareTo(other.getState()); 115 114 cc = this.getState().compareTo(other.getState()); 116 115 if (cc == 0) { 117 cc = this.getCity().compareTo(other.getCity()); 118 116 cc = this.getCity().compareTo(other.getCity()); 119 117 if (cc == 0) { 120 cc = this.getStreet().compareTo(other.getStreet()); 121 118 cc = this.getStreet().compareTo(other.getStreet()); 122 119 if (cc == 0) { 123 120 cc = this.getHouseNumber().compareTo(other.getHouseNumber()); … … 128 125 129 126 return cc; 127 } 128 129 /** 130 * Applies the street name from the specified street node. 131 * @param node 132 */ 133 public void assignStreet(StreetNode node) { 134 if (node == null || !node.hasName()) return; 135 136 if (!node.getName().equals(getStreet())) { 137 setStreetName(node.getName()); 138 node.addAddress(this); 139 } 140 } 141 142 /** 143 * Sets the street name of the address node. 144 * @param streetName 145 */ 146 public void setStreetName(String streetName) { 147 if (streetName != null && streetName.length() == 0) return; 148 149 this.osmObject.put(TagUtils.ADDR_STREET_TAG, streetName); 150 } 151 152 /** 153 * Sets the state of the address node. 154 * @param state 155 */ 156 public void setState(String state) { 157 if (state != null && state.length() == 0) return; 158 159 this.osmObject.put(TagUtils.ADDR_STATE_TAG, state); 160 } 161 162 /** 163 * Sets the country of the address node. 164 * @param country 165 */ 166 public void setCountry(String country) { 167 if (country != null && country.length() == 0) return; 168 169 this.osmObject.put(TagUtils.ADDR_COUNTRY_TAG, country); 170 } 171 172 /** 173 * Sets the post code of the address node. 174 * @param postCode 175 */ 176 public void setPostCode(String postCode) { 177 if (postCode != null && postCode.length() == 0) return; 178 179 this.osmObject.put(TagUtils.ADDR_POSTCODE_TAG, postCode); 130 180 } 131 181 -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/StreetNode.java
r23816 r23829 16 16 import java.util.ArrayList; 17 17 import java.util.Collections; 18 import java.util.HashMap; 19 import java.util.HashSet; 18 20 import java.util.List; 19 21 … … 81 83 } 82 84 85 /** 86 * Gets the number of addresses associated with this street. 87 * @return 88 */ 89 public int getNumberOfAddresses() { 90 if (addresses == null) return 0; 91 92 return addresses.size(); 93 } 94 95 /** 96 * Gets the number of street segments of this street. 97 * @return 98 */ 99 public int getNumberOfSegments() { 100 if (children == null) return 0; 101 102 int sc = 0; 103 for (INodeEntity node : children) { 104 if (node instanceof StreetSegmentNode) { 105 sc++; 106 } 107 } 108 return sc; 109 } 110 111 /** 112 * Gets the road type(s) of this street. If the street has different types, 113 * they are separated by comma. 114 * @return 115 */ 116 public String getType() { 117 List<String> types = new ArrayList<String>(); 118 119 for (INodeEntity seg : getChildren()) { 120 OsmPrimitive osmPrim = seg.getOsmObject(); 121 if (TagUtils.hasHighwayTag(osmPrim)) { 122 String val = osmPrim.get(TagUtils.HIGHWAY_TAG); 123 if (!types.contains(val)) { 124 types.add(val); 125 } 126 } 127 } 128 129 StringBuffer sb = new StringBuffer(20); 130 for (String string : types) { 131 if (sb.length() > 0) { 132 sb.append(", "); 133 } 134 sb.append(string); 135 136 } 137 return sb.toString(); 138 } 139 140 /* (non-Javadoc) 141 * @see org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#toString() 142 */ 83 143 @Override 84 144 public String toString() { -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AddressEditDialog.java
r23816 r23829 31 31 import javax.swing.JSeparator; 32 32 import javax.swing.JSplitPane; 33 import javax.swing.JTable; 33 34 import javax.swing.JTree; 35 import javax.swing.ListSelectionModel; 36 import javax.swing.event.ListSelectionEvent; 37 import javax.swing.event.ListSelectionListener; 34 38 import javax.swing.event.TreeSelectionEvent; 35 39 import javax.swing.event.TreeSelectionListener; 40 import javax.swing.table.DefaultTableModel; 36 41 import javax.swing.tree.DefaultMutableTreeNode; 37 42 import javax.swing.tree.DefaultTreeModel; 38 import javax.swing.tree.TreeSelectionModel;39 43 40 public class AddressEditDialog extends JFrame implements ActionListener, TreeSelectionListener { 44 import org.openstreetmap.josm.Main; 45 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 46 import org.openstreetmap.josm.data.osm.event.DataChangedEvent; 47 import org.openstreetmap.josm.data.osm.event.DataSetListener; 48 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent; 49 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent; 50 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent; 51 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent; 52 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 53 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 54 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 55 56 public class AddressEditDialog extends JFrame implements ActionListener, TreeSelectionListener, ListSelectionListener { 41 57 private static final String CANCEL_COMMAND = "Cancel"; 42 58 private static final String OK_COMMAND = "Ok"; … … 45 61 */ 46 62 private static final long serialVersionUID = 6251676464816335631L; 47 private AddressEdit Modelmodel;63 private AddressEditContainer model; 48 64 private JTree unresolvedTree; 49 65 private JTree incompleteTree; 50 private JT ree streetsTree;66 private JTable streetList; 51 67 private DefaultMutableTreeNode selStreet; 52 68 private DefaultMutableTreeNode selUnrAddr; … … 63 79 * @throws HeadlessException 64 80 */ 65 public AddressEditDialog(AddressEdit Model model) throws HeadlessException {81 public AddressEditDialog(AddressEditContainer addressEditContainer) throws HeadlessException { 66 82 super(tr("Edit Addresses")); 67 83 68 this.model = model;84 this.model = addressEditContainer; 69 85 setLayout(new BorderLayout()); 70 86 setSize(800,600); 71 87 // TODO: Center on screen 72 88 setLocation(100, 100); 73 89 74 90 // TODO: Proper init, if model is null 75 if ( model!= null) {91 if (addressEditContainer != null) { 76 92 JPanel streetPanel = new JPanel(new BorderLayout()); 77 streetsTree = new JTree(new DefaultTreeModel(model.getStreetsTree())); 93 /* 94 streetsTree = new JTree(new DefaultTreeModel(addressEditContainer.getStreetsTree())); 78 95 streetsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 79 96 streetsTree.addTreeSelectionListener(this); 80 97 streetsTree.setCellRenderer(new StreetTreeCellRenderer()); 98 */ 99 streetList = new JTable(new StreetTableModel(model)); 100 streetList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 81 101 82 JScrollPane scroll1 = new JScrollPane(street sTree);102 JScrollPane scroll1 = new JScrollPane(streetList); 83 103 streetPanel.add(scroll1, BorderLayout.CENTER); 84 104 streetPanel.add(new JLabel("Unresolved Addresses"), BorderLayout.NORTH); 85 streetPanel.setMinimumSize(new Dimension(3 00, 400));105 streetPanel.setMinimumSize(new Dimension(350, 400)); 86 106 87 107 JPanel unresolvedPanel = new JPanel(new BorderLayout()); 88 unresolvedTree = new JTree(new DefaultTreeModel( model.getUnresolvedAddressesTree()));108 unresolvedTree = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode())); 89 109 unresolvedTree.addTreeSelectionListener(this); 90 110 … … 92 112 unresolvedPanel.add(scroll2, BorderLayout.CENTER); 93 113 unresolvedPanel.add(new JLabel("Unresolved Addresses"), BorderLayout.NORTH); 94 unresolvedPanel.setMinimumSize(new Dimension(3 00, 200));114 unresolvedPanel.setMinimumSize(new Dimension(350, 200)); 95 115 96 116 JPanel unresolvedButtons = new JPanel(new FlowLayout()); … … 100 120 101 121 JPanel incompletePanel = new JPanel(new BorderLayout()); 102 incompleteTree = new JTree(new DefaultTreeModel( model.getIncompleteAddressesTree()));122 incompleteTree = new JTree(new DefaultTreeModel(new DefaultMutableTreeNode())); 103 123 incompleteTree.addTreeSelectionListener(this); 104 124 JScrollPane scroll3 = new JScrollPane(incompleteTree); 105 125 incompletePanel.add(scroll3, BorderLayout.CENTER); 106 126 incompletePanel.add(new JLabel("Incomplete Addresses"), BorderLayout.NORTH); 107 incompletePanel.setMinimumSize(new Dimension(3 00, 200));127 incompletePanel.setMinimumSize(new Dimension(350, 200)); 108 128 109 129 JSplitPane addrSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, unresolvedPanel, incompletePanel); … … 112 132 this.getContentPane().add(pane, BorderLayout.CENTER); 113 133 } else { 134 streetList = new JTable(new DefaultTableModel()); 114 135 this.getContentPane().add(new JLabel(tr("(No data)")), BorderLayout.CENTER); 115 136 } … … 131 152 } 132 153 133 public AddressEditModel getModel() {134 return model;135 }136 137 public void setModel(AddressEditModel model) {138 if (this.model != model) {139 this.model = model;140 if (model != null) {141 streetsTree.setModel(new DefaultTreeModel(model.getStreetsTree()));142 unresolvedTree.setModel(new DefaultTreeModel(model.getUnresolvedAddressesTree()));143 incompleteTree.setModel(new DefaultTreeModel(model.getIncompleteAddressesTree()));144 }145 }146 }147 148 154 @Override 149 155 public void actionPerformed(ActionEvent e) { … … 161 167 public void valueChanged(TreeSelectionEvent event) { 162 168 // Updates the selection 163 if (event.getSource() == streetsTree) { 164 selStreet = (DefaultMutableTreeNode) streetsTree.getLastSelectedPathComponent(); 169 if (event.getSource() == streetList) { 170 int selStr = streetList.getSelectedRow(); 171 165 172 } 166 173 167 if (event.getSource() == unresolvedTree) { 168 selUnrAddr = (DefaultMutableTreeNode) unresolvedTree.getLastSelectedPathComponent(); 169 } 170 171 if (event.getSource() == incompleteTree) { 172 selIncAddr = (DefaultMutableTreeNode) incompleteTree.getLastSelectedPathComponent(); 173 } 174 174 /* 175 175 AddressSelectionEvent ev = new AddressSelectionEvent(event.getSource(), 176 176 selStreet, selUnrAddr, selIncAddr); 177 177 for (AbstractAddressEditAction action : actions) { 178 178 action.updateEnabledState(ev); 179 } 179 }*/ 180 180 } 181 182 @Override 183 public void valueChanged(ListSelectionEvent e) { 184 // TODO Auto-generated method stub 185 186 } 187 181 188 }
Note:
See TracChangeset
for help on using the changeset viewer.