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 218995
Collapse All | Expand All

(-)a/editor.lib/apichanges.xml (+53 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="removing-find">
111
            <summary>Removing old deprecatted find implementations</summary>
112
            <version major="3" minor="30"/>
113
            <date day="5" month="10" year="2012"/>
114
            <author login="mkristofic"/>
115
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible" addition="no" deprecation="yes" deletion="yes" modification="yes"/>
116
            <description>
117
                <p>
118
                    The old find apis and implementations (<code>org.netbeans.editor.FindSupport</code> &amp; co.)
119
                    has been removed. The current implementation is in editor.lib2 and editor.search
120
                </p>
121
                <p>The exact API changes are listed in the sigtest report below.</p>
122
<pre>
123
-sigtest-init:
124
     [echo] sigtest check: editor.lib; cnb: org-netbeans-modules-editor-lib; email: api-changes@netbeans.org; type: check
125
126
check-sigtest:
127
    [mkdir] Created dir: /home/mito/nb/develop/editor.lib/build/test/sigtest/results
128
  [sigtest] /home/mito/nb/develop/editor.lib/build/test/sigtest/results/org.netbeans.modules.editor.lib
129
  [sigtest] Packages: org.netbeans.editor.*, org.netbeans.editor.ext.*, org.netbeans.editor.view.spi.*, org.netbeans.lib.editor.hyperlink.spi.*, org.netbeans.lib.editor.view.*
130
  [sigtest]
131
  [sigtest] email: api-changes@netbeans.org
132
  [sigtest] SignatureTest report
133
  [sigtest] Base version: 3.29.0
134
  [sigtest] Tested version: 3.29.0
135
  [sigtest] Check mode: bin [throws removed]
136
  [sigtest] Constant checking: on
137
  [sigtest]
138
  [sigtest]
139
  [sigtest] Class org.netbeans.editor.FindSupport
140
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.FindSupport
141
  [sigtest]
142
  [sigtest] Class org.netbeans.editor.FindSupport$SearchPatternWrapper
143
  [sigtest]   "E1.2 - API type removed" : CLASS public static org.netbeans.editor.FindSupport$SearchPatternWrapper
144
  [sigtest]
145
  [sigtest] Class org.netbeans.editor.ext.ExtKit$FindAction
146
  [sigtest]   "E1.2 - API type removed" : CLASS public static org.netbeans.editor.ext.ExtKit$FindAction
147
  [sigtest]
148
  [sigtest] Class org.netbeans.editor.ext.ExtKit$ReplaceAction
149
  [sigtest]   "E1.2 - API type removed" : CLASS public static org.netbeans.editor.ext.ExtKit$ReplaceAction
150
  [sigtest]
151
  [sigtest] Class org.netbeans.editor.ext.FindDialogPanel
152
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.FindDialogPanel
153
  [sigtest]
154
  [sigtest] Class org.netbeans.editor.ext.FindDialogSupport
155
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.FindDialogSupport
156
  [sigtest]
157
  [sigtest] /home/mito/nb/develop/editor.lib/build/test/sigtest/results/org-netbeans-modules-editor-lib.xml: 1 failures in /home/mito/nb/develop/editor.lib/nbproject/org-netbeans-modules-editor-lib.sig
158
159
</pre>
160
            </description>
161
            <issue number="189638"/>
162
        </change>
110
        <change id="programmatic.tooltips.visible">
163
        <change id="programmatic.tooltips.visible">
111
            <summary>Support to show tooltips not tied to the view hierarchy</summary>
164
            <summary>Support to show tooltips not tied to the view hierarchy</summary>
112
            <version major="3" minor="28"/>
165
            <version major="3" minor="28"/>
(-)a/editor.lib/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint:unchecked
43
javac.compilerargs=-Xlint:unchecked
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=3.29.0
45
spec.version.base=3.30.0
46
is.autoload=true
46
is.autoload=true
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
(-)a/editor.lib/src/org/netbeans/editor/BaseDocument.java (-21 lines)
Lines 272-280 Link Here
272
    /* Was the document modified by doing inert/remove */
272
    /* Was the document modified by doing inert/remove */
273
    protected boolean modified;
273
    protected boolean modified;
274
274
275
    /** Listener to changes in find support */
276
    PropertyChangeListener findSupportListener;
277
278
    /** Default element - lazily inited */
275
    /** Default element - lazily inited */
279
    protected Element defaultRootElem;
276
    protected Element defaultRootElem;
280
277
Lines 559-575 Link Here
559
            ((BaseKit) kit).initDocument(this);
556
            ((BaseKit) kit).initDocument(this);
560
        }
557
        }
561
558
562
        // Start listen on find-support
563
        findSupportListener = new PropertyChangeListener() {
564
                                  public @Override void propertyChange(PropertyChangeEvent evt) {
565
                                      findSupportChange(evt);
566
                                  }
567
                              };
568
        findSupportChange(null); // update doc by find settings
569
570
        FindSupport.getFindSupport().addPropertyChangeListener(findSupportListener);
571
        findSupportChange(null); // update doc by find settings
572
573
        ModRootElement modElementRoot = new ModRootElement(this);
559
        ModRootElement modElementRoot = new ModRootElement(this);
574
        this.addUpdateDocumentListener(modElementRoot);
560
        this.addUpdateDocumentListener(modElementRoot);
575
        modElementRoot.setEnabled(true);
561
        modElementRoot.setEnabled(true);
Lines 603-615 Link Here
603
        };
589
        };
604
    }
590
    }
605
591
606
    private void findSupportChange(PropertyChangeEvent evt) {
607
        // set all finders to null
608
        putProperty(STRING_FINDER_PROP, null);
609
        putProperty(STRING_BWD_FINDER_PROP, null);
610
        putProperty(BLOCKS_FINDER_PROP, null);
611
    }
