Crossfire JXClient, Trunk  R20561
GUIClassesComboBox.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.combobox;
23 
30 import java.awt.Component;
31 import javax.swing.JLabel;
32 import javax.swing.JList;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
40 public class GUIClassesComboBox extends GUIComboBox<String> {
41 
45  private static final long serialVersionUID = 1L;
46 
50  @NotNull
51  private final Model model;
52 
56  @NotNull
57  private final JLabel renderer = new JLabel();
58 
62  @NotNull
64 
65  @Override
66  public void classListChanged() {
67  updateModel();
68  }
69 
70  @Override
71  public void classInfoChanged(@NotNull final String className) {
73  }
74 
75  @Override
76  public void raceListChanged() {
77  // ignore
78  }
79 
80  @Override
81  public void raceInfoChanged(@NotNull final String raceName) {
82  // ignore
83  }
84 
85  };
86 
95  public GUIClassesComboBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Model model, @Nullable final GUILabelLog label) {
96  super(tooltipManager, elementListener, name, label);
97  this.model = model;
98  model.getNewCharacterInformation().addNewCharacterInformationListener(newCharacterInformationListener);
99  updateModel();
100  }
101 
105  @Override
106  public void dispose() {
107  super.dispose();
108  model.getNewCharacterInformation().removeNewCharacterInformationListener(newCharacterInformationListener);
109  }
110 
115  private void updateModel() {
118  }
119 
123  @NotNull
124  @Override
125  protected Component getListCellRendererComponent(@NotNull final JList<? extends String> list, @Nullable final String value, final int index, final boolean selected, final boolean cellHasFocus) {
126  final ClassRaceInfo classInfo = value == null ? null : model.getNewCharacterInformation().getClassInfo(value);
127  renderer.setText(classInfo == null ? value : classInfo.getName());
128  return renderer;
129  }
130 
134  @NotNull
135  @Override
136  protected String getDescription(@NotNull final String item) {
137  final ClassRaceInfo classInfo = model.getNewCharacterInformation().getClassInfo(item);
138  return classInfo == null ? "" : classInfo.getMsg();
139  }
140 
141 }
Iterable< String > getClassesList()
Returns all defined classes available for character creation.
String getName()
Returns the human readable race name.
GUIClassesComboBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Model model, @Nullable final GUILabelLog label)
Creates a new instance.
void addNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Registers a NewCharacterInformationListener to be notified of changes.
String getMsg()
Returns the long description.
A gui element implementing a static text field which may contain media tags.
Combines all model classes that are updated.
Definition: Model.java:44
void removeNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Unregisters a NewCharacterInformationListener not to be notified of changes.
void updateModel()
Updates the combo box model to reflect the current class list of model.
A GUIComboBox that shows available classes for character creation.
void updateSelectedItem()
Called whenever the selected item has changed.
A GUIElement that displays a combo box.
One possible class or race for character creation.
ClassRaceInfo getClassInfo(@NotNull final String className)
Returns a class info by class name.
final NewCharacterInformationListener newCharacterInformationListener
The NewCharacterInformationListener attached to model.
Component getListCellRendererComponent(@NotNull final JList<? extends String > list, @Nullable final String value, final int index, final boolean selected, final boolean cellHasFocus)
Interface for listeners interested in NewCharacterInformation related events.
NewCharacterInformation getNewCharacterInformation()
Returns the NewCharacterInformation for creating new characters.
Definition: Model.java:163
final Model model
The Model to track for available classes.
final JLabel renderer
The JLabel that displays the list values.