Changeset 23851 in osm for applications
- Timestamp:
- 2010-10-26T20:03:29+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AddressEditDialog.java
r23835 r23851 17 17 18 18 import java.awt.BorderLayout; 19 import java.awt.Color; 19 20 import java.awt.Dimension; 20 21 import java.awt.FlowLayout; 22 import java.awt.Font; 21 23 import java.awt.GridLayout; 22 24 import java.awt.HeadlessException; 23 25 import java.awt.event.ActionEvent; 24 26 import java.awt.event.ActionListener; 27 import java.util.List; 25 28 26 29 import javax.swing.JButton; … … 36 39 import javax.swing.event.ListSelectionListener; 37 40 41 import org.openstreetmap.gui.jmapviewer.JMapViewer; 42 import org.openstreetmap.gui.jmapviewer.MapMarkerDot; 43 import org.openstreetmap.josm.data.osm.BBox; 44 import org.openstreetmap.josm.data.osm.Node; 45 import org.openstreetmap.josm.data.osm.Way; 38 46 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 39 40 public class AddressEditDialog extends JFrame implements ActionListener, ListSelectionListener { 47 import org.openstreetmap.josm.plugins.addressEdit.AddressNode; 48 import org.openstreetmap.josm.plugins.addressEdit.IAddressEditContainerListener; 49 import org.openstreetmap.josm.plugins.addressEdit.INodeEntity; 50 import org.openstreetmap.josm.plugins.addressEdit.StreetNode; 51 import org.openstreetmap.josm.plugins.addressEdit.StreetSegmentNode; 52 53 public class AddressEditDialog extends JFrame implements ActionListener, ListSelectionListener, IAddressEditContainerListener { 54 private static final String INCOMPLETE_HEADER_FMT = tr("Incomplete Addresses (%d)"); 55 private static final String UNRESOLVED_HEADER_FMT = tr("Unresolved Addresses (%d)"); 56 private static final String STREET_HEADER_FMT = tr("Streets (%d)"); 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 AddressEditContainer addressContainer;63 private AddressEditContainer editContainer; 48 64 private JTable unresolvedTable; 49 65 private JTable incompleteTable; … … 55 71 resolveAction 56 72 }; 73 private JLabel streetLabel; 74 private JLabel incompleteAddressesLabel; 75 private JLabel unresolvedAddressesLabel; 76 private JMapViewer mapViewer; 77 private JLabel mapLabel; 57 78 58 79 /** … … 63 84 super(tr("Edit Addresses")); 64 85 65 this.addressContainer = addressEditContainer; 86 this.editContainer = addressEditContainer; 87 this.editContainer.addChangedListener(this); 66 88 setLayout(new BorderLayout()); 67 setSize( 800,600);89 setSize(1024,600); 68 90 // TODO: Center on screen 69 91 setLocation(100, 100); 92 70 93 71 94 // TODO: Proper init, if model is null 72 95 if (addressEditContainer != null) { 96 /* Panel for street table */ 73 97 JPanel streetPanel = new JPanel(new BorderLayout()); 74 streetList = new JTable(new StreetTableModel( addressContainer));98 streetList = new JTable(new StreetTableModel(editContainer)); 75 99 streetList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 76 100 streetList.getSelectionModel().addListSelectionListener(this); … … 78 102 JScrollPane scroll1 = new JScrollPane(streetList); 79 103 streetPanel.add(scroll1, BorderLayout.CENTER); 80 streetPanel.add(new JLabel("Streets"), BorderLayout.NORTH); 81 streetPanel.setMinimumSize(new Dimension(350, 400)); 82 104 105 streetLabel = createHeaderLabel(STREET_HEADER_FMT, editContainer.getNumberOfStreets()); 106 streetPanel.add(streetLabel, BorderLayout.NORTH); 107 streetPanel.setMinimumSize(new Dimension(350, 300)); 108 109 /* Panel for unresolved addresses table */ 83 110 JPanel unresolvedPanel = new JPanel(new BorderLayout()); 84 unresolvedTable = new JTable(new UnresolvedAddressesTableModel( addressContainer));111 unresolvedTable = new JTable(new UnresolvedAddressesTableModel(editContainer)); 85 112 unresolvedTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 86 113 unresolvedTable.getSelectionModel().addListSelectionListener(this); … … 88 115 JScrollPane scroll2 = new JScrollPane(unresolvedTable); 89 116 unresolvedPanel.add(scroll2, BorderLayout.CENTER); 90 unresolvedPanel.add(new JLabel("Unresolved Addresses"), BorderLayout.NORTH); 117 unresolvedAddressesLabel = createHeaderLabel( 118 UNRESOLVED_HEADER_FMT, editContainer.getNumberOfUnresolvedAddresses()); 119 unresolvedPanel.add(unresolvedAddressesLabel , BorderLayout.NORTH); 91 120 unresolvedPanel.setMinimumSize(new Dimension(350, 200)); 92 121 … … 96 125 unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH); 97 126 98 JPanel incompletePanel = new JPanel(new BorderLayout());99 100 incompleteTable = new JTable(new IncompleteAddressesTableModel( addressContainer));127 /* Panel for incomplete addresses */ 128 JPanel incompletePanel = new JPanel(new BorderLayout()); 129 incompleteTable = new JTable(new IncompleteAddressesTableModel(editContainer)); 101 130 incompleteTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 102 131 incompleteTable.getSelectionModel().addListSelectionListener(this); … … 104 133 105 134 incompletePanel.add(scroll3, BorderLayout.CENTER); 106 incompletePanel.add(new JLabel("Incomplete Addresses"), BorderLayout.NORTH); 135 incompleteAddressesLabel = createHeaderLabel( 136 INCOMPLETE_HEADER_FMT, editContainer.getNumberOfUnresolvedAddresses()); 137 incompletePanel.add(incompleteAddressesLabel, BorderLayout.NORTH); 107 138 incompletePanel.setMinimumSize(new Dimension(350, 200)); 108 139 109 JSplitPane addrSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, unresolvedPanel, incompletePanel); 110 111 JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, streetPanel, addrSplitPane); 140 /* Edit panel for incomplete addresses */ 141 JPanel incompleteEditPanel = new JPanel(); 142 incompleteEditPanel.setMinimumSize(new Dimension(350, 300)); 143 144 /* Combine panels */ 145 JSplitPane unresSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, streetPanel, unresolvedPanel); 146 JSplitPane addrSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, incompleteEditPanel, incompletePanel); 147 JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, unresSplitPane, addrSplitPane); 148 149 /* Map Panel */ 150 JPanel mapPanel = new JPanel(new BorderLayout()); 151 mapViewer = new JMapViewer(); 152 mapPanel.add(mapViewer, BorderLayout.CENTER); 153 mapPanel.setMinimumSize(new Dimension(200, 200)); 154 mapLabel = createHeaderLabel(tr("Map")); 155 mapPanel.add(mapLabel, BorderLayout.NORTH); 156 mapPanel.add(new JSeparator(), BorderLayout.SOUTH); 157 mapViewer.setVisible(false); 158 112 159 this.getContentPane().add(pane, BorderLayout.CENTER); 160 this.getContentPane().add(mapPanel, BorderLayout.EAST); 113 161 } else { 114 162 this.getContentPane().add(new JLabel(tr("(No data)")), BorderLayout.CENTER); … … 120 168 buttonPanel.add(ok); 121 169 170 // JMapViewer 171 122 172 // Murks 123 173 for (int i = 0; i < 8; i++) { … … 128 178 } 129 179 180 private JLabel createHeaderLabel(String text) { 181 JLabel label = new JLabel(text); 182 label.setFont(label.getFont().deriveFont(Font.BOLD)); 183 return label; 184 } 185 186 private JLabel createHeaderLabel(String fmtString, int n) { 187 JLabel label = new JLabel(String.format(fmtString, n)); 188 label.setFont(label.getFont().deriveFont(Font.BOLD)); 189 return label; 190 } 191 192 private void updateHeaders() { 193 if (editContainer != null) { 194 streetLabel.setText(String.format(STREET_HEADER_FMT, editContainer.getNumberOfStreets())); 195 incompleteAddressesLabel.setText(String.format(INCOMPLETE_HEADER_FMT, editContainer.getNumberOfIncompleteAddresses())); 196 unresolvedAddressesLabel.setText(String.format(UNRESOLVED_HEADER_FMT, editContainer.getNumberOfUnresolvedAddresses())); 197 } else { 198 streetLabel.setText(String.format(STREET_HEADER_FMT, 0)); 199 incompleteAddressesLabel.setText(String.format(INCOMPLETE_HEADER_FMT, 0)); 200 unresolvedAddressesLabel.setText(String.format(UNRESOLVED_HEADER_FMT, 0)); 201 } 202 } 203 130 204 @Override 131 205 public void actionPerformed(ActionEvent e) { … … 144 218 145 219 AddressEditSelectionEvent ev = new AddressEditSelectionEvent(e.getSource(), 146 streetList, unresolvedTable, incompleteTable, addressContainer);220 streetList, unresolvedTable, incompleteTable, editContainer); 147 221 148 222 for (AbstractAddressEditAction action : actions) { 149 223 action.updateEnabledState(ev); 150 224 } 225 226 clearMapViewer(); 227 StreetNode sNode = ev.getSelectedStreet(); 228 if (sNode != null) { 229 230 //mapViewer.addMapRectangle(new BBoxMapRectangle(bb)); 231 for (INodeEntity seg : sNode.getChildren()) { 232 Way way = (Way) seg.getOsmObject(); 233 //BBox bb = way.getBBox(); 234 235 for (Node node : way.getNodes()) { 236 mapViewer.addMapMarker(new MapMarkerDot(Color.GREEN, node.getCoor().lat(), node.getCoor().lon())); 237 } 238 } 239 240 List<AddressNode> incAddresses = ev.getSelectedIncompleteAddresses(); 241 if (incAddresses != null) { 242 for (AddressNode aNode : incAddresses) { 243 Node node = (Node) aNode.getOsmObject(); 244 mapViewer.addMapMarker(new MapMarkerDot(Color.RED, node.getCoor().lat(), node.getCoor().lon())); 245 } 246 } 247 248 List<AddressNode> unrAddresses = ev.getSelectedUnresolvedAddresses(); 249 if (unrAddresses != null) { 250 for (AddressNode aNode : unrAddresses) { 251 Node node = (Node) aNode.getOsmObject(); 252 mapViewer.addMapMarker(new MapMarkerDot(Color.ORANGE, node.getCoor().lat(), node.getCoor().lon())); 253 } 254 } 255 mapViewer.setDisplayToFitMapMarkers(); 256 mapViewer.setVisible(true); 257 } 258 } 259 260 private void clearMapViewer() { 261 mapViewer.setVisible(false); 262 // remove markers and rectangles from map viewer 263 mapViewer.getMapMarkerList().clear(); 264 mapViewer.getMapRectangleList().clear(); 265 } 266 267 @Override 268 public void containerChanged(AddressEditContainer container) { 269 updateHeaders(); 270 } 271 272 @Override 273 public void entityChanged() { 274 updateHeaders(); 151 275 } 152 276
Note:
See TracChangeset
for help on using the changeset viewer.