- Timestamp:
- 2016-04-06T23:06:38+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r10089 r10113 11 11 import java.awt.GridBagConstraints; 12 12 import java.awt.GridBagLayout; 13 import java.awt.Window; 13 14 import java.awt.event.ActionEvent; 14 15 import java.awt.event.FocusAdapter; … … 34 35 import javax.swing.JComponent; 35 36 import javax.swing.JLabel; 36 import javax.swing.JMenu;37 37 import javax.swing.JMenuItem; 38 38 import javax.swing.JOptionPane; 39 39 import javax.swing.JPanel; 40 import javax.swing.JRootPane; 40 41 import javax.swing.JScrollPane; 41 42 import javax.swing.JSplitPane; 42 43 import javax.swing.JTabbedPane; 44 import javax.swing.JTable; 43 45 import javax.swing.JToolBar; 44 46 import javax.swing.KeyStroke; … … 111 113 112 114 /** the member table and its model */ 113 private MemberTable memberTable;115 private final MemberTable memberTable; 114 116 private final MemberTableModel memberTableModel; 115 117 116 118 /** the selection table and its model */ 117 private SelectionTable selectionTable;119 private final SelectionTable selectionTable; 118 120 private final SelectionTableModel selectionTableModel; 119 121 120 private AutoCompletingTextField tfRole;122 private final AutoCompletingTextField tfRole; 121 123 122 124 /** … … 125 127 private JMenuItem windowMenuItem; 126 128 /** 127 * Button for performing the {@link org.openstreetmap.josm.gui.dialogs.relation.actions.SortBelowAction}.128 */ 129 private JButton sortBelowButton;129 * The toolbar with the buttons on the left 130 */ 131 private final LeftButtonToolbar leftButtonToolbar; 130 132 /** 131 133 * Action for performing the {@link RefreshAction} 132 134 */ 133 private RefreshAction refreshAction;135 private final RefreshAction refreshAction; 134 136 /** 135 137 * Action for performing the {@link ApplyAction} 136 138 */ 137 private ApplyAction applyAction; 139 private final ApplyAction applyAction; 140 /** 141 * Action for performing the {@link DuplicateRelationAction} 142 */ 143 private final DuplicateRelationAction duplicateAction; 144 /** 145 * Action for performing the {@link DeleteCurrentRelationAction} 146 */ 147 private final DeleteCurrentRelationAction deleteAction; 148 /** 149 * Action for performing the {@link OKAction} 150 */ 151 private final OKAction okAction; 138 152 /** 139 153 * Action for performing the {@link CancelAction} 140 154 */ 141 private CancelAction cancelAction;155 private final CancelAction cancelAction; 142 156 143 157 /** … … 184 198 tagEditorPanel.getModel().ensureOneTag(); 185 199 186 JSplitPane pane = buildSplitPane(); 200 // setting up the member table 201 memberTable = new MemberTable(getLayer(), getRelation(), memberTableModel); 202 memberTable.addMouseListener(new MemberTableDblClickAdapter()); 203 memberTableModel.addMemberModelListener(memberTable); 204 205 MemberRoleCellEditor ce = (MemberRoleCellEditor) memberTable.getColumnModel().getColumn(0).getCellEditor(); 206 selectionTable = new SelectionTable(selectionTableModel, memberTableModel); 207 selectionTable.setRowHeight(ce.getEditor().getPreferredSize().height); 208 209 leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, this); 210 tfRole = buildRoleTextField(this); 211 212 JSplitPane pane = buildSplitPane( 213 buildTagEditorPanel(tagEditorPanel), 214 buildMemberEditorPanel(memberTable, memberTableModel, selectionTable, selectionTableModel, this, leftButtonToolbar, tfRole), 215 this); 187 216 pane.setPreferredSize(new Dimension(100, 100)); 188 217 … … 211 240 ); 212 241 213 getContentPane().add(buildToolBar(), BorderLayout.NORTH); 242 refreshAction = new RefreshAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this); 243 applyAction = new ApplyAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this); 244 duplicateAction = new DuplicateRelationAction(memberTableModel, tagEditorPanel.getModel(), getLayer()); 245 deleteAction = new DeleteCurrentRelationAction(getLayer(), this); 246 addPropertyChangeListener(deleteAction); 247 248 okAction = new OKAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole); 249 cancelAction = new CancelAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole); 250 251 getContentPane().add(buildToolBar(refreshAction, applyAction, duplicateAction, deleteAction), BorderLayout.NORTH); 214 252 getContentPane().add(tabbedPane, BorderLayout.CENTER); 215 getContentPane().add(buildOkCancelButtonPanel( ), BorderLayout.SOUTH);253 getContentPane().add(buildOkCancelButtonPanel(okAction, cancelAction), BorderLayout.SOUTH); 216 254 217 255 setSize(findMaxDialogSize()); … … 222 260 @Override 223 261 public void windowOpened(WindowEvent e) { 224 cleanSelfReferences( );262 cleanSelfReferences(memberTableModel, getRelation()); 225 263 } 226 264 … … 233 271 // CHECKSTYLE.OFF: LineLength 234 272 registerCopyPasteAction(tagEditorPanel.getPasteAction(), "PASTE_TAGS", 235 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.CTRL_SHIFT).getKeyStroke()); 273 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.CTRL_SHIFT).getKeyStroke(), 274 getRootPane(), memberTable, selectionTable); 236 275 // CHECKSTYLE.ON: LineLength 237 276 … … 242 281 tfRole.requestFocusInWindow(); 243 282 } 244 }, "PASTE_MEMBERS", Shortcut.getPasteKeyStroke() );283 }, "PASTE_MEMBERS", Shortcut.getPasteKeyStroke(), getRootPane(), memberTable, selectionTable); 245 284 246 285 registerCopyPasteAction(new CopyMembersAction(memberTableModel, getLayer(), this), 247 "COPY_MEMBERS", Shortcut.getCopyKeyStroke() );286 "COPY_MEMBERS", Shortcut.getCopyKeyStroke(), getRootPane(), memberTable, selectionTable); 248 287 249 288 tagEditorPanel.setNextFocusComponent(memberTable); … … 292 331 /** 293 332 * Creates the toolbar 333 * @param refreshAction refresh action 334 * @param applyAction apply action 335 * @param duplicateAction duplicate action 336 * @param deleteAction delete action 294 337 * 295 338 * @return the toolbar 296 339 */ 297 protected JToolBar buildToolBar() { 340 protected static JToolBar buildToolBar(RefreshAction refreshAction, ApplyAction applyAction, 341 DuplicateRelationAction duplicateAction, DeleteCurrentRelationAction deleteAction) { 298 342 JToolBar tb = new JToolBar(); 299 343 tb.setFloatable(false); 300 refreshAction = new RefreshAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this);301 applyAction = new ApplyAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this);302 344 tb.add(refreshAction); 303 345 tb.add(applyAction); 304 tb.add(new DuplicateRelationAction(memberTableModel, tagEditorPanel.getModel(), getLayer())); 305 DeleteCurrentRelationAction deleteAction = new DeleteCurrentRelationAction(getLayer(), this); 306 addPropertyChangeListener(deleteAction); 346 tb.add(duplicateAction); 307 347 tb.add(deleteAction); 308 348 return tb; … … 311 351 /** 312 352 * builds the panel with the OK and the Cancel button 353 * @param okAction OK action 354 * @param cancelAction Cancel action 313 355 * 314 356 * @return the panel with the OK and the Cancel button 315 357 */ 316 protected JPanel buildOkCancelButtonPanel() {358 protected static JPanel buildOkCancelButtonPanel(OKAction okAction, CancelAction cancelAction) { 317 359 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 318 pnl.add(new SideButton(new OKAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole))); 319 cancelAction = new CancelAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole); 360 pnl.add(new SideButton(okAction)); 320 361 pnl.add(new SideButton(cancelAction)); 321 362 pnl.add(new SideButton(new ContextSensitiveHelpAction(ht("/Dialog/RelationEditor")))); … … 325 366 /** 326 367 * builds the panel with the tag editor 368 * @param tagEditorPanel tag editor panel 327 369 * 328 370 * @return the panel with the tag editor 329 371 */ 330 protected JPanel buildTagEditorPanel() {372 protected static JPanel buildTagEditorPanel(TagEditorPanel tagEditorPanel) { 331 373 JPanel pnl = new JPanel(new GridBagLayout()); 332 374 … … 353 395 354 396 /** 397 * builds the role text field 398 * @param re relation editor 399 * @return the role text field 400 */ 401 protected static AutoCompletingTextField buildRoleTextField(final IRelationEditor re) { 402 final AutoCompletingTextField tfRole = new AutoCompletingTextField(10); 403 tfRole.setToolTipText(tr("Enter a role and apply it to the selected relation members")); 404 tfRole.addFocusListener(new FocusAdapter() { 405 @Override 406 public void focusGained(FocusEvent e) { 407 tfRole.selectAll(); 408 } 409 }); 410 tfRole.setAutoCompletionList(new AutoCompletionList()); 411 tfRole.addFocusListener( 412 new FocusAdapter() { 413 @Override 414 public void focusGained(FocusEvent e) { 415 AutoCompletionList list = tfRole.getAutoCompletionList(); 416 if (list != null) { 417 list.clear(); 418 re.getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list, re.getRelation()); 419 } 420 } 421 } 422 ); 423 tfRole.setText(Main.pref.get("relation.editor.generic.lastrole", "")); 424 return tfRole; 425 } 426 427 /** 355 428 * builds the panel for the relation member editor 429 * @param memberTable member table 430 * @param memberTableModel member table model 431 * @param selectionTable selection table 432 * @param selectionTableModel selection table model 433 * @param re relation editor 434 * @param leftButtonToolbar left button toolbar 435 * @param tfRole role text field 356 436 * 357 437 * @return the panel for the relation member editor 358 438 */ 359 protected JPanel buildMemberEditorPanel() { 439 protected static JPanel buildMemberEditorPanel(final MemberTable memberTable, MemberTableModel memberTableModel, 440 SelectionTable selectionTable, SelectionTableModel selectionTableModel, IRelationEditor re, 441 LeftButtonToolbar leftButtonToolbar, final AutoCompletingTextField tfRole) { 360 442 final JPanel pnl = new JPanel(new GridBagLayout()); 361 // setting up the member table362 memberTable = new MemberTable(getLayer(), getRelation(), memberTableModel);363 memberTable.addMouseListener(new MemberTableDblClickAdapter());364 memberTableModel.addMemberModelListener(memberTable);365 366 443 final JScrollPane scrollPane = new JScrollPane(memberTable); 367 444 … … 384 461 gc.weightx = 0.0; 385 462 gc.weighty = 1.0; 386 pnl.add( buildLeftButtonPanel(), gc);463 pnl.add(leftButtonToolbar, gc); 387 464 388 465 gc.gridx = 1; … … 398 475 JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); 399 476 p3.add(new JLabel(tr("Apply Role:"))); 400 tfRole = new AutoCompletingTextField(10);401 tfRole.setToolTipText(tr("Enter a role and apply it to the selected relation members"));402 tfRole.addFocusListener(new FocusAdapter() {403 @Override404 public void focusGained(FocusEvent e) {405 tfRole.selectAll();406 }407 });408 tfRole.setAutoCompletionList(new AutoCompletionList());409 tfRole.addFocusListener(410 new FocusAdapter() {411 @Override412 public void focusGained(FocusEvent e) {413 AutoCompletionList list = tfRole.getAutoCompletionList();414 if (list != null) {415 list.clear();416 getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list, getRelation());417 }418 }419 }420 );421 tfRole.setText(Main.pref.get("relation.editor.generic.lastrole", ""));422 477 p3.add(tfRole); 423 478 SetRoleAction setRoleAction = new SetRoleAction(memberTable, memberTableModel, tfRole); … … 467 522 gc.weightx = 0.0; 468 523 gc.weighty = 1.0; 469 pnl2.add(buildSelectionControlButton Panel(), gc);524 pnl2.add(buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re), gc); 470 525 471 526 gc.gridx = 1; … … 474 529 gc.weighty = 1.0; 475 530 gc.fill = GridBagConstraints.BOTH; 476 pnl2.add(buildSelectionTablePanel( ), gc);531 pnl2.add(buildSelectionTablePanel(selectionTable), gc); 477 532 478 533 final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); … … 480 535 splitPane.setRightComponent(pnl2); 481 536 splitPane.setOneTouchExpandable(false); 482 addWindowListener(new WindowAdapter() { 483 @Override 484 public void windowOpened(WindowEvent e) { 485 // has to be called when the window is visible, otherwise 486 // no effect 487 splitPane.setDividerLocation(0.6); 488 } 489 }); 537 if (re instanceof Window) { 538 ((Window) re).addWindowListener(new WindowAdapter() { 539 @Override 540 public void windowOpened(WindowEvent e) { 541 // has to be called when the window is visible, otherwise no effect 542 splitPane.setDividerLocation(0.6); 543 } 544 }); 545 } 490 546 491 547 JPanel pnl3 = new JPanel(new BorderLayout()); … … 497 553 /** 498 554 * builds the panel with the table displaying the currently selected primitives 555 * @param selectionTable selection table 499 556 * 500 557 * @return panel with current selection 501 558 */ 502 protected JPanel buildSelectionTablePanel() {559 protected static JPanel buildSelectionTablePanel(SelectionTable selectionTable) { 503 560 JPanel pnl = new JPanel(new BorderLayout()); 504 MemberRoleCellEditor ce = (MemberRoleCellEditor) memberTable.getColumnModel().getColumn(0).getCellEditor();505 selectionTable = new SelectionTable(selectionTableModel, memberTableModel);506 selectionTable.setRowHeight(ce.getEditor().getPreferredSize().height);507 561 pnl.add(new JScrollPane(selectionTable), BorderLayout.CENTER); 508 562 return pnl; … … 511 565 /** 512 566 * builds the {@link JSplitPane} which divides the editor in an upper and a lower half 567 * @param top top panel 568 * @param bottom bottom panel 569 * @param re relation editor 513 570 * 514 571 * @return the split panel 515 572 */ 516 protected JSplitPane buildSplitPane() {573 protected static JSplitPane buildSplitPane(JPanel top, JPanel bottom, IRelationEditor re) { 517 574 final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 518 pane.setTopComponent( buildTagEditorPanel());519 pane.setBottomComponent(b uildMemberEditorPanel());575 pane.setTopComponent(top); 576 pane.setBottomComponent(bottom); 520 577 pane.setOneTouchExpandable(true); 521 addWindowListener(new WindowAdapter() { 522 @Override 523 public void windowOpened(WindowEvent e) { 524 // has to be called when the window is visible, otherwise no effect 525 pane.setDividerLocation(0.3); 526 } 527 }); 578 if (re instanceof Window) { 579 ((Window) re).addWindowListener(new WindowAdapter() { 580 @Override 581 public void windowOpened(WindowEvent e) { 582 // has to be called when the window is visible, otherwise no effect 583 pane.setDividerLocation(0.3); 584 } 585 }); 586 } 528 587 return pane; 529 588 } 530 589 531 590 /** 532 * build the panel with the buttons on the left 533 * 534 * @return left button panel 535 */ 536 protected JToolBar buildLeftButtonPanel() { 537 JToolBar tb = new JToolBar(); 538 tb.setOrientation(JToolBar.VERTICAL); 539 tb.setFloatable(false); 540 541 // -- move up action 542 MoveUpAction moveUpAction = new MoveUpAction(memberTable, memberTableModel, "moveUp"); 543 memberTableModel.getSelectionModel().addListSelectionListener(moveUpAction); 544 tb.add(moveUpAction); 545 546 // -- move down action 547 MoveDownAction moveDownAction = new MoveDownAction(memberTable, memberTableModel, "moveDown"); 548 memberTableModel.getSelectionModel().addListSelectionListener(moveDownAction); 549 tb.add(moveDownAction); 550 551 tb.addSeparator(); 552 553 // -- edit action 554 EditAction editAction = new EditAction(memberTable, memberTableModel, getLayer()); 555 memberTableModel.getSelectionModel().addListSelectionListener(editAction); 556 tb.add(editAction); 557 558 // -- delete action 559 RemoveAction removeSelectedAction = new RemoveAction(memberTable, memberTableModel, "removeSelected"); 560 memberTable.getSelectionModel().addListSelectionListener(removeSelectedAction); 561 tb.add(removeSelectedAction); 562 563 tb.addSeparator(); 564 // -- sort action 565 SortAction sortAction = new SortAction(memberTable, memberTableModel); 566 memberTableModel.addTableModelListener(sortAction); 567 tb.add(sortAction); 568 final SortBelowAction sortBelowAction = new SortBelowAction(memberTable, memberTableModel); 569 memberTableModel.addTableModelListener(sortBelowAction); 570 memberTableModel.getSelectionModel().addListSelectionListener(sortBelowAction); 571 sortBelowButton = tb.add(sortBelowAction); 572 573 // -- reverse action 574 ReverseAction reverseAction = new ReverseAction(memberTable, memberTableModel); 575 memberTableModel.addTableModelListener(reverseAction); 576 tb.add(reverseAction); 577 578 tb.addSeparator(); 579 580 // -- download action 581 DownloadIncompleteMembersAction downloadIncompleteMembersAction = new DownloadIncompleteMembersAction( 582 memberTable, memberTableModel, "downloadIncomplete", getLayer(), this); 583 memberTable.getModel().addTableModelListener(downloadIncompleteMembersAction); 584 tb.add(downloadIncompleteMembersAction); 585 586 // -- download selected action 587 DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction( 588 memberTable, memberTableModel, null, getLayer(), this); 589 memberTable.getModel().addTableModelListener(downloadSelectedIncompleteMembersAction); 590 memberTable.getSelectionModel().addListSelectionListener(downloadSelectedIncompleteMembersAction); 591 tb.add(downloadSelectedIncompleteMembersAction); 592 593 InputMap inputMap = memberTable.getInputMap(MemberTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 594 inputMap.put((KeyStroke) removeSelectedAction.getValue(AbstractAction.ACCELERATOR_KEY), "removeSelected"); 595 inputMap.put((KeyStroke) moveUpAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveUp"); 596 inputMap.put((KeyStroke) moveDownAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveDown"); 597 inputMap.put((KeyStroke) downloadIncompleteMembersAction.getValue(AbstractAction.ACCELERATOR_KEY), "downloadIncomplete"); 598 599 return tb; 600 } 601 602 /** 603 * build the panel with the buttons for adding or removing the current selection 591 * The toolbar with the buttons on the left 592 */ 593 static class LeftButtonToolbar extends JToolBar { 594 595 /** 596 * Button for performing the {@link org.openstreetmap.josm.gui.dialogs.relation.actions.SortBelowAction}. 597 */ 598 final JButton sortBelowButton; 599 600 /** 601 * Constructs a new {@code LeftButtonToolbar}. 602 * @param memberTable member table 603 * @param memberTableModel member table model 604 * @param re relation editor 605 */ 606 LeftButtonToolbar(MemberTable memberTable, MemberTableModel memberTableModel, IRelationEditor re) { 607 setOrientation(JToolBar.VERTICAL); 608 setFloatable(false); 609 610 // -- move up action 611 MoveUpAction moveUpAction = new MoveUpAction(memberTable, memberTableModel, "moveUp"); 612 memberTableModel.getSelectionModel().addListSelectionListener(moveUpAction); 613 add(moveUpAction); 614 615 // -- move down action 616 MoveDownAction moveDownAction = new MoveDownAction(memberTable, memberTableModel, "moveDown"); 617 memberTableModel.getSelectionModel().addListSelectionListener(moveDownAction); 618 add(moveDownAction); 619 620 addSeparator(); 621 622 // -- edit action 623 EditAction editAction = new EditAction(memberTable, memberTableModel, re.getLayer()); 624 memberTableModel.getSelectionModel().addListSelectionListener(editAction); 625 add(editAction); 626 627 // -- delete action 628 RemoveAction removeSelectedAction = new RemoveAction(memberTable, memberTableModel, "removeSelected"); 629 memberTable.getSelectionModel().addListSelectionListener(removeSelectedAction); 630 add(removeSelectedAction); 631 632 addSeparator(); 633 // -- sort action 634 SortAction sortAction = new SortAction(memberTable, memberTableModel); 635 memberTableModel.addTableModelListener(sortAction); 636 add(sortAction); 637 final SortBelowAction sortBelowAction = new SortBelowAction(memberTable, memberTableModel); 638 memberTableModel.addTableModelListener(sortBelowAction); 639 memberTableModel.getSelectionModel().addListSelectionListener(sortBelowAction); 640 sortBelowButton = add(sortBelowAction); 641 642 // -- reverse action 643 ReverseAction reverseAction = new ReverseAction(memberTable, memberTableModel); 644 memberTableModel.addTableModelListener(reverseAction); 645 add(reverseAction); 646 647 addSeparator(); 648 649 // -- download action 650 DownloadIncompleteMembersAction downloadIncompleteMembersAction = new DownloadIncompleteMembersAction( 651 memberTable, memberTableModel, "downloadIncomplete", re.getLayer(), re); 652 memberTable.getModel().addTableModelListener(downloadIncompleteMembersAction); 653 add(downloadIncompleteMembersAction); 654 655 // -- download selected action 656 DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction( 657 memberTable, memberTableModel, null, re.getLayer(), re); 658 memberTable.getModel().addTableModelListener(downloadSelectedIncompleteMembersAction); 659 memberTable.getSelectionModel().addListSelectionListener(downloadSelectedIncompleteMembersAction); 660 add(downloadSelectedIncompleteMembersAction); 661 662 InputMap inputMap = memberTable.getInputMap(MemberTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 663 inputMap.put((KeyStroke) removeSelectedAction.getValue(AbstractAction.ACCELERATOR_KEY), "removeSelected"); 664 inputMap.put((KeyStroke) moveUpAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveUp"); 665 inputMap.put((KeyStroke) moveDownAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveDown"); 666 inputMap.put((KeyStroke) downloadIncompleteMembersAction.getValue(AbstractAction.ACCELERATOR_KEY), "downloadIncomplete"); 667 } 668 } 669 670 /** 671 * build the toolbar with the buttons for adding or removing the current selection 672 * @param memberTable member table 673 * @param memberTableModel member table model 674 * @param selectionTableModel selection table model 675 * @param re relation editor 604 676 * 605 677 * @return control buttons panel for selection/members 606 678 */ 607 protected JToolBar buildSelectionControlButtonPanel() { 679 protected static JToolBar buildSelectionControlButtonToolbar(MemberTable memberTable, 680 MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor re) { 608 681 JToolBar tb = new JToolBar(JToolBar.VERTICAL); 609 682 tb.setFloatable(false); … … 611 684 // -- add at start action 612 685 AddSelectedAtStartAction addSelectionAction = new AddSelectedAtStartAction( 613 memberTableModel, selectionTableModel, this);686 memberTableModel, selectionTableModel, re); 614 687 selectionTableModel.addTableModelListener(addSelectionAction); 615 688 tb.add(addSelectionAction); … … 617 690 // -- add before selected action 618 691 AddSelectedBeforeSelection addSelectedBeforeSelectionAction = new AddSelectedBeforeSelection( 619 memberTableModel, selectionTableModel, this);692 memberTableModel, selectionTableModel, re); 620 693 selectionTableModel.addTableModelListener(addSelectedBeforeSelectionAction); 621 694 memberTableModel.getSelectionModel().addListSelectionListener(addSelectedBeforeSelectionAction); … … 624 697 // -- add after selected action 625 698 AddSelectedAfterSelection addSelectedAfterSelectionAction = new AddSelectedAfterSelection( 626 memberTableModel, selectionTableModel, this);699 memberTableModel, selectionTableModel, re); 627 700 selectionTableModel.addTableModelListener(addSelectedAfterSelectionAction); 628 701 memberTableModel.getSelectionModel().addListSelectionListener(addSelectedAfterSelectionAction); … … 631 704 // -- add at end action 632 705 AddSelectedAtEndAction addSelectedAtEndAction = new AddSelectedAtEndAction( 633 memberTableModel, selectionTableModel, this);706 memberTableModel, selectionTableModel, re); 634 707 selectionTableModel.addTableModelListener(addSelectedAtEndAction); 635 708 tb.add(addSelectedAtEndAction); … … 639 712 // -- select members action 640 713 SelectedMembersForSelectionAction selectMembersForSelectionAction = new SelectedMembersForSelectionAction( 641 memberTableModel, selectionTableModel, getLayer());714 memberTableModel, selectionTableModel, re.getLayer()); 642 715 selectionTableModel.addTableModelListener(selectMembersForSelectionAction); 643 716 memberTableModel.addTableModelListener(selectMembersForSelectionAction); … … 646 719 // -- select action 647 720 SelectPrimitivesForSelectedMembersAction selectAction = new SelectPrimitivesForSelectedMembersAction( 648 memberTable, memberTableModel, getLayer());721 memberTable, memberTableModel, re.getLayer()); 649 722 memberTable.getSelectionModel().addListSelectionListener(selectAction); 650 723 tb.add(selectAction); … … 653 726 654 727 // -- remove selected action 655 RemoveSelectedAction removeSelectedAction = new RemoveSelectedAction(memberTableModel, selectionTableModel, getLayer());728 RemoveSelectedAction removeSelectedAction = new RemoveSelectedAction(memberTableModel, selectionTableModel, re.getLayer()); 656 729 selectionTableModel.addTableModelListener(removeSelectedAction); 657 730 tb.add(removeSelectedAction); … … 672 745 super.setVisible(visible); 673 746 if (visible) { 674 sortBelowButton.setVisible(ExpertToggleAction.isExpert());747 leftButtonToolbar.sortBelowButton.setVisible(ExpertToggleAction.isExpert()); 675 748 RelationDialogManager.getRelationDialogManager().positionOnScreen(this); 676 749 if (windowMenuItem == null) { 677 addToWindowMenu();750 windowMenuItem = addToWindowMenu(this, getLayer().getName()); 678 751 } 679 752 tagEditorPanel.requestFocusInWindow(); … … 693 766 } 694 767 695 /** adds current relation editor to the windows menu (in the "volatile" group) o*/ 696 protected void addToWindowMenu() { 697 String name = getRelation() == null ? tr("New Relation") : getRelation().getLocalName(); 698 final String tt = tr("Focus Relation Editor with relation ''{0}'' in layer ''{1}''", 699 name, getLayer().getName()); 700 name = tr("Relation Editor: {0}", name == null ? getRelation().getId() : name); 701 final JMenu wm = Main.main.menu.windowMenu; 702 final JosmAction focusAction = new JosmAction(name, "dialogs/relationlist", tt, null, false, false) { 768 /** 769 * Adds current relation editor to the windows menu (in the "volatile" group) 770 * @param re relation editor 771 * @param layerName layer name 772 * @return created menu item 773 */ 774 protected static JMenuItem addToWindowMenu(IRelationEditor re, String layerName) { 775 Relation r = re.getRelation(); 776 String name = r == null ? tr("New Relation") : r.getLocalName(); 777 JosmAction focusAction = new JosmAction( 778 tr("Relation Editor: {0}", name == null && r != null ? r.getId() : name), 779 "dialogs/relationlist", 780 tr("Focus Relation Editor with relation ''{0}'' in layer ''{1}''", name, layerName), 781 null, false, false) { 703 782 @Override 704 783 public void actionPerformed(ActionEvent e) { 705 final RelationEditor r = (RelationEditor) getValue("relationEditor"); 706 r.setVisible(true); 784 ((RelationEditor) getValue("relationEditor")).setVisible(true); 707 785 } 708 786 }; 709 focusAction.putValue("relationEditor", this);710 windowMenuItem = MainMenu.add(wm, focusAction, MainMenu.WINDOW_MENU_GROUP.VOLATILE);787 focusAction.putValue("relationEditor", re); 788 return MainMenu.add(Main.main.menu.windowMenu, focusAction, MainMenu.WINDOW_MENU_GROUP.VOLATILE); 711 789 } 712 790 … … 714 792 * checks whether the current relation has members referring to itself. If so, 715 793 * warns the users and provides an option for removing these members. 716 * 717 */ 718 protected void cleanSelfReferences() { 794 * @param memberTableModel member table model 795 * @param relation relation 796 */ 797 protected static void cleanSelfReferences(MemberTableModel memberTableModel, Relation relation) { 719 798 List<OsmPrimitive> toCheck = new ArrayList<>(); 720 toCheck.add( getRelation());799 toCheck.add(relation); 721 800 if (memberTableModel.hasMembersReferringTo(toCheck)) { 722 801 int ret = ConditionalOptionPaneUtil.showOptionDialog( … … 745 824 } 746 825 747 private void registerCopyPasteAction(AbstractAction action, Object actionName, KeyStroke shortcut) { 826 private static void registerCopyPasteAction(AbstractAction action, Object actionName, KeyStroke shortcut, 827 JRootPane rootPane, JTable... tables) { 748 828 int mods = shortcut.getModifiers(); 749 829 int code = shortcut.getKeyCode(); … … 752 832 return; 753 833 } 754 getRootPane().getActionMap().put(actionName, action);755 getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName);834 rootPane.getActionMap().put(actionName, action); 835 rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 756 836 // Assign also to JTables because they have their own Copy&Paste implementation 757 837 // (which is disabled in this case but eats key shortcuts anyway) 758 memberTable.getInputMap(JComponent.WHEN_FOCUSED).put(shortcut, actionName); 759 memberTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(shortcut, actionName); 760 memberTable.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 761 selectionTable.getInputMap(JComponent.WHEN_FOCUSED).put(shortcut, actionName); 762 selectionTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(shortcut, actionName); 763 selectionTable.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 838 for (JTable table : tables) { 839 table.getInputMap(JComponent.WHEN_FOCUSED).put(shortcut, actionName); 840 table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(shortcut, actionName); 841 table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, actionName); 842 } 764 843 } 765 844 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/IRelationEditor.java
r9665 r10113 3 3 4 4 import org.openstreetmap.josm.data.osm.Relation; 5 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 5 6 6 7 /** … … 45 46 */ 46 47 void reloadDataFromRelation(); 48 49 /** 50 * Replies the {@link OsmDataLayer} in whose context this relation editor is open 51 * 52 * @return the {@link OsmDataLayer} in whose context this relation editor is open 53 */ 54 OsmDataLayer getLayer(); 47 55 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r9997 r10113 149 149 } 150 150 151 /** 152 * Replies the {@link OsmDataLayer} in whose context this relation editor is open 153 * 154 * @return the {@link OsmDataLayer} in whose context this relation editor is open 155 */ 156 protected final OsmDataLayer getLayer() { 151 @Override 152 public final OsmDataLayer getLayer() { 157 153 return layer; 158 154 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java
r9669 r10113 7 7 import java.util.Collections; 8 8 9 import javax.swing.JPanel; 10 9 11 import org.junit.BeforeClass; 10 12 import org.junit.Test; 11 13 import org.openstreetmap.josm.JOSMFixture; 14 import org.openstreetmap.josm.data.osm.DataSet; 12 15 import org.openstreetmap.josm.data.osm.Node; 13 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 17 import org.openstreetmap.josm.data.osm.Relation; 15 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.LeftButtonToolbar; 20 import org.openstreetmap.josm.gui.dialogs.relation.actions.ApplyAction; 21 import org.openstreetmap.josm.gui.dialogs.relation.actions.CancelAction; 22 import org.openstreetmap.josm.gui.dialogs.relation.actions.DeleteCurrentRelationAction; 23 import org.openstreetmap.josm.gui.dialogs.relation.actions.DuplicateRelationAction; 24 import org.openstreetmap.josm.gui.dialogs.relation.actions.OKAction; 25 import org.openstreetmap.josm.gui.dialogs.relation.actions.RefreshAction; 26 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 28 import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 29 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 16 30 17 31 /** … … 25 39 @BeforeClass 26 40 public static void setUpBeforeClass() { 27 JOSMFixture.createUnitTestFixture().init(); 41 JOSMFixture.createUnitTestFixture().init(true); 42 } 43 44 /** 45 * Returns a new relation editor for unit tests. 46 * @param orig relation 47 * @param layer data layer 48 * @return new relation editor for unit tests 49 */ 50 public static IRelationEditor newRelationEditor(final Relation orig, final OsmDataLayer layer) { 51 return new IRelationEditor() { 52 private Relation r = orig; 53 54 @Override 55 public void setRelation(Relation relation) { 56 r = relation; 57 } 58 59 @Override 60 public boolean isDirtyRelation() { 61 return false; 62 } 63 64 @Override 65 public Relation getRelationSnapshot() { 66 return r; 67 } 68 69 @Override 70 public Relation getRelation() { 71 return r; 72 } 73 74 @Override 75 public void reloadDataFromRelation() { 76 // Do nothing 77 } 78 79 @Override 80 public OsmDataLayer getLayer() { 81 return layer; 82 } 83 }; 28 84 } 29 85 … … 41 97 } 42 98 99 /** 100 * Unit test of {@code GenericRelationEditor#build*} methods. 101 */ 102 @Test 103 public void testBuild() { 104 DataSet ds = new DataSet(); 105 Relation relation = new Relation(1); 106 ds.addPrimitive(relation); 107 OsmDataLayer layer = new OsmDataLayer(ds, "test", null); 108 IRelationEditor re = newRelationEditor(relation, layer); 109 110 MemberTableModel memberTableModel = new MemberTableModel(relation, layer, null); 111 MemberTable memberTable = new MemberTable(layer, relation, memberTableModel); 112 113 SelectionTableModel selectionTableModel = new SelectionTableModel(layer); 114 SelectionTable selectionTable = new SelectionTable(selectionTableModel, memberTableModel); 115 116 LeftButtonToolbar leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, re); 117 assertNotNull(leftButtonToolbar.sortBelowButton); 118 119 AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re); 120 assertNotNull(tfRole); 121 122 TagEditorPanel tagEditorPanel = new TagEditorPanel(relation, null); 123 124 JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel); 125 JPanel bottom = GenericRelationEditor.buildMemberEditorPanel( 126 memberTable, memberTableModel, selectionTable, selectionTableModel, re, leftButtonToolbar, tfRole); 127 assertNotNull(top); 128 assertNotNull(bottom); 129 assertNotNull(GenericRelationEditor.buildSplitPane(top, bottom, re)); 130 131 TagEditorModel tagModel = tagEditorPanel.getModel(); 132 133 assertNotNull(GenericRelationEditor.buildOkCancelButtonPanel( 134 new OKAction(memberTable, memberTableModel, tagModel, layer, re, tfRole), 135 new CancelAction(memberTable, memberTableModel, tagModel, layer, re, tfRole))); 136 assertNotNull(GenericRelationEditor.buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re)); 137 assertNotNull(GenericRelationEditor.buildSelectionTablePanel(selectionTable)); 138 139 assertNotNull(GenericRelationEditor.buildToolBar( 140 new RefreshAction(memberTable, memberTableModel, tagModel, layer, re), 141 new ApplyAction(memberTable, memberTableModel, tagModel, layer, re), 142 new DuplicateRelationAction(memberTableModel, tagModel, layer), 143 new DeleteCurrentRelationAction(layer, re))); 144 } 43 145 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java
r9669 r10113 7 7 import org.openstreetmap.josm.data.osm.DataSet; 8 8 import org.openstreetmap.josm.data.osm.Relation; 9 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditorTest; 9 10 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor; 10 11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable; … … 36 37 final Relation orig = new Relation(1); 37 38 ds.addPrimitive(orig); 38 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "test", null);39 final OsmDataLayer layer = new OsmDataLayer(ds, "test", null); 39 40 MemberTableModel memberTableModel = new MemberTableModel(orig, layer, null); 40 41 SelectionTableModel selectionTableModel = new SelectionTableModel(layer); 41 42 42 IRelationEditor editor = new IRelationEditor() { 43 private Relation r = orig; 44 45 @Override 46 public void setRelation(Relation relation) { 47 r = relation; 48 } 49 50 @Override 51 public boolean isDirtyRelation() { 52 return false; 53 } 54 55 @Override 56 public Relation getRelationSnapshot() { 57 return r; 58 } 59 60 @Override 61 public Relation getRelation() { 62 return r; 63 } 64 65 @Override 66 public void reloadDataFromRelation() { 67 // Do nothing 68 } 69 }; 43 IRelationEditor editor = GenericRelationEditorTest.newRelationEditor(orig, layer); 70 44 71 45 MemberTable memberTable = new MemberTable(layer, editor.getRelation(), memberTableModel);
Note:
See TracChangeset
for help on using the changeset viewer.