Changeset 8005 in josm for trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java
- Timestamp:
- 2015-02-03T21:53:19+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java
r8002 r8005 46 46 47 47 protected JTextComponent component = null; 48 protected boolean undoRedo; 48 49 protected final UndoAction undoAction = new UndoAction(); 49 50 protected final RedoAction redoAction = new RedoAction(); … … 82 83 * @see #detach() 83 84 */ 84 protected TextContextualPopupMenu attach(JTextComponent component ) {85 protected TextContextualPopupMenu attach(JTextComponent component, boolean undoRedo) { 85 86 if (component != null && !isAttached()) { 86 87 this.component = component; 87 if (component.isEditable()) { 88 this.undoRedo = undoRedo; 89 if (undoRedo && component.isEditable()) { 88 90 component.getDocument().addUndoableEditListener(undoEditListener); 89 91 if (!GraphicsEnvironment.isHeadless()) { … … 102 104 private void addMenuEntries() { 103 105 if (component.isEditable()) { 104 add(new JMenuItem(undoAction)); 105 add(new JMenuItem(redoAction)); 106 addSeparator(); 106 if (undoRedo) { 107 add(new JMenuItem(undoAction)); 108 add(new JMenuItem(redoAction)); 109 addSeparator(); 110 } 107 111 addMenuEntry(component, tr("Cut"), DefaultEditorKit.cutAction, null); 108 112 } … … 125 129 component.removePropertyChangeListener(EDITABLE, propertyChangeListener); 126 130 removeAll(); 127 component.getDocument().removeUndoableEditListener(undoEditListener); 131 if (undoRedo) { 132 component.getDocument().removeUndoableEditListener(undoEditListener); 133 } 128 134 component = null; 129 135 } … … 134 140 * Creates a new {@link TextContextualPopupMenu} and enables it for the given text component. 135 141 * @param component The component that will display the menu and handle its actions. 142 * @param undoRedo Enables or not Undo/Redo feature. Not recommended for table cell editors, unless each cell provides its own editor 136 143 * @return The {@link PopupMenuLauncher} responsible of displaying the popup menu. 137 144 * Call {@link #disableMenuFor} with this object if you want to disable the menu later. 138 * @see #disableMenuFor (JTextComponent, PopupMenuLauncher)139 */ 140 public static PopupMenuLauncher enableMenuFor(JTextComponent component ) {141 PopupMenuLauncher launcher = new PopupMenuLauncher(new TextContextualPopupMenu().attach(component ), true);145 * @see #disableMenuFor 146 */ 147 public static PopupMenuLauncher enableMenuFor(JTextComponent component, boolean undoRedo) { 148 PopupMenuLauncher launcher = new PopupMenuLauncher(new TextContextualPopupMenu().attach(component, undoRedo), true); 142 149 component.addMouseListener(launcher); 143 150 return launcher; … … 148 155 * @param component The component that currently displays the menu and handles its actions. 149 156 * @param launcher The {@link PopupMenuLauncher} obtained via {@link #enableMenuFor}. 150 * @see #enableMenuFor (JTextComponent)157 * @see #enableMenuFor 151 158 */ 152 159 public static void disableMenuFor(JTextComponent component, PopupMenuLauncher launcher) {
Note:
See TracChangeset
for help on using the changeset viewer.