Changeset 32395 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/CreateRelationAction.java
- Timestamp:
- 2016-06-24T09:10:57+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/CreateRelationAction.java
r27927 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.actions; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.Dialog.ModalityType; 4 7 import java.awt.GridBagLayout; 5 import java.util.Collection;6 import org.openstreetmap.josm.data.osm.OsmPrimitive;7 import static org.openstreetmap.josm.tools.I18n.tr;8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.ActionListener; 10 10 import java.awt.event.KeyEvent; 11 11 import java.util.Arrays; 12 import java.util.Collection; 12 13 import java.util.List; 14 13 15 import javax.swing.Box; 14 16 import javax.swing.JDialog; … … 16 18 import javax.swing.JOptionPane; 17 19 import javax.swing.JPanel; 20 18 21 import org.openstreetmap.josm.Main; 19 22 import org.openstreetmap.josm.actions.JosmAction; 20 23 import org.openstreetmap.josm.command.AddCommand; 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 25 import org.openstreetmap.josm.data.osm.Relation; 22 26 import org.openstreetmap.josm.data.osm.RelationMember; … … 24 28 import org.openstreetmap.josm.tools.GBC; 25 29 import org.openstreetmap.josm.tools.Shortcut; 30 26 31 import relcontext.ChosenRelation; 27 32 … … 36 41 protected ChosenRelation chRel; 37 42 38 public CreateRelationAction( ChosenRelation chRel) {43 public CreateRelationAction(ChosenRelation chRel) { 39 44 super(tr("New"), "data/relation", tr("Create a relation from selected objects"), 40 45 Shortcut.registerShortcut("reltoolbox:create", tr("Relation Toolbox: {0}", tr("Create a new relation")), 41 KeyEvent.VK_N, Shortcut.ALT_CTRL), false);46 KeyEvent.VK_N, Shortcut.ALT_CTRL), false); 42 47 this.chRel = chRel; 43 48 updateEnabledState(); … … 48 53 } 49 54 50 public void actionPerformed( ActionEvent e ) { 55 @Override 56 public void actionPerformed(ActionEvent e) { 51 57 String type = askForType(); 52 if (type == null )58 if (type == null ) 53 59 return; 54 60 55 61 Relation rel = new Relation(); 56 if ( type.length() > 0 )62 if (type.length() > 0 ) { 57 63 rel.put("type", type); 58 for( OsmPrimitive selected : getCurrentDataSet().getSelected() ) 64 } 65 for (OsmPrimitive selected : getCurrentDataSet().getSelected() ) { 59 66 rel.addMember(new RelationMember("", selected)); 67 } 60 68 61 69 Main.main.undoRedo.add(new AddCommand(rel)); 62 70 63 if ( chRel != null) {71 if (chRel != null) { 64 72 chRel.set(rel); 65 73 } … … 68 76 @Override 69 77 protected void updateEnabledState() { 70 if ( getCurrentDataSet() == null) {78 if (getCurrentDataSet() == null) { 71 79 setEnabled(false); 72 80 } else { … … 76 84 77 85 @Override 78 protected void updateEnabledState( Collection<? extends OsmPrimitive> selection) {86 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 79 87 setEnabled(selection != null && !selection.isEmpty()); 80 88 } … … 82 90 // Thanks to TagInfo for the list 83 91 private static final List<String> RELATION_TYPES = Arrays.asList(new String[] { 84 "multipolygon", "boundary", "route", "site", "restriction", "associatedStreet", "public_transport",85 "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction",86 "waterway", "bridge", "tunnel", "surveillance"92 "multipolygon", "boundary", "route", "site", "restriction", "associatedStreet", "public_transport", 93 "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction", 94 "waterway", "bridge", "tunnel", "surveillance" 87 95 }); 88 96 … … 111 119 112 120 keys.getEditor().addActionListener(new ActionListener() { 113 public void actionPerformed( ActionEvent e ) { 121 @Override 122 public void actionPerformed(ActionEvent e) { 114 123 dlg.setVisible(false); 115 124 optionPane.setValue(JOptionPane.OK_OPTION); … … 120 129 121 130 Object answer = optionPane.getValue(); 122 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE123 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION) ) {131 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE 132 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) 124 133 return null; 125 }126 134 127 135 String result = keys.getEditor().getItem().toString().trim();
Note:
See TracChangeset
for help on using the changeset viewer.