20 package net.sf.gridarta.gui.dialog.bookmarks;
22 import java.awt.Component;
23 import javax.swing.Box;
24 import javax.swing.BoxLayout;
25 import javax.swing.JButton;
26 import javax.swing.JDialog;
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.JTextField;
30 import javax.swing.WindowConstants;
31 import javax.swing.event.DocumentEvent;
32 import javax.swing.event.DocumentListener;
33 import javax.swing.text.JTextComponent;
37 import net.
sf.japi.swing.action.ActionBuilder;
38 import net.
sf.japi.swing.action.ActionBuilderFactory;
39 import net.
sf.japi.swing.action.ActionMethod;
40 import org.jetbrains.annotations.NotNull;
57 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
78 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"editBookmarkOkay",
this));
85 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"editBookmarkCancel",
this));
92 public EditBookmarkDialog(@NotNull
final Component parentComponent, @NotNull
final String defaultDescription) {
93 okButton.setDefaultCapable(
true);
94 setOptions(
new Object[] {
okButton, cancelButton });
99 descriptionField.setText(defaultDescription);
101 final DocumentListener documentListener =
new DocumentListener() {
104 public void insertUpdate(@NotNull
final DocumentEvent e) {
109 public void removeUpdate(@NotNull
final DocumentEvent e) {
114 public void changedUpdate(@NotNull
final DocumentEvent e) {
119 descriptionField.getDocument().addDocumentListener(documentListener);
123 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
124 dialog.getRootPane().setDefaultButton(okButton);
126 dialog.setLocationRelativeTo(parentComponent);
134 dialog.setVisible(
true);
144 final JPanel mainPanel =
new JPanel();
145 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
150 mainPanel.add(Box.createVerticalStrut(5));
152 mainPanel.add(descriptionField);
153 mainPanel.add(Box.createVerticalStrut(5));
173 setValue(cancelButton);
182 return descriptionField.getText().trim();
String getDescription()
Returns the description.
boolean isOkEnabled()
Returns whether the "ok" button is enabled.
Graphical User Interface of Gridarta.
JPanel createPanel()
Creates the GUI.
void editBookmarkCancel()
Action method for cancel.
final JButton okButton
The JButton for ok.
static final long serialVersionUID
The serial Version UID.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Utility class for JTextComponent related functions.
A dialog that displays one bookmark and allows to edit the values.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
final JDialog dialog
The dialog.
final JButton cancelButton
The JButton for cancel.
boolean showDialog()
Opens the dialog.
Utility class for ActionBuilder related functions.
EditBookmarkDialog(@NotNull final Component parentComponent, @NotNull final String defaultDescription)
Creates a new instance.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
void editBookmarkOkay()
Action method for okay.
void updateOkButton()
Sets the enabled state of okButton depending on the contents of descriptionField. ...
final JTextComponent descriptionField
The text input field for the description.
Defines common UI constants used in different dialogs.