This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 167063
Collapse All | Expand All

(-)a/editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/ToggleBookmarkAction.java (-70 / +26 lines)
Lines 41-56 Link Here
41
41
42
package org.netbeans.lib.editor.bookmarks.actions;
42
package org.netbeans.lib.editor.bookmarks.actions;
43
43
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionEvent;
46
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeListener;
48
import javax.swing.AbstractAction;
47
import javax.swing.AbstractAction;
49
import javax.swing.AbstractButton;
50
import javax.swing.Action;
48
import javax.swing.Action;
51
import javax.swing.ButtonModel;
52
import javax.swing.ImageIcon;
53
import javax.swing.JButton;
54
import javax.swing.JEditorPane;
49
import javax.swing.JEditorPane;
55
import javax.swing.JToggleButton;
50
import javax.swing.JToggleButton;
56
import javax.swing.event.ChangeEvent;
51
import javax.swing.event.ChangeEvent;
Lines 59-64 Link Here
59
import javax.swing.text.Caret;
54
import javax.swing.text.Caret;
60
import javax.swing.text.Document;
55
import javax.swing.text.Document;
61
import javax.swing.text.JTextComponent;
56
import javax.swing.text.JTextComponent;
57
import org.netbeans.api.editor.EditorActionButtonModel;
58
import org.netbeans.api.editor.EditorActionRegistration;
59
import org.netbeans.api.editor.EditorActionTextComponent;
62
import org.netbeans.editor.BaseDocument;
60
import org.netbeans.editor.BaseDocument;
63
import org.netbeans.lib.editor.bookmarks.api.Bookmark;
61
import org.netbeans.lib.editor.bookmarks.api.Bookmark;
64
import org.netbeans.lib.editor.bookmarks.api.BookmarkList;
62
import org.netbeans.lib.editor.bookmarks.api.BookmarkList;
Lines 70-76 Link Here
70
import org.openide.util.NbBundle;
68
import org.openide.util.NbBundle;
71
import org.openide.util.Utilities;
69
import org.openide.util.Utilities;
72
import org.openide.util.WeakListeners;
70
import org.openide.util.WeakListeners;
73
import org.openide.util.actions.Presenter;
74
71
75
72
76
/**
73
/**
Lines 78-84 Link Here
78
 *
75
 *
79
 * @author Vita Stejskal
76
 * @author Vita Stejskal
80
 */
77
 */
81
public final class ToggleBookmarkAction extends AbstractAction implements ContextAwareAction, Presenter.Toolbar {
78
@EditorActionRegistration(name="bookmark-toggle",
79
        iconResource = "org/netbeans/modules/editor/resources/toggle_bookmark.png")
80
public final class ToggleBookmarkAction extends AbstractAction implements ContextAwareAction {
82
81
83
    private static final String ACTION_NAME = "bookmark-toggle"; // NOI18N
82
    private static final String ACTION_NAME = "bookmark-toggle"; // NOI18N
84
    private static final String ACTION_ICON = "org/netbeans/modules/editor/bookmarks/resources/toggle_bookmark.png"; // NOI18N
83
    private static final String ACTION_ICON = "org/netbeans/modules/editor/bookmarks/resources/toggle_bookmark.png"; // NOI18N
Lines 98-108 Link Here
98
        this.component = component;
97
        this.component = component;
99
    }
98
    }
100
99
100
    @Override
101
    public Action createContextAwareInstance(Lookup actionContext) {
101
    public Action createContextAwareInstance(Lookup actionContext) {
102
        JTextComponent jtc = findComponent(actionContext);
102
        JTextComponent jtc = findComponent(actionContext);
103
        return new ToggleBookmarkAction(jtc);
103
        return new ToggleBookmarkAction(jtc);
104
    }
104
    }
105
105
106
    @Override
106
    public void actionPerformed(ActionEvent arg0) {
107
    public void actionPerformed(ActionEvent arg0) {
107
        if (component != null) {
108
        if (component != null) {
108
            // cloned action with context
109
            // cloned action with context
Lines 116-121 Link Here
116
        }
117
        }
117
    }
118
    }
118
119
120
    @Override
119
    public boolean isEnabled() {
121
    public boolean isEnabled() {
120
        if (component != null) {
122
        if (component != null) {
121
            return true;
123
            return true;
Lines 125-148 Link Here
125
        }
127
        }
126
    }
128
    }
127
129
128
    public Component getToolbarPresenter() {
129
        AbstractButton b;
130
        
131
        if (component != null) {
132
            b = new MyGaGaButton();
133
            b.setModel(new BookmarkButtonModel(component));
134
        } else {
135
            b = new JButton();
136
        }
137
        
138
        b.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
139
        b.setAction(this);
140
        
141
        return b;
142
    }
143
144
    private static JTextComponent findComponent(Lookup lookup) {
130
    private static JTextComponent findComponent(Lookup lookup) {
145
        EditorCookie ec = (EditorCookie) lookup.lookup(EditorCookie.class);
131
        EditorCookie ec = lookup.lookup(EditorCookie.class);
146
        if (ec != null) {
132
        if (ec != null) {
147
            JEditorPane panes[] = ec.getOpenedPanes();
133
            JEditorPane panes[] = ec.getOpenedPanes();
148
            if (panes != null && panes.length > 0) {
134
            if (panes != null && panes.length > 0) {
Lines 164-186 Link Here
164
            }
150
            }
165
        }
151
        }
166
    }
152
    }
167
    