612
613
    Syntax getFreeSyntax() {
592
    Syntax getFreeSyntax() {
614
        EditorKit kit = getEditorKit();
593
        EditorKit kit = getEditorKit();
615
        if (kit instanceof BaseKit) {
594
        if (kit instanceof BaseKit) {
(-)a/editor.lib/src/org/netbeans/editor/Bundle.properties (-44 lines)
Lines 249-298 Link Here
249
ACSD_LBL_KSIP_Sequence=
249
ACSD_LBL_KSIP_Sequence=
250
ACSD_KSIP=
250
ACSD_KSIP=
251
251
252
#FindDialogPanel
253
find-what=Find What:
254
find-what-mnemonic=F
255
ACSD_find-what=
256
find-replace-with=Replace With:
257
find-replace-with-mnemonic=l
258
ACSD_find-replace-with=
259
find-highlight-search=\ Highligh&t Results
260
find-highlight-search-tooltip=Highlights all occurrences of the searched text.
261
find-inc-search=\ &Incremental Search
262
find-inc-search-tooltip=Tries to find text as you type.
263
find-match-case=\ &Match Case
264
find-match-case-tooltip=Search the document only for text with the same capitalization.
265
find-smart-case=\ Smart Case
266
find-smart-case-mnemonic=S
267
find-smart-case-tooltip=Matches case if at least one character in the searched text is uppercase.
268
find-preserve-case=\ Preser&ve Case when Replacing
269
find-preserve-case-tooltip=Preserve case according to found instance of word.
270
find-whole-words=\ &Whole Words
271
find-whole-words-tooltip=Matches the searched text only to whole words in the document.
272
find-backward-search=\ Search &Backwards
273
find-backward-search-tooltip=Searches backwards from the current cursor position.
274
find-wrap-search=\ Wra&p Around
275
find-wrap-search-tooltip=Continues search from the beginning if end of the document is reached.
276
find-reg-exp=\ Regular &Expressions
277
find-reg-exp-tooltip=Uses regular expressions to search the document.
278
find-block-search=\ Sear&ch Selection
279
find-block-search-tooltip=Searches for occurrences in a selected block of text only.
280
ACSD_find=
281
282
#FindDialogSupport
283
find-title=Find
284
replace-title=Replace
285
find-button-find=Find
286
find-button-find-mnemonic=D
287
find-button-replace=Replace
288
find-button-replace-mnemonic=R
289
find-button-replace-all=Replace All
290
find-button-replace-all-mnemonic=A
291
find-button-cancel=Close
292
ACSD_find-button-find=
293
ACSD_find-button-replace=
294
ACSD_find-button-replace-all=
295
ACSD_find-button-cancel=
296
252
297
# GotoDialogPanel
253
# GotoDialogPanel
298
goto-line=Go To &Line or Bookmark:
254
goto-line=Go To &Line or Bookmark:
(-)a/editor.lib/src/org/netbeans/editor/FindSupport.java (-330 lines)
Lines 1-330 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.editor;
46
47
import java.beans.PropertyChangeEvent;
48
import java.beans.PropertyChangeListener;
49
import java.lang.ref.WeakReference;
50
import java.util.List;
51
import java.util.Map;
52
import javax.swing.text.JTextComponent;
53
import javax.swing.text.BadLocationException;
54
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
55
56
/**
57
* Find management
58
*
59
* @author Miloslav Metelka
60
* @version 1.00
61
* @deprecated use org.netbeans.modules.editor.lib2.search.EditorFindSupport;
62
*/
63
public class FindSupport {
64
65
    public static final String REVERT_MAP = EditorFindSupport.REVERT_MAP;
66
    public static final String FIND_HISTORY_PROP = EditorFindSupport.FIND_HISTORY_PROP;
67
    public static final String FIND_HISTORY_CHANGED_PROP = EditorFindSupport.FIND_HISTORY_CHANGED_PROP;
68
    
69
    /** Shared instance of FindSupport class */
70
    static FindSupport findSupport;
71
72
    /** Support for firing change events */
73
    WeakPropertyChangeSupport changeSupport = new WeakPropertyChangeSupport();
74
    
75
    SearchPatternWrapper lastSelected;
76
    List historyList;/*<SearchPatternWrapper>*/
77
78
    private FindSupport() {
79
        // prevent instance creation
80
    }
81
82
    /** Get shared instance of find support */
83
    public static FindSupport getFindSupport() {
84
        if (findSupport == null) {
85
            findSupport = new FindSupport();
86
        }
87
        return findSupport;
88
    }
89
90
    public Map getDefaultFindProperties() {
91
        return EditorFindSupport.getInstance().createDefaultFindProperties();
92
    }
93
94
    public Map getFindProperties() {
95
        return EditorFindSupport.getInstance().getFindProperties();
96
    }
97
98
    /** Get find property with specified name */
99
    public Object getFindProperty(String name) {
100
        return EditorFindSupport.getInstance().getFindProperty(name);
101
    }
102
103
    int[] getBlocks(int[] blocks, BaseDocument doc,
104
                    int startPos, int endPos) throws BadLocationException {
105
        return EditorFindSupport.getInstance().getBlocks(blocks, doc, startPos, endPos);
106
    }
107
108
    /** Set find property with specified name and fire change.
109
    */
110
    public void putFindProperty(String name, Object newValue) {
111
        EditorFindSupport.getInstance().putFindProperty(name, newValue);
112
    }
113
114
    /** Add/replace properties from some other map
115
    * to current find properties. If the added properties
116
    * are different than the original ones,
117
    * the property change is fired.
118
    */
119
    public void putFindProperties(Map propsToAdd) {
120
        EditorFindSupport.getInstance().putFindProperties(propsToAdd);
121
    }
122
    
123
    public void setBlockSearchHighlight(int startSelection, int endSelection){
124
        EditorFindSupport.getInstance().setBlockSearchHighlight(startSelection, endSelection);
125
    }
126
    
127
    public boolean incSearch(Map props, int caretPos) {
128
        return EditorFindSupport.getInstance().incSearch(props, caretPos);
129
    }
130
131
    public void incSearchReset() {
132
        EditorFindSupport.getInstance().incSearchReset();
133
    }
134
    
135
    /** Find the text from the caret position.
136
    * @param props search properties
137
    * @param oppositeDir whether search in opposite direction
138
    */
139
    public boolean find(Map props, boolean oppositeDir) {
140
        return EditorFindSupport.getInstance().find(props, oppositeDir);
141
    }
142
143
    /** Find the searched expression
144
    * @param startPos position from which to search. It must be inside the block.
145
    * @param blockStartPos starting position of the block. It must
146
    *   be valid position greater or equal than zero. It must be lower than
147
    *   or equal to blockEndPos (except blockEndPos=-1).
148
    * @param blockEndPos ending position of the block. It can be -1 for the end
149
    *   of document. It must be greater or equal than blockStartPos (except blockEndPos=-1).
150
    * @param props search properties
151
    * @param oppositeDir whether search in opposite direction
152
    * @param displayWrap whether display messages about the wrapping
153
    * @return either null when nothing was found or integer array with three members
154
    *    ret[0] - starting position of the found string
155
    *    ret[1] - ending position of the found string
156
    *    ret[2] - 1 or 0 when wrap was or wasn't performed in order to find the string 
157
    */
158
    public int[] findInBlock(JTextComponent c, int startPos, int blockStartPos,
159
        int blockEndPos, Map props, boolean oppositeDir) throws BadLocationException
160
    {
161
        return EditorFindSupport.getInstance().findInBlock(
162
            c, startPos, blockStartPos, blockEndPos, props, oppositeDir);
163
    }
164
165
    public boolean replace(Map props, boolean oppositeDir) throws BadLocationException {
166
        return EditorFindSupport.getInstance().replace(props, oppositeDir);
167
    }
168
169
    public void replaceAll(Map props) {
170
        EditorFindSupport.getInstance().replaceAll(props);
171
    }
172
173
// TODO: remove
174
//    /** Get position of wrap mark for some document */
175
//    public int getWrapSearchMarkPos(BaseDocument doc) {
176
//        return EditorFindSupport.getInstance().getWrapSearchMarkPos(doc);
177
//    }
178
//
179
//    /** Set new position of wrap mark for some document */
180
//    public void setWrapSearchMarkPos(BaseDocument doc, int pos) {
181
//        EditorFindSupport.getInstance().setWrapSearchMarkPos(doc, pos);
182
//    }
183
184
    /** Add weak listener to listen to change of any property. The caller must
185
    * hold the listener object in some instance variable to prevent it
186
    * from being garbage collected.
187
    */
188
    public void addPropertyChangeListener(PropertyChangeListener l) {
189
        EditorFindSupport.getInstance().addPropertyChangeListener(new WeakPropL(l));
190
    }
191
192
    public synchronized void addPropertyChangeListener(
193
        String findPropertyName, PropertyChangeListener l)
194
    {
195
        EditorFindSupport.getInstance().addPropertyChangeListener(
196
            findPropertyName, new WeakPropL(l));
197
    }
198
199
    /** Remove listener for changes in properties */
200
    public void removePropertyChangeListener(PropertyChangeListener l) {
201
        // no-op
202
    }
203
204
    void firePropertyChange(String settingName, Object oldValue, Object newValue) {
205
        EditorFindSupport.getInstance().firePropertyChange(settingName, oldValue, newValue);
206
    }
207
208
    public void setHistory(List/*<SearchPatternWrapper>*/ spwList){
209
        EditorFindSupport.getInstance().setHistory(spwList);
210
    }
211
    
212
    public List/*<SearchPatternWrapper>*/ getHistory(){
213
        return EditorFindSupport.getInstance().getHistory();
214
    }
215
    
216
    public void setLastSelected(SearchPatternWrapper spw) {
217
        EditorFindSupport.SPW editorSpw = new EditorFindSupport.SPW(
218
            spw.getSearchExpression(), spw.isWholeWords(), spw.isMatchCase(), spw.isRegExp()
219
        );
220
        EditorFindSupport.getInstance().setLastSelected(editorSpw);
221
    }
222
    
223
    public SearchPatternWrapper getLastSelected(){
224
        EditorFindSupport.SPW spw =  EditorFindSupport.getInstance().getLastSelected();
225
        return new SearchPatternWrapper(spw.getSearchExpression(), spw.isWholeWords(), spw.isMatchCase(), spw.isRegExp());
226
    }
227
    
228
    public void addToHistory(SearchPatternWrapper spw){
229
        EditorFindSupport.SPW editorSpw = new EditorFindSupport.SPW(
230
            spw.getSearchExpression(), spw.isWholeWords(), spw.isMatchCase(), spw.isRegExp()
231
        );
232
        EditorFindSupport.getInstance().addToHistory(editorSpw);
233
    }
234
    
235
    public static class SearchPatternWrapper{
236
        private String searchExpression;
237
        private boolean wholeWords;
238
        private boolean matchCase;
239
        private boolean regExp;
240
        
241
        public SearchPatternWrapper(String searchExpression, boolean wholeWords,
242
            boolean matchCase, boolean regExp){
243
            this.searchExpression = searchExpression;
244
            this.wholeWords = wholeWords;
245
            this.matchCase = matchCase;
246
            this.regExp = regExp;
247
        }
248
        
249
        /** @return searchExpression */
250
        public String getSearchExpression(){
251
            return searchExpression;
252
        }
253
254
        /** @return true if the wholeWords parameter was used during search performing */
255
        public boolean isWholeWords(){
256
            return wholeWords;
257
        }
258
259
        /** @return true if the matchCase parameter was used during search performing */
260
        public boolean isMatchCase(){
261
            return matchCase;
262
        }
263
264
        /** @return true if the regExp parameter was used during search performing */
265
        public boolean isRegExp(){
266
            return regExp;
267
        }
268
        
269
        public boolean equals(Object obj){
270
            if (!(obj instanceof SearchPatternWrapper)){
271
                return false;
272
            }
273
            SearchPatternWrapper sp = (SearchPatternWrapper)obj;
274
            return (this.searchExpression.equals(sp.getSearchExpression()) &&
275
                    this.wholeWords == sp.isWholeWords() &&
276
                    this.matchCase == sp.isMatchCase() &&
277
                    this.regExp == sp.isRegExp());
278
        }
279
280
        public int hashCode() {
281
            int result = 17;
282
            result = 37*result + (this.wholeWords ? 1:0);
283
            result = 37*result + (this.matchCase ? 1:0);
284
            result = 37*result + (this.regExp ? 1:0);
285
            result = 37*result + this.searchExpression.hashCode();
286
            return result;
287
        }
288
        
289
        public String toString(){
290
            StringBuffer sb = new StringBuffer("[SearchPatternWrapper:]\nsearchExpression:"+searchExpression);//NOI18N
291
            sb.append('\n');
292
            sb.append("wholeWords:");//NOI18N
293
            sb.append(wholeWords);
294
            sb.append('\n');
295
            sb.append("matchCase:");//NOI18N
296
            sb.append(matchCase);
297
            sb.append('\n');
298
            sb.append("regExp:");//NOI18N
299
            sb.append(regExp);
300
            return  sb.toString();
301
        }
302
    } // End of SearchPatternWrapper class
303
    
304
    private static final class WeakPropL extends WeakReference implements PropertyChangeListener {
305
        
306
        public WeakPropL(PropertyChangeListener origL) {
307
            super(origL);
308
        }
309
        
310
        public void propertyChange(PropertyChangeEvent evt) {
311
            PropertyChangeListener origL = (PropertyChangeListener) get();
312
            if (origL != null) {
313
                origL.propertyChange(new PropertyChangeEvent(this, evt.getPropertyName(), 
314
                    convert(evt.getOldValue()), convert(evt.getNewValue())));
315
            } else {
316
                EditorFindSupport.getInstance().removePropertyChangeListener(this);
317
            }
318
        }
319
        
320
        private Object convert(Object o) {
321
            if (o instanceof EditorFindSupport.SPW) {
322
                EditorFindSupport.SPW spw = (EditorFindSupport.SPW) o;
323
                return new SearchPatternWrapper(
324
                    spw.getSearchExpression(), spw.isWholeWords(), spw.isMatchCase(), spw.isRegExp());
325
            } else {
326
                return o;
327
            }
328
        }
329
    } // End of WeakPropL class
330
}
(-)a/editor.lib/src/org/netbeans/editor/ext/ExtKit.java (-59 lines)
Lines 167-178 Link Here
167
   
167
   
168
    /** Trimmed text for go to submenu*/
168
    /** Trimmed text for go to submenu*/
169
    public static final String TRIMMED_TEXT = "trimmed-text";    //NOI18N
169
    public static final String TRIMMED_TEXT = "trimmed-text";    //NOI18N
170
    
171
    /** Shared suport for find and replace dialogs */
172
    private static FindDialogSupport findDialogSupport;
173
    
174
    private static FindAction findActionDef = new FindAction();
175
    private static ReplaceAction replaceActionDef = new ReplaceAction();
176
170
177
    private static final String editorBundleHash = "org.netbeans.editor.Bundle#";
171
    private static final String editorBundleHash = "org.netbeans.editor.Bundle#";
178
172
Lines 478-536 Link Here
478
472
479
    }
473
    }
480
474
481
    /**
482
     * @deprecated Without any replacement.
483
     */
484
    public static class FindAction extends BaseKitLocalizedAction {
485
    // Not registered by annotation since it's not actively used
486
487
        static final long serialVersionUID =719554648887497427L;
488
489
        public FindAction() {
490
            super(findAction, ABBREV_RESET
491
                  | MAGIC_POSITION_RESET | UNDO_MERGE_RESET | NO_RECORDING);
492
            putValue(BaseAction.ICON_RESOURCE_PROPERTY,
493
                    "org/netbeans/modules/editor/resources/find"); //NOI18N
494
        }
495
496
        public FindDialogSupport getSupport() {
497
            return FindDialogSupport.getFindDialogSupport();
498
        }
499
500
        public void actionPerformed(ActionEvent evt, JTextComponent target) {
501
            if (target != null) {
502
                getSupport().showFindDialog(new KeyEventBlocker(target, false));
503
            }
504
        }
505
506
    }
507
508
    /**
509
     * @deprecated Without any replacement.
510
     */
511
    public static class ReplaceAction extends BaseKitLocalizedAction {
512
513
        static final long serialVersionUID =1828017436079834384L;
514
515
        public ReplaceAction() {
516
            super(replaceAction, ABBREV_RESET
517
                  | MAGIC_POSITION_RESET | UNDO_MERGE_RESET | NO_RECORDING);
518
        }
519
520
        public FindDialogSupport getSupport() {
521
            return FindDialogSupport.getFindDialogSupport();
522
        }
523
524
        public void actionPerformed(ActionEvent evt, JTextComponent target) {
525
            if (target != null) {
526
                // make KeyEventBlocker to discard the first key typed event (Ctrl-H)
527
                // because it is mapped to backspace in the replace dialog
528
                getSupport().showReplaceDialog(new KeyEventBlocker(target, true));
529
            }
530
        }
531
532
    }
533
534
    @EditorActionRegistration(
475
    @EditorActionRegistration(
535
            name = gotoAction,
476
            name = gotoAction,
536
            shortDescription = editorBundleHash + "goto_trimmed"
477
            shortDescription = editorBundleHash + "goto_trimmed"
(-)a/editor.lib/src/org/netbeans/editor/ext/FindDialogPanel.form (-197 lines)
Lines 1-197 Link Here
1
<?xml version="1.1" encoding="UTF-8" ?>
2
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
10
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
11
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="1"/>
13
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
14
  </AuxValues>
15
16
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
17
  <SubComponents>
18
    <Container class="javax.swing.JPanel" name="findWhatPanel">
19
      <AuxValues>
20
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
21
      </AuxValues>
22
      <Constraints>
23
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
24
          <GridBagConstraints gridX="0" gridY="0" gridWidth="3" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="11" weightX="1.0" weightY="0.0"/>
25
        </Constraint>
26
      </Constraints>
27
28
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
29
    </Container>
30
    <Component class="javax.swing.JLabel" name="findWhatLabel">
31
      <Properties>
32
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
33
          <Connection code="findWhat" type="code"/>
34
        </Property>
35
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
36
          <Connection code="bundle.getString(EditorFindSupport.FIND_WHAT ) " type="code"/>
37
        </Property>
38
      </Properties>
39
      <AuxValues>
40
        <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="findWhatLabel.setDisplayedMnemonic(bundle.getString(EditorFindSupport.FIND_WHAT + &quot;-mnemonic&quot;).charAt(0));"/>
41
        <AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="FindDialogPanel_findWhatLabel"/>
42
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
43
      </AuxValues>
44
      <Constraints>
45
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
46
          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="12" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
47
        </Constraint>
48
      </Constraints>
49
    </Component>
50
    <Component class="javax.swing.JComboBox" name="findWhat">
51
      <Properties>
52
        <Property name="editable" type="boolean" value="true"/>
53
      </Properties>
54
      <AuxValues>
55
        <AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="FindDialogPanel_findWhat"/>
56
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
57
      </AuxValues>
58
      <Constraints>
59
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
60
          <GridBagConstraints gridX="1" gridY="1" gridWidth="0" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="11" insetsBottom="9" insetsRight="10" anchor="10" weightX="1.0" weightY="0.0"/>
61
        </Constraint>
62
      </Constraints>
63
    </Component>
64
    <Component class="javax.swing.JLabel" name="replaceWithLabel">
65
      <Properties>
66
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
67
          <Connection code="replaceWith" type="code"/>
68
        </Property>
69
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
70
          <Connection code="bundle.getString(EditorFindSupport.FIND_REPLACE_WITH ) " type="code"/>
71
        </Property>
72
      </Properties>
73
      <AuxValues>
74
        <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="replaceWithLabel.setDisplayedMnemonic(bundle.getString(EditorFindSupport.FIND_REPLACE_WITH + &quot;-mnemonic&quot;).charAt(0));"/>
75
        <AuxValue name="JavaCodeGenerator_InitCodePre" type="java.lang.String" value=""/>
76
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
77
      </AuxValues>
78
      <Constraints>
79
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
80
          <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="12" insetsBottom="9" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
81
        </Constraint>
82
      </Constraints>
83
    </Component>
84
    <Component class="javax.swing.JComboBox" name="replaceWith">
85
      <Properties>
86
        <Property name="editable" type="boolean" value="true"/>
87
      </Properties>
88
      <AuxValues>
89
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
90
      </AuxValues>
91
      <Constraints>
92
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
93
          <GridBagConstraints gridX="1" gridY="2" gridWidth="0" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="11" insetsBottom="9" insetsRight="10" anchor="10" weightX="1.0" weightY="0.0"/>
94
        </Constraint>
95
      </Constraints>
96
    </Component>
97
    <Component class="javax.swing.JCheckBox" name="highlightSearch">
98
      <AuxValues>
99
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_HIGHLIGHT_SEARCH, &apos;H&apos; );"/>
100
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
101
      </AuxValues>
102
      <Constraints>
103
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
104
          <GridBagConstraints gridX="1" gridY="7" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="11" insetsLeft="11" insetsBottom="11" insetsRight="0" anchor="18" weightX="0.0" weightY="1.0"/>
105
        </Constraint>
106
      </Constraints>
107
    </Component>
108
    <Component class="javax.swing.JCheckBox" name="incSearch">
109
      <AuxValues>
110
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_INC_SEARCH, &apos;I&apos; );"/>
111
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
112
      </AuxValues>
113
      <Constraints>
114
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
115
          <GridBagConstraints gridX="2" gridY="7" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="11" insetsLeft="11" insetsBottom="11" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
116
        </Constraint>
117
      </Constraints>
118
    </Component>
119
    <Component class="javax.swing.JCheckBox" name="matchCase">
120
      <AuxValues>
121
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_MATCH_CASE, &apos;C&apos; );"/>
122
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
123
      </AuxValues>
124
      <Constraints>
125
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
126
          <GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="3" insetsLeft="11" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
127
        </Constraint>
128
      </Constraints>
129
    </Component>
130
    <Component class="javax.swing.JCheckBox" name="wholeWords">
131
      <AuxValues>
132
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_WHOLE_WORDS, &apos;W&apos; );"/>
133
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
134
      </AuxValues>
