Changeset 8005 in josm for trunk


Ignore:
Timestamp:
2015-02-03T21:53:19+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #11064 - disable undo/redo feature for table cell editors

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverColumnModel.java

    r7509 r8005  
    6262    protected final void createColumns() {
    6363
    64         AutoCompletingTextField roleEditor = new AutoCompletingTextField();
     64        AutoCompletingTextField roleEditor = new AutoCompletingTextField(0, false);
    6565        RelationMemberConflictDecisionRenderer decisionRenderer = new RelationMemberConflictDecisionRenderer();
    6666        RelationMemberConflictDecisionEditor decisionEditor = new RelationMemberConflictDecisionEditor();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java

    r7556 r8005  
    3030        this.ds = ds;
    3131        this.relation = relation;
    32         editor = new AutoCompletingTextField();
     32        editor = new AutoCompletingTextField(0, false);
    3333        editor.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
    3434        autoCompletionList = new AutoCompletionList();
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java

    r6084 r8005  
    3333     */
    3434    public TagCellEditor() {
    35         editor = new AutoCompletingTextField();
     35        editor = new AutoCompletingTextField(0, false);
    3636        editor.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    3737    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingTextField.java

    r7509 r8005  
    154154     */
    155155    public AutoCompletingTextField() {
    156         init();
     156        this(0);
    157157    }
    158158
     
    163163     */
    164164    public AutoCompletingTextField(int columns) {
    165         super(columns);
     165        this(columns, true);
     166    }
     167
     168    /**
     169     * Constructs a new {@code AutoCompletingTextField}.
     170     * @param columns the number of columns to use to calculate the preferred width;
     171     * if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
     172     * @param undoRedo Enables or not Undo/Redo feature. Not recommended for table cell editors, unless each cell provides its own editor
     173     */
     174    public AutoCompletingTextField(int columns, boolean undoRedo) {
     175        super(null, null, columns, undoRedo);
    166176        init();
    167177    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java

    r7937 r8005  
    181181        private PopupMenuLauncher launcher;
    182182
    183         @Override public void propertyChange(PropertyChangeEvent evt) {
     183        @Override
     184        public void propertyChange(PropertyChangeEvent evt) {
    184185            if ("editable".equals(evt.getPropertyName())) {
    185186                if (evt.getNewValue().equals(true)) {
     
    202203                    component = (JTextComponent) editorComponent;
    203204                    component.addMouseListener(this);
    204                     launcher = TextContextualPopupMenu.enableMenuFor(component);
     205                    launcher = TextContextualPopupMenu.enableMenuFor(component, true);
    205206                }
    206207            }
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmEditorPane.java

    r7937 r8005  
    3232     */
    3333    public JosmEditorPane() {
    34         TextContextualPopupMenu.enableMenuFor(this);
     34        TextContextualPopupMenu.enableMenuFor(this, true);
    3535    }
    3636
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextArea.java

    r7937 r8005  
    8686    public JosmTextArea(Document doc, String text, int rows, int columns) {
    8787        super(doc, text, rows, columns);
    88         TextContextualPopupMenu.enableMenuFor(this);
     88        TextContextualPopupMenu.enableMenuFor(this, true);
    8989        addFocusListener(this);
    9090    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r8002 r8005  
    4545     */
    4646    public JosmTextField(Document doc, String text, int columns) {
     47        this(doc, text, columns, true);
     48    }
     49
     50    /**
     51     * Constructs a new <code>JosmTextField</code> that uses the given text
     52     * storage model and the given number of columns.
     53     * This is the constructor through which the other constructors feed.
     54     * If the document is <code>null</code>, a default model is created.
     55     *
     56     * @param doc  the text storage to use; if this is <code>null</code>,
     57     *      a default will be provided by calling the
     58     *      <code>createDefaultModel</code> method
     59     * @param text  the initial string to display, or <code>null</code>
     60     * @param columns  the number of columns to use to calculate
     61     *   the preferred width &gt;= 0; if <code>columns</code>
     62     *   is set to zero, the preferred width will be whatever
     63     *   naturally results from the component implementation
     64     * @param undoRedo Enables or not Undo/Redo feature. Not recommended for table cell editors, unless each cell provides its own editor
     65     * @exception IllegalArgumentException if <code>columns</code> &lt; 0
     66     */
     67    public JosmTextField(Document doc, String text, int columns, boolean undoRedo) {
    4768        super(doc, text, columns);
    48         TextContextualPopupMenu.enableMenuFor(this);
     69        TextContextualPopupMenu.enableMenuFor(this, undoRedo);
    4970        // Fix minimum size when columns are specified
    5071        if (columns > 0) {
  • trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

    r8002 r8005  
    4646
    4747    protected JTextComponent component = null;
     48    protected boolean undoRedo;
    4849    protected final UndoAction undoAction = new UndoAction();
    4950    protected final RedoAction redoAction = new RedoAction();
     
    8283     * @see #detach()
    8384     */
    84     protected TextContextualPopupMenu attach(JTextComponent component) {
     85    protected TextContextualPopupMenu attach(JTextComponent component, boolean undoRedo) {
    8586        if (component != null && !isAttached()) {
    8687            this.component = component;
    87             if (component.isEditable()) {
     88            this.undoRedo = undoRedo;
     89            if (undoRedo && component.isEditable()) {
    8890                component.getDocument().addUndoableEditListener(undoEditListener);
    8991                if (!GraphicsEnvironment.isHeadless()) {
     
    102104    private void addMenuEntries() {
    103105        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            }
    107111            addMenuEntry(component, tr("Cut"), DefaultEditorKit.cutAction, null);
    108112        }
     
    125129            component.removePropertyChangeListener(EDITABLE, propertyChangeListener);
    126130            removeAll();
    127             component.getDocument().removeUndoableEditListener(undoEditListener);
     131            if (undoRedo) {
     132                component.getDocument().removeUndoableEditListener(undoEditListener);
     133            }
    128134            component = null;
    129135        }
     
    134140     * Creates a new {@link TextContextualPopupMenu} and enables it for the given text component.
    135141     * @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
    136143     * @return The {@link PopupMenuLauncher} responsible of displaying the popup menu.
    137144     *         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);
    142149        component.addMouseListener(launcher);
    143150        return launcher;
     
    148155     * @param component The component that currently displays the menu and handles its actions.
    149156     * @param launcher The {@link PopupMenuLauncher} obtained via {@link #enableMenuFor}.
    150      * @see #enableMenuFor(JTextComponent)
     157     * @see #enableMenuFor
    151158     */
    152159    public static void disableMenuFor(JTextComponent component, PopupMenuLauncher launcher) {
Note: See TracChangeset for help on using the changeset viewer.