Changeset 25679 in osm for applications/editors/josm/plugins/relcontext
- Timestamp:
- 2011-03-23T17:23:31+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext/src/relcontext
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelation.java
r25673 r25679 47 47 48 48 private final static String[] MULTIPOLYGON_TYPES = new String[] { 49 "multipolygon", "boundary" , "natural_reserve"49 "multipolygon", "boundary" 50 50 }; 51 51 -
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25678 r25679 1 1 package relcontext; 2 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ComponentEvent; 5 import java.awt.event.FocusEvent; 6 import java.beans.PropertyChangeEvent; 7 import static org.openstreetmap.josm.tools.I18n.tr; 3 import org.openstreetmap.josm.gui.DefaultNameFormatter; 4 import org.openstreetmap.josm.data.osm.NameFormatter; 5 import java.awt.Component; 6 import javax.swing.event.ListSelectionEvent; 7 import javax.swing.table.DefaultTableCellRenderer; 8 import javax.swing.table.TableColumnModel; 9 import javax.swing.table.DefaultTableModel; 10 import java.awt.event.*; 11 import java.util.*; 12 import javax.swing.*; 13 import relcontext.actions.*; 8 14 9 15 import java.awt.BorderLayout; 10 16 import java.awt.Dialog.ModalityType; 11 import java.awt.Dimension;12 17 import java.awt.FlowLayout; 13 18 import java.awt.GridBagLayout; 14 import java.awt.event.ActionListener; 15 import java.awt.event.ComponentAdapter; 16 import java.awt.event.FocusAdapter; 17 import java.awt.event.KeyEvent; 18 import java.awt.event.MouseEvent; 19 import java.awt.event.MouseAdapter; 19 import java.beans.PropertyChangeEvent; 20 20 import java.beans.PropertyChangeListener; 21 import javax.swing.event.ListSelectionListener; 21 22 22 23 import org.openstreetmap.josm.Main; … … 26 27 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 27 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.RelationMember; 30 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 28 31 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 32 import org.openstreetmap.josm.gui.MapView; … … 32 35 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 33 36 import org.openstreetmap.josm.tools.Shortcut; 34 35 import java.util.*; 36 import javax.swing.*; 37 import org.openstreetmap.josm.tools.GBC; 37 38 import org.openstreetmap.josm.command.ChangeCommand; 38 import org.openstreetmap.josm.data.osm.RelationMember;39 import org.openstreetmap.josm.data.osm.event.DatasetEventManager;40 39 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 41 40 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 42 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 43 import org.openstreetmap.josm.tools.GBC; 44 import relcontext.actions.*; 41 import static org.openstreetmap.josm.tools.I18n.tr; 45 42 46 43 /** … … 50 47 */ 51 48 public class RelContextDialog extends ToggleDialog implements EditLayerChangeListener, ChosenRelationListener, SelectionChangedListener { 52 private JList relationsList; 53 private final Default ListModel relationsData;49 50 private final DefaultTableModel relationsData; 54 51 private ChosenRelation chosenRelation; 55 52 private JPanel chosenRelationPanel; … … 71 68 MapView.addEditLayerChangeListener(chosenRelation); 72 69 73 relationsData = new DefaultListModel(); 74 relationsList = new JList(relationsData); 75 relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 76 relationsList.setCellRenderer(new OsmPrimitivRenderer() { 77 @Override 78 protected String getComponentToolTipText( OsmPrimitive value ) { 79 return null; 80 } 81 }); 82 relationsList.addMouseListener(new MouseAdapter() { 83 @Override 84 public void mouseClicked( MouseEvent e ) { 85 if( Main.main.getEditLayer() == null ) { 86 return; 87 } 88 chosenRelation.set((Relation)relationsList.getSelectedValue()); 89 relationsList.clearSelection(); 90 } 91 }); 92 rcPanel.add(new JScrollPane(relationsList), BorderLayout.CENTER); 70 relationsData = new RelationTableModel(); 71 relationsData.setColumnIdentifiers(new String[] {tr("Member Of"), tr("Role")}); 72 final JTable relationsTable = new JTable(relationsData); 73 configureRelationsTable(relationsTable); 74 rcPanel.add(new JScrollPane(relationsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER); 93 75 94 76 chosenRelationPanel = new JPanel(new BorderLayout()); … … 173 155 } 174 156 157 private void configureRelationList( final JList relationsList ) { 158 relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 159 relationsList.setCellRenderer(new OsmPrimitivRenderer() { 160 @Override 161 protected String getComponentToolTipText( OsmPrimitive value ) { 162 return null; 163 } 164 }); 165 relationsList.addMouseListener(new MouseAdapter() { 166 @Override 167 public void mouseClicked( MouseEvent e ) { 168 if( Main.main.getEditLayer() == null ) { 169 return; 170 } 171 chosenRelation.set((Relation)relationsList.getSelectedValue()); 172 relationsList.clearSelection(); 173 } 174 }); 175 } 176 177 private void configureRelationsTable( final JTable relationsTable ) { 178 relationsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 179 relationsTable.setTableHeader(null); 180 TableColumnModel columns = relationsTable.getColumnModel(); 181 columns.getColumn(0).setCellRenderer(new OsmPrimitivRenderer() { 182 @Override 183 protected String getComponentToolTipText( OsmPrimitive value ) { 184 return null; 185 } 186 }); 187 columns.getColumn(1).setPreferredWidth(40); 188 columns.getColumn(0).setPreferredWidth(220); 189 relationsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { 190 public void valueChanged( ListSelectionEvent e ) { 191 int selectedRow = relationsTable.getSelectedRow(); 192 if( selectedRow >= 0 ) { 193 chosenRelation.set((Relation)relationsData.getValueAt(selectedRow, 0)); 194 relationsTable.clearSelection(); 195 } 196 } 197 }); 198 } 199 175 200 @Override 176 201 public void hideNotify() { … … 226 251 updateRoleIndicator(); 227 252 // repopulate relations table 228 relationsData. clear();253 relationsData.setRowCount(0); 229 254 if( newSelection == null ) 230 255 return; 231 Set<Relation> rels = new HashSet<Relation>(); 256 257 final NameFormatter formatter = DefaultNameFormatter.getInstance(); 258 Set<Relation> relations = new TreeSet<Relation>(new Comparator<Relation>() { 259 public int compare( Relation r1, Relation r2 ) { 260 return r1.getDisplayName(formatter).compareTo(r2.getDisplayName(formatter)); 261 } 262 }); 232 263 for( OsmPrimitive element : newSelection ) { 233 264 for( OsmPrimitive ref : element.getReferrers() ) { 234 265 if( ref instanceof Relation && !ref.isIncomplete() && !ref.isDeleted() ) { 235 rels.add((Relation) ref); 236 } 237 } 238 } 239 for( Relation rel : rels ) 240 relationsData.addElement(rel); 266 relations.add((Relation) ref); 267 } 268 } 269 } 270 271 for( Relation rel : relations ) { 272 String role = null; 273 for( RelationMember m : rel.getMembers() ) { 274 for( OsmPrimitive element : newSelection ) { 275 if( m.getMember().equals(element) ) { 276 if( role == null ) 277 role = m.getRole(); 278 else if( !role.equals(m.getRole()) ) { 279 role = tr("<different>"); 280 break; 281 } 282 } 283 } 284 } 285 relationsData.addRow(new Object[] {rel, role == null ? "" : role}); 286 } 241 287 } 242 288 … … 257 303 possibleRoles.put("boundary", new String[] {"admin_centre", "label", "subarea"}); 258 304 possibleRoles.put("route", new String[] {"forward", "backward", "stop", "platform"}); 305 possibleRoles.put("restriction", new String[] {"from", "to", "via", "location_hint"}); 306 possibleRoles.put("enforcement", new String[] {"device", "from", "to", "force"}); 307 possibleRoles.put("destination_sign", new String[] {"to", "from", "intersection", "sign"}); 308 possibleRoles.put("site", new String[] {"perimeter", "entrance", "label"}); 309 possibleRoles.put("bridge", new String[] {"across", "under", "outline", "edge"}); 310 possibleRoles.put("tunnel", new String[] {"through", "outline", "edge"}); 311 possibleRoles.put("surveillance", new String[] {"camera", "extent", "visible", "hidden"}); 259 312 } 260 313 … … 262 315 String currentRole = roleBox.getSelectedItem() == null ? null : ((AutoCompletionListItem)roleBox.getSelectedItem()).getValue(); 263 316 List<String> items = new ArrayList<String>(); 264 items.add(" ");317 items.add(" "); 265 318 if( chosenRelation != null && chosenRelation.get() != null ) { 266 319 if( chosenRelation.isMultipolygon() ) { … … 271 324 String[] values = possibleRoles.get(chosenRelation.get().get("type")); 272 325 if( values != null ) 273 for( String value : values ) 274 items.add(value); 326 items.addAll(Arrays.asList(values)); 275 327 } 276 328 for( RelationMember m : chosenRelation.get().getMembers() ) 277 329 if( !items.contains(m.getRole()) ) 278 330 items.add(m.getRole()); 331 } 332 if( currentRole != null && currentRole.length() > 1 ) { 279 333 lastSelectedRole = currentRole; 280 } else if( currentRole != null && currentRole.length() > 0 ) {281 lastSelectedRole = currentRole;282 334 } 283 335 roleBox.setPossibleItems(items); 284 // todo: store last non-empty role and try to select it if present, but do not store if empty role was chosen 285 // if( lastSelectedRole != null && items.contains(lastSelectedRole) ) 286 // roleBox.setSelectedItem(lastSelectedRole); 287 // else if( lastSelectedRole == null && items.contains("outer") ) 288 // roleBox.setSelectedItem("outer"); 336 if( lastSelectedRole != null && items.contains(lastSelectedRole) ) 337 roleBox.setSelectedItem(lastSelectedRole); 338 // todo: do we really want empty role as default one? Maybe, store last selected role in preferences 289 339 } 290 340 … … 351 401 private void checkPopup( MouseEvent e ) { 352 402 if( e.isPopupTrigger() && chosenRelation.get() != null ) { 353 popupMenu.show(e.getComponent(), e.getX(), e.getY() );403 popupMenu.show(e.getComponent(), e.getX(), e.getY() - 5); 354 404 } 355 405 } … … 360 410 add(new SelectMembersAction(chosenRelation)); 361 411 add(new DeleteChosenRelationAction(chosenRelation)); 412 add(new DownloadParentsAction(chosenRelation)); 362 413 } 363 414 } … … 421 472 } 422 473 } 474 475 private static class RelationTableModel extends DefaultTableModel { 476 @Override 477 public boolean isCellEditable(int row, int column) { 478 return false; 479 } 480 481 @Override 482 public Class<?> getColumnClass(int columnIndex) { 483 return columnIndex == 0 ? Relation.class : String.class; 484 } 485 } 423 486 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java
r25677 r25679 76 76 } 77 77 78 // Thanks to TagInfo for the list 78 79 private static final List<String> RELATION_TYPES = Arrays.asList(new String[] { 79 "multipolygon", "boundary", "route" 80 "multipolygon", "boundary", "route", "site", "restriction", "associatedStreet", "public_transport", 81 "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction", "site", 82 "waterway", "bridge", "tunnel", "surveillance" 80 83 }); 81 84
Note:
See TracChangeset
for help on using the changeset viewer.