 |
Gridarta Editor
|
Go to the documentation of this file.
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());
104 textArea.select(foundIndex, foundIndex +
textToReplace.length());
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));
212 replacePanel.add(findTextPanel);
213 replacePanel.add(Box.createVerticalStrut(5));
216 final Container replaceTextPanel =
new JPanel(
new FlowLayout(FlowLayout.RIGHT));
220 replacePanel.add(replaceTextPanel);
221 replacePanel.add(Box.createVerticalStrut(5));
String textToReplace
The text that was previously selected as replacement.
jEdit's text area component.
Classes for the script editor used within the editor to create and modify Python and Lua scripts.
final JButton replaceButton
JButton for ok.
Action listener for "replace".
JPanel createPanel()
Creates the text field panel.
boolean replace(@NotNull final JEditTextArea textArea)
Replace the next occurrence of textToFind with {}.
This package contains the other part of the script editor.
final JButton cancelButton
JButton for ok.
Base package of all Gridarta classes.
static final FindAgain FIND_AGAIN
The "find again" action listener.
static final long serialVersionUID
The serial version UID.
final JEditTextArea textArea
The text area to replace in.
static final ActionBuilder ACTION_BUILDER
Action Builder.
The replace dialog implementation.
An input handler converts the user's key strokes into concrete actions.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
JDialog dialog
The dialog.
A document implementation that can be tokenized by the syntax highlighting system.
final JTextComponent findTextField
Textfield for the text to find.
String getSelectedText()
Returns the selected text, or null if no selection is active.
ReplaceDialog(@NotNull final JEditTextArea textArea)
Creates a new instance.
void cancelButton()
Action method for cancel.
static void beginCompoundEdit()
Starts a compound edit that can be undone in one operation.
void actionPerformed(final ActionEvent e)
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
Actions used by the script editor.
static void endCompoundEdit()
Ends a compound edit that can be undone in one operation.
void setType(@NotNull final FindType type)
Sets the operation to perform.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
String textToFind
The text that was previously selected to find.
Utility class for ActionBuilder related functions.
final JTextComponent replaceTextField
Textfield for the text to replace with.
void replaceButton()
Action method for okay.