135
      <Constraints>
136
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
137
          <GridBagConstraints gridX="1" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="11" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
138
        </Constraint>
139
      </Constraints>
140
    </Component>
141
    <Component class="javax.swing.JCheckBox" name="bwdSearch">
142
      <AuxValues>
143
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_BACKWARD_SEARCH, &apos;B&apos; );"/>
144
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
145
      </AuxValues>
146
      <Constraints>
147
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
148
          <GridBagConstraints gridX="2" gridY="5" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="11" insetsBottom="0" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
149
        </Constraint>
150
      </Constraints>
151
    </Component>
152
    <Component class="javax.swing.JCheckBox" name="wrapSearch">
153
      <AuxValues>
154
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_WRAP_SEARCH, &apos;p&apos; );"/>
155
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
156
      </AuxValues>
157
      <Constraints>
158
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
159
          <GridBagConstraints gridX="2" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="3" insetsLeft="11" insetsBottom="0" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
160
        </Constraint>
161
      </Constraints>
162
    </Component>
163
    <Component class="javax.swing.JCheckBox" name="regExp">
164
      <AuxValues>
165
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_REG_EXP, &apos;E&apos; );"/>
166
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
167
      </AuxValues>
168
      <Constraints>
169
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
170
          <GridBagConstraints gridX="1" gridY="5" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="11" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
