20 package net.sf.gridarta.textedit.textarea.actions;
22 import java.awt.Container;
23 import java.awt.FlowLayout;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import javax.swing.Box;
27 import javax.swing.BoxLayout;
28 import javax.swing.JButton;
29 import javax.swing.JDialog;
30 import javax.swing.JOptionPane;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
33 import javax.swing.WindowConstants;
34 import javax.swing.text.JTextComponent;
40 import net.
sf.japi.swing.action.ActionBuilder;
41 import net.
sf.japi.swing.action.ActionBuilderFactory;
42 import net.
sf.japi.swing.action.ActionMethod;
43 import org.jetbrains.annotations.NotNull;
44 import org.jetbrains.annotations.Nullable;
50 public class Replace implements ActionListener {
56 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
76 pane.
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
78 pane.
dialog.setModal(
false);
79 pane.
dialog.setVisible(
true);
92 final int startPos = textArea.getCaretPosition();
93 final String text = textArea.getText();
94 final int foundIndex = text.indexOf(textToFind, startPos + 1);
95 if (foundIndex == -1) {
102 textArea.select(foundIndex, foundIndex + textToFind.length());
103 textArea.setSelectedText(textToReplace);
104 textArea.select(foundIndex, foundIndex + textToReplace.length());
127 private final JButton
replaceButton =
new JButton(ACTION_BUILDER.createAction(
false,
"replaceButton",
this));
134 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"cancelButton",
this));
170 replaceButton.setDefaultCapable(
true);
180 textToFind = findTextField.getText();
181 textToReplace = replaceTextField.getText();
183 setValue(replaceButton);
193 setValue(cancelButton);
203 final JPanel replacePanel =
new JPanel();
204 replacePanel.setLayout(
new BoxLayout(replacePanel, BoxLayout.Y_AXIS));
207 final Container findTextPanel =
new JPanel(
new FlowLayout(FlowLayout.RIGHT));
209 findTextPanel.add(findTextField);
211 findTextField.setText(selectedText != null ? selectedText : textToFind);
212 replacePanel.add(findTextPanel);
213 replacePanel.add(Box.createVerticalStrut(5));
216 final Container replaceTextPanel =
new JPanel(
new FlowLayout(FlowLayout.RIGHT));
218 replaceTextPanel.add(replaceTextField);
219 replaceTextField.setText(textToReplace);
220 replacePanel.add(replaceTextPanel);
221 replacePanel.add(Box.createVerticalStrut(5));
static final ActionBuilder ACTION_BUILDER
Action Builder.
The replace dialog implementation.
A document implementation that can be tokenized by the syntax highlighting system.
String textToReplace
The text that was previously selected as replacement.
final JTextComponent replaceTextField
Textfield for the text to replace with.
ReplaceDialog(@NotNull final JEditTextArea textArea)
Create a new instance.
void cancelButton()
Action method for cancel.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
An input handler converts the user's key strokes into concrete actions.
Base package of all Gridarta classes.
This package contains the classes for the script editor used within the editor to create and modify P...
Action listener for "replace".
Actions used by the script editor.
final JButton replaceButton
JButton for ok.
final JTextComponent findTextField
Textfield for the text to find.
final JEditTextArea textArea
The text area to replace in.
static void beginCompoundEdit()
Starts a compound edit that can be undone in one operation.
String textToFind
The text that was previously selected to find.
JPanel createPanel()
Creates the text field panel.
String getSelectedText()
Returns the selected text, or null if no selection is active.
static final long serialVersionUID
The serial version UID.
This package contains the other part of the script editor.
static void endCompoundEdit()
Ends a compound edit that can be undone in one operation.
void setType(@NotNull final FindType type)
Set the operation to perform.
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
Utility class for ActionBuilder related functions.
JDialog dialog
The dialog.
void actionPerformed(final ActionEvent e)
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
static final FindAgain FIND_AGAIN
The "find again" action listener.
jEdit's text area component.
boolean replace(@NotNull final JEditTextArea textArea)
Replace the next occurrence of textToFind with textToReplace.
void replaceButton()
Action method for okay.