153
168
    private static final class BookmarkButtonModel extends JToggleButton.ToggleButtonModel implements PropertyChangeListener, ChangeListener {
154
    @EditorActionButtonModel(name="bookmark-toggle")
169
        
155
    public static final class BookmarkButtonModel extends JToggleButton.ToggleButtonModel implements PropertyChangeListener, ChangeListener {
170
        private final JTextComponent component;
156
157
        private JTextComponent component;
171
        private Caret caret;
158
        private Caret caret;
172
        private BookmarkList bookmarks;
159
        private BookmarkList bookmarks;
173
        private int lastCurrentLineStartOffset = -1;
160
        private int lastCurrentLineStartOffset = -1;
174
        
161
175
        private PropertyChangeListener bookmarksListener = null;
162
        private PropertyChangeListener bookmarksListener = null;
176
        private ChangeListener caretListener = null;
163
        private ChangeListener caretListener = null;
164
165
        public BookmarkButtonModel() {
166
        }
177
        
167
        
178
        public BookmarkButtonModel(JTextComponent component) {
168
        public BookmarkButtonModel(JTextComponent component) {
169
            setAssociatedComponent(component);
170
        }
171
172
        @EditorActionTextComponent
173
        public void setAssociatedComponent(JTextComponent component) {
179
            this.component = component;
174
            this.component = component;
180
            this.component.addPropertyChangeListener(WeakListeners.propertyChange(this, this.component));
175
            this.component.addPropertyChangeListener(WeakListeners.propertyChange(this, this.component));
181
            rebuild();
176
            rebuild();
182
        }
177
        }
183
178
179
        @Override
184
        public void propertyChange(PropertyChangeEvent evt) {
180
        public void propertyChange(PropertyChangeEvent evt) {
185
            if (evt.getPropertyName() == null || 
181
            if (evt.getPropertyName() == null || 
186
                "document".equals(evt.getPropertyName()) || //NOI18N
182
                "document".equals(evt.getPropertyName()) || //NOI18N
Lines 193-198 Link Here
193
            }
189
            }
194
        }
190
        }
195
191
192
        @Override
196
        public void stateChanged(ChangeEvent evt) {
193
        public void stateChanged(ChangeEvent evt) {
197
            updateState();
194
            updateState();
198
        }
195
        }
Lines 260-306 Link Here
260
            }
257
            }
261
        }
258
        }
262
    } // End of BookmarkButtonModel class
259
    } // End of BookmarkButtonModel class
263
    
264
    private static final class MyGaGaButton extends JToggleButton implements ChangeListener {
265
266
        public MyGaGaButton() {
267
268
        }
269
270
        public void setModel(ButtonModel model) {
271
            ButtonModel oldModel = getModel();
272
            if (oldModel != null) {
273
                oldModel.removeChangeListener(this);
274
            }
275
276
            super.setModel(model);
277
278
            ButtonModel newModel = getModel();
279
            if (newModel != null) {
280
                newModel.addChangeListener(this);
281
            }
282
283
            stateChanged(null);
284
        }
285
286
        public void stateChanged(ChangeEvent evt) {
287
            boolean selected = isSelected();
288
            super.setContentAreaFilled(selected);
289
            super.setBorderPainted(selected);
290
        }
291
292
        public void setBorderPainted(boolean arg0) {
293
            if (!isSelected()) {
294
                super.setBorderPainted(arg0);
295
            }
296
        }
297
298
        public void setContentAreaFilled(boolean arg0) {
299
            if (!isSelected()) {
300
                super.setContentAreaFilled(arg0);
301
            }
302
        }
303
    } // End of MyGaGaButton class
304
260
305
}
261
}
306
262
(-)a/editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/api/Bookmark.java (-1 / +1 lines)
Lines 190-196 Link Here
190
        private WeakReference<BookmarkList> bookmarkListReference;
190
        private WeakReference<BookmarkList> bookmarkListReference;
191
191
192
        LineListener (BookmarkList bookmarkList) {
192
        LineListener (BookmarkList bookmarkList) {
193
            bookmarkListReference = new WeakReference (bookmarkList);
193
            bookmarkListReference = new WeakReference<BookmarkList> (bookmarkList);
194
        }
194
        }
