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;
38 import net.
sf.japi.swing.action.ActionBuilder;
39 import net.
sf.japi.swing.action.ActionBuilderFactory;
40 import net.
sf.japi.swing.action.ActionMethod;
41 import org.jetbrains.annotations.NotNull;
58 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
79 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"bookmarkDirectoryOkay",
this));
86 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"bookmarkDirectoryCancel",
this));
94 okButton.setDefaultCapable(
true);
95 setOptions(
new Object[] {
okButton, cancelButton });
100 directoryField.setText(defaultDirectory);
102 final DocumentListener documentListener =
new DocumentListener() {
105 public void insertUpdate(@NotNull
final DocumentEvent e) {
110 public void removeUpdate(@NotNull
final DocumentEvent e) {
115 public void changedUpdate(@NotNull
final DocumentEvent e) {
120 directoryField.getDocument().addDocumentListener(documentListener);
124 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
125 dialog.getRootPane().setDefaultButton(okButton);
127 dialog.setLocationRelativeTo(parentComponent);
135 dialog.setVisible(
true);
145 final JPanel mainPanel =
new JPanel();
146 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
151 mainPanel.add(Box.createVerticalStrut(5));
153 mainPanel.add(directoryField);
154 mainPanel.add(Box.createVerticalStrut(5));
174 setValue(cancelButton);
183 return directoryField.getText().trim();
Graphical User Interface of Gridarta.
BookmarkDirectoryDialog(@NotNull final Component parentComponent, @NotNull final String defaultDirectory)
Creates a new instance.
boolean isOkEnabled()
Returns whether the "ok" button is enabled.
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.
final JDialog dialog
The dialog.
void bookmarkDirectoryCancel()
Action method for cancel.
static final long serialVersionUID
The serial Version UID.
final JButton cancelButton
The JButton for cancel.
boolean showDialog()
Opens the dialog.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
final JTextComponent directoryField
The text input field for the directory name.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
Utility class for ActionBuilder related functions.
A dialog that queries a bookmark directory name.
JPanel createPanel()
Creates the GUI.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
void bookmarkDirectoryOkay()
Action method for okay.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
String getDirectory()
Returns the directory name.
final JButton okButton
The JButton for ok.
Defines common UI constants used in different dialogs.
void updateOkButton()
Sets the enabled state of okButton depending on the contents of directoryField.