# HG changeset patch # Parent 5aef10fd7f9be55267b57adfa7645ff77ff910c4 #211098: Regular Expression option for file name pattern is confusing diff --git a/api.search/src/org/netbeans/api/search/ui/ScopeOptionsController.java b/api.search/src/org/netbeans/api/search/ui/ScopeOptionsController.java --- a/api.search/src/org/netbeans/api/search/ui/ScopeOptionsController.java +++ b/api.search/src/org/netbeans/api/search/ui/ScopeOptionsController.java @@ -57,6 +57,7 @@ import org.netbeans.modules.search.ui.CheckBoxWithButtonPanel; import org.netbeans.modules.search.ui.FormLayoutHelper; import org.netbeans.modules.search.ui.UiUtils; +import org.openide.util.NbBundle; /** * Component controller for setting search scope options. @@ -116,6 +117,8 @@ private void init() { btnTestFileNamePattern = new JButton(); chkFileNameRegex = new JCheckBox(); + chkFileNameRegex.setToolTipText(UiUtils.getText( + "BasicSearchForm.chkFileNameRegex.tooltip")); //NOI18N if (!replacing) { chkArchives = new JCheckBox(); diff --git a/api.search/src/org/netbeans/modules/search/BasicSearchForm.java b/api.search/src/org/netbeans/modules/search/BasicSearchForm.java --- a/api.search/src/org/netbeans/modules/search/BasicSearchForm.java +++ b/api.search/src/org/netbeans/modules/search/BasicSearchForm.java @@ -46,8 +46,12 @@ import java.awt.Color; import java.awt.Component; -import java.awt.FlowLayout; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; import java.awt.ItemSelectable; +import java.awt.SystemColor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -58,6 +62,7 @@ import java.util.List; import java.util.logging.Logger; import javax.swing.*; +import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.JTextComponent; @@ -140,6 +145,8 @@ } useCurrentlySelectedText(); setSearchCriteriaValues(); + lblTextToFind.setVisible(!searchCriteria.isRegexp()); + lblFileNameHint.setVisible(!searchCriteria.isFileNameRegexp()); } /** @@ -223,6 +230,8 @@ cboxTextToFind = ComponentUtils.adjustComboForSearchPattern(new JComboBox()); lblTextToFind.setLabelFor(cboxTextToFind.getComponent()); btnTestTextToFind = new JButton(); + lblTextToFindHint = new JLabel(); + lblTextToFindHint.setForeground(SystemColor.controlDkShadow); if (searchAndReplace) { lblReplacement = new JLabel(); @@ -239,6 +248,8 @@ lblScope.setLabelFor(cboxScope.getComponent()); lblFileNamePattern = new JLabel(); + lblFileNameHint = new JLabel(); + lblFileNameHint.setForeground(SystemColor.controlDkShadow); cboxFileNamePattern = ComponentUtils.adjustComboForFileName( new JComboBox()); lblFileNamePattern.setLabelFor(cboxFileNamePattern.getComponent()); @@ -271,14 +282,19 @@ formPanel = new SearchFormPanel(); formPanel.addRow(lblTextToFind, cboxTextToFind.getComponent()); + formPanel.addRow(new JLabel(), lblTextToFindHint); initContainingTextOptionsRow(searchAndReplace); if (searchAndReplace) { formPanel.addRow(lblReplacement, cboxReplacement); } + formPanel.addSeparator(); formPanel.addRow(lblScope, cboxScope.getComponent()); + formPanel.addSeparator(); formPanel.addRow(lblFileNamePattern, cboxFileNamePattern.getComponent()); + formPanel.addRow(new JLabel(), lblFileNameHint); initScopeOptionsRow(searchAndReplace); + formPanel.addEmptyLine(); } /** @@ -299,11 +315,10 @@ formPanel.addRow(new JLabel(), jp); } else { - jp.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0)); + jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS)); jp.add(chkCaseSensitive); jp.add(chkWholeWords); jp.add(new CheckBoxWithButtonPanel(chkRegexp, btnTestTextToFind)); - jp.setMaximumSize(jp.getPreferredSize()); formPanel.addRow(new JLabel(), jp); } } @@ -424,6 +439,8 @@ cboxFileNamePattern.getFileNamePattern()); searchCriteria.setFileNameRegexp( cboxFileNamePattern.isRegularExpression()); + lblFileNameHint.setVisible( + !cboxFileNamePattern.isRegularExpression()); } }); @@ -625,6 +642,7 @@ "BasicSearchForm.cboxTextToFind.tooltip"); //NOI18N } cboxTextToFind.getComponent().setToolTipText(t); + lblTextToFindHint.setVisible(t != null); } /** @@ -708,9 +726,13 @@ private void setMnemonics(boolean searchAndReplace) { lclz(lblTextToFind, "BasicSearchForm.lblTextToFind.text"); //NOI18N + lclz(lblTextToFindHint, + "BasicSearchForm.cboxTextToFind.tooltip"); //NOI18N lclz(lblScope, "BasicSearchForm.lblScope.text"); //NOI18N lclz(lblFileNamePattern, "BasicSearchForm.lblFileNamePattern.text"); //NOI18N + lclz(lblFileNameHint, + "BasicSearchForm.cboxFileNamePattern.tooltip"); //NOI18N lclz(chkWholeWords, "BasicSearchForm.chkWholeWords.text"); //NOI18N lclz(chkCaseSensitive, "BasicSearchForm.chkCaseSensitive.text");//NOI18N lclz(chkRegexp, "BasicSearchForm.chkRegexp.text"); //NOI18N @@ -751,8 +773,10 @@ protected SearchFormPanel formPanel; private JButton btnTestTextToFind; private JLabel lblTextToFind; + private JLabel lblTextToFindHint; private ScopeController cboxScope; private JLabel lblFileNamePattern; + private JLabel lblFileNameHint; private JLabel lblScope; private JLabel lblReplacement; private Color errorTextColor, defaultTextColor; @@ -766,18 +790,60 @@ private final class SearchFormPanel extends JPanel { private FormLayoutHelper flh; + private int row = 0; public SearchFormPanel() { super(); - this.flh = new FormLayoutHelper(this, - FormLayoutHelper.DEFAULT_COLUMN, - FormLayoutHelper.DEFAULT_COLUMN); - flh.setAllGaps(true); + setLayout(new GridBagLayout()); + setBorder(new EmptyBorder(5, 5, 5, 5)); } public void addRow(JComponent label, JComponent component) { - flh.addRow(label, component); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.anchor = GridBagConstraints.NORTHWEST; + c.gridy = row; + c.weightx = 0; + c.weighty = 0; + c.insets = new Insets(5, 5, 5, 5); + add(label, c); + + c.gridx = 1; + c.weightx = 1; + c.fill = GridBagConstraints.HORIZONTAL; + add(component, c); + + row++; + } + + public void addSeparator() { + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = row; + c.gridwidth = 2; + c.weightx = 1; + c.insets = new Insets(5, 5, 5, 5); + c.fill = GridBagConstraints.HORIZONTAL; + JSeparator separator = new JSeparator(JSeparator.HORIZONTAL); + separator.setForeground(SystemColor.controlShadow); + add(separator, c); + row++; + } + + public void addEmptyLine() { + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = row; + c.gridwidth = 2; + c.fill = GridBagConstraints.HORIZONTAL; + c.weighty = 1; + c.weightx = 0.1; + JLabel emptyLabel = new JLabel(); + emptyLabel.setPreferredSize(new Dimension(0, 0)); + emptyLabel.setMinimumSize(new Dimension(0, 0)); + add(emptyLabel, c); + row++; } } diff --git a/api.search/src/org/netbeans/modules/search/Bundle.properties b/api.search/src/org/netbeans/modules/search/Bundle.properties --- a/api.search/src/org/netbeans/modules/search/Bundle.properties +++ b/api.search/src/org/netbeans/modules/search/Bundle.properties @@ -214,11 +214,11 @@ BasicSearchForm.lblReplacement.text=&Replace With\: -BasicSearchForm.lblScope.text=&Scope +BasicSearchForm.lblScope.text=&Scope: BasicSearchForm.lblFileNamePattern.text=File Name &Patterns\: -BasicSearchForm.cboxFileNamePattern.tooltip=(Example\: *.java, FZP??.jsp, web/**/main/*.?htm?) +BasicSearchForm.cboxFileNamePattern.tooltip=(Example\: *.java, FZP??.jsp) BasicSearchForm.cboxFileNamePattern.allFiles=(all files) @@ -245,6 +245,7 @@ BasicSearchForm.chkGenerated.text=Search in &Generated Sources BasicSearchForm.chkFileNameRegex.text=Regular E&xpression +BasicSearchForm.chkFileNameRegex.tooltip=Use regular expression for the file path BasicSearchForm.btnTestTextToFind.text=test