Gridarta Editor
AnimTreeChooseAction.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.event.ActionEvent;
23 import javax.swing.AbstractButton;
24 import javax.swing.Icon;
25 import javax.swing.ImageIcon;
26 import javax.swing.text.JTextComponent;
31 import org.jetbrains.annotations.NotNull;
32 
37 public class AnimTreeChooseAction extends TreeChooseAction {
38 
42  private static final long serialVersionUID = 1L;
43 
47  @NotNull
48  private final AbstractButton icon;
49 
53  @NotNull
55 
59  @NotNull
61 
65  @NotNull
66  private final ImageIcon noFaceSquareIcon;
67 
71  @NotNull
72  private final ImageIcon unknownSquareIcon;
73 
87  public AnimTreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final AbstractButton icon, @NotNull final AnimationObjects animationObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon) {
88  super(text, textComponent, animationObjects, faceObjectProviders);
89  this.icon = icon;
90  this.animationObjects = animationObjects;
91  this.faceObjectProviders = faceObjectProviders;
92  this.unknownSquareIcon = unknownSquareIcon;
93  this.noFaceSquareIcon = noFaceSquareIcon;
94 
95  final FaceObjectProvidersListener faceObjectProvidersListener = this::updateIconLabel;
96  faceObjectProviders.addFaceObjectProvidersListener(faceObjectProvidersListener);
97 
99  }
100 
101  @Override
102  public void actionPerformed(@NotNull final ActionEvent e) {
103  super.actionPerformed(e);
104  updateIconLabel();
105  }
106 
110  public final void updateIconLabel() {
111  final String animationName = getFaceName();
112  final Icon face;
113  if (animationName.isEmpty() || animationName.equals("NONE")) {
114  face = noFaceSquareIcon;
115  } else {
116  final NamedObject animationObject = animationObjects.get(animationName);
117  if (animationObject == null) {
118  face = unknownSquareIcon;
119  } else {
120  final Icon tmp = faceObjectProviders.getDisplayIcon(animationObject);
121  face = tmp == null ? unknownSquareIcon : tmp;
122  }
123  }
124  icon.setIcon(face);
125  }
126 
127  @NotNull
128  @Override
129  protected Object clone() {
130  return super.clone();
131  }
132 
133  @Override
134  public void setEnabled(final boolean newValue) {
135  super.setEnabled(newValue);
136  icon.setEnabled(newValue);
137  }
138 
139 }
The data package contains classes for handling data that is organized in a tree.
String getFaceName()
Returns the current face name.
void actionPerformed(@NotNull final ActionEvent e)
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
final void updateIconLabel()
Updates the icon of icon to reflect the current animation name.
final JTextComponent textComponent
The JTextComponent that holds the current face/animation name.
ImageIcon getDisplayIcon(@NotNull final NamedObject namedObject)
Returns the display icon for a NamedObject.
Base package of all Gridarta classes.
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
final ImageIcon noFaceSquareIcon
The ImageIcon for no animations.
AnimationObjects is a container for AnimationObjects.
final ImageIcon unknownSquareIcon
The ImageIcon for undefined animations.
final AbstractButton icon
The button showing the icon.
Action for choosing a face or animation.
A TreeChooseAction that updates an animation label.
Interface for listeners interested in FaceObjectProviders related events.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
AnimTreeChooseAction(@NotNull final String text, @NotNull final JTextComponent textComponent, @NotNull final AbstractButton icon, @NotNull final AnimationObjects animationObjects, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon)
Create a TreeChooseAction.
static final long serialVersionUID
The serial version UID.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
final AnimationObjects animationObjects
The AnimationObjects to select from.