Changeset 18413 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
- Timestamp:
- 2022-03-23T17:07:59+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r18211 r18413 48 48 import javax.swing.JToolBar; 49 49 import javax.swing.KeyStroke; 50 import javax.swing.event.TableModelListener; 50 51 51 52 import org.openstreetmap.josm.actions.JosmAction; … … 55 56 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 56 57 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 58 import org.openstreetmap.josm.data.osm.IRelation; 57 59 import org.openstreetmap.josm.data.osm.OsmPrimitive; 58 60 import org.openstreetmap.josm.data.osm.Relation; … … 133 135 134 136 private final AutoCompletingTextField tfRole; 137 private final RelationEditorActionAccess actionAccess; 135 138 136 139 /** … … 263 266 }); 264 267 265 IRelationEditorActionAccessactionAccess = new RelationEditorActionAccess();268 actionAccess = new RelationEditorActionAccess(); 266 269 267 270 refreshAction = new RefreshAction(actionAccess); … … 270 273 duplicateAction = new DuplicateRelationAction(actionAccess); 271 274 deleteAction = new DeleteCurrentRelationAction(actionAccess); 275 276 this.memberTableModel.addTableModelListener(applyAction); 277 this.tagEditorPanel.getModel().addTableModelListener(applyAction); 278 272 279 addPropertyChangeListener(deleteAction); 273 280 … … 277 284 getContentPane().add(buildToolBar(refreshAction, applyAction, selectAction, duplicateAction, deleteAction), BorderLayout.NORTH); 278 285 getContentPane().add(tabbedPane, BorderLayout.CENTER); 279 getContentPane().add(buildOkCancelButtonPanel(okAction, cancelAction), BorderLayout.SOUTH); 286 getContentPane().add(buildOkCancelButtonPanel(okAction, deleteAction, cancelAction), BorderLayout.SOUTH); 280 287 281 288 setSize(findMaxDialogSize()); … … 408 415 * @return the panel with the OK and the Cancel button 409 416 */ 410 protected static JPanel buildOkCancelButtonPanel(OKAction okAction, CancelAction cancelAction) { 411 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 412 pnl.add(new JButton(okAction)); 417 protected final JPanel buildOkCancelButtonPanel(OKAction okAction, DeleteCurrentRelationAction deleteAction, 418 CancelAction cancelAction) { 419 final JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 420 final JButton okButton = new JButton(okAction); 421 final JButton deleteButton = new JButton(deleteAction); 422 okButton.setPreferredSize(deleteButton.getPreferredSize()); 423 pnl.add(okButton); 424 pnl.add(deleteButton); 413 425 pnl.add(new JButton(cancelAction)); 414 426 pnl.add(new JButton(new ContextSensitiveHelpAction(ht("/Dialog/RelationEditor")))); 427 // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type" 428 // AND must contain at least one other OSM object. 429 final TableModelListener listener = l -> updateOkPanel(this.actionAccess.getChangedRelation(), okButton, deleteButton); 430 listener.tableChanged(null); 431 this.memberTableModel.addTableModelListener(listener); 432 this.tagEditorPanel.getModel().addTableModelListener(listener); 415 433 return pnl; 434 } 435 436 /** 437 * Update the OK panel area 438 * @param newRelation What the new relation would "look" like if it were to be saved now 439 * @param okButton The OK button 440 * @param deleteButton The delete button 441 */ 442 private void updateOkPanel(IRelation<?> newRelation, JButton okButton, JButton deleteButton) { 443 okButton.setVisible(newRelation.isUseful() || this.getRelationSnapshot() == null); 444 deleteButton.setVisible(!newRelation.isUseful() && this.getRelationSnapshot() != null); 445 if (this.getRelationSnapshot() == null && !newRelation.isUseful()) { 446 okButton.setText(tr("Delete")); 447 } else { 448 okButton.setText(tr("OK")); 449 } 416 450 } 417 451 … … 1002 1036 public void mouseClicked(MouseEvent e) { 1003 1037 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { 1004 new EditAction( new RelationEditorActionAccess()).actionPerformed(null);1038 new EditAction(actionAccess).actionPerformed(null); 1005 1039 } 1006 1040 }
Note:
See TracChangeset
for help on using the changeset viewer.
