Crossfire JXClient, Trunk
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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.combobox;
24 
34 import java.awt.Component;
35 import java.util.ArrayList;
36 import java.util.List;
37 import javax.swing.JLabel;
38 import javax.swing.JList;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
41 
46 public class GUIClassesComboBox extends GUIComboBox<String> {
47 
51  private static final long serialVersionUID = 1L;
52 
56  @NotNull
57  private final Model model;
58 
62  @NotNull
63  private final NewCharModel newCharModel;
64 
68  @NotNull
69  private final JLabel renderer = new JLabel();
70 
74  @NotNull
76 
77  @Override
78  public void classListChanged() {
79  updateModel();
80  }
81 
82  @Override
83  public void classInfoChanged(@NotNull final String className) {
84  updateModel();
85  }
86 
87  @Override
88  public void raceListChanged() {
89  // ignore
90  }
91 
92  @Override
93  public void raceInfoChanged(@NotNull final String raceName) {
94  // ignore
95  }
96 
97  @Override
98  public void startingMapListChanged() {
99  // ignore
100  }
101 
102  @Override
103  public void startingMapInfoChanged(@NotNull final String startingMapName) {
104  // ignore
105  }
106 
107  };
108 
112  @NotNull
114 
115  @Override
116  public void changed() {
118  }
119 
120  };
121 
132  public GUIClassesComboBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Model model, @NotNull final NewCharModel newCharModel, @Nullable final GUILabelLog label, @NotNull final GuiFactory guiFactory) {
133  super(tooltipManager, elementListener, name, label, guiFactory);
134  this.model = model;
135  this.newCharModel = newCharModel;
138  updateModel();
140  }
141 
142  @Override
143  public void dispose() {
144  super.dispose();
147  }
148 
149  @Override
150  public void notifyOpen() {
151  }
152 
157  private void updateModel() {
158  final List<String> tmp = new ArrayList<>(model.getNewCharacterInformation().getClassesList());
159  tmp.sort((o1, o2) -> {
160  final ClassRaceInfo info1 = model.getNewCharacterInformation().getClassInfo(o1);
161  final ClassRaceInfo info2 = model.getNewCharacterInformation().getClassInfo(o2);
162  return info1 == null || info2 == null ? 0 : info1.getName().compareTo(info2.getName());
163  });
164  updateModel(tmp);
166  }
167 
168  @NotNull
169  @Override
170  protected Component getListCellRendererComponent(@NotNull final JList<? extends String> list, @Nullable final String value, final int index, final boolean selected, final boolean cellHasFocus) {
171  final ClassRaceInfo classInfo = value == null ? null : model.getNewCharacterInformation().getClassInfo(value);
172  renderer.setText(classInfo == null ? value : classInfo.getName());
173  return renderer;
174  }
175 
176  @Override
177  protected void updateSelectedItem(@Nullable final String item) {
178  if (item != null) {
179  newCharModel.setClass(item);
180  }
181  }
182 
183  @NotNull
184  @Override
185  protected String getDescription(@Nullable final String item) {
186  final ClassRaceInfo classInfo = item == null ? null : model.getNewCharacterInformation().getClassInfo(item);
187  return classInfo == null ? "" : classInfo.getMsg();
188  }
189 
190 }
com.realtime.crossfire.jxclient.gui.label.NewCharModel.getClass_
String getClass_()
Definition: NewCharModel.java:267
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin
Definition: DefaultJXCSkin.java:23
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.notifyOpen
void notifyOpen()
Definition: GUIClassesComboBox.java:150
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.newCharacterInformationListener
final NewCharacterInformationListener newCharacterInformationListener
Definition: GUIClassesComboBox.java:75
com.realtime.crossfire.jxclient.character.NewCharacterInformationListener
Definition: NewCharacterInformationListener.java:33
com.realtime.crossfire.jxclient.server.crossfire.Model.getNewCharacterInformation
NewCharacterInformation getNewCharacterInformation()
Definition: Model.java:156
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.updateSelectedItem
void updateSelectedItem(@Nullable final String item)
Definition: GUIClassesComboBox.java:177
com.realtime.crossfire.jxclient.gui.label.NewCharModelListener
Definition: NewCharModelListener.java:30
com.realtime.crossfire.jxclient.character.ClassRaceInfo.getMsg
String getMsg()
Definition: ClassRaceInfo.java:108
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.getDescription
String getDescription(@Nullable final String item)
Definition: GUIClassesComboBox.java:185
com.realtime.crossfire.jxclient.character.NewCharacterInformation.getClassesList
List< String > getClassesList()
Definition: NewCharacterInformation.java:214
com.realtime.crossfire.jxclient.gui.combobox.GUIComboBox< String >::setSelectedItem
void setSelectedItem( @NotNull final T item)
Definition: GUIComboBox.java:221
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
com.realtime.crossfire.jxclient.gui.label.NewCharModel.addListener
void addListener(@NotNull final NewCharModelListener listener)
Definition: NewCharModel.java:208
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.gui.log.GUILabelLog
Definition: GUILabelLog.java:38
com.realtime.crossfire.jxclient.gui.log
Definition: Buffer.java:23
com.realtime.crossfire.jxclient.gui.combobox.GUIComboBox
Definition: GUIComboBox.java:50
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.model
final Model model
Definition: GUIClassesComboBox.java:57
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.newCharModelListener
final NewCharModelListener newCharModelListener
Definition: GUIClassesComboBox.java:113
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.getListCellRendererComponent
Component getListCellRendererComponent(@NotNull final JList<? extends String > list, @Nullable final String value, final int index, final boolean selected, final boolean cellHasFocus)
Definition: GUIClassesComboBox.java:170
com.realtime.crossfire.jxclient.character.ClassRaceInfo
Definition: ClassRaceInfo.java:37
com.realtime.crossfire.jxclient.gui.combobox.GUIComboBox< String >::updateSelectedItem
void updateSelectedItem()
Definition: GUIComboBox.java:195
com.realtime.crossfire.jxclient.server.crossfire.Model
Definition: Model.java:43
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.newCharModel
final NewCharModel newCharModel
Definition: GUIClassesComboBox.java:63
com.realtime.crossfire.jxclient.gui.combobox.GUIComboBox< String >::label
final GUILabelLog label
Definition: GUIComboBox.java:79
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.character.NewCharacterInformation.removeNewCharacterInformationListener
void removeNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Definition: NewCharacterInformation.java:103
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.renderer
final JLabel renderer
Definition: GUIClassesComboBox.java:69
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.gui.gui.TooltipManager
Definition: TooltipManager.java:33
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.updateModel
void updateModel()
Definition: GUIClassesComboBox.java:157
com.realtime.crossfire.jxclient.character.NewCharacterInformation.getClassInfo
ClassRaceInfo getClassInfo(@NotNull final String className)
Definition: NewCharacterInformation.java:236
com.realtime.crossfire.jxclient.gui.label.NewCharModel
Definition: NewCharModel.java:43
com.realtime.crossfire.jxclient.character.ClassRaceInfo.getName
String getName()
Definition: ClassRaceInfo.java:99
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire
com.realtime
com.realtime.crossfire.jxclient.gui.label.NewCharModel.setClass
void setClass(@NotNull final String class_)
Definition: NewCharModel.java:275
com
com.realtime.crossfire.jxclient.character
Definition: Choice.java:23
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox
Definition: GUIClassesComboBox.java:46
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.dispose
void dispose()
Definition: GUIClassesComboBox.java:143
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.serialVersionUID
static final long serialVersionUID
Definition: GUIClassesComboBox.java:51
com.realtime.crossfire.jxclient.character.NewCharacterInformation.addNewCharacterInformationListener
void addNewCharacterInformationListener(@NotNull final NewCharacterInformationListener newCharacterInformationListener)
Definition: NewCharacterInformation.java:94
com.realtime.crossfire.jxclient.gui.combobox.GUIClassesComboBox.GUIClassesComboBox
GUIClassesComboBox(@NotNull final TooltipManager tooltipManager, @NotNull final GUIElementListener elementListener, @NotNull final String name, @NotNull final Model model, @NotNull final NewCharModel newCharModel, @Nullable final GUILabelLog label, @NotNull final GuiFactory guiFactory)
Definition: GUIClassesComboBox.java:132
com.realtime.crossfire.jxclient.gui.label.NewCharModel.removeListener
void removeListener(@NotNull final NewCharModelListener listener)
Definition: NewCharModel.java:216
com.realtime.crossfire.jxclient.gui.gui.GUIElementListener
Definition: GUIElementListener.java:32