Changeset 27357 in osm for applications/editors/josm/plugins/FixAddresses/src/org
- Timestamp:
- 2011-12-30T18:43:30+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesDialog.java
r27322 r27357 16 16 import static org.openstreetmap.josm.tools.I18n.tr; 17 17 18 import java.awt.BorderLayout; 19 20 import javax.swing.JPanel; 21 import javax.swing.JScrollPane; 18 import java.util.LinkedList; 19 22 20 import javax.swing.JTable; 23 21 import javax.swing.SwingUtilities; … … 48 46 @SuppressWarnings("serial") 49 47 public class IncompleteAddressesDialog extends ToggleDialog implements DataSetListener, ListSelectionListener, IAddressEditContainerListener { 50 private static final String FIXED_DIALOG_TITLE = tr("Incomplete Addresses"); 51 52 private AddressEditContainer container; 53 54 55 // Array containing the available actions 56 private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[]{ 57 AddressActions.getSelectAction(), 58 AddressActions.getGuessAddressAction(), 59 AddressActions.getApplyGuessesAction(), 60 AddressActions.getRemoveTagsAction(), 61 }; 62 63 64 private JTable incompleteAddr; 65 66 /** 67 * Instantiates a new "incomplete addresses" dialog. 68 * 69 */ 70 public IncompleteAddressesDialog() { 71 super(FIXED_DIALOG_TITLE, "incompleteaddress_24", tr("Show incomplete addresses"), null, 150); 72 73 this.container = new AddressEditContainer(); 74 container.addChangedListener(this); 75 // Top-level panel 76 JPanel p = new JPanel(new BorderLayout()); 77 // Table containing address entities 78 IncompleteAddressesTableModel model = new IncompleteAddressesTableModel(container); 79 incompleteAddr = new JTable(model); 80 JTableHeader header = incompleteAddr.getTableHeader(); 81 header.addMouseListener(model.new ColumnListener(incompleteAddr)); 82 incompleteAddr.getSelectionModel().addListSelectionListener(this); 83 84 // Scroll pane hosting the table 85 JScrollPane sp = new JScrollPane(incompleteAddr); 86 p.add(sp, BorderLayout.CENTER); 87 this.add(p); 88 89 // Button panel containing the commands 90 JPanel buttonPanel = getButtonPanel(actions.length); 91 92 // Populate panel with actions 93 for (int i = 0; i < actions.length; i++) { 94 SideButton sb = new SideButton(actions[i]); 95 buttonPanel.add(sb); 96 } 97 98 this.add(buttonPanel, BorderLayout.SOUTH); 99 100 // Link actions with address container 101 for (AbstractAddressEditAction action : actions) { 102 action.setContainer(container); 103 } 104 } 105 106 /* (non-Javadoc) 107 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#hideNotify() 108 */ 109 @Override 110 public void hideNotify() { 111 super.hideNotify(); 112 DatasetEventManager.getInstance().removeDatasetListener(this); 113 } 114 115 /* (non-Javadoc) 116 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#showNotify() 117 */ 118 @Override 119 public void showNotify() { 120 super.showNotify(); 121 DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED); 122 } 123 124 /* (non-Javadoc) 125 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent) 126 */ 127 @Override 128 public void dataChanged(DataChangedEvent event) { 129 container.invalidate(); 130 } 131 132 /* (non-Javadoc) 133 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent) 134 */ 135 @Override 136 public void nodeMoved(NodeMovedEvent event) { 137 138 } 139 140 /* (non-Javadoc) 141 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent) 142 */ 143 @Override 144 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 145 // TODO Auto-generated method stub 146 147 } 148 149 /* (non-Javadoc) 150 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent) 151 */ 48 private static final String FIXED_DIALOG_TITLE = tr("Incomplete Addresses"); 49 50 private AddressEditContainer container; 51 52 // Array containing the available actions 53 private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[]{ 54 AddressActions.getSelectAction(), 55 AddressActions.getGuessAddressAction(), 56 AddressActions.getApplyGuessesAction(), 57 AddressActions.getRemoveTagsAction(), 58 }; 59 60 private JTable incompleteAddr; 61 62 /** 63 * Instantiates a new "incomplete addresses" dialog. 64 * 65 */ 66 public IncompleteAddressesDialog() { 67 super(FIXED_DIALOG_TITLE, "incompleteaddress_24", tr("Show incomplete addresses"), null, 150); 68 69 this.container = new AddressEditContainer(); 70 container.addChangedListener(this); 71 // Table containing address entities 72 IncompleteAddressesTableModel model = new IncompleteAddressesTableModel(container); 73 incompleteAddr = new JTable(model); 74 JTableHeader header = incompleteAddr.getTableHeader(); 75 header.addMouseListener(model.new ColumnListener(incompleteAddr)); 76 incompleteAddr.getSelectionModel().addListSelectionListener(this); 77 78 LinkedList<SideButton> buttons = new LinkedList<SideButton>(); 79 // Link actions with address container 80 for (AbstractAddressEditAction action : actions) { 81 buttons.add(new SideButton(action)); 82 action.setContainer(container); 83 } 84 createLayout(incompleteAddr, true, buttons); 85 } 86 87 /* (non-Javadoc) 88 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#hideNotify() 89 */ 90 @Override 91 public void hideNotify() { 92 super.hideNotify(); 93 DatasetEventManager.getInstance().removeDatasetListener(this); 94 } 95 96 /* (non-Javadoc) 97 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#showNotify() 98 */ 99 @Override 100 public void showNotify() { 101 super.showNotify(); 102 DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED); 103 } 104 105 /* (non-Javadoc) 106 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent) 107 */ 108 @Override 109 public void dataChanged(DataChangedEvent event) { 110 container.invalidate(); 111 } 112 113 /* (non-Javadoc) 114 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent) 115 */ 116 @Override 117 public void nodeMoved(NodeMovedEvent event) { 118 119 } 120 121 /* (non-Javadoc) 122 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent) 123 */ 124 @Override 125 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 126 // TODO Auto-generated method stub 127 128 } 129 130 /* (non-Javadoc) 131 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent) 132 */ 152 133 @Override 153 154 155 156 157 158 159 160 134 public void primitivesAdded(PrimitivesAddedEvent event) { 135 container.invalidate(); 136 137 } 138 139 /* (non-Javadoc) 140 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesRemoved(org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent) 141 */ 161 142 @Override 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 143 public void primitivesRemoved(PrimitivesRemovedEvent event) { 144 container.invalidate(); 145 } 146 147 /* (non-Javadoc) 148 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#relationMembersChanged(org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent) 149 */ 150 @Override 151 public void relationMembersChanged(RelationMembersChangedEvent event) { 152 container.invalidate(); 153 } 154 155 /* (non-Javadoc) 156 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#tagsChanged(org.openstreetmap.josm.data.osm.event.TagsChangedEvent) 157 */ 158 @Override 159 public void tagsChanged(TagsChangedEvent event) { 160 container.invalidate(); 161 162 } 163 164 /* (non-Javadoc) 165 * @see org.openstreetmap.josm.data.osm.event.DataSetListener#wayNodesChanged(org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent) 166 */ 167 @Override 168 public void wayNodesChanged(WayNodesChangedEvent event) { 169 container.invalidate(); 170 } 171 172 /* (non-Javadoc) 173 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) 174 */ 175 @Override 176 public void valueChanged(ListSelectionEvent e) { 177 AddressEditSelectionEvent event = new AddressEditSelectionEvent(e, null, null, incompleteAddr, container); 178 179 for (AbstractAddressEditAction action : actions) { 180 action.setEvent(event); 181 } 182 183 OsmUtils.zoomAddresses(event.getSelectedIncompleteAddresses()); 184 } 185 186 /* (non-Javadoc) 187 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer) 188 */ 189 @Override 190 public void containerChanged(AddressEditContainer container) { 191 if (SwingUtilities.isEventDispatchThread()) { 192 if (container != null && container.getNumberOfIncompleteAddresses() > 0) { 193 setTitle(String.format("%s (%d %s)", FIXED_DIALOG_TITLE, container.getNumberOfIncompleteAddresses(), tr("items"))); 194 } else { 195 setTitle(String.format("%s (%s)", FIXED_DIALOG_TITLE, tr("no items"))); 196 } 197 } 198 } 199 200 /* (non-Javadoc) 201 * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity) 202 */ 203 @Override 204 public void entityChanged(IOSMEntity node) { 205 if (SwingUtilities.isEventDispatchThread()) { 206 container.invalidate(); 207 } 208 } 228 209 }
Note:
See TracChangeset
for help on using the changeset viewer.