20 package net.sf.gridarta.gui.utils;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.event.FocusEvent;
27 import java.awt.event.FocusListener;
28 import javax.swing.AbstractButton;
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
35 import org.jetbrains.annotations.NotNull;
52 private final JTextField
textField =
new JTextField();
70 public FaceComponent(@NotNull
final String faceName, @NotNull
final FaceObjects faceObjects, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final ImageIcon noFaceSquareIcon, @NotNull
final ImageIcon unknownSquareIcon, @NotNull
final String tooltip) {
71 super(
new GridBagLayout());
73 textField.setText(faceName);
74 textField.setColumns(8);
75 final AbstractButton label =
new JButton();
76 label.setMargin(
new Insets(0, 0, 0, 0));
77 faceTreeChooseAction =
new FaceTreeChooseAction(
"...", textField, label, faceObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon);
78 label.addActionListener(faceTreeChooseAction);
79 final AbstractButton button =
new JButton(faceTreeChooseAction);
80 button.setMargin(
new Insets(0, 1, 0, 1));
81 textField.addFocusListener(
new FocusListener() {
84 public void focusGained(
final FocusEvent e) {
89 public void focusLost(
final FocusEvent e) {
94 final GridBagConstraints gbc =
new GridBagConstraints();
95 gbc.anchor = GridBagConstraints.CENTER;
96 gbc.gridx = GridBagConstraints.RELATIVE;
99 gbc.fill = GridBagConstraints.NONE;
103 gbc.fill = GridBagConstraints.HORIZONTAL;
107 gbc.fill = GridBagConstraints.NONE;
111 if (!tooltip.isEmpty()) {
112 label.setToolTipText(tooltip.replace(
"\n",
" "));
113 textField.setToolTipText(tooltip.replace(
"\n",
" "));
114 button.setToolTipText(tooltip.replace(
"\n",
" "));
124 return textField.getText();
132 textField.setText(faceName);
138 super.setEnabled(enabled);
139 textField.setEnabled(enabled);
void setEnabled(final boolean newValue)
A JPanel that allows the user to select a face name.
final void updateIconLabel()
Updates the icon of icon to reflect the current face name.
static final long serialVersionUID
The serial version UID.
FaceComponent(@NotNull final String faceName, @NotNull final FaceObjects faceObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon, @NotNull final String tooltip)
Creates a new instance.
Base package of all Gridarta classes.
void setEnabled(final boolean enabled)
final FaceTreeChooseAction faceTreeChooseAction
The associated FaceTreeChooseAction.
Component getInputComponent()
Returns the input field component.
FaceObjects is a container for FaceObjects.
A TreeChooseAction that updates a face label.
String getFaceName()
Returns the current face name.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
final JTextField textField
The JTextField that displays the face name.
void setFaceName(@NotNull final String faceName)
Sets the current face name.