Crossfire JXClient, Trunk  R20561
GUIRacesComboBox.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 GUIRacesComboBox 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  // ignore
68  }
69 
70  @Override
71  public void classInfoChanged(@NotNull final String className) {
72  // ignore
73  }
74 
75  @Override
76  public void raceListChanged() {
77  updateModel();
78  }
79 
80  @Override
81  public void raceInfoChanged(@NotNull final String raceName) {
83  }
84 
85  };
86 
95  public GUIRacesComboBox(@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 raceInfo = value == null ? null : model.getNewCharacterInformation().getRaceInfo(value);
127  renderer.setText(raceInfo == null ? value : raceInfo.getName());
128  return renderer;
129  }
130 
134  @NotNull
135  @Override
136  protected String getDescription(@NotNull final String item) {
137  final ClassRaceInfo classInfo = model.getNewCharacterInformation().getRaceInfo(item);
138  return classInfo == null ? "" : classInfo.getMsg();
139  }
140 
141 }
static final long serialVersionUID
The serial version UID.
A GUIComboBox that shows available races for character creation.
String getName()
Returns the human readable race name.
final JLabel renderer
The JLabel that displays the list values.
void addNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Registers a NewCharacterInformationListener to be notified of changes.
String getMsg()
Returns the long description.
Component getListCellRendererComponent(@NotNull final JList<? extends String > list, @Nullable final String value, final int index, final boolean selected, final boolean cellHasFocus)
A gui element implementing a static text field which may contain media tags.
final Model model
The Model to track for available races.
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.
final NewCharacterInformationListener newCharacterInformationListener
The NewCharacterInformationListener attached to model.
void updateSelectedItem()
Called whenever the selected item has changed.
Iterable< String > getRaceList()
Returns all defined races available for character creation.
void updateModel()
Updates the combo box model to reflect the current race list of model.
A GUIElement that displays a combo box.
One possible class or race for character creation.
GUIRacesComboBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Model model, @Nullable final GUILabelLog label)
Creates a new instance.
ClassRaceInfo getRaceInfo(@NotNull final String race)
Returns a ClassRaceInfo by race name.
Interface for listeners interested in NewCharacterInformation related events.
NewCharacterInformation getNewCharacterInformation()
Returns the NewCharacterInformation for creating new characters.
Definition: Model.java:163