171
        </Constraint>
172
      </Constraints>
173
    </Component>
174
    <Component class="javax.swing.JCheckBox" name="blockSearch">
175
      <AuxValues>
176
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_BLOCK_SEARCH, &apos;l&apos; );"/>
177
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
178
      </AuxValues>
179
      <Constraints>
180
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
181
          <GridBagConstraints gridX="2" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="11" insetsBottom="0" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
182
        </Constraint>
183
      </Constraints>
184
    </Component>
185
    <Component class="javax.swing.JCheckBox" name="preserveCase">
186
      <AuxValues>
187
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="createCheckBox( EditorFindSupport.FIND_PRESERVE_CASE, &apos;v&apos; )"/>
188
        <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="4"/>
189
      </AuxValues>
190
      <Constraints>
191
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
192
          <GridBagConstraints gridX="1" gridY="6" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="11" insetsLeft="11" insetsBottom="11" insetsRight="0" anchor="18" weightX="0.0" weightY="1.0"/>
193
        </Constraint>
194
      </Constraints>
195
    </Component>
196
  </SubComponents>
197
</Form>
(-)a/editor.lib/src/org/netbeans/editor/ext/FindDialogPanel.java (-245 lines)
Lines 1-245 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.editor.ext;
46
47
import java.awt.Dimension;
48
import java.util.ResourceBundle;
49
import javax.swing.JCheckBox;
50
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
51
import org.openide.awt.Mnemonics;
52
import org.openide.util.NbBundle;
53
54
/**
55
 *
56
 * @author Miloslav Metelka, Petr Nejedly
57
 * @version 1.0
58
 * @deprecated Without any replacement.
59
 */
60
public class FindDialogPanel extends javax.swing.JPanel {
61
62
    static final long serialVersionUID =5048601763767383114L;
63
64
    private final ResourceBundle bundle = NbBundle.getBundle(org.netbeans.editor.BaseKit.class);
65
66
    /** Initializes the Form */
67
    public FindDialogPanel() {
68
        initComponents ();
69
        getAccessibleContext().setAccessibleName(bundle.getString("find-title")); // NOI18N
70
        getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find")); // NOI18N
71
        findWhat.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_" + EditorFindSupport.FIND_WHAT)); // NOI18N
72
        replaceWith.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_" + EditorFindSupport.FIND_REPLACE_WITH)); // NOI18N
73
        
74
        // #71956
75
        Dimension findPrefSize = findWhat.getPreferredSize();
76
        Dimension replacePrefSize = replaceWith.getPreferredSize();
77
        if (findPrefSize != null){
78
            findWhat.setPreferredSize(new Dimension((int)findPrefSize.getWidth(), (int)findPrefSize.getHeight()));
79
        }
80
        if (replacePrefSize != null){
81
            replaceWith.setPreferredSize(new Dimension((int)replacePrefSize.getWidth(), (int)replacePrefSize.getHeight()));
82
        }
83
    }
84
85
    /** This method is called from within the constructor to
86
     * initialize the form.
87
     * WARNING: Do NOT modify this code. The content of this method is
88
     * always regenerated by the FormEditor.
89
     */
90
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
91
    private void initComponents() {
92
        java.awt.GridBagConstraints gridBagConstraints;
93
94
        findWhatPanel = new javax.swing.JPanel();
95
        findWhatLabel = new javax.swing.JLabel();
96
        findWhat = new javax.swing.JComboBox();
97
        replaceWithLabel = new javax.swing.JLabel();
98
        replaceWith = new javax.swing.JComboBox();
99
        highlightSearch = createCheckBox( EditorFindSupport.FIND_HIGHLIGHT_SEARCH, 'H' );
100
        incSearch = createCheckBox( EditorFindSupport.FIND_INC_SEARCH, 'I' );
101
        matchCase = createCheckBox( EditorFindSupport.FIND_MATCH_CASE, 'C' );
102
        wholeWords = createCheckBox( EditorFindSupport.FIND_WHOLE_WORDS, 'W' );
103
        bwdSearch = createCheckBox( EditorFindSupport.FIND_BACKWARD_SEARCH, 'B' );
104
        wrapSearch = createCheckBox( EditorFindSupport.FIND_WRAP_SEARCH, 'p' );
105
        regExp = createCheckBox( EditorFindSupport.FIND_REG_EXP, 'E' );
106
        blockSearch = createCheckBox( EditorFindSupport.FIND_BLOCK_SEARCH, 'l' );
107
        preserveCase = createCheckBox( EditorFindSupport.FIND_PRESERVE_CASE, 'v' );
108
109
        setLayout(new java.awt.GridBagLayout());
110
111
        findWhatPanel.setLayout(new java.awt.GridBagLayout());
112
        gridBagConstraints = new java.awt.GridBagConstraints();
113
        gridBagConstraints.gridx = 0;
114
        gridBagConstraints.gridy = 0;
115
        gridBagConstraints.gridwidth = 3;
116
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
117
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
118
        gridBagConstraints.weightx = 1.0;
119
        gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
120
        add(findWhatPanel, gridBagConstraints);
121
122
        findWhatLabel.setLabelFor(findWhat);
123
        findWhatLabel.setText(bundle.getString(EditorFindSupport.FIND_WHAT ) );
124
        findWhatLabel.setDisplayedMnemonic(bundle.getString(EditorFindSupport.FIND_WHAT + "-mnemonic").charAt(0));
125
        gridBagConstraints = new java.awt.GridBagConstraints();
126
        gridBagConstraints.gridx = 0;
127
        gridBagConstraints.gridy = 1;
128
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
129
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
130
        add(findWhatLabel, gridBagConstraints);
131
132
        findWhat.setEditable(true);
133
        gridBagConstraints = new java.awt.GridBagConstraints();
134
        gridBagConstraints.gridx = 1;
135
        gridBagConstraints.gridy = 1;
136
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
137
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
138
        gridBagConstraints.weightx = 1.0;
139
        gridBagConstraints.insets = new java.awt.Insets(0, 11, 9, 10);
140
        add(findWhat, gridBagConstraints);
141
142
        replaceWithLabel.setLabelFor(replaceWith);
143
        replaceWithLabel.setText(bundle.getString(EditorFindSupport.FIND_REPLACE_WITH ) );
144
        replaceWithLabel.setDisplayedMnemonic(bundle.getString(EditorFindSupport.FIND_REPLACE_WITH + "-mnemonic").charAt(0));
145
        gridBagConstraints = new java.awt.GridBagConstraints();
146
        gridBagConstraints.gridx = 0;
147
        gridBagConstraints.gridy = 2;
148
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
149
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 9, 0);
150
        add(replaceWithLabel, gridBagConstraints);
151
152
        replaceWith.setEditable(true);
153
        gridBagConstraints = new java.awt.GridBagConstraints();
154
        gridBagConstraints.gridx = 1;
155
        gridBagConstraints.gridy = 2;
156
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
157
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158
        gridBagConstraints.weightx = 1.0;
159
        gridBagConstraints.insets = new java.awt.Insets(0, 11, 9, 10);
160
        add(replaceWith, gridBagConstraints);
161
        gridBagConstraints = new java.awt.GridBagConstraints();
162
        gridBagConstraints.gridx = 1;
163
        gridBagConstraints.gridy = 7;
164
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
165
        gridBagConstraints.weighty = 1.0;
166
        gridBagConstraints.insets = new java.awt.Insets(11, 11, 11, 0);
167
        add(highlightSearch, gridBagConstraints);
168
        gridBagConstraints = new java.awt.GridBagConstraints();
169
        gridBagConstraints.gridx = 2;
170
        gridBagConstraints.gridy = 7;
171
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
172
        gridBagConstraints.insets = new java.awt.Insets(11, 11, 11, 10);
173
        add(incSearch, gridBagConstraints);
174
        gridBagConstraints = new java.awt.GridBagConstraints();
175
        gridBagConstraints.gridx = 1;
176
        gridBagConstraints.gridy = 3;
177
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
178
        gridBagConstraints.insets = new java.awt.Insets(3, 11, 0, 0);
179
        add(matchCase, gridBagConstraints);
180
        gridBagConstraints = new java.awt.GridBagConstraints();
181
        gridBagConstraints.gridx = 1;
182
        gridBagConstraints.gridy = 4;
183
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
184
        gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 0);
185
        add(wholeWords, gridBagConstraints);
186
        gridBagConstraints = new java.awt.GridBagConstraints();
187
        gridBagConstraints.gridx = 2;
188
        gridBagConstraints.gridy = 5;
189
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
190
        gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 10);
191
        add(bwdSearch, gridBagConstraints);
192
        gridBagConstraints = new java.awt.GridBagConstraints();
193
        gridBagConstraints.gridx = 2;
194
        gridBagConstraints.gridy = 3;
195
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
196
        gridBagConstraints.insets = new java.awt.Insets(3, 11, 0, 10);
197
        add(wrapSearch, gridBagConstraints);
198
        gridBagConstraints = new java.awt.GridBagConstraints();
