Changeset 25672 in osm
- Timestamp:
- 2011-03-23T09:44:28+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext
-
Property svn:ignore
set to
build
nbbuild.xml
nbproject
-
Property svn:ignore
set to
-
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25671 r25672 1 1 package relcontext; 2 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ComponentEvent; 5 import java.awt.event.FocusEvent; 3 6 import java.beans.PropertyChangeEvent; 4 7 import static org.openstreetmap.josm.tools.I18n.tr; 5 8 6 9 import java.awt.BorderLayout; 10 import java.awt.Dimension; 7 11 import java.awt.FlowLayout; 12 import java.awt.GridBagLayout; 13 import java.awt.event.ComponentAdapter; 14 import java.awt.event.FocusAdapter; 8 15 import java.awt.event.KeyEvent; 9 16 import java.awt.event.MouseEvent; … … 26 33 import java.util.*; 27 34 import javax.swing.*; 35 import org.openstreetmap.josm.command.ChangeCommand; 36 import org.openstreetmap.josm.data.osm.RelationMember; 28 37 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 38 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 39 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 40 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 41 import org.openstreetmap.josm.tools.GBC; 29 42 import relcontext.actions.*; 30 43 … … 38 51 private final DefaultListModel relationsData; 39 52 private ChosenRelation chosenRelation; 40 private JPanel topLine;53 private JPanel chosenRelationPanel; 41 54 private ChosenRelationPopupMenu popupMenu; 55 private JLabel crRoleIndicator; 56 private AutoCompletingComboBox roleBox; 57 private String lastSelectedRole; 42 58 43 59 public RelContextDialog() { … … 74 90 rcPanel.add(new JScrollPane(relationsList), BorderLayout.CENTER); 75 91 92 chosenRelationPanel = new JPanel(new BorderLayout()); 93 94 // [^] roles [new role][V][Apply] 95 final JPanel rolePanel = new JPanel(new GridBagLayout()); 96 final JButton toggleRolePanelButtonTop = new JButton(new TogglePanelAction(rolePanel)); 97 final JButton toggleRolePanelButtonIn = new JButton(new TogglePanelAction(rolePanel)); 98 rolePanel.add(toggleRolePanelButtonIn, GBC.std()); 99 crRoleIndicator = new JLabel(); 100 rolePanel.add(crRoleIndicator, GBC.std().insets(5, 0, 5, 0)); 101 102 // autocompleting role chooser 103 roleBox = new AutoCompletingComboBox(); 104 final Action applyNewRoleAction = new ApplyNewRoleAction(); 105 // roleBox.getEditor().addActionListener(applyNewRoleAction); 106 roleBox.setEditable(false); 107 rolePanel.add(roleBox, GBC.std().fill(GBC.HORIZONTAL)); 108 rolePanel.add(new JButton(applyNewRoleAction), GBC.eol()); 109 rolePanel.setVisible(false); 110 76 111 // [±][X] relation U [AZ][Down][Edit] 77 topLine = new JPanel(new BorderLayout());112 JPanel topLine = new JPanel(new BorderLayout()); 78 113 JPanel topLeftButtons = new JPanel(new FlowLayout(FlowLayout.LEFT)); 79 114 topLeftButtons.add(new JButton(new AddRemoveMemberAction(chosenRelation))); 115 topLeftButtons.add(toggleRolePanelButtonTop); 80 116 topLeftButtons.add(new JButton(new ClearChosenRelationAction(chosenRelation))); 81 117 topLine.add(topLeftButtons, BorderLayout.WEST); … … 92 128 topRightButtons.add(new JButton(new EditChosenRelationAction(chosenRelation))); 93 129 topLine.add(topRightButtons, BorderLayout.EAST); 94 rcPanel.add(topLine, BorderLayout.NORTH); 130 131 chosenRelationPanel.add(topLine, BorderLayout.CENTER); 132 chosenRelationPanel.add(rolePanel, BorderLayout.SOUTH); 133 rcPanel.add(chosenRelationPanel, BorderLayout.NORTH); 134 135 rolePanel.addComponentListener(new ComponentAdapter() { 136 @Override 137 public void componentHidden( ComponentEvent e ) { 138 toggleRolePanelButtonTop.setVisible(true); 139 } 140 141 @Override 142 public void componentShown( ComponentEvent e ) { 143 toggleRolePanelButtonTop.setVisible(false); 144 } 145 }); 95 146 96 147 sortAndFixAction.addPropertyChangeListener(new PropertyChangeListener() { … … 107 158 }); 108 159 downloadButton.setVisible(false); 109 topLine.setVisible(false);160 chosenRelationPanel.setVisible(false); 110 161 111 162 // [+][Multi] [X]Adm [X]Tags [X]1 … … 139 190 140 191 public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) { 141 if( topLine!= null )142 topLine.setVisible(newRelation != null);192 if( chosenRelationPanel != null ) 193 chosenRelationPanel.setVisible(newRelation != null); 143 194 if( oldRelation != newRelation && Main.main.getCurrentDataSet() != null ) 144 195 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 196 updateRoleIndicator(); 197 updateRoleAutoCompletionList(); 145 198 // ? 199 } 200 201 private void updateRoleIndicator() { 202 if( crRoleIndicator == null ) 203 return; 204 String role = ""; 205 if( chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) { 206 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 207 for( RelationMember m : chosenRelation.get().getMembers() ) { 208 if( selected.contains(m.getMember()) ) { 209 if( role.length() == 0 && m.getRole() != null ) 210 role = m.getRole(); 211 else if( !role.equals(m.getRole()) ) { 212 role = tr("<different>"); 213 break; 214 } 215 } 216 } 217 } 218 crRoleIndicator.setText(role); 146 219 } 147 220 … … 149 222 if( !isVisible() || relationsData == null ) 150 223 return; 224 updateRoleIndicator(); 151 225 // repopulate relations table 152 226 relationsData.clear(); … … 177 251 } 178 252 253 private static final Map<String, String[]> possibleRoles = new HashMap<String, String[]>(); 254 { 255 possibleRoles.put("boundary", new String[] {"admin_centre", "label", "subarea"}); 256 possibleRoles.put("route", new String[] {"forward", "backward", "stop", "platform"}); 257 } 258 259 private void updateRoleAutoCompletionList() { 260 List<String> items = new ArrayList<String>(); 261 items.add(""); 262 if( chosenRelation != null && chosenRelation.get() != null ) { 263 if( chosenRelation.isMultipolygon() ) { 264 items.add("outer"); 265 items.add("inner"); 266 } 267 if( chosenRelation.get().get("type") != null ) { 268 String[] values = possibleRoles.get(chosenRelation.get().get("type")); 269 if( values != null ) 270 for( String value : values ) 271 items.add(value); 272 } 273 } else if( roleBox.getSelectedItem() != null ) { 274 lastSelectedRole = ((AutoCompletionListItem)roleBox.getSelectedItem()).getValue(); 275 } 276 roleBox.setPossibleItems(items); 277 if( lastSelectedRole != null && items.contains(lastSelectedRole) ) 278 roleBox.setSelectedItem(lastSelectedRole); 279 } 280 179 281 private class ChosenRelationMouseAdapter extends MouseAdapter { 180 282 @Override … … 208 310 } 209 311 } 312 313 private class TogglePanelAction extends AbstractAction { 314 private JComponent component; 315 316 public TogglePanelAction( JPanel panel ) { 317 super("R"); 318 this.component = panel; 319 } 320 321 public void actionPerformed( ActionEvent e ) { 322 component.setVisible(!component.isVisible()); 323 } 324 } 325 326 private class ApplyNewRoleAction extends AbstractAction { 327 public ApplyNewRoleAction() { 328 super("OK"); 329 } 330 331 public void actionPerformed( ActionEvent e ) { 332 Object selectedItem = roleBox == null ? null : roleBox.getSelectedItem(); 333 if( selectedItem != null && chosenRelation != null && chosenRelation.get() != null && Main.main.getCurrentDataSet() != null && !Main.main.getCurrentDataSet().selectionEmpty() ) { 334 // String role = roleBox.getEditor().getItem().toString().trim(); 335 if( selectedItem instanceof AutoCompletionListItem ) 336 selectedItem = ((AutoCompletionListItem)selectedItem).getValue(); 337 String role = selectedItem.toString().trim(); 338 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 339 Relation r = new Relation(chosenRelation.get()); 340 boolean fixed = false; 341 for( int i = 0; i < r.getMembersCount(); i++ ) { 342 RelationMember m = r.getMember(i); 343 if( selected.contains(m.getMember()) ) { 344 if( !role.equals(m.getRole()) ) { 345 r.setMember(i, new RelationMember(role, m.getMember())); 346 fixed = true; 347 } 348 } 349 } 350 if( fixed ) 351 Main.main.undoRedo.add(new ChangeCommand(chosenRelation.get(), r)); 352 } 353 } 354 } 210 355 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java
r25669 r25672 1 1 package relcontext.actions; 2 2 3 import java.awt.Dialog.ModalityType; 4 import java.awt.GridBagLayout; 3 5 import java.util.Collection; 4 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 7 import static org.openstreetmap.josm.tools.I18n.tr; 6 8 import java.awt.event.ActionEvent; 9 import java.awt.event.ActionListener; 10 import java.util.Arrays; 7 11 import java.util.LinkedList; 12 import java.util.List; 13 import javax.swing.Box; 14 import javax.swing.JDialog; 15 import javax.swing.JLabel; 16 import javax.swing.JOptionPane; 17 import javax.swing.JPanel; 8 18 import org.openstreetmap.josm.Main; 9 19 import org.openstreetmap.josm.actions.JosmAction; … … 12 22 import org.openstreetmap.josm.data.osm.Relation; 13 23 import org.openstreetmap.josm.data.osm.RelationMember; 24 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 25 import org.openstreetmap.josm.tools.GBC; 14 26 import relcontext.ChosenRelation; 15 27 … … 35 47 36 48 public void actionPerformed( ActionEvent e ) { 37 // todo: ask user for relation type 38 String type = ""; 49 String type = askForType(); 50 if( type == null ) 51 return; 39 52 40 53 Relation rel = new Relation(); 41 if( type != null && type.length() > 0 ) {54 if( type.length() > 0 ) 42 55 rel.put("type", type); 43 } 44 for( OsmPrimitive selected : getCurrentDataSet().getSelected() ) { 56 for( OsmPrimitive selected : getCurrentDataSet().getSelected() ) 45 57 rel.addMember(new RelationMember("", selected)); 46 }47 58 48 59 Main.main.undoRedo.add(new AddCommand(rel)); … … 66 77 setEnabled(selection != null && !selection.isEmpty()); 67 78 } 79 80 private static final List<String> RELATION_TYPES = Arrays.asList(new String[] { 81 "multipolygon", "boundary", "route" 82 }); 83 84 private String askForType() { 85 JPanel panel = new JPanel(new GridBagLayout()); 86 panel.add(new JLabel(tr("Choose type for the new relation:")), GBC.eol().insets(0, 0, 0, 5)); 87 88 final AutoCompletingComboBox keys = new AutoCompletingComboBox(); 89 keys.setPossibleItems(RELATION_TYPES); 90 keys.setEditable(true); 91 92 panel.add(new JLabel(tr("Type")), GBC.std()); 93 panel.add(Box.createHorizontalStrut(10), GBC.std()); 94 panel.add(keys, GBC.eol().fill(GBC.HORIZONTAL)); 95 96 final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) { 97 @Override 98 public void selectInitialValue() { 99 keys.requestFocusInWindow(); 100 keys.getEditor().selectAll(); 101 } 102 }; 103 final JDialog dlg = optionPane.createDialog(Main.parent, tr("Create relation")); 104 dlg.setModalityType(ModalityType.DOCUMENT_MODAL); 105 106 keys.getEditor().addActionListener(new ActionListener() { 107 public void actionPerformed( ActionEvent e ) { 108 dlg.setVisible(false); 109 optionPane.setValue(JOptionPane.OK_OPTION); 110 } 111 }); 112 113 dlg.setVisible(true); 114 115 Object answer = optionPane.getValue(); 116 if( answer == null || answer == JOptionPane.UNINITIALIZED_VALUE 117 || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION) ) { 118 return null; 119 } 120 121 return keys.getEditor().getItem().toString().trim(); 122 } 68 123 }
Note:
See TracChangeset
for help on using the changeset viewer.