initialValues = new SearchSetting();
}
// -- prepare the combo box with the search expressions
//
JLabel label = new JLabel( initialValues instanceof Filter ? tr("Filter string:") : tr("Search string:"));
final HistoryComboBox hcbSearchString = new HistoryComboBox();
hcbSearchString.setText(initialValues.text);
hcbSearchString.setToolTipText(tr("Enter the search expression"));
// we have to reverse the history, because ComboBoxHistory will reverse it again
// in addElement()
//
List<String> searchExpressionHistory = getSearchExpressionHistory();
Collections.reverse(searchExpressionHistory);
hcbSearchString.setPossibleItems(searchExpressionHistory);
hcbSearchString.setPreferredSize(new Dimension(40, hcbSearchString.getPreferredSize().height));
JRadioButton replace = new JRadioButton(tr("replace selection"), initialValues.mode == SearchMode.replace);
JRadioButton add = new JRadioButton(tr("add to selection"), initialValues.mode == SearchMode.add);
JRadioButton remove = new JRadioButton(tr("remove from selection"), initialValues.mode == SearchMode.remove);
JRadioButton in_selection = new JRadioButton(tr("find in selection"), initialValues.mode == SearchMode.in_selection);
ButtonGroup bg = new ButtonGroup();
bg.add(replace);
bg.add(add);
bg.add(remove);
bg.add(in_selection);
final JCheckBox caseSensitive = new JCheckBox(tr("case sensitive"), initialValues.caseSensitive);
JCheckBox allElements = new JCheckBox(tr("all objects"), initialValues.allElements);
allElements.setToolTipText(tr("Also include incomplete and deleted objects in search."));
final JCheckBox regexSearch = new JCheckBox(tr("regular expression"), initialValues.regexSearch);
final JCheckBox addOnToolbar = new JCheckBox(tr("add toolbar button"), false);
JPanel top = new JPanel(new GridBagLayout());
top.add(label, GBC.std().insets(0, 0, 5, 0));
top.add(hcbSearchString, GBC.eol().fill(GBC.HORIZONTAL));
JPanel left = new JPanel(new GridBagLayout());
left.add(replace, GBC.eol());
left.add(add, GBC.eol());
left.add(remove, GBC.eol());
left.add(in_selection, GBC.eop());
left.add(caseSensitive, GBC.eol());
if(Main.pref.getBoolean("expert", false))
{
left.add(allElements, GBC.eol());
left.add(regexSearch, GBC.eol());
left.add(addOnToolbar, GBC.eol());
}
final JPanel right;
if (Main.pref.getBoolean("dialog.search.new", true)) {
right = new JPanel(new GridBagLayout());
buildHintsNew(right, hcbSearchString);
} else {
right = new JPanel();
buildHints(right);
}
final JPanel p = new JPanel(new GridBagLayout());
p.add(top, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 0));
p.add(left, GBC.std().anchor(GBC.NORTH).insets(5, 10, 10, 0));
p.add(right, GBC.eol());
ExtendedDialog dialog = new ExtendedDialog(
Main.parent,
initialValues instanceof Filter ? tr("Filter") : tr("Search"),
new String[] {
initialValues instanceof Filter ? tr("Submit filter") : tr("Start Search"),
tr("Cancel")}
) {
@Override
protected void buttonAction(int buttonIndex, ActionEvent evt) {
if (buttonIndex == 0) {
try {
SearchCompiler.compile(hcbSearchString.getText(), caseSensitive.isSelected(), regexSearch.isSelected());
super.buttonAction(buttonIndex, evt);
} catch (ParseError e) {
JOptionPane.showMessageDialog(
Main.parent,
tr("Search expression is not valid: \n\n {0}", e.getMessage()),
tr("Invalid search expression"),
JOptionPane.ERROR_MESSAGE);
}
} else {
super.buttonAction(buttonIndex, evt);
}
}
};
dialog.setButtonIcons(new String[] {"dialogs/search.png", "cancel.png"});
dialog.configureContextsensitiveHelp("/Action/Search", true /* show help button */);
dialog.setContent(p);
dialog.showDialog();
int result = dialog.getValue();
if(result != 1) return null;
// User pressed OK - let's perform the search
SearchMode mode = replace.isSelected() ? SearchAction.SearchMode.replace
: (add.isSelected() ? SearchAction.SearchMode.add
: (remove.isSelected() ? SearchAction.SearchMode.remove : SearchAction.SearchMode.in_selection));
initialValues.text = hcbSearchString.getText();
initialValues.mode = mode;
initialValues.caseSensitive = caseSensitive.isSelected();
initialValues.allElements = allElements.isSelected();
initialValues.regexSearch = regexSearch.isSelected();