199
        gridBagConstraints.gridx = 1;
200
        gridBagConstraints.gridy = 5;
201
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
202
        gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 0);
203
        add(regExp, gridBagConstraints);
204
        gridBagConstraints = new java.awt.GridBagConstraints();
205
        gridBagConstraints.gridx = 2;
206
        gridBagConstraints.gridy = 4;
207
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
208
        gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 10);
209
        add(blockSearch, gridBagConstraints);
210
        gridBagConstraints = new java.awt.GridBagConstraints();
211
        gridBagConstraints.gridx = 1;
212
        gridBagConstraints.gridy = 6;
213
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
214
        gridBagConstraints.weighty = 1.0;
215
        gridBagConstraints.insets = new java.awt.Insets(11, 11, 11, 0);
216
        add(preserveCase, gridBagConstraints);
217
    }// </editor-fold>//GEN-END:initComponents
218
219
220
    // Variables declaration - do not modify//GEN-BEGIN:variables
221
    protected javax.swing.JCheckBox blockSearch;
222
    protected javax.swing.JCheckBox bwdSearch;
223
    protected javax.swing.JComboBox findWhat;
224
    protected javax.swing.JLabel findWhatLabel;
225
    protected javax.swing.JPanel findWhatPanel;
226
    protected javax.swing.JCheckBox highlightSearch;
227
    protected javax.swing.JCheckBox incSearch;
228
    protected javax.swing.JCheckBox matchCase;
229
    protected javax.swing.JCheckBox preserveCase;
230
    protected javax.swing.JCheckBox regExp;
231
    protected javax.swing.JComboBox replaceWith;
232
    protected javax.swing.JLabel replaceWithLabel;
233
    protected javax.swing.JCheckBox wholeWords;
234
    protected javax.swing.JCheckBox wrapSearch;
235
    // End of variables declaration//GEN-END:variables
236
237
238
    private JCheckBox createCheckBox( String key , char ch) {
239
        JCheckBox box = new JCheckBox();
240
        Mnemonics.setLocalizedText(box, bundle.getString(key));
241
        box.setToolTipText( bundle.getString( key + "-tooltip" ) );
242
        return box;
243
    }
244
    
245
}
(-)a/editor.lib/src/org/netbeans/editor/ext/FindDialogSupport.java (-823 lines)
Lines 1-823 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.editor.ext;
46
47
import java.awt.Color;
48
import java.awt.Component;
49
import java.awt.Dialog;
50
import java.awt.event.*;
51
import java.beans.PropertyChangeEvent;
52
import java.beans.PropertyChangeListener;
53
import java.util.ArrayList;
54
import java.util.List;
55
import java.util.Map;
56
import java.util.HashMap;
57
import java.util.Collections;
58
import java.util.ResourceBundle;
59
import javax.swing.*;
60
import javax.swing.JComponent;
61
import javax.swing.text.JTextComponent;
62
import javax.swing.text.BadLocationException;
63
import javax.swing.text.Position;
64
import org.netbeans.editor.BaseKit;
65
import org.netbeans.editor.DialogSupport;
66
import org.netbeans.editor.GuardedException;
67
import org.netbeans.editor.Utilities;
68
import java.util.Iterator;
69
import java.util.regex.Pattern;
70
import java.util.regex.PatternSyntaxException;
71
import javax.swing.text.DefaultEditorKit;
72
import javax.swing.text.Document;
73
import org.netbeans.editor.BaseDocument;
74
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
75
import org.openide.util.NbBundle;
76
77
/**
78
* Support for displaying find and replace dialogs
79
*
80
* @author Miloslav Metelka
81
* @version 1.00
82
* @deprecated Without any replacement.
83
*/
84
85
public class FindDialogSupport extends WindowAdapter implements ActionListener {
86
    
87
    /** This lock is used to create a barrier between showing/hiding/changing
88
     *  the dialog and testing if the dialog is already shown.
89
     *  it is used to make test-and-change / test-and-display actions atomic.
90
     *  It covers the following four fields: findDialog, isReplaceDialog,
91
     *  findPanel, findButtons
92
     */
93
    private static Object dialogLock = new Object();
94
    
95
    /** Whether the currently visible dialog is for replace */
96
    private  static boolean isReplaceDialog = false;
97
98
    /** The buttons used in the visible dialog */
99
    private  static JButton findButtons[];
100
    
101
    private static JButton findDialogButtons[];
102
    private static JButton replaceDialogButtons[];
103
    
104
    /** The FindPanel used inside the visible dialog */
105
    private  static FindPanel findPanel;
106
107
    /** Currently visible dialog */
108
    private  static Dialog findDialog = null;
109
110
    private int caretPosition;
111
112
    private static FindDialogSupport singleton = null;
113
    
114
    private boolean findPerformed = false;
115
    
116
    private static int xPos = Integer.MIN_VALUE;
117
    private static int yPos = Integer.MIN_VALUE;
118
119
    /** Flag for determining a dialog invocation. It the dialog
120
     *  is invoked by keystroke or by the menu the value is true.
121
     *  If the dialog was already shown and the focus was bring to it only,
122
     *  value is false - needed for fixing the issue #68021
123
     */
124
    private static boolean dialogInvokedViaKeystroke;
125
126
    /** Whether the block search checkbox was selected by code or by a user. */
127
    private static boolean expectedBlockSearchItemChange;
128
    
129
    public static FindDialogSupport getFindDialogSupport() {
130
        if (singleton == null) {
131
            singleton = new FindDialogSupport();
132
        }
133
        return singleton;
134
    }
135
136
    private FindDialogSupport() {
137
    }
138
139
    private void createFindButtons() {
140
        if (findButtons == null) {
141
            ResourceBundle bundle = NbBundle.getBundle(BaseKit.class);
142
            findButtons = new JButton[] {
143
                new JButton(bundle.getString("find-button-find")), // NOI18N
144
                new JButton(bundle.getString("find-button-replace")), // NOI18N
145
                new JButton(bundle.getString("find-button-replace-all")), // NOI18N
146
                new JButton(bundle.getString("find-button-cancel")) // NOI18N
147
            };
148
149
            findButtons[0].setMnemonic(bundle.getString("find-button-find-mnemonic").charAt(0)); // NOI18N
150
            findButtons[1].setMnemonic(bundle.getString("find-button-replace-mnemonic").charAt(0)); // NOI18N
151
            findButtons[2].setMnemonic(bundle.getString("find-button-replace-all-mnemonic").charAt(0)); // NOI18N
152
153
            findButtons[0].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-find")); // NOI18N
154
            findButtons[1].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-replace")); // NOI18N
155
            findButtons[2].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-replace-all")); // NOI18N
156
            findButtons[3].getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_find-button-cancel")); // NOI18N
157
            
158
            findDialogButtons = new JButton[2];
159
            findDialogButtons[0] = findButtons[0];
160
            findDialogButtons[1] = findButtons[3];
161
            
162
            replaceDialogButtons = new JButton[4];
163
            replaceDialogButtons[0] = findButtons[0];
164
            replaceDialogButtons[1] = findButtons[1];
165
            replaceDialogButtons[2] = findButtons[2];
166
            replaceDialogButtons[3] = findButtons[3];
167
        }
168
    }
169
170
    private void createFindPanel() {
171
        if (findPanel == null) {
172
            findPanel = new FindPanel();
173
        }
174
    }
175
176
    private Dialog createFindDialog(JPanel findPanel, final JButton[] buttons,
177
                                      final ActionListener l) {
178
        Dialog d = DialogSupport.createDialog(
179
                isReplaceDialog
180
                    ? NbBundle.getBundle(BaseKit.class).getString ("replace-title")
181
                    : NbBundle.getBundle(BaseKit.class).getString ("find-title" ), // NOI18N
182
                findPanel, false, // non-modal
183
                buttons, true, // sidebuttons,
184
                0, // defaultIndex = 0 => findButton
185
                isReplaceDialog ? 3 : 1, // cancelIndex = 3 => cancelButton
186
                l //listener
187
        );
188
189
        return d;
190
    }
191
192
    private void showFindDialogImpl( boolean isReplace, KeyEventBlocker blocker) {
193
        dialogInvokedViaKeystroke = true;
194
        synchronized( dialogLock ) {
195
            if (findDialog != null && isReplaceDialog != isReplace ) {
196
                xPos = findDialog.getLocation().x;
197
                yPos = findDialog.getLocation().y;
198
                findDialog.dispose();
199
                findDialog = null;
200
            }
201
            if (findDialog == null) { // create and show new dialog of required type
202
                isReplaceDialog = isReplace;                            
203
                createFindButtons();
204
                createFindPanel();
205
                findPanel.changeVisibility(isReplace);
206
                
207
                findDialog = createFindDialog( findPanel, isReplace ? replaceDialogButtons : findDialogButtons, this );
208
                findDialog.addWindowListener( this );
209
                ((JDialog)findDialog).getRootPane().setFocusable(false);
210
                if(xPos > Integer.MIN_VALUE){
211
                    findDialog.setLocation(xPos, yPos);
212
                }
213
            }            
214
        } // end of synchronized section
215
        
216
        findDialog.pack();
217
        findPanel.init(isReplace, blocker);
218
        findDialog.setVisible(true);
219
        findPanel.showNotify();
220
        findPanel.initBlockSearch();
221
        updateCaretPosition();
222
    }
223
224
    private void updateCaretPosition() {
225
        JTextComponent c = Utilities.getLastActiveComponent();
226
        if (c != null) {
227
            caretPosition = c.getCaret().getDot();
228
        }
229
    }
230
231
    public @Override void windowActivated(WindowEvent evt) {
232
        findPerformed = false;
233
        createFindPanel();
234
        findPanel.initBlockSearch();
235
        updateCaretPosition();
236
    }
237
       
238
    public @Override void windowDeactivated(WindowEvent evt) {
239
        JTextComponent c = Utilities.getLastActiveComponent();
240
        EditorFindSupport.getInstance().incSearchReset();     
241
        KeyEventBlocker blocker = findPanel.getBlocker();
242
        if (blocker!=null){
243
            blocker.stopBlocking(false);
244
        }
245
    }
246
247
    public @Override void windowClosing(WindowEvent e) {
248
        hideDialog();
249
    }
250
251
    public @Override void windowClosed(WindowEvent e) {
252
        synchronized (dialogLock) {
253
            if (findDialog != null){
254
                xPos = findDialog.getLocation().x;
255
                yPos = findDialog.getLocation().y;
256
            }
257
        }
258
        Map findProps = findPanel.getFindProps();
259
        if (Boolean.TRUE.equals(findProps.get(EditorFindSupport.FIND_BLOCK_SEARCH))) {
260
            Position startPos = (Position) findProps.get(EditorFindSupport.FIND_BLOCK_SEARCH_START);
261
            Position endPos = (Position) findProps.get(EditorFindSupport.FIND_BLOCK_SEARCH_END);
262
            if (startPos != null && endPos != null) {
263
                JTextComponent c = Utilities.getLastActiveComponent();
264
                if (c != null) {
265
                    c.select(startPos.getOffset(), endPos.getOffset());
266
                }
267
268
            }
269
        }
270
        EditorFindSupport.getInstance().incSearchReset();
271
        findPanel.resetBlockSearch();
272
        EditorFindSupport.getInstance().setBlockSearchHighlight(0, 0);
273
        findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH, Boolean.FALSE);
274
        findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH_START, null);
