Gridarta Editor
FaceComponent.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.utils;
21 
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;
36 
41 public class FaceComponent extends JPanel {
42 
46  private static final long serialVersionUID = 1L;
47 
51  @NotNull
52  private final JTextField textField = new JTextField();
53 
57  @NotNull
59 
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());
72 
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() {
82 
83  @Override
84  public void focusGained(final FocusEvent e) {
85  // ignore
86  }
87 
88  @Override
89  public void focusLost(final FocusEvent e) {
91  }
92  });
93 
94  final GridBagConstraints gbc = new GridBagConstraints();
95  gbc.anchor = GridBagConstraints.CENTER;
96  gbc.gridx = GridBagConstraints.RELATIVE;
97  gbc.ipadx = 2;
98 
99  gbc.fill = GridBagConstraints.NONE;
100  gbc.weightx = 0.0;
101  add(label, gbc);
102 
103  gbc.fill = GridBagConstraints.HORIZONTAL;
104  gbc.weightx = 1.0;
105  add(textField, gbc);
106 
107  gbc.fill = GridBagConstraints.NONE;
108  gbc.weightx = 0.0;
109  add(button, gbc);
110 
111  if (!tooltip.isEmpty()) {
112  label.setToolTipText(tooltip.replace("\n", " "));
113  textField.setToolTipText(tooltip.replace("\n", " "));
114  button.setToolTipText(tooltip.replace("\n", " "));
115  }
116  }
117 
122  @NotNull
123  public String getFaceName() {
124  return textField.getText();
125  }
126 
131  public void setFaceName(@NotNull final String faceName) {
132  textField.setText(faceName);
134  }
135 
136  @Override
137  public void setEnabled(final boolean enabled) {
138  super.setEnabled(enabled);
139  textField.setEnabled(enabled);
141  }
142 
147  @NotNull
148  public Component getInputComponent() {
149  return textField;
150  }
151 
152 }
net.sf.gridarta.gui.utils.FaceComponent.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: FaceComponent.java:46
net.sf.gridarta.gui.utils.FaceComponent
A JPanel that allows the user to select a face name.
Definition: FaceComponent.java:41
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.utils.FaceTreeChooseAction
A TreeChooseAction that updates a face label.
Definition: FaceTreeChooseAction.java:37
net.sf.gridarta.gui.utils.FaceComponent.textField
final JTextField textField
The JTextField that displays the face name.
Definition: FaceComponent.java:52
net.sf
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.gui.utils.FaceComponent.setEnabled
void setEnabled(final boolean enabled)
Definition: FaceComponent.java:137
net
net.sf.gridarta.gui.utils.FaceComponent.setFaceName
void setFaceName(@NotNull final String faceName)
Sets the current face name.
Definition: FaceComponent.java:131
net.sf.gridarta.gui.utils.FaceComponent.getFaceName
String getFaceName()
Returns the current face name.
Definition: FaceComponent.java:123
net.sf.gridarta.model.face.FaceObjects
FaceObjects is a container for FaceObjects.
Definition: FaceObjects.java:31
net.sf.gridarta.model
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.gui.utils.FaceComponent.getInputComponent
Component getInputComponent()
Returns the input field component.
Definition: FaceComponent.java:148
net.sf.gridarta.gui.utils.FaceTreeChooseAction.setEnabled
void setEnabled(final boolean newValue)
Definition: FaceTreeChooseAction.java:120
net.sf.gridarta.gui.utils.FaceTreeChooseAction.updateIconLabel
final void updateIconLabel()
Updates the icon of icon to reflect the current face name.
Definition: FaceTreeChooseAction.java:101
net.sf.gridarta.gui.utils.FaceComponent.FaceComponent
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.
Definition: FaceComponent.java:70
net.sf.gridarta.gui.utils.FaceComponent.faceTreeChooseAction
final FaceTreeChooseAction faceTreeChooseAction
The associated FaceTreeChooseAction.
Definition: FaceComponent.java:58