195
195
196
        public void propertyChange(PropertyChangeEvent evt) {
196
        public void propertyChange(PropertyChangeEvent evt) {
(-)a/editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/api/BookmarkList.java (-16 / +22 lines)
Lines 91-107 Link Here
91
    /**
91
    /**
92
     * List of bookmark instances.
92
     * List of bookmark instances.
93
     */
93
     */
94
    private List            bookmarks;
94
    private List<Bookmark>            bookmarks;
95
95
96
    private final PropertyChangeSupport 
96
    private final PropertyChangeSupport 
97
                            propertyChangeSupport = new PropertyChangeSupport (this);
97
                            propertyChangeSupport = new PropertyChangeSupport (this);
98
    
98
    
99
    @SuppressWarnings("LeakingThisInConstructor")
99
    private BookmarkList (Document document) {
100
    private BookmarkList (Document document) {
100
        if (document == null) {
101
        if (document == null) {
101
            throw new NullPointerException ("Document cannot be null"); // NOI18N
102
            throw new NullPointerException ("Document cannot be null"); // NOI18N
102
        }
103
        }
103
        this.document = document;
104
        this.document = document;
104
        this.bookmarks = new ArrayList ();
105
        this.bookmarks = new ArrayList<Bookmark> ();
105
        BookmarksPersistence.loadBookmarks (this);
106
        BookmarksPersistence.loadBookmarks (this);
106
        
107
        
107
        DataObject dataObject = NbEditorUtilities.getDataObject (document);
108
        DataObject dataObject = NbEditorUtilities.getDataObject (document);
Lines 186-204 Link Here
186
     */
187
     */
187
    public Bookmark getPreviousBookmark (int offset, boolean wrapSearch) {
188
    public Bookmark getPreviousBookmark (int offset, boolean wrapSearch) {
188
        checkOffsetNonNegative (offset);
189
        checkOffsetNonNegative (offset);
189
        List<Bookmark> bookmarks = new ArrayList<Bookmark> (getBookmarks ());
190
        List<Bookmark> previousBookmarks = new ArrayList<Bookmark> (getBookmarks ());
190
        Bookmark bookmark; // result
191
        Bookmark bookmark; // result
191
        if (!bookmarks.isEmpty ()) {
192
        if (!previousBookmarks.isEmpty ()) {
192
            offset--; // search from previous offset
193
            offset--; // search from previous offset
193
            bookmark = getNextBookmark (offset);
194
            bookmark = getNextBookmark (offset);
194
            if (bookmark == null || bookmark.getOffset () != offset) {
195
            if (bookmark == null || bookmark.getOffset () != offset) {
195
                // go below
196
                // go below
196
                int index = bookmark == null ?
197
                int index = bookmark == null ?
197
                    bookmarks.size () :
198
                    previousBookmarks.size () :
198
                    bookmarks.indexOf (bookmark);
199
                    previousBookmarks.indexOf (bookmark);
199
                index--;
200
                index--;
200
                if (index >= 0) {
201
                if (index >= 0) {
201
                    bookmark = bookmarks.get (index);
202
                    bookmark = previousBookmarks.get (index);
202
                } else { // prior first bookmark
203
                } else { // prior first bookmark
203
                    if (wrapSearch) {
204
                    if (wrapSearch) {
204
                        bookmark = getPreviousBookmark(Integer.MAX_VALUE, false);
205
                        bookmark = getPreviousBookmark(Integer.MAX_VALUE, false);
Lines 228-240 Link Here
228
    private Bookmark getNextBookmark (int offset) {
229
    private Bookmark getNextBookmark (int offset) {
229
        // Find next bookmark by binary search
230
        // Find next bookmark by binary search
230
        int low = 0;
231
        int low = 0;
231
        List<Bookmark> bookmarks = new ArrayList<Bookmark> (getBookmarks ());
232
        List<Bookmark> nextBookmarks = new ArrayList<Bookmark> (getBookmarks ());
232
        if (bookmarks.isEmpty ()) return null;
233
        if (nextBookmarks.isEmpty ()) return null;
233
        int high = bookmarks.size () - 1;
234
        int high = nextBookmarks.size () - 1;
234
        
235
        
235
        while (low <= high) {
236
        while (low <= high) {
236
            int mid = (low + high) / 2;
237
            int mid = (low + high) / 2;
237
            int midOffset = bookmarks.get (mid).getOffset();
238
            int midOffset = nextBookmarks.get (mid).getOffset();
238
            
239
            
239
            if (midOffset < offset) {
240
            if (midOffset < offset) {
240
                low = mid + 1;
241
                low = mid + 1;
Lines 244-260 Link Here
244
                // Goto first bookmark of possible ones at the same line
245
                // Goto first bookmark of possible ones at the same line
245
                mid--;
246
                mid--;
246
                while (mid >= 0) {
247
                while (mid >= 0) {
247
                    if (bookmarks.get (mid).getOffset() != offset) {
248
                    if (nextBookmarks.get (mid).getOffset() != offset) {
248
                        break;
249
                        break;
249
                    }
250
                    }
250
                    mid--;
251
                    mid--;
251
                }
252
                }
252
                mid++;
253
                mid++;
253
                return bookmarks.get (mid);
254
                return nextBookmarks.get (mid);
254
            }
255
            }
255
        }
256
        }
256
        if (low < bookmarks.size ())
257
        if (low < nextBookmarks.size ())
257
            return bookmarks.get (low);
258
            return nextBookmarks.get (low);
258
        return null;
259
        return null;
259
    }
260
    }
260
    
261
    
Lines 306-311 Link Here
306
        if (removed) {
307
        if (removed) {
307
            bookmark.release();
308
            bookmark.release();
308
            SwingUtilities.invokeLater (new Runnable () {
309
            SwingUtilities.invokeLater (new Runnable () {
310
                @Override
309
                public void run () {
311
                public void run () {
310
                    propertyChangeSupport.firePropertyChange (PROP_BOOKMARKS, null, null);
312
                    propertyChangeSupport.firePropertyChange (PROP_BOOKMARKS, null, null);
311
                }
313
                }
Lines 318-328 Link Here
318
    public synchronized void removeAllBookmarks (){
320
    public synchronized void removeAllBookmarks (){
319
        if (!bookmarks.isEmpty()) {
321
        if (!bookmarks.isEmpty()) {
320
            for (int i = 0; i < bookmarks.size (); i++){
322
            for (int i = 0; i < bookmarks.size (); i++){
321
                Bookmark bookmark = (Bookmark) bookmarks.get (i);
323
                Bookmark bookmark = bookmarks.get (i);
322
                bookmark.release();
324
                bookmark.release();
323
            }
325
            }
324
            bookmarks.clear();
326
            bookmarks.clear();
325
            SwingUtilities.invokeLater (new Runnable () {
327
            SwingUtilities.invokeLater (new Runnable () {
328
                @Override
326
                public void run () {
329
                public void run () {
327
                    propertyChangeSupport.firePropertyChange (PROP_BOOKMARKS, null, null);
330
                    propertyChangeSupport.firePropertyChange (PROP_BOOKMARKS, null, null);
328
                }
331
                }
Lines 341-346 Link Here
341
        bookmarks.add (bookmark);
344
        bookmarks.add (bookmark);
342
        Collections.sort (bookmarks, breakpointsComparator);
345
        Collections.sort (bookmarks, breakpointsComparator);
343
        SwingUtilities.invokeLater (new Runnable () {
346
        SwingUtilities.invokeLater (new Runnable () {
347
            @Override
344
            public void run() {
348
            public void run() {
345
                propertyChangeSupport.firePropertyChange (PROP_BOOKMARKS, null, null);
349
                propertyChangeSupport.firePropertyChange (PROP_BOOKMARKS, null, null);
346
            }
350
            }
Lines 382-387 Link Here
382
    private static PropertyChangeListener 
386
    private static PropertyChangeListener 
383
                            documentModifiedListener = new PropertyChangeListener () {
387
                            documentModifiedListener = new PropertyChangeListener () {
384
388
389
        @Override
385
        public void propertyChange (PropertyChangeEvent evt) {
390
        public void propertyChange (PropertyChangeEvent evt) {
386
            if ("modified".equals (evt.getPropertyName ()) &&
391
            if ("modified".equals (evt.getPropertyName ()) &&
387
                Boolean.FALSE.equals (evt.getNewValue ())
392
                Boolean.FALSE.equals (evt.getNewValue ())
Lines 399-404 Link Here
399
    
404
    
400
    private static final Comparator<Bookmark> breakpointsComparator = new Comparator<Bookmark> () {
405
    private static final Comparator<Bookmark> breakpointsComparator = new Comparator<Bookmark> () {
401
406
407
        @Override
402
        public int compare (Bookmark bookmark1, Bookmark bookmark2) {
408
        public int compare (Bookmark bookmark1, Bookmark bookmark2) {
403
            return bookmark1.getOffset () - bookmark2.getOffset ();
409
            return bookmark1.getOffset () - bookmark2.getOffset ();
404
        }
410
        }
(-)a/editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/BookmarksPersistence.java (-6 / +7 lines)
Lines 50-56 Link Here
50
import java.util.ArrayList;
50
import java.util.ArrayList;
51
import java.util.Arrays;
51
import java.util.Arrays;
52
import java.util.HashMap;
52
import java.util.HashMap;
53
import java.util.Iterator;
54
import java.util.List;
53
import java.util.List;
55
import java.util.Map;
54
import java.util.Map;
56
import java.util.WeakHashMap;
55
import java.util.WeakHashMap;
Lines 99-105 Link Here
99
            projectsListener.destroy ();
98
            projectsListener.destroy ();
100
        }
99
        }
101
    
100
    
102
        List<Project> projects = new ArrayList (projectToBookmarks.keySet ());
101
        List<Project> projects = new ArrayList<Project> (projectToBookmarks.keySet ());
103
        for (Project project : projects)
102
        for (Project project : projects)
104
            saveBookmarks (project);
103
            saveBookmarks (project);
105
    }
104
    }
Lines 332-350 Link Here
332
        
331
        
333
        private static List<Project>    lastOpenProjects;
332
        private static List<Project>    lastOpenProjects;
334
333
334
        @SuppressWarnings("LeakingThisInConstructor")
335
        public ProjectsListener () {
335
        public ProjectsListener () {
336
            OpenProjects openProjects = OpenProjects.getDefault ();
336
            OpenProjects openProjects = OpenProjects.getDefault ();
337
            lastOpenProjects = new ArrayList (Arrays.asList (openProjects.getOpenProjects ()));
337
            lastOpenProjects = new ArrayList<Project> (Arrays.asList (openProjects.getOpenProjects ()));
338
            openProjects.addPropertyChangeListener (this);
338
            openProjects.addPropertyChangeListener (this);
339
        }
339
        }
340
        
340
        
341
        @Override
341
        public void propertyChange (PropertyChangeEvent evt) {
342
        public void propertyChange (PropertyChangeEvent evt) {
342
            List<Project> openProjects = Arrays.asList (OpenProjects.getDefault ().getOpenProjects ());
343
            List<Project> openProjects = Arrays.asList (OpenProjects.getDefault ().getOpenProjects ());
343
            // lastOpenProjects will contain the just closed projects
344
            // lastOpenProjects will contain the just closed projects
344
            lastOpenProjects.removeAll (openProjects);
345
            lastOpenProjects.removeAll (openProjects);
345
            for (Iterator<Project> it = lastOpenProjects.iterator (); it.hasNext ();)
346
            for (Project project : lastOpenProjects)
346
                saveBookmarks (it.next ());
347
                saveBookmarks (project);
347
            lastOpenProjects = new ArrayList (openProjects);
348
            lastOpenProjects = new ArrayList<Project> (openProjects);
348
        }
349
        }
349
        
350
        
350
        void destroy () {
351
        void destroy () {
(-)a/editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/Bundle.properties (+3 lines)
Lines 43-45 Link Here
43
OpenIDE-Module-Long-Description=Editor Bookmarks module contains support for adding/removing/jumping through the bookmarks in the edited source files.
43
OpenIDE-Module-Long-Description=Editor Bookmarks module contains support for adding/removing/jumping through the bookmarks in the edited source files.
44
44
45
HINT_BOOKMARK=Bookmark
45
HINT_BOOKMARK=Bookmark
46
47
bookmark-next=Next Bookmark
48
bookmark-previous=Previous Bookmark
(-)a/editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/WrapperBookmarkAction.java (+5 lines)
Lines 46-51 Link Here
46
import java.util.Set;
46
import java.util.Set;
47
import javax.swing.Action;
47
import javax.swing.Action;
48
import javax.swing.JEditorPane;
48
import javax.swing.JEditorPane;
49
import org.netbeans.api.editor.EditorActionRegistration;
49
50
50
import org.netbeans.editor.BaseAction;
51
import org.netbeans.editor.BaseAction;
51
import org.netbeans.lib.editor.bookmarks.actions.ClearDocumentBookmarksAction;
52
import org.netbeans.lib.editor.bookmarks.actions.ClearDocumentBookmarksAction;
Lines 123-128 Link Here
123
        return (String)originalAction.getValue(BaseAction.ICON_RESOURCE_PROPERTY);
124
        return (String)originalAction.getValue(BaseAction.ICON_RESOURCE_PROPERTY);
124
    }
125
    }
125
126
127
    @EditorActionRegistration(name="bookmark-next",
128
            iconResource = "org/netbeans/modules/editor/resources/next_bookmark.png")
126
    public static final class Next extends WrapperBookmarkAction {
129
    public static final class Next extends WrapperBookmarkAction {
127
        
130
        
128
        public Next() {
131
        public Next() {
Lines 131-136 Link Here
131
134
132
    }
135
    }
133
136
137
    @EditorActionRegistration(name="bookmark-previous",
138
            iconResource = "org/netbeans/modules/editor/resources/previous_bookmark.png")
134
    public static final class Previous extends WrapperBookmarkAction {
139
    public static final class Previous extends WrapperBookmarkAction {
135
        
140
        
136
        public Previous() {
141
        public Previous() {
(-)a/editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/resources/layer.xml (-2 / +2 lines)
Lines 85-91 Link Here
85
    </folder>
85
    </folder>
86
    
86
    
87
    <folder name="Editors">
87
    <folder name="Editors">
88
        <folder name="Toolbars">
88
        <!--folder name="Toolbars">
89
            <folder name="Default">
89
            <folder name="Default">
90
                <file name="bookmark-previous.shadow">
90
                <file name="bookmark-previous.shadow">
91
                    <attr name="originalFile" stringvalue="Actions/Edit/bookmark-previous.instance"/>
91
                    <attr name="originalFile" stringvalue="Actions/Edit/bookmark-previous.instance"/>
Lines 104-110 Link Here
104
                    <attr name="position" intvalue="14000"/>
104
                    <attr name="position" intvalue="14000"/>
105
                </file>
105
                </file>
106
                </folder>
106
                </folder>
107
        </folder>
107
        </folder-->
108
108
109
        <folder name="AnnotationTypes">
109
        <folder name="AnnotationTypes">
110
            <file name="bookmark.xml" url="bookmark.xml"/>
110
            <file name="bookmark.xml" url="bookmark.xml"/>
(-)a/editor.lib/src/org/netbeans/editor/ActionFactory.java (-63 / +7 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 41-47 Link Here
41
41
42
package org.netbeans.editor;
42
package org.netbeans.editor;
43
43
44
import java.awt.Component;
45
import java.awt.Rectangle;
44
import java.awt.Rectangle;
46
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionEvent;
47
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeEvent;
Lines 51-58 Link Here
51
import java.util.HashSet;
50
import java.util.HashSet;
52
import javax.swing.Action;
51
import javax.swing.Action;
53
import javax.swing.ActionMap;
52
import javax.swing.ActionMap;
54
import javax.swing.ButtonModel;
55
import javax.swing.event.ChangeEvent;
56
import javax.swing.plaf.TextUI;
53
import javax.swing.plaf.TextUI;
57
import javax.swing.text.BadLocationException;
54
import javax.swing.text.BadLocationException;
58
import javax.swing.text.DefaultEditorKit;
55
import javax.swing.text.DefaultEditorKit;
Lines 75-83 Link Here
75
import java.util.logging.Level;
72
import java.util.logging.Level;
76
import java.util.logging.Logger;
73
import java.util.logging.Logger;
77
import javax.swing.JToggleButton;
74
import javax.swing.JToggleButton;
78
import javax.swing.event.ChangeListener;
79
import javax.swing.text.AbstractDocument;
75
import javax.swing.text.AbstractDocument;
80
import javax.swing.text.View;
76
import javax.swing.text.View;
77
import org.netbeans.api.editor.EditorActionButtonModel;
81
import org.netbeans.api.editor.EditorActionRegistration;
78
import org.netbeans.api.editor.EditorActionRegistration;
82
import org.netbeans.api.editor.EditorActionRegistrations;
79
import org.netbeans.api.editor.EditorActionRegistrations;
83
import org.netbeans.api.editor.fold.Fold;
80
import org.netbeans.api.editor.fold.Fold;
Lines 86-95 Link Here
86
import org.netbeans.api.progress.ProgressUtils;
83
import org.netbeans.api.progress.ProgressUtils;
87
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
84
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
88
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
85
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
89
import org.netbeans.lib.editor.view.GapBoxView;
90
import org.openide.util.NbBundle;
86
import org.openide.util.NbBundle;
91
import org.openide.util.WeakListeners;
87
import org.openide.util.WeakListeners;
92
import org.openide.util.actions.Presenter;
93
88
94
/**
89
/**
95
* Actions that are not considered basic and therefore
90
* Actions that are not considered basic and therefore
Lines 1193-1199 Link Here
1193
1188
1194
    @EditorActionRegistration(name = BaseKit.toggleHighlightSearchAction,
1189
    @EditorActionRegistration(name = BaseKit.toggleHighlightSearchAction,
1195
            iconResource = "org/netbeans/modules/editor/resources/toggle_highlight.png")
1190
            iconResource = "org/netbeans/modules/editor/resources/toggle_highlight.png")
1196
    public static class ToggleHighlightSearchAction extends LocalBaseAction implements Presenter.Toolbar {
1191
    public static class ToggleHighlightSearchAction extends LocalBaseAction {
1197
1192
1198
        static final long serialVersionUID =4603809175771743200L;
1193
        static final long serialVersionUID =4603809175771743200L;
1199
1194
Lines 1215-1237 Link Here
1215
            }
1210
            }
1216
        }
1211
        }
1217
1212
1218
        public Component getToolbarPresenter() {
1213
        @EditorActionButtonModel(name=BaseKit.toggleHighlightSearchAction)
1219
            JToggleButton b = new MyGaGaButton();
1214
        public static final class HighlightButtonModel extends JToggleButton.ToggleButtonModel implements PropertyChangeListener {
1220
            b.setModel(new HighlightButtonModel());
1221
            b.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
1222
            b.setAction(this);
1223
            
1224
            return b;
1225
        }
1226
        
1227
        private static final class HighlightButtonModel extends JToggleButton.ToggleButtonModel implements PropertyChangeListener {
1228
            
1215
            
1229
            public HighlightButtonModel() {
1216
            public HighlightButtonModel() {
1230
                EditorFindSupport efs = EditorFindSupport.getInstance();
1217
                EditorFindSupport efs = EditorFindSupport.getInstance();
1231
                efs.addPropertyChangeListener(WeakListeners.propertyChange(this, efs));
1218
                efs.addPropertyChangeListener(WeakListeners.propertyChange(this, efs));
1232
                propertyChange(null);
1219
                propertyChange(null);
1233
            }
1220
            }
1234
        
1221
1222
            @Override
1235
            public void propertyChange(PropertyChangeEvent evt) {
1223
            public void propertyChange(PropertyChangeEvent evt) {
1236
                if (evt == null || evt.getPropertyName() == null || evt.getPropertyName().equals(EditorFindSupport.FIND_HIGHLIGHT_SEARCH)) {
1224
                if (evt == null || evt.getPropertyName() == null || evt.getPropertyName().equals(EditorFindSupport.FIND_HIGHLIGHT_SEARCH)) {
1237
                    Boolean value = (Boolean) EditorFindSupport.getInstance().getFindProperty(EditorFindSupport.FIND_HIGHLIGHT_SEARCH);
1225
                    Boolean value = (Boolean) EditorFindSupport.getInstance().getFindProperty(EditorFindSupport.FIND_HIGHLIGHT_SEARCH);
Lines 1239-1288 Link Here
1239
                }
1227
                }
1240
            }
1228
            }
1241
        } // End of HighlightButtonModel class
1229
        } // End of HighlightButtonModel class
1242
        
1243
        private static final class MyGaGaButton extends JToggleButton implements ChangeListener {
1244
            
1245
            public MyGaGaButton() {
1246
                
1247
            }
1248
            
1249
            @Override
1250
            public void setModel(ButtonModel model) {
1251
                ButtonModel oldModel = getModel();
1252
                if (oldModel != null) {
1253
                    oldModel.removeChangeListener(this);
1254
                }
1255
                
1256
                super.setModel(model);
1257
                
1258
                ButtonModel newModel = getModel();
1259
                if (newModel != null) {
1260
                    newModel.addChangeListener(this);
1261
                }
1262
                
1263
                stateChanged(null);
1264
            }
1265
1266
            public void stateChanged(ChangeEvent evt) {
1267
                boolean selected = isSelected();
1268
                super.setContentAreaFilled(selected);
1269
                super.setBorderPainted(selected);
1270
            }
1271
1272
            @Override
1273
            public void setBorderPainted(boolean arg0) {
1274
                if (!isSelected()) {
1275
                    super.setBorderPainted(arg0);
1276
                }
1277
            }
1278
1279
            @Override
1280
            public void setContentAreaFilled(boolean arg0) {
1281
                if (!isSelected()) {
1282
                    super.setContentAreaFilled(arg0);
1283
                }
1284
            }
1285
        }
1286
    } // End of ToggleHighlightSearchAction class
1230
    } // End of ToggleHighlightSearchAction class
1287
1231
1288
    public static class UndoAction extends LocalBaseAction {
1232
    public static class UndoAction extends LocalBaseAction {
(-)a/editor.lib/src/org/netbeans/editor/BaseKit.java (-3 / +3 lines)
Lines 196-205 Link Here
196
    /** Switch the case of the selected text or current character */
196
    /** Switch the case of the selected text or current character */
197
    public static final String switchCaseAction = "switch-case"; // NOI18N
197
    public static final String switchCaseAction = "switch-case"; // NOI18N
198
198
199
    /** Find next occurence action */
199
    /** Find next occurrence action */
200
    public static final String findNextAction = "find-next"; // NOI18N
200
    public static final String findNextAction = "find-next"; // NOI18N
201
201
202
    /** Find previous occurence action */
202
    /** Find previous occurrence action */
203
    public static final String findPreviousAction = "find-previous"; // NOI18N
203
    public static final String findPreviousAction = "find-previous"; // NOI18N
204
204
205
    /** Toggle highlight search action */
205
    /** Toggle highlight search action */
Lines 220-226 Link Here
220
    /** Word match prev */
220
    /** Word match prev */
221
    public static final String wordMatchPrevAction = "word-match-prev"; // NOI18N
221
    public static final String wordMatchPrevAction = "word-match-prev"; // NOI18N
222
222
223
    /** Reindent Line action */
223
    /** Re-indent Line action */
224
    public static final String reindentLineAction = "reindent-line"; // NOI18N
224
    public static final String reindentLineAction = "reindent-line"; // NOI18N
225
225
226
    /** Shift line right action */
226
    /** Shift line right action */
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/EditorActionRegistrationProcessor.java (-5 / +32 lines)
Lines 40-47 Link Here
40
package org.netbeans.modules.editor.lib2;
40
package org.netbeans.modules.editor.lib2;
41
41
42
import java.util.Arrays;
42
import java.util.Arrays;
43
import java.util.HashMap;
43
import java.util.HashSet;
44
import java.util.HashSet;
44
import java.util.List;
45
import java.util.List;
46
import java.util.Map;
45
import org.netbeans.modules.editor.lib2.actions.EditorActionUtilities;
47
import org.netbeans.modules.editor.lib2.actions.EditorActionUtilities;
46
import org.netbeans.modules.editor.lib2.actions.PresenterEditorAction;
48
import org.netbeans.modules.editor.lib2.actions.PresenterEditorAction;
47
import java.util.Set;
49
import java.util.Set;
Lines 57-62 Link Here
57
import javax.lang.model.type.TypeMirror;
59
import javax.lang.model.type.TypeMirror;
58
import javax.lang.model.util.ElementFilter;
60
import javax.lang.model.util.ElementFilter;
59
import javax.swing.Action;
61
import javax.swing.Action;
62
import org.netbeans.api.editor.EditorActionButtonModel;
63
import org.netbeans.api.editor.EditorActionTextComponent;
60
import org.netbeans.api.editor.EditorActionRegistration;
64
import org.netbeans.api.editor.EditorActionRegistration;
61
import org.netbeans.api.editor.EditorActionRegistrations;
65
import org.netbeans.api.editor.EditorActionRegistrations;
62
import org.openide.filesystems.annotations.LayerBuilder;
66
import org.openide.filesystems.annotations.LayerBuilder;
Lines 75-81 Link Here
75
    public @Override Set<String> getSupportedAnnotationTypes() {
79
    public @Override Set<String> getSupportedAnnotationTypes() {
76
        return new HashSet<String>(Arrays.asList(
80
        return new HashSet<String>(Arrays.asList(
77
            EditorActionRegistration.class.getCanonicalName(),
81
            EditorActionRegistration.class.getCanonicalName(),
78
            EditorActionRegistrations.class.getCanonicalName()
82
            EditorActionRegistrations.class.getCanonicalName(),
83
            EditorActionButtonModel.class.getCanonicalName(),
84
            EditorActionTextComponent.class.getCanonicalName()
79
        ));
85
        ));
80
    }
86
    }
81
87
Lines 86-105 Link Here
86
        if (roundEnv.processingOver()) {
92
        if (roundEnv.processingOver()) {
87
            return false;
93
            return false;
88
        }
94
        }
95
        Map<String,String> namedModels = new HashMap<String, String>();
96
        Map<String,String> modelTextComponents = new HashMap<String, String>();
97
        for (Element e : roundEnv.getElementsAnnotatedWith(EditorActionButtonModel.class)) {
98
            EditorActionButtonModel annotation = e.getAnnotation(EditorActionButtonModel.class);
99
            String className = processingEnv.getElementUtils().getBinaryName((TypeElement)e).toString();
100
            namedModels.put(annotation.name(), className);
101
        }
102
        for (Element e : roundEnv.getElementsAnnotatedWith(EditorActionTextComponent.class)) {
103
            String modelClass = processingEnv.getElementUtils().getBinaryName((TypeElement)e.getEnclosingElement()).toString();
104
            modelTextComponents.put(modelClass,e.getSimpleName().toString());
105
        }
106
89
        for (Element e : roundEnv.getElementsAnnotatedWith(EditorActionRegistration.class)) {
107
        for (Element e : roundEnv.getElementsAnnotatedWith(EditorActionRegistration.class)) {
90
            EditorActionRegistration annotation = e.getAnnotation(EditorActionRegistration.class);
108
            EditorActionRegistration annotation = e.getAnnotation(EditorActionRegistration.class);
91
            register(e, annotation);
109
            register(e, annotation, namedModels, modelTextComponents);
92
        }
110
        }
93
        for (Element e : roundEnv.getElementsAnnotatedWith(EditorActionRegistrations.class)) {
111
        for (Element e : roundEnv.getElementsAnnotatedWith(EditorActionRegistrations.class)) {
94
            EditorActionRegistrations annotationArray = e.getAnnotation(EditorActionRegistrations.class);
112
            EditorActionRegistrations annotationArray = e.getAnnotation(EditorActionRegistrations.class);
95
            for (EditorActionRegistration annotation : annotationArray.value()) {
113
            for (EditorActionRegistration annotation : annotationArray.value()) {
96
                register(e, annotation);
114
                register(e, annotation, namedModels, modelTextComponents);
97
            }
115
            }
98
        }
116
        }
99
        return true;
117
        return true;
100
    }
118
    }
101
119
102
    private void register(Element e, EditorActionRegistration annotation) throws LayerGenerationException {
120
    private void register(Element e, EditorActionRegistration annotation, Map<String,String> namedModels, Map<String,String> modelTextComponents) throws LayerGenerationException {
103
        String className;
121
        String className;
104
        String methodName;
122
        String methodName;
105
        TypeMirror swingActionType = processingEnv.getTypeUtils().getDeclaredType(
123
        TypeMirror swingActionType = processingEnv.getTypeUtils().getDeclaredType(
Lines 311-316 Link Here
311
        // some tools may query FO's properties and expect it there.
329
        // some tools may query FO's properties and expect it there.
312
        file.stringvalue(Action.NAME, actionName);
330
        file.stringvalue(Action.NAME, actionName);
313
331
332
        if (namedModels.containsKey(actionName)) {
333
            String modelClass = namedModels.get(actionName);
334
            file.newvalue("buttonModel", modelClass);
335
336
            String textComponentMethod = modelTextComponents.get(modelClass);
337
            if (textComponentMethod!=null) {
338
                file.stringvalue("textComponentMethod", textComponentMethod);
339
            }
340
        }
341
314
        if (directActionCreation) {
342
        if (directActionCreation) {
315
            if (methodName != null) {
343
            if (methodName != null) {
316
                file.methodvalue("instanceCreate", className, methodName);
344
                file.methodvalue("instanceCreate", className, methodName);
Lines 340-344 Link Here
340
        presenterActionFile.write();
368
        presenterActionFile.write();
341
        return presenterActionName;
369
        return presenterActionName;
342
    }
370
    }
343
344
}
371
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/search/EditorFindSupport.java (-3 / +3 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 170-176 Link Here
170
        
170
        
171
        props.put(FIND_WHAT, null);
171
        props.put(FIND_WHAT, null);
172
        props.put(FIND_REPLACE_WITH, null);
172
        props.put(FIND_REPLACE_WITH, null);
173
        props.put(FIND_HIGHLIGHT_SEARCH, Boolean.TRUE);
173
        props.put(FIND_HIGHLIGHT_SEARCH, Boolean.FALSE);
174
        props.put(FIND_INC_SEARCH, Boolean.TRUE);
174
        props.put(FIND_INC_SEARCH, Boolean.TRUE);
175
        props.put(FIND_BACKWARD_SEARCH, Boolean.FALSE);
175
        props.put(FIND_BACKWARD_SEARCH, Boolean.FALSE);
176
        props.put(FIND_WRAP_SEARCH, Boolean.TRUE);
176
        props.put(FIND_WRAP_SEARCH, Boolean.TRUE);
Lines 1024-1030 Link Here
1024
        }
1024
        }
1025
        
1025
        
1026
        public @Override String toString(){
1026
        public @Override String toString(){
1027
            StringBuffer sb = new StringBuffer("[SearchPatternWrapper:]\nsearchExpression:"+searchExpression);//NOI18N
1027
            StringBuilder sb = new StringBuilder("[SearchPatternWrapper:]\nsearchExpression:"+searchExpression);//NOI18N
1028
            sb.append('\n');
1028
            sb.append('\n');
1029
            sb.append("wholeWords:");//NOI18N
1029
            sb.append("wholeWords:");//NOI18N
1030
            sb.append(wholeWords);
1030
            sb.append(wholeWords);
(-)a/editor/src/org/netbeans/modules/editor/NbEditorToolBar.java (-10 / +104 lines)
Lines 53-58 Link Here
53
import java.beans.PropertyChangeListener;
53
import java.beans.PropertyChangeListener;
54
import java.lang.ref.Reference;
54
import java.lang.ref.Reference;
55
import java.lang.ref.WeakReference;
55
import java.lang.ref.WeakReference;
56
import java.lang.reflect.InvocationTargetException;
57
import java.lang.reflect.Method;
56
import java.util.ArrayList;
58
import java.util.ArrayList;
57
import java.util.Collection;
59
import java.util.Collection;
58
import java.util.Collections;
60
import java.util.Collections;
Lines 65-70 Link Here
65
import javax.swing.AbstractAction;
67
import javax.swing.AbstractAction;
66
import javax.swing.AbstractButton;
68
import javax.swing.AbstractButton;
67
import javax.swing.Action;
69
import javax.swing.Action;
70
import javax.swing.ButtonModel;
68
import javax.swing.ImageIcon;
71
import javax.swing.ImageIcon;
69
import javax.swing.InputMap;
72
import javax.swing.InputMap;
70
import javax.swing.JButton;
73
import javax.swing.JButton;
Lines 74-79 Link Here
74
import javax.swing.JToolBar;
77
import javax.swing.JToolBar;
75
import javax.swing.KeyStroke;
78
import javax.swing.KeyStroke;
76
import javax.swing.UIManager;
79
import javax.swing.UIManager;
80
import javax.swing.event.ChangeEvent;
81
import javax.swing.event.ChangeListener;
77
import javax.swing.plaf.TextUI;
82
import javax.swing.plaf.TextUI;
78
import javax.swing.plaf.ToolBarUI;
83
import javax.swing.plaf.ToolBarUI;
79
import javax.swing.text.DefaultEditorKit;
84
import javax.swing.text.DefaultEditorKit;
Lines 99-104 Link Here
99
import org.openide.loaders.DataObject;
104
import org.openide.loaders.DataObject;
100
import org.openide.nodes.Node;
105
import org.openide.nodes.Node;
101
import org.openide.util.ContextAwareAction;
106
import org.openide.util.ContextAwareAction;
107
import org.openide.util.Exceptions;
102
import org.openide.util.ImageUtilities;
108
import org.openide.util.ImageUtilities;
103
import org.openide.util.Lookup;
109
import org.openide.util.Lookup;
104
import org.openide.util.LookupEvent;
110
import org.openide.util.LookupEvent;
Lines 523-539 Link Here
523
            if (item instanceof Component) {
529
            if (item instanceof Component) {
524
                add((Component)item);
530
                add((Component)item);
525
            } else if (item instanceof Action) {
531
            } else if (item instanceof Action) {
526
                // Wrap action to execute on the proper text component
532
                Action a = (Action) item;
527
                // because the default fallback in TextAction.getTextComponent()
533
                ButtonModel model = (ButtonModel) a.getValue("buttonModel"); // NOI18N
528
                // might not work properly if the focus was switched
534
                if (model!=null) { // NOI18N
529
                // to e.g. a JTextField and then toolbar was clicked.
535
                    JToggleButton button = new GenericButton(a);
530
                Action a = new WrapperAction(componentRef, (Action) item);
536
                    button.setModel(model);
531
                
537
                    updateIcon(button, a);
532
                // Try to find an icon if not present
538
                    String textComponentMethodName = (String) a.getValue("textComponentMethod"); //NOI18N
533
                updateIcon(a);
539
                    updateTextComponent(c, model, textComponentMethodName);
540
                    item = button;
541
                    add(button);
542
                } else {
543
                    // Wrap action to execute on the proper text component
544
                    // because the default fallback in TextAction.getTextComponent()
545
                    // might not work properly if the focus was switched
546
                    // to e.g. a JTextField and then toolbar was clicked.
547
                    a = new WrapperAction(componentRef, a);
534
548
535
                // Add the action and let the JToolbar to creat a presenter for it
549
                    // Try to find an icon if not present
536
                item = add(a);
550
                    updateIcon(a);
551
552
                    // Add the action and let the JToolbar to create a presenter for it
553
                    item = add(a);
554
                }
537
            } else {
555
            } else {
538
                // Some sort of crappy item -> ignore
556
                // Some sort of crappy item -> ignore
539
                continue;
557
                continue;
Lines 569-574 Link Here
569
        }
587
        }
570
    }
588
    }
571
589
590
    private static void updateIcon(JToggleButton button, Action a) {
591
        String iconImageName = (String)a.getValue("iconBase"); // NOI18N
592
        if (iconImageName!=null) {
593
            Image img = ImageUtilities.loadImage(iconImageName);
594
            if (img!=null) {
595
                button.setIcon(new ImageIcon(img));
596
            }
597
        }
598
    }
599
600
    private static void updateTextComponent(JTextComponent c, ButtonModel model, String textComponentMethodName) {
601
        if (textComponentMethodName!=null && textComponentMethodName.length()>0) {
602
            try {
603
                Method componentSettingMethod = model.getClass().getMethod(textComponentMethodName, JTextComponent.class);
604
                componentSettingMethod.invoke(model, c);
605
            } catch (IllegalAccessException ex) {
606
                Exceptions.printStackTrace(ex);
607
            } catch (IllegalArgumentException ex) {
608
                Exceptions.printStackTrace(ex);
609
            } catch (InvocationTargetException ex) {
610
                Exceptions.printStackTrace(ex);
611
            } catch (NoSuchMethodException ex) {
612
                Exceptions.printStackTrace(ex);
613
            } catch (SecurityException ex) {
614
                Exceptions.printStackTrace(ex);
615
            }
616
        }
617
    }
618
572
    private static void updateTooltip(AbstractButton b, List<? extends MultiKeyBinding> keybindings) {
619
    private static void updateTooltip(AbstractButton b, List<? extends MultiKeyBinding> keybindings) {
573
        Action a = b.getAction();
620
        Action a = b.getAction();
574
        String actionName = a == null ? null : (String) a.getValue(Action.NAME);
621
        String actionName = a == null ? null : (String) a.getValue(Action.NAME);
Lines 701-706 Link Here
701
        }
748
        }
702
        
749
        
703
        public Object getValue(String key) {
750
        public Object getValue(String key) {
751
            if (key==null||delegate==null) return null;
704
            return delegate.getValue(key);
752
            return delegate.getValue(key);
705
        }
753
        }
706
754
Lines 732-735 Link Here
732
            delegate.actionPerformed(e);
780
            delegate.actionPerformed(e);
733
        }
781
        }
734
    } // End of WrapperAction class
782
    } // End of WrapperAction class
783
784
    private static final class GenericButton extends JToggleButton implements ChangeListener {
785
786
        GenericButton(Action a) {
787
            setAction(a);
788
            setHideActionText(true);
789
        }
790
791
        @Override
792
        public void setModel(ButtonModel model) {
793
            ButtonModel oldModel = getModel();
794
            if (oldModel != null) {
795
                oldModel.removeChangeListener(this);
796
            }
797
798
            super.setModel(model);
799
800
            ButtonModel newModel = getModel();
801
            if (newModel != null) {
802
                newModel.addChangeListener(this);
803
            }
804
805
            stateChanged(null);
806
        }
807
808
        @Override
809
        public void stateChanged(ChangeEvent evt) {
810
            boolean selected = isSelected();
811
            super.setContentAreaFilled(selected);
812
            super.setBorderPainted(selected);
813
        }
814
815
        @Override
816
        public void setBorderPainted(boolean paint) {
817
            if (!isSelected()) {
818
                super.setBorderPainted(paint);
819
            }
820
        }
821
822
        @Override
823
        public void setContentAreaFilled(boolean fill) {
824
            if (!isSelected()) {
825
                super.setContentAreaFilled(fill);
826
            }
827
        }
828
    }
735
}
829
}
(-)a/editor/src/org/netbeans/modules/editor/resources/layer.xml (+13 lines)
Lines 306-311 Link Here
306
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
306
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
307
                    <attr name="position" intvalue="10000"/>
307
                    <attr name="position" intvalue="10000"/>
308
                </file>
308
                </file>
309
                <file name="bookmark-previous">
310
                    <attr name="position" intvalue="11000"/>
311
                </file>
312
                <file name="bookmark-next">
313
                    <attr name="position" intvalue="12000"/>
314
                </file>
315
                <file name="bookmark-toggle">
316
                    <attr name="position" intvalue="13000"/>
317
                </file>
318
                <file name="Separator-after-bookmark-toggle.instance">
319
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
320
                    <attr name="position" intvalue="14000"/>
321
                </file>
309
                <file name="shift-line-left">
322
                <file name="shift-line-left">
310
                    <attr name="position" intvalue="15000"/>
323
                    <attr name="position" intvalue="15000"/>
311
                </file>
324
                </file>
(-)a/editor/test/qa-functional/data/org/netbeans/test/editor/data/layer.xml (-3 lines)
Lines 307-315 Link Here
307
                <file name="find-next">
307
                <file name="find-next">
308
                    <attr name="position" intvalue="8000"/>
308
                    <attr name="position" intvalue="8000"/>
309
                </file>
309
                </file>
310
                <file name="toggle-highlight-search">
311
                    <attr name="position" intvalue="9000"/>
312
                </file>
313
                <file name="Separator-after-toggle-highlight-search.instance">
310
                <file name="Separator-after-toggle-highlight-search.instance">
314
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
311
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
315
                    <attr name="position" intvalue="10000"/>
312
                    <attr name="position" intvalue="10000"/>

Return to bug 167063