275
        findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH_END, null);
276
        EditorFindSupport.getInstance().putFindProperties(findProps);
277
        KeyEventBlocker blocker = findPanel.getBlocker();
278
        if (blocker!=null){
279
            blocker.stopBlocking(false);
280
        }
281
        findPanel.reset();
282
283
        Utilities.returnFocus();
284
    }
285
286
    public void showFindDialog(KeyEventBlocker blocker) {
287
        showFindDialogImpl(false, blocker);
288
    }
289
290
    public void showReplaceDialog(KeyEventBlocker blocker) {
291
        showFindDialogImpl(true, blocker);
292
    }
293
294
    public void hideDialog() {
295
        synchronized (dialogLock) {
296
            if (findDialog != null){
297
                xPos = findDialog.getLocation().x;
298
                yPos = findDialog.getLocation().y;
299
                findDialog.dispose();
300
            }
301
            findDialog = null;
302
        }
303
    }
304
    
305
    private List getHistoryList(){
306
        List<EditorFindSupport.SPW> histList = (List)EditorFindSupport.getInstance().getHistory();
307
        if (histList == null) histList = new ArrayList();
308
        List<String> list = new ArrayList<String>();
309
        for (EditorFindSupport.SPW spw : histList){
310
            list.add(spw.getSearchExpression());
311
        }
312
        return list;
313
    }
314
    
315
    private boolean getBooleanProp(String propName, Map map){
316
        Boolean b = (Boolean) map.get(propName);
317
        return (b!=null) ? b.booleanValue() : false;
318
    }
319
320
    @Override
321
    public void actionPerformed(ActionEvent evt) {
322
        if( findButtons == null ) return;
323
        
324
        Object src = evt.getSource();
325
        EditorFindSupport fSup = EditorFindSupport.getInstance();
326
        Map findPanelMap = findPanel.getFindProps();
327
        
328
        EditorFindSupport.SPW spw = new EditorFindSupport.SPW((String)findPanelMap.get(EditorFindSupport.FIND_WHAT),
329
                getBooleanProp(EditorFindSupport.FIND_WHOLE_WORDS, findPanelMap),
330
                getBooleanProp(EditorFindSupport.FIND_MATCH_CASE, findPanelMap),
331
                getBooleanProp(EditorFindSupport.FIND_REG_EXP, findPanelMap));
332
333
        if (src == findButtons[0]) { // Find button
334
            fSup.addToHistory(spw); 
335
            findPanel.updateFindHistory();
336
            fSup.putFindProperties(findPanelMap);
337
            fSup.find(null, false);
338
            updateCaretPosition();
339
            findPerformed = true;
340
        } else if (src == findButtons[1]) { // Replace button
341
            fSup.addToHistory(spw);
342
            findPanel.updateFindHistory();
343
            findPanel.updateReplaceHistory();
344
            fSup.putFindProperties(findPanelMap);
345
            try {
346
                if (fSup.replace(null, false)) { // replaced
347
                    findPanelMap.put(EditorFindSupport.FIND_BLOCK_SEARCH_START,
348
                            fSup.getFindProperty(EditorFindSupport.FIND_BLOCK_SEARCH_START));
349
                    fSup.find(null, false);
350
                }
351
            } catch (GuardedException e) {
352
                // replace in guarded block
353
            } catch (BadLocationException e) {
354
                e.printStackTrace();
355
            }
356
            updateCaretPosition();
357
            findPerformed = true;
358
        } else if (src == findButtons[2]) { // Replace All button
359
            fSup.addToHistory(spw);
360
            findPanel.updateFindHistory();
361
            findPanel.updateReplaceHistory();
362
            fSup.putFindProperties(findPanelMap);
363
            fSup.replaceAll(null);
364
            findPanelMap.put(EditorFindSupport.FIND_BLOCK_SEARCH_START,
365
                    fSup.getFindProperty(EditorFindSupport.FIND_BLOCK_SEARCH_START));
366
            findPerformed = true;
367
        } else if (src == findButtons[3]) { // Cancel button
368
            hideDialog();
369
        }
370
    }
371
    
372
    /** Panel that holds the find logic */
373
    private class FindPanel extends FindDialogPanel
374
        implements ItemListener, KeyListener, ActionListener, FocusListener {
375
376
        private Map findProps = Collections.synchronizedMap(new HashMap(20));
377
        private Map objToProps = Collections.synchronizedMap(new HashMap(20));
378
379
        private javax.swing.DefaultComboBoxModel findHistory = new javax.swing.DefaultComboBoxModel();
380
        private javax.swing.DefaultComboBoxModel replaceHistory = new javax.swing.DefaultComboBoxModel();
381
382
        private KeyEventBlocker blocker;
383
        
384
        private Position blockSearchStartPos;
385
        private Position blockSearchEndPos;
386
387
388
        FindPanel() {
389
            objToProps.put(findWhat, EditorFindSupport.FIND_WHAT);
390
            objToProps.put(replaceWith, EditorFindSupport.FIND_REPLACE_WITH);
391
            objToProps.put(highlightSearch, EditorFindSupport.FIND_HIGHLIGHT_SEARCH);
392
            objToProps.put(incSearch, EditorFindSupport.FIND_INC_SEARCH);
393
            objToProps.put(matchCase, EditorFindSupport.FIND_MATCH_CASE);
394
            objToProps.put(preserveCase, EditorFindSupport.FIND_PRESERVE_CASE);
395
            //objToProps.put(smartCase, SettingsNames.FIND_SMART_CASE);
396
            objToProps.put(wholeWords, EditorFindSupport.FIND_WHOLE_WORDS);
397
            objToProps.put(regExp, EditorFindSupport.FIND_REG_EXP);
398
            objToProps.put(bwdSearch, EditorFindSupport.FIND_BACKWARD_SEARCH);
399
            objToProps.put(wrapSearch, EditorFindSupport.FIND_WRAP_SEARCH);
400
            objToProps.put(blockSearch, EditorFindSupport.FIND_BLOCK_SEARCH);
401
            
402
            findProps.putAll(EditorFindSupport.getInstance().getFindProperties());
403
            revertMap();
404
405
            findWhat.setModel(findHistory);
406
            findWhat.getEditor().setItem(getProperty(findWhat));
407
            Component editorC = findWhat.getEditor().getEditorComponent();
408
            if (editorC instanceof JComponent) {
409
                InputMap inputMap = ((JComponent)editorC).getInputMap();
410
                inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK),
411
                        DefaultEditorKit.pasteAction);
412
                inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_MASK),
413
                        DefaultEditorKit.copyAction);
414
            }
415
            replaceWith.setModel(replaceHistory);
416
            replaceWith.getEditor().setItem(getProperty(replaceWith));
417
            highlightSearch.setSelected(getBooleanProperty(highlightSearch));
418
            incSearch.setSelected(getBooleanProperty(incSearch));
419
            matchCase.setSelected(getBooleanProperty(matchCase));
420
            preserveCase.setSelected(getBooleanProperty(preserveCase));
421
            preserveCase.setVisible(isReplaceDialog);
422
            //smartCase.setSelected(getBooleanProperty(smartCase));
423
            wholeWords.setSelected(getBooleanProperty(wholeWords));
424
            regExp.setSelected(getBooleanProperty(regExp));
425
            bwdSearch.setSelected(getBooleanProperty(bwdSearch));
426
            wrapSearch.setSelected(getBooleanProperty(wrapSearch));
427
            updateFindDialogUI();
428
429
            findWhat.getEditor().getEditorComponent().addKeyListener(this);
430
            findWhat.addActionListener(this);
431
            replaceWith.getEditor().getEditorComponent().addKeyListener(this);
432
            replaceWith.addActionListener(this);
433
            highlightSearch.addItemListener(this);
434
            incSearch.addItemListener(this);
435
            matchCase.addItemListener(this);
436
            preserveCase.addItemListener(this);
