Gridarta Editor
AnimationComponent.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 AnimationComponent extends JPanel {
42 
46  private static final long serialVersionUID = 1L;
47 
51  @NotNull
52  private final JTextField textField = new JTextField();
53 
57  @NotNull
59 
69  public AnimationComponent(@NotNull final String animationName, @NotNull final AnimationObjects animationObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon) {
70  super(new GridBagLayout());
71 
72  textField.setText(animationName);
73  textField.setColumns(8);
74  final AbstractButton label = new JButton();
75  label.setMargin(new Insets(0, 0, 0, 0));
76  animTreeChooseAction = new AnimTreeChooseAction("...", textField, label, animationObjects, faceObjectProviders, noFaceSquareIcon, unknownSquareIcon);
77  label.addActionListener(animTreeChooseAction);
78  final AbstractButton button = new JButton(animTreeChooseAction);
79  button.setMargin(new Insets(0, 1, 0, 1));
80  textField.addFocusListener(new FocusListener() {
81 
82  @Override
83  public void focusGained(final FocusEvent e) {
84  // ignore
85  }
86 
87  @Override
88  public void focusLost(final FocusEvent e) {
90  }
91  });
92 
93  final GridBagConstraints gbc = new GridBagConstraints();
94  gbc.anchor = GridBagConstraints.CENTER;
95  gbc.gridx = GridBagConstraints.RELATIVE;
96  gbc.ipadx = 2;
97 
98  gbc.fill = GridBagConstraints.NONE;
99  gbc.weightx = 0.0;
100  add(label, gbc);
101 
102  gbc.fill = GridBagConstraints.HORIZONTAL;
103  gbc.weightx = 1.0;
104  add(textField, gbc);
105 
106  gbc.fill = GridBagConstraints.NONE;
107  gbc.weightx = 0.0;
108  add(button, gbc);
109  }
110 
115  @NotNull
116  public String getAnimName() {
117  return textField.getText();
118  }
119 
124  public void setAnimName(@NotNull final String animName) {
125  textField.setText(animName);
127  }
128 
129  @Override
130  public void setEnabled(final boolean enabled) {
131  super.setEnabled(enabled);
132  textField.setEnabled(enabled);
134  }
135 
140  @NotNull
141  public Component getInputComponent() {
142  return textField;
143  }
144 
145 }
net.sf.gridarta.gui.utils.AnimationComponent.setEnabled
void setEnabled(final boolean enabled)
Definition: AnimationComponent.java:130
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.anim.AnimationObjects
AnimationObjects is a container for AnimationObjects.
Definition: AnimationObjects.java:30
net.sf.gridarta.gui.utils.AnimationComponent.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: AnimationComponent.java:46
net.sf
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.gui.utils.AnimationComponent.AnimationComponent
AnimationComponent(@NotNull final String animationName, @NotNull final AnimationObjects animationObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon)
Creates a new instance.
Definition: AnimationComponent.java:69
net.sf.gridarta.gui.utils.AnimationComponent
A JPanel that allows the user to select an animation name.
Definition: AnimationComponent.java:41
net
net.sf.gridarta.gui.utils.AnimationComponent.getAnimName
String getAnimName()
Returns the current animation name.
Definition: AnimationComponent.java:116
net.sf.gridarta.gui.utils.AnimationComponent.setAnimName
void setAnimName(@NotNull final String animName)
Sets the current animation name.
Definition: AnimationComponent.java:124
net.sf.gridarta.gui.utils.AnimTreeChooseAction.setEnabled
void setEnabled(final boolean newValue)
Definition: AnimTreeChooseAction.java:134
net.sf.gridarta.gui.utils.AnimTreeChooseAction.updateIconLabel
final void updateIconLabel()
Updates the icon of icon to reflect the current animation name.
Definition: AnimTreeChooseAction.java:110
net.sf.gridarta.gui.utils.AnimationComponent.animTreeChooseAction
final AnimTreeChooseAction animTreeChooseAction
The associated AnimTreeChooseAction.
Definition: AnimationComponent.java:58
net.sf.gridarta.model
net.sf.gridarta.gui.utils.AnimationComponent.textField
final JTextField textField
The JTextField that displays the animation name.
Definition: AnimationComponent.java:52
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.anim
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Definition: AbstractAnimationObjects.java:20
net.sf.gridarta.gui.utils.AnimationComponent.getInputComponent
Component getInputComponent()
Returns the input field component.
Definition: AnimationComponent.java:141
net.sf.gridarta.gui.utils.AnimTreeChooseAction
A TreeChooseAction that updates an animation label.
Definition: AnimTreeChooseAction.java:37