KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > search > types > FullTextCustomizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.search.types;
21
22 import java.util.List JavaDoc;
23 import javax.accessibility.AccessibleContext JavaDoc;
24 import javax.swing.Box JavaDoc;
25 import javax.swing.BoxLayout JavaDoc;
26 import javax.swing.JComboBox JavaDoc;
27 import javax.swing.JLabel JavaDoc;
28 import org.openide.awt.Mnemonics;
29 import org.openide.util.*;
30 import org.openidex.search.SearchHistory;
31 import org.openidex.search.SearchPattern;
32 //import org.netbeans.modules.search.res.*;
33

34
35 /**
36  *
37  * @author Petr Kuzel
38  * @author Marian Petras
39  */

40 public final class FullTextCustomizer extends TextCustomizer {
41
42     /** editable combo-box for entering a replacement text */
43     private final JComboBox JavaDoc replaceComboBox = new JComboBox JavaDoc();
44     
45     /** Creates new FullTextCustomizer. */
46     public FullTextCustomizer() {
47         super();
48         addReplacePanel(createReplacePanel());
49         
50         HelpCtx.setHelpIDString(this, FullTextType.class.toString());
51     }
52     
53     /**
54      * Creates a panel with an editable combo-box for entering a replacement
55      * text, together with a label for it.
56      *
57      * @return created panel
58      */

59     private Box JavaDoc createReplacePanel() {
60         JLabel JavaDoc lblReplaceWith = new JLabel JavaDoc();
61         
62         Mnemonics.setLocalizedText(
63                 lblReplaceWith,
64                 NbBundle.getMessage(FullTextCustomizer.class,
65                                     "TEXT_LABEL_REPLACE_WITH")); //NOI18N
66
AccessibleContext JavaDoc ac = replaceComboBox.getAccessibleContext();
67         ac.setAccessibleName(
68                 NbBundle.getMessage(getClass(), "ACSN_REPLACE_STRING"));//NOI18N
69
ac.setAccessibleDescription(
70                 NbBundle.getMessage(getClass(), "ACSD_REPLACE_STRING"));//NOI18N
71

72         lblReplaceWith.setLabelFor(replaceComboBox);
73         replaceComboBox.setEditable(true);
74         activateEnterKeyBypass(replaceComboBox);
75         
76         Box JavaDoc box = new Box JavaDoc(BoxLayout.Y_AXIS);
77         box.add(lblReplaceWith);
78         box.add(Box.createVerticalStrut(4));
79         box.add(replaceComboBox);
80         
81         return box;
82     }
83     
84     /**
85      * Overridden to also store the text in the replace combo-box.
86      */

87     @Override JavaDoc
88     public void onOk() {
89         final String JavaDoc text = getComboText(replaceComboBox);
90         ((FullTextType) peer).setReplaceString((text != null) ? text
91                                                               : ""); //NOI18N
92
super.onOk();
93     }
94     
95 /** Reuse text customizer. */
96     protected String JavaDoc getBorderLabel() {
97         return NbBundle.getMessage(FullTextType.class,
98                                    "TEXT_LABEL_TEXT_CONTAINS"); //NOI18N
99
}
100
101     /**
102      * Returns an unmodifiable List of SearchPatterns.
103      * The list is obtained from the global list of search patterns through
104      * openidex/search api.
105      *
106      * @return unmodifiable List of SearchPatterns
107      */

108     protected List JavaDoc/*SearchPattern*/ getSearchPatterns() {
109         return SearchHistory.getDefault().getSearchPatterns();
110     }
111     
112     /** Adds SearchPattern to SearchHistory. Delegates to the global history
113      * of search patterns through the openidex/search api.
114      * @param pattern the SearchPattern to add
115      */

116     protected void addSearchPattern(SearchPattern pattern) {
117         SearchHistory.getDefault().add(pattern);
118     }
119 }
120
Popular Tags