437
            //smartCase.addItemListener(this);
438
            wholeWords.addItemListener(this);
439
            regExp.addItemListener(this);
440
            bwdSearch.addItemListener(this);
441
            wrapSearch.addItemListener(this);
442
            blockSearch.addItemListener(this);
443
        }
444
445
        protected Map getFindProps() {
446
            return findProps;
447
        }
448
        
449
        private KeyEventBlocker getBlocker(){
450
            return blocker;
451
        }
452
453
        private void putProperty(Object component, Object value) {
454
            String prop = (String)objToProps.get(component);
455
            if (prop != null) {
456
                findProps.put(prop, value);
457
            }
458
        }
459
460
        private Object getProperty(Object component) {
461
            String prop = (String)objToProps.get(component);
462
            return (prop != null) ? findProps.get(prop) : null;
463
        }
464
465
        private boolean getBooleanProperty(Object component) {
466
            Object prop = getProperty(component);
467
            return (prop != null) ? ((Boolean)prop).booleanValue() : false;
468
        }
469
470
        protected void changeVisibility(boolean v) {
471
            replaceWith.setVisible(v);
472
            replaceWithLabel.setVisible(v);
473
        }
474
475
        /**
476
         * update dialog view based on search and replace texts
477
         */
478
        private void updateFindDialogUI()
479
        {
480
            boolean wrongFindPattern=false;
481
            boolean wrongReplacePattern=false;
482
            String what=findWhat.getEditor().getItem().toString();
483
            String toWhat=replaceWith.getEditor().getItem().toString();
484
            if(what==null || what.length()==0)wrongFindPattern=true;
485
            if(toWhat==null)wrongReplacePattern=true;
486
            if(regExp.isSelected())
487
            {
488
                Pattern searchPattern;
489
                int numGroups=0;
490
                if(!wrongFindPattern)
491
                {
492
                    try
493
                    {
494
                        searchPattern=Pattern.compile(what);
495
                        numGroups=searchPattern.matcher("").groupCount();
496
                    }
497
                    catch(PatternSyntaxException ex)
498
                    {
499
                        wrongFindPattern=true;
500
                    }
501
                }
502
                if(!wrongReplacePattern)
503
                {
504
                    //the obly problemmatic part of replacement is references to initial pattern
505
                    //emulate replacement below to find any problems
506
                    String pseudoText="0123456789";//NOI18N
507
                    String pseudoWhat="";//NOI18N
508
                    for(int i=0;i<numGroups;i++)
509
                    {
510
                        pseudoWhat+="("+i+")";//NOI18N
511
                    }
512
                    Pattern pseudoP=Pattern.compile(pseudoWhat);
513
                    try
514
                    {
515
                        pseudoP.matcher(pseudoText).replaceFirst(toWhat);
516
                    }
517
                    catch(Exception ex)
518
                    {
519
                        //got probem with group reference, either not a number after $ or not existent group
520
                        wrongReplacePattern=true;
521
                    }
522
                }
523
            }
524
            findButtons[0].setEnabled(!wrongFindPattern);//find button
525
            findButtons[1].setEnabled(!wrongReplacePattern && !wrongFindPattern);//replace button
526
            findButtons[2].setEnabled(!wrongReplacePattern && !wrongFindPattern);//replace all button
527
            findWhat.getEditor().getEditorComponent().setForeground(wrongFindPattern ? Color.RED : UIManager.getColor("textText")); //NOI18N
528
            replaceWith.getEditor().getEditorComponent().setForeground(wrongReplacePattern ? Color.RED : UIManager.getColor("textText")); //NOI18N
529
        }
530
531
        private void resetBlockSearch() {
532
            findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH, Boolean.FALSE);
533
            EditorFindSupport.getInstance().setBlockSearchHighlight(0,0);
534
            EditorFindSupport.getInstance().putFindProperties(findProps);
535
        }
536
        
537
        private void initBlockSearch() {
538
            JTextComponent c = Utilities.getLastActiveComponent();
539
            String selText;
540
            boolean multiLineSelection;
541
            boolean invokedViaKeystroke = dialogInvokedViaKeystroke;
542
            dialogInvokedViaKeystroke = false;
543
544
            if (c != null) {
545
                Document doc = c.getDocument();
546
                int blockSearchStartOffset = c.getSelectionStart();
547
                int blockSearchEndOffset = c.getSelectionEnd();
548
                try {
549
                    blockSearchStartPos = doc.createPosition(blockSearchStartOffset);
550
                    blockSearchEndPos = doc.createPosition(blockSearchEndOffset);
551
                } catch (BadLocationException e) {
552
                    // Should never happen
553
                }
554
                BaseDocument bdoc = (BaseDocument) doc;
555
                try{
556
                    multiLineSelection = (blockSearchEndOffset != blockSearchStartOffset)
557
                            && (doc instanceof BaseDocument) &&
558
                               (Utilities.getLineOffset((BaseDocument)doc, blockSearchEndOffset) >
559
                                    Utilities.getLineOffset((BaseDocument)doc, blockSearchStartOffset));
560
                } catch (BadLocationException ble){
561
                    multiLineSelection = false;
562
                }
563
564
                caretPosition = bwdSearch.isSelected() ? blockSearchEndOffset : blockSearchStartOffset;
565
                
566
                if (!multiLineSelection && invokedViaKeystroke) {
567
                    selText = c.getSelectedText();
568
                    if (selText != null && selText.length() > 0) {
569
                        int n = selText.indexOf( '\n' );
570
                        if (n >= 0 ) selText = selText.substring(0, n);
571
                        findWhat.getEditor().setItem(selText);
572
                    }
573
                }
574
575
                // For multi-line selection turn on block-search checkbox automatically
576
                if (invokedViaKeystroke) {
577
                    expectedBlockSearchItemChange = true;
578
                    blockSearch.setSelected(multiLineSelection);
579
                }
580
581
                findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH, blockSearch.isSelected());
582
                findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH_START, blockSearchStartPos);
583
                findProps.put(EditorFindSupport.FIND_BLOCK_SEARCH_END, blockSearchEndPos);
584
                EditorFindSupport.getInstance().setBlockSearchHighlight(
585
                        blockSearchStartOffset, blockSearchEndOffset);
586
            }
587
        }
588
589
        protected void init(boolean isReplace, KeyEventBlocker blocker) {
590
            this.blocker = blocker;
591
            findHistory.setSelectedItem(null);
592
            replaceHistory.setSelectedItem(null);
593
            findWhat.getEditor().getEditorComponent().addFocusListener(this);
594
            if (isReplace) {
595
                replaceWith.getEditor().getEditorComponent().addFocusListener(this);
596
            }
597
598
            findProps.putAll(EditorFindSupport.getInstance().getFindProperties());
599
            revertMap();
600
601
            highlightSearch.setSelected(getBooleanProperty(highlightSearch));
602
            incSearch.setSelected(getBooleanProperty(incSearch));
603
            matchCase.setSelected(getBooleanProperty(matchCase));
604
            preserveCase.setSelected(getBooleanProperty(preserveCase));
605
            preserveCase.setVisible(isReplaceDialog);
606
            //smartCase.setSelected(getBooleanProperty(smartCase));
607
            wholeWords.setSelected(getBooleanProperty(wholeWords));
608
            boolean regExpValue = getBooleanProperty(regExp);
609
            regExp.setSelected(regExpValue);
610
            wholeWords.setEnabled(!regExpValue);
611
            incSearch.setEnabled(!regExpValue);
612
            preserveCase.setEnabled(!(getBooleanProperty(regExp) || getBooleanProperty(matchCase)));
613
            bwdSearch.setSelected(getBooleanProperty(bwdSearch));
614
            wrapSearch.setSelected(getBooleanProperty(wrapSearch));
615
            findHistory = new DefaultComboBoxModel(getHistoryList().toArray());
616
            findWhat.setModel(findHistory);
617
        }
618
619
        protected void reset() {
620
            this.blocker = null;
621
        }
622
        
623
        protected void showNotify() {
624
            // fix of issue #66217 
625
            boolean focused = findWhat.getEditor().getEditorComponent().requestFocusInWindow();
626
            if (focused == false){
627
                SwingUtilities.invokeLater(new Runnable(){
628
                    @Override
629
                    public void run(){
630
                        findWhat.getEditor().getEditorComponent().requestFocusInWindow();
631
                    }
632
                });
633
            }
634
        }
635
636
        private void updateHistory(JComboBox c, javax.swing.DefaultComboBoxModel history) {
637
            Object item = c.getEditor().getItem();
638
            if( item != null && !item.equals("")) { //NOI18N
639
                history.removeElement(item);
640
                history.insertElementAt(item, 0);
641
                history.setSelectedItem(null);
642
            }
643
            c.getEditor().setItem(item);
644
        }
645
        
646
        protected void updateFindHistory() {
647
            //updateHistory(findWhat, findHistory);
648
            /*
649
            List list = new ArrayList();
650
            for (int i = 0; i<findHistory.getSize(); i++){
651
                list.add(findHistory.getElementAt(i));
652
            }
653
            EditorFindSupport.getInstance().putFindProperty(SettingsNames.FIND_HISTORY, list);
654
            findProps.put(SettingsNames.FIND_HISTORY, list);
655
             */
656
            Object obj = findWhat.getEditor().getItem();
657
            findHistory = new DefaultComboBoxModel(getHistoryList().toArray());
658
            findWhat.setModel(findHistory);
659
            if (obj != null){
660
                findWhat.getEditor().setItem(obj);
661
            }
662
        }
663
664
        protected void updateReplaceHistory() {
665
            updateHistory(replaceWith, replaceHistory);
666
        }
