Changeset 25670 in osm for applications/editors/josm
- Timestamp:
- 2011-03-22T22:57:56+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext/src/relcontext
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelationComponent.java
r25669 r25670 1 /*2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5 6 1 package relcontext; 7 2 8 import java.awt.event.MouseAdapter;9 import java.awt.event.MouseEvent;10 3 import javax.swing.JLabel; 11 import org.openstreetmap.josm.Main;12 4 import org.openstreetmap.josm.data.osm.Relation; 13 import org.openstreetmap.josm.gui.DefaultNameFormatter;14 5 15 6 /** … … 28 19 this.chRel = rel; 29 20 rel.addChosenRelationListener(this); 30 addMouseListener(new MouseAdapter() {31 @Override32 public void mouseClicked( MouseEvent e ) {33 if( chRel.get() != null && Main.map.mapView.getEditLayer() != null )34 Main.map.mapView.getEditLayer().data.setSelected(chRel.get());35 }36 });37 21 } 38 22 -
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25669 r25670 26 26 import java.util.*; 27 27 import javax.swing.*; 28 import org.openstreetmap.josm.data.osm.DataSet;29 28 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 30 29 import relcontext.actions.*; … … 40 39 private ChosenRelation chosenRelation; 41 40 private JPanel topLine; 41 private ChosenRelationPopupMenu popupMenu; 42 42 43 43 public RelContextDialog() { … … 80 80 topLeftButtons.add(new JButton(new ClearChosenRelationAction(chosenRelation))); 81 81 topLine.add(topLeftButtons, BorderLayout.WEST); 82 topLine.add(new ChosenRelationComponent(chosenRelation), BorderLayout.CENTER); 82 final ChosenRelationComponent chosenRelationComponent = new ChosenRelationComponent(chosenRelation); 83 chosenRelationComponent.addMouseListener(new ChosenRelationMouseAdapter()); 84 topLine.add(chosenRelationComponent, BorderLayout.CENTER); 83 85 JPanel topRightButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 84 86 final Action downloadChosenRelationAction = new DownloadChosenRelationAction(chosenRelation); … … 104 106 105 107 add(rcPanel, BorderLayout.CENTER); 108 109 popupMenu = new ChosenRelationPopupMenu(); 106 110 } 107 111 … … 160 164 updateSelection(); 161 165 } 166 167 private class ChosenRelationMouseAdapter extends MouseAdapter { 168 @Override 169 public void mouseClicked( MouseEvent e ) { 170 if( SwingUtilities.isLeftMouseButton(e) && chosenRelation.get() != null && Main.map.mapView.getEditLayer() != null ) { 171 Main.map.mapView.getEditLayer().data.setSelected(chosenRelation.get()); 172 } 173 } 174 175 @Override 176 public void mousePressed( MouseEvent e ) { 177 checkPopup(e); 178 } 179 180 @Override 181 public void mouseReleased( MouseEvent e ) { 182 checkPopup(e); 183 } 184 185 private void checkPopup( MouseEvent e ) { 186 if( e.isPopupTrigger() && chosenRelation.get() != null ) { 187 popupMenu.show(e.getComponent(), e.getX(), e.getY()); 188 } 189 } 190 } 191 192 private class ChosenRelationPopupMenu extends JPopupMenu { 193 public ChosenRelationPopupMenu() { 194 add(new SelectMembersAction(chosenRelation)); 195 add(new DeleteChosenRelationAction(chosenRelation)); 196 } 197 } 162 198 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java
r25669 r25670 1 1 package relcontext.actions; 2 2 3 import java.util.Collection;4 3 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 import java.awt.event.ActionEvent; 7 import java.util.LinkedList; 6 import java.util.*; 7 import javax.swing.JOptionPane; 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.actions.JosmAction; 10 10 import org.openstreetmap.josm.command.AddCommand; 11 import org.openstreetmap.josm.command.ChangePropertyCommand; 11 12 import org.openstreetmap.josm.command.Command; 13 import org.openstreetmap.josm.command.SequenceCommand; 14 import org.openstreetmap.josm.data.osm.MultipolygonCreate; 12 15 import org.openstreetmap.josm.data.osm.Relation; 13 16 import org.openstreetmap.josm.data.osm.RelationMember; … … 36 39 37 40 public void actionPerformed( ActionEvent e ) { 38 // todo! 39 41 // for now, just copying standard action 42 MultipolygonCreate mpc = new MultipolygonCreate(); 43 String error = mpc.makeFromWays(getCurrentDataSet().getSelectedWays()); 44 if( error != null ) { 45 JOptionPane.showMessageDialog(Main.parent, error); 46 return; 47 } 40 48 Relation rel = new Relation(); 41 49 rel.put("type", "multipolygon"); 42 for( OsmPrimitive selected : getCurrentDataSet().getSelected() ) { 43 rel.addMember(new RelationMember("", selected)); 44 } 45 46 Collection<Command> cmds = new LinkedList<Command>(); 47 Main.main.undoRedo.add(new AddCommand(rel)); 48 49 if( chRel != null ) { 50 for( MultipolygonCreate.JoinedPolygon poly : mpc.outerWays ) 51 for( Way w : poly.ways ) 52 rel.addMember(new RelationMember("outer", w)); 53 for( MultipolygonCreate.JoinedPolygon poly : mpc.innerWays ) 54 for( Way w : poly.ways ) 55 rel.addMember(new RelationMember("inner", w)); 56 List<Command> list = removeTagsFromInnerWays(rel); 57 list.add(new AddCommand(rel)); 58 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), list)); 59 60 if( chRel != null ) 50 61 chRel.set(rel); 51 }52 62 } 53 63 … … 75 85 setEnabled(enabled); 76 86 } 87 88 /** 89 * This method removes tags/value pairs from inner ways that are present in relation or outer ways. 90 * It was copypasted from the standard {@link org.openstreetmap.josm.actions.CreateMultipolygonAction}. 91 * Todo: rewrite it. 92 */ 93 private List<Command> removeTagsFromInnerWays(Relation relation) { 94 Map<String, String> values = new HashMap<String, String>(); 95 96 if (relation.hasKeys()){ 97 for(String key: relation.keySet()) { 98 values.put(key, relation.get(key)); 99 } 100 } 101 102 List<Way> innerWays = new ArrayList<Way>(); 103 104 for (RelationMember m: relation.getMembers()) { 105 106 if (m.hasRole() && m.getRole() == "inner" && m.isWay() && m.getWay().hasKeys()) { 107 innerWays.add(m.getWay()); 108 } 109 110 if (m.hasRole() && m.getRole() == "outer" && m.isWay() && m.getWay().hasKeys()) { 111 Way way = m.getWay(); 112 for (String key: way.keySet()) { 113 if (!values.containsKey(key)) { //relation values take precedence 114 values.put(key, way.get(key)); 115 } 116 } 117 } 118 } 119 120 List<Command> commands = new ArrayList<Command>(); 121 122 for(String key: values.keySet()) { 123 List<OsmPrimitive> affectedWays = new ArrayList<OsmPrimitive>(); 124 String value = values.get(key); 125 126 for (Way way: innerWays) { 127 if (value.equals(way.get(key))) { 128 affectedWays.add(way); 129 } 130 } 131 132 if (affectedWays.size() > 0) { 133 commands.add(new ChangePropertyCommand(affectedWays, key, null)); 134 } 135 } 136 137 return commands; 138 } 77 139 }
Note:
See TracChangeset
for help on using the changeset viewer.