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-2015 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) {
89  animTreeChooseAction.updateIconLabel();
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);
126  animTreeChooseAction.updateIconLabel();
127  }
128 
129  @Override
130  public void setEnabled(final boolean enabled) {
131  super.setEnabled(enabled);
132  textField.setEnabled(enabled);
133  animTreeChooseAction.setEnabled(enabled);
134  }
135 
140  @NotNull
141  public Component getInputComponent() {
142  return textField;
143  }
144 
145 }
void setAnimName(@NotNull final String animName)
Sets the current animation name.
Component getInputComponent()
Returns the input field component.
A JPanel that allows the user to select an animation name.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
String getAnimName()
Returns the current animation name.
final void updateIconLabel()
Updates the icon of icon to reflect the current animation name.
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.
Base package of all Gridarta classes.
AnimationObjects is a container for AnimationObjects.
final JTextField textField
The JTextField that displays the animation name.
A TreeChooseAction that updates an animation label.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
final AnimTreeChooseAction animTreeChooseAction
The associated AnimTreeChooseAction.
static final long serialVersionUID
The serial version UID.