667
668
        private void revertMap(){
669
            Object prop = findProps.get(EditorFindSupport.REVERT_MAP);
670
            if (!(prop instanceof Map)) return;
671
            Map revertMap = (Map)prop;
672
673
            for( Iterator i = revertMap.keySet().iterator(); i.hasNext(); ) {
674
                String key = (String)i.next();
675
676
                Object obj = findProps.get(key);
677
                boolean value = ( obj != null ) ? ((Boolean)obj).booleanValue() : false;
678
                if (value != ((Boolean)revertMap.get(key)).booleanValue());
679
                    findProps.put(key, value ? Boolean.FALSE : Boolean.TRUE);
680
            }
681
682
            findProps.put(EditorFindSupport.REVERT_MAP, null);
683
        }
684
685
        private void changeFindWhat(boolean performIncSearch) {
686
            Object old = getProperty(findWhat);
687
            Object cur = findWhat.getEditor().getItem();
688
            if ((old == null && cur != null && !cur.equals("")) || (old != null && !old.equals(cur))) { // NOI18N
689
                putProperty(findWhat, cur);
690
                if (performIncSearch){
691
                    findPerformed = EditorFindSupport.getInstance().incSearch(getFindProps(), caretPosition);  
692
                }
693
            }
694
        }
695
696
        private void changeReplaceWith() {
697
            Object old = getProperty(replaceWith);
698
            Object cur = replaceWith.getEditor().getItem();
699
            if ((old == null && cur != null && !cur.equals("")) || (old != null && !old.equals(cur))) { // NOI18N
700
                putProperty(replaceWith, cur);
701
            }
702
        }
703
704
        private void postChangeCombos(final boolean performIncSearch) {
705
            SwingUtilities.invokeLater(
706
                new Runnable() {
707
                @Override
708
                    public void run() {
709
                        updateFindDialogUI();
710
                        changeFindWhat(performIncSearch);
711
                        changeReplaceWith();
712
                    }
713
                }
714
            );
715
        }
716
717
        @Override
718
        public void keyPressed(KeyEvent evt) {
719
            if (evt.getKeyChar() == '\n') {
720
                evt.consume();
721
            }
722
        }
723
724
        @Override
725
        public void keyReleased(KeyEvent evt) {
726
            if (evt.getKeyChar() == '\n') {
727
                evt.consume();
728
            } else if (evt.getKeyCode() == KeyEvent.VK_INSERT){
729
                postChangeCombos(true);
730
            }
731
        }
732
733
        @Override
734
        public void keyTyped(KeyEvent evt) {
735
            if (evt.getKeyChar() == '\n') {
736
                findButtons[0].doClick(20);
737
                evt.consume();
738
                ((JComboBox)((JTextField)evt.getSource()).getParent()).hidePopup();
739
            } else {
740
                postChangeCombos(true);
741
            }
742
        }
743
744
        @Override
745
        public void itemStateChanged(ItemEvent evt)  {
746
            Boolean val = (evt.getStateChange() == ItemEvent.SELECTED) ? Boolean.TRUE
747
                          : Boolean.FALSE;
748
            if (evt.getItem() == bwdSearch){
749
                if (blockSearch.isSelected()) {
750
                    boolean value = val.booleanValue();
751
                    JTextComponent c = Utilities.getLastActiveComponent();
752
                    if (c!=null) {
753
                        Position pos = value ? blockSearchEndPos : blockSearchStartPos;
754
                        c.getCaret().setDot(pos.getOffset());
755
                        updateCaretPosition();
756
                    }
757
                    
758
                }
759
            }
760
            if (evt.getItem() == regExp){
761
                boolean value = val.booleanValue();
762
                incSearch.setEnabled(!value);
763
                wholeWords.setEnabled(!value);
764
                preserveCase.setEnabled(!(value || getBooleanProperty(matchCase)));
765
                updateFindDialogUI();
766
            }
767
            if (evt.getItem() == matchCase) {
768
                boolean value = val.booleanValue();
769
                preserveCase.setEnabled(!(getBooleanProperty(regExp) || value));
770
                updateFindDialogUI();
771
            }
772
            if (evt.getItem() == blockSearch){
773
                boolean expectedChange = expectedBlockSearchItemChange;
774
                expectedBlockSearchItemChange = false;
775
                boolean value = val.booleanValue();
776
                if (value){
777
                    if (!expectedChange) {
778
                        JTextComponent c = Utilities.getLastActiveComponent();
779
                        if (c != null) {
780
                            Position pos = bwdSearch.isSelected() ? blockSearchEndPos : blockSearchStartPos;
781
                            c.getCaret().setDot(pos.getOffset());
782
                            updateCaretPosition();
783
                            findPerformed = EditorFindSupport.getInstance().incSearch(getFindProps(), caretPosition);
784
                        }
785
                    }
786
                    EditorFindSupport.getInstance().setBlockSearchHighlight(
787
                            blockSearchStartPos.getOffset(), blockSearchEndPos.getOffset());
788
                } else {
789
                    EditorFindSupport.getInstance().putFindProperty(EditorFindSupport.FIND_BLOCK_SEARCH, Boolean.FALSE);
790
                    EditorFindSupport.getInstance().setBlockSearchHighlight(0, 0);
791
                }
792
            }
793
                          
794
            putProperty(evt.getSource(), val);
795
            
796
            if (evt.getItem() == regExp){
797
                updateFindHistory();
798
            }
799
        }
800
801
        public void actionPerformed(ActionEvent evt) {
802
            postChangeCombos(false);
803
        }
804
805
        public void focusGained(FocusEvent e) {
806
            if (e.getSource() instanceof JTextField) {
807
                ((JTextField)e.getSource()).selectAll();
808
                if (blocker != null){
809
                    blocker.stopBlocking();
810
                }
811
            }
812
            ((JComponent)e.getSource()).removeFocusListener(this);
813
        }
814
815
        public void focusLost(FocusEvent e) {
816
            
817
        }
818
819
820
821
    }
822
823
}
(-)a/editor.search/src/org/netbeans/modules/editor/search/SearchNbEditorKit.java (-2 lines)
Lines 63-70 Link Here
63
    public static final String INCREMENTAL_SEARCH_FORWARD = "incremental-search-forward"; // NOI18N
63
    public static final String INCREMENTAL_SEARCH_FORWARD = "incremental-search-forward"; // NOI18N
64
    public static final String INCREMENTAL_SEARCH_BACKWARD = "incremental-search-backward"; // NOI18N
64
    public static final String INCREMENTAL_SEARCH_BACKWARD = "incremental-search-backward"; // NOI18N
65
    public static final String REPLACE_ACTION = "replace"; // NOI18N
65
    public static final String REPLACE_ACTION = "replace"; // NOI18N
66
    public static final ExtKit.FindAction DIALOG_FIND_ACTION = new FindAction();
67
    public static final ExtKit.ReplaceAction DIALOG_REPLACE_ACTION = new ReplaceAction();
68
    public static final String SEARCHBAR_MIMETYPE = "text/x-editor-search"; // NOI18N
66
    public static final String SEARCHBAR_MIMETYPE = "text/x-editor-search"; // NOI18N
69
    public static final String PROP_SEARCH_CONTAINER = "diff.search.container"; // NOI18N
67
    public static final String PROP_SEARCH_CONTAINER = "diff.search.container"; // NOI18N
70
68
(-)a/editor/src/org/netbeans/modules/editor/impl/NbDialogFactory.java (-3 / +1 lines)
Lines 69-75 Link Here
69
    private static HashMap helpIDs;
69
    private static HashMap helpIDs;
70
    
70
    
71
    private static final String HELP_ID_MacroSavePanel = "editing.macros.recording"; // !!! NOI18N
71
    private static final String HELP_ID_MacroSavePanel = "editing.macros.recording"; // !!! NOI18N
72
    private static final String HELP_ID_FindPanel = "editing.find"; // !!! NOI18N
73
    private static final String HELP_ID_JavaFastImportPanel = "editing.fastimport"; // !!! NOI18N
72
    private static final String HELP_ID_JavaFastImportPanel = "editing.fastimport"; // !!! NOI18N
74
    private static final String HELP_ID_ScrollCompletionPane = "editing.codecompletion"; // !!! NOI18N
73
    private static final String HELP_ID_ScrollCompletionPane = "editing.codecompletion"; // !!! NOI18N
75
    
74
    
Lines 78-85 Link Here
78
        if (helpIDs == null)
77
        if (helpIDs == null)
79
        {
78
        {
80
            helpIDs = new HashMap(7);
79
            helpIDs = new HashMap(7);
81
            helpIDs.put("org.netbeans.editor.MacroSavePanel", HELP_ID_MacroSavePanel); // NOI18N
80
            helpIDs.put("org.netbeans.editor.MacroSavePanel", HELP_ID_MacroSavePanel); // NOI18Nq
82
            helpIDs.put("org.netbeans.editor.ext.FindDialogSupport$FindPanel", HELP_ID_FindPanel); // NOI18N
83
            helpIDs.put("org.netbeans.editor.ext.ScrollCompletionPane", HELP_ID_ScrollCompletionPane); // NOI18N
81
            helpIDs.put("org.netbeans.editor.ext.ScrollCompletionPane", HELP_ID_ScrollCompletionPane); // NOI18N
84
            helpIDs.put("org.netbeans.editor.ext.java.JavaFastImportPanel", HELP_ID_JavaFastImportPanel); // NOI18N
82
            helpIDs.put("org.netbeans.editor.ext.java.JavaFastImportPanel", HELP_ID_JavaFastImportPanel); // NOI18N
85
        }
83
        }

Return to bug 218995