Changeset 8000 in josm for trunk/src/org/openstreetmap/josm/gui/widgets
- Timestamp:
- 2015-02-02T21:46:25+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java
r7937 r8000 18 18 /** 19 19 * Subclass of {@link JTextField} that:<ul> 20 * <li>adds a "native" context menu ( cut/copy/paste/select all)</li>20 * <li>adds a "native" context menu (undo/cut/copy/paste/select all)</li> 21 21 * <li>adds an optional "hint" displayed when no text has been entered</li> 22 22 * <li>disables the global advanced key press detector when focused</li> -
trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java
r7937 r8000 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Toolkit; 6 7 import java.awt.event.ActionEvent; 8 import java.awt.event.KeyEvent; 7 9 import java.beans.PropertyChangeEvent; 8 10 import java.beans.PropertyChangeListener; … … 13 15 import javax.swing.JMenuItem; 14 16 import javax.swing.JPopupMenu; 17 import javax.swing.KeyStroke; 15 18 import javax.swing.event.UndoableEditEvent; 16 19 import javax.swing.event.UndoableEditListener; … … 37 40 public class TextContextualPopupMenu extends JPopupMenu { 38 41 42 private static final String EDITABLE = "editable"; 43 39 44 protected JTextComponent component = null; 40 45 protected UndoAction undoAction = null; … … 42 47 protected final PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { 43 48 @Override public void propertyChange(PropertyChangeEvent evt) { 44 if ( "editable".equals(evt.getPropertyName())) {49 if (EDITABLE.equals(evt.getPropertyName())) { 45 50 removeAll(); 46 51 addMenuEntries(); … … 68 73 undoAction = new UndoAction(); 69 74 component.getDocument().addUndoableEditListener(undoAction); 75 component.getInputMap().put( 76 KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), undoAction); 70 77 } 71 78 addMenuEntries(); 72 component.addPropertyChangeListener( "editable", propertyChangeListener);79 component.addPropertyChangeListener(EDITABLE, propertyChangeListener); 73 80 } 74 81 return this; … … 97 104 protected TextContextualPopupMenu detach() { 98 105 if (isAttached()) { 99 component.removePropertyChangeListener( "editable", propertyChangeListener);106 component.removePropertyChangeListener(EDITABLE, propertyChangeListener); 100 107 removeAll(); 101 108 if (undoAction != null) { … … 161 168 private final UndoManager undoManager = new UndoManager(); 162 169 170 /** 171 * Constructs a new {@code UndoAction}. 172 */ 163 173 public UndoAction() { 164 174 super(tr("Undo")); … … 177 187 undoManager.undo(); 178 188 } catch (CannotUndoException ex) { 179 // Ignored 189 if (Main.isTraceEnabled()) { 190 Main.trace(ex.getMessage()); 191 } 180 192 } finally { 181 193 setEnabled(undoManager.canUndo());
Note:
See TracChangeset
for help on using the changeset viewer.