20 package net.sf.gridarta.gui.dialog.shortcuts;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import javax.swing.Action;
26 import javax.swing.JButton;
27 import javax.swing.JComponent;
28 import javax.swing.JDialog;
29 import javax.swing.JOptionPane;
30 import javax.swing.JPanel;
31 import javax.swing.JTextArea;
32 import javax.swing.KeyStroke;
33 import javax.swing.WindowConstants;
34 import javax.swing.border.TitledBorder;
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;
42 import org.jetbrains.annotations.Nullable;
59 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
79 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"keyStrokeOkay",
this));
86 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"keyStrokeCancel",
this));
120 okButton.setDefaultCapable(
true);
127 public void keyStrokeChanged(@NotNull
final KeyStroke keyStroke) {
132 keyStroke.addKeyStrokeListener(keyStrokeFieldListener);
134 conflictsTextArea.setEditable(
false);
135 conflictsTextArea.setLineWrap(
true);
136 conflictsTextArea.setWrapStyleWord(
true);
137 conflictsTextArea.setFocusable(
false);
138 conflictsTextArea.setRows(3);
143 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
144 dialog.getRootPane().setDefaultButton(okButton);
145 dialog.setModal(
true);
154 public boolean showDialog(@NotNull
final Component parentComponent) {
155 dialog.setLocationRelativeTo(parentComponent);
157 keyStroke.requestFocusInWindow();
158 setInitialValue(keyStroke);
159 dialog.setVisible(
true);
169 final GridBagConstraints gbc =
new GridBagConstraints();
171 final JComponent keyStrokePanel =
new JPanel(
new GridBagLayout());
175 gbc.fill = GridBagConstraints.HORIZONTAL;
177 keyStrokePanel.add(keyStroke, gbc);
179 final JComponent conflictsPanel =
new JPanel(
new GridBagLayout());
183 gbc.fill = GridBagConstraints.BOTH;
186 conflictsPanel.add(conflictsTextArea, gbc);
188 final JPanel panel =
new JPanel(
new GridBagLayout());
191 gbc.fill = GridBagConstraints.HORIZONTAL;
194 panel.add(keyStrokePanel, gbc);
196 gbc.fill = GridBagConstraints.BOTH;
198 panel.add(conflictsPanel, gbc);
221 public void setValue(@Nullable
final Object newValue) {
222 super.setValue(newValue);
223 if (newValue != UNINITIALIZED_VALUE) {
233 Action conflictAction = null;
234 if (newKeyStroke != null) {
235 for (
final Action tmp : shortcutsManager) {
238 if (newKeyStroke.equals(tmpKeyStroke)) {
239 conflictAction = tmp;
245 if (conflictAction == null) {
246 conflictsTextArea.setText(
"");
247 okButton.setEnabled(
true);
250 okButton.setEnabled(
false);
259 @SuppressWarnings(
"NullableProblems")
KeyStroke getKeyStroke()
Returns the currently shown key stroke.
final ShortcutsManager shortcutsManager
The ShortcutsManager for checking conflicts.
Graphical User Interface of Gridarta.
final JTextArea conflictsTextArea
The text area showing conflicts between the new key stroke and assigned key strokes.
boolean showDialog(@NotNull final Component parentComponent)
Opens the dialog.
static String getActionCategory(@NotNull final Action action)
Returns an Action's category.
Utility class implementing Action related functions.
KeyStrokeDialog(@NotNull final Component parentComponent, @NotNull final ShortcutsManager shortcutsManager, @NotNull final Action action)
Creates a new instance.
final JDialog dialog
The JDialog instance.
Interface for listeners interested in KeyStrokeField related events.
static final long serialVersionUID
The serial Version UID.
void updateKeyStroke()
Updates the information shown for the selected action.
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.
A dialog that asks for a KeyStroke.
JPanel createPanel()
Creates the GUI.
KeyStroke getKeyStroke()
Returns the currently shown KeyStroke.
final JButton cancelButton
The JButton for cancel.
final KeyStrokeField keyStroke
The key stroke input field.
Manager for shortcuts of all Actions in an ActionBuilder instance.
final JButton okButton
The JButton for ok.
void keyStrokeOkay()
Action method for okay.
A javax.swing.JComponent for selecting a KeyStroke.
static KeyStroke getShortcut(@NotNull final Action action)
Returns the shortcut of an Action.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
Utility class for ActionBuilder related functions.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static String getActionName(@NotNull final Action action)
Returns the name of an Action.
final Action action
The Action being redefined.
void setValue(@Nullable final Object newValue)
void keyStrokeCancel()
Action method for cancel.
Defines common UI constants used in different dialogs.