Changeset 25688 in osm for applications/editors/josm/plugins/relcontext/src/relcontext
- Timestamp:
- 2011-03-24T14:52:57+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext/src/relcontext
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelationComponent.java
r25685 r25688 1 1 package relcontext; 2 2 3 import java.awt.Color; 3 4 import javax.swing.JLabel; 5 import javax.swing.border.BevelBorder; 6 import javax.swing.border.LineBorder; 4 7 import org.openstreetmap.josm.data.osm.Relation; 5 8 … … 17 20 public ChosenRelationComponent(ChosenRelation rel) { 18 21 super(""); 22 /* setBackground(Color.white); 23 setOpaque(true); 24 setBorder(new LineBorder(Color.black, 1, true));*/ 19 25 this.chRel = rel; 20 26 rel.addChosenRelationListener(this); -
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25685 r25688 1 1 package relcontext; 2 2 3 import java.awt.Component; 3 4 import java.awt.Dimension; 4 5 import org.openstreetmap.josm.tools.ImageProvider; … … 14 15 15 16 import java.awt.BorderLayout; 17 import java.awt.Color; 16 18 import java.awt.Dialog.ModalityType; 17 import java.awt.FlowLayout;18 19 import java.awt.GridBagLayout; 19 20 import java.beans.PropertyChangeEvent; 20 21 import java.beans.PropertyChangeListener; 21 22 import javax.swing.event.ListSelectionListener; 23 import javax.swing.table.DefaultTableCellRenderer; 22 24 23 25 import org.openstreetmap.josm.Main; … … 37 39 import org.openstreetmap.josm.tools.GBC; 38 40 import org.openstreetmap.josm.command.ChangeCommand; 39 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;40 41 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 41 42 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; … … 58 59 59 60 public RelContextDialog() { 60 super(tr(" Advanced Relation Editor"), "icon_relcontext",61 tr("Open s advancedrelation/multipolygon editor panel"),62 Shortcut.registerShortcut(" view:relcontext", tr("Toggle: {0}", tr("Open Relation Editor")),61 super(tr("Relation Toolbox"), "reltoolbox", 62 tr("Open relation/multipolygon editor panel"), 63 Shortcut.registerShortcut("subwindow:reltoolbox", tr("Toggle: {0}", tr("Relation Toolbox")), 63 64 KeyEvent.VK_R, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150, true); 64 65 // todo: shrink all panels to ~20 pixels66 65 67 66 JPanel rcPanel = new JPanel(new BorderLayout()); … … 166 165 } 167 166 167 private static final Color CHOSEN_RELATION_COLOR = new Color(255, 255, 128); 168 168 169 private void configureRelationsTable( final JTable relationsTable ) { 169 170 relationsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 174 175 protected String getComponentToolTipText( OsmPrimitive value ) { 175 176 return null; 177 } 178 179 @Override 180 public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) { 181 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 182 if( !isSelected && value instanceof Relation && chosenRelation.get() != null && value.equals(chosenRelation.get()) ) 183 c.setBackground(CHOSEN_RELATION_COLOR); 184 else 185 c.setBackground(table.getBackground()); 186 return c; 187 } 188 189 }); 190 columns.getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 191 @Override 192 public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) { 193 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 194 if( !isSelected && chosenRelation.get() != null && table.getValueAt(row, 0).equals(chosenRelation.get()) ) 195 c.setBackground(CHOSEN_RELATION_COLOR); 196 else 197 c.setBackground(table.getBackground()); 198 return c; 176 199 } 177 200 }); … … 307 330 possibleRoles.put("tunnel", new String[] {"through", "outline", "edge"}); 308 331 possibleRoles.put("surveillance", new String[] {"camera", "extent", "visible", "hidden"}); 332 possibleRoles.put("street", new String[] {"street", "address", "house", "associated"}); 333 possibleRoles.put("collection", new String[] {"member", "street", "river", "railway", "address", "associated"}); 309 334 } 310 335 … … 341 366 final AutoCompletingComboBox role = new AutoCompletingComboBox(); 342 367 List<AutoCompletionListItem> items = new ArrayList<AutoCompletionListItem>(); 343 for( int i = 0; i < roleBox.getModel().getSize(); i++ ) 344 items.add((AutoCompletionListItem)roleBox.getModel().getElementAt(i)); 368 for( int i = 0; i < roleBox.getModel().getSize(); i++ ) { 369 final AutoCompletionListItem item = (AutoCompletionListItem)roleBox.getModel().getElementAt(i); 370 if( item.getValue().length() > 1 ) 371 items.add(item); 372 } 345 373 role.setPossibleACItems(items); 346 374 role.setEditable(true); -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/AddRemoveMemberAction.java
r25682 r25688 8 8 import org.openstreetmap.josm.actions.JosmAction; 9 9 import org.openstreetmap.josm.command.ChangeCommand; 10 import org.openstreetmap.josm.data.osm.Node; 11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 10 12 import org.openstreetmap.josm.data.osm.Relation; 11 13 import org.openstreetmap.josm.data.osm.RelationMember; 14 import org.openstreetmap.josm.data.osm.Way; 12 15 import org.openstreetmap.josm.tools.ImageProvider; 13 16 import relcontext.ChosenRelation; … … 47 50 // 2. add all new members 48 51 for( OsmPrimitive p : toAdd ) { 49 r.addMember(new RelationMember("", p)); 52 int pos = -1; //p instanceof Way ? findAdjacentMember(p, r) : -1; 53 if( pos < 0 ) 54 r.addMember(new RelationMember("", p)); 55 else 56 r.addMember(pos, new RelationMember("", p)); 50 57 } 51 58 52 59 if( !r.getMemberPrimitives().equals(rel.get().getMemberPrimitives()) ) 53 60 Main.main.undoRedo.add(new ChangeCommand(rel.get(), r)); 61 } 62 63 /** 64 * Finds two relation members between which to place given way. Incomplete. 65 * @see org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel#determineDirection 66 */ 67 protected int findAdjacentMember( Way w, Relation r ) { 68 Node firstNode = w.firstNode(); 69 Node lastNode = w.lastNode(); 70 71 if( firstNode != null && !firstNode.equals(lastNode) ) { 72 for( int i = 0; i < r.getMembersCount(); i++ ) { 73 if( r.getMember(i).getType().equals(OsmPrimitiveType.WAY) ) { 74 Way rw = (Way)r.getMember(i).getMember(); 75 Node firstNodeR = rw.firstNode(); 76 Node lastNodeR = rw.lastNode(); 77 if( firstNode.equals(firstNodeR) || firstNode.equals(lastNodeR) || lastNode.equals(firstNodeR) || lastNode.equals(lastNodeR) ) 78 return i + 1; 79 } 80 } 81 } 82 return -1; 54 83 } 55 84 -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java
r25682 r25688 79 79 private static final List<String> RELATION_TYPES = Arrays.asList(new String[] { 80 80 "multipolygon", "boundary", "route", "site", "restriction", "associatedStreet", "public_transport", 81 "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction", "site",81 "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction", 82 82 "waterway", "bridge", "tunnel", "surveillance" 83 83 }); -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/SortAndFixAction.java
r25682 r25688 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.command.ChangeCommand; 10 import org.openstreetmap.josm.command.Command;11 import org.openstreetmap.josm.command.SequenceCommand;12 10 import org.openstreetmap.josm.data.osm.*; 13 11 import org.openstreetmap.josm.tools.ImageProvider; … … 31 29 if( rel.get() == null ) return; 32 30 Relation r = rel.get(); 33 List<Command> commands = new ArrayList<Command>();31 boolean fixed = false; 34 32 // todo: sort members 35 33 // todo: set roles for multipolygon members 36 Relation fixed = fixMultipolygonRoles(rel.get());37 if( fixed!= null ) {38 commands.add(new ChangeCommand(r, fixed));39 r = fixed;34 Relation rr = fixMultipolygonRoles(r); 35 if( rr != null ) { 36 r = rr; 37 fixed = true; 40 38 } 41 39 // todo: set roles for boundary members 40 rr= fixBoundaryRoles(r); 41 if( rr != null ) { 42 r = rr; 43 fixed = true; 44 } 42 45 43 if( !commands.isEmpty())44 Main.main.undoRedo.add(new SequenceCommand(tr("Sort and fix relation"), commands));46 if( fixed ) 47 Main.main.undoRedo.add(new ChangeCommand(rel.get(), r)); 45 48 } 46 49 47 50 public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) { 48 setEnabled(newRelation != null && areMultipolygonTagsEmpty()); 49 // todo: enable when needs fixing (empty roles or not ordered members) 51 setEnabled(newRelation != null && !isIncomplete(newRelation) && (areMultipolygonTagsEmpty() || areBoundaryTagsNotRight())); 50 52 } 51 53 54 protected boolean isIncomplete( Relation r ) { 55 if( r == null || r.isIncomplete() || r.isDeleted() ) 56 return true; 57 for( RelationMember m : r.getMembers()) 58 if( m.getMember().isIncomplete() ) 59 return true; 60 return false; 61 } 62 63 /** 64 * Check for ways that have roles different from "outer" and "inner". 65 */ 52 66 private boolean areMultipolygonTagsEmpty() { 53 67 Relation r = rel == null ? null : rel.get(); … … 56 70 for( RelationMember m : r.getMembers() ) { 57 71 if( m.getType().equals(OsmPrimitiveType.WAY) && (m.getRole() == null || (!m.getRole().equals("outer") && !m.getRole().equals("inner"))) ) 72 return true; 73 } 74 return false; 75 } 76 77 /** 78 * Check for nodes and relations without needed roles. 79 */ 80 private boolean areBoundaryTagsNotRight() { 81 Relation r = rel == null ? null : rel.get(); 82 if( r == null || r.getMembersCount() == 0 || !r.hasKey("type") || !r.get("type").equals("boundary") ) 83 return false; 84 for( RelationMember m : r.getMembers() ) { 85 if( m.getType().equals(OsmPrimitiveType.RELATION) && (m.getRole() == null || !m.getRole().equals("subarea")) ) 86 return true; 87 else if(m.getType().equals(OsmPrimitiveType.NODE) && (m.getRole() == null || (!m.getRole().equals("label") && !m.getRole().equals("admin_centre"))) ) 58 88 return true; 59 89 } … … 88 118 if( m.getType().equals(OsmPrimitiveType.WAY) ) { 89 119 String role = null; 90 if( outerWays.contains( m.getMember()) )120 if( outerWays.contains((Way)m.getMember()) ) 91 121 role = "outer"; 92 else if( innerWays.contains( m.getMember()) )122 else if( innerWays.contains((Way)m.getMember()) ) 93 123 role = "inner"; 94 124 if( role != null && !role.equals(m.getRole()) ) { … … 100 130 return fixed ? r : null; 101 131 } 132 133 private Relation fixBoundaryRoles( Relation source ) { 134 Relation r = new Relation(source); 135 boolean fixed = false; 136 for( int i = 0; i < r.getMembersCount(); i++ ) { 137 RelationMember m = r.getMember(i); 138 String role = null; 139 if( m.getType().equals(OsmPrimitiveType.RELATION) ) 140 role = "subarea"; 141 else if( m.getType().equals(OsmPrimitiveType.NODE) ) { 142 Node n = (Node)m.getMember(); 143 if( !n.isIncomplete() ) { 144 if( n.hasKey("place") ) 145 role = "admin_centre"; 146 else 147 role = "label"; 148 } 149 } 150 if( role != null && !role.equals(m.getRole()) ) { 151 r.setMember(i, new RelationMember(role, m.getMember())); 152 fixed = true; 153 } 154 } 155 return fixed ? r : null; 156 } 102 157 }
Note:
See TracChangeset
for help on using the changeset viewer.