Crossfire JXClient, Trunk
DefaultJXCSkin.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.skin.skin;
24 
37 import java.util.ArrayList;
38 import java.util.Collection;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import org.jetbrains.annotations.NotNull;
42 import org.jetbrains.annotations.Nullable;
43 
48 public class DefaultJXCSkin implements JXCSkin {
49 
53  @NotNull
54  private String skinName = "unknown";
55 
59  @NotNull
60  private Resolution minResolution = new Resolution(1, 1);
61 
65  @NotNull
66  private Resolution maxResolution = new Resolution(1, 1);
67 
71  @NotNull
72  private final Collection<CommandList> initEvents = new ArrayList<>();
73 
77  @NotNull
78  private final JXCSkinCache<CommandList> definedCommandLists = new JXCSkinCache<>("command list");
79 
83  @NotNull
84  private final Collection<GUIElement> guiElements = new HashSet<>();
85 
89  @NotNull
90  private final Collection<SkinEvent> skinEvents = new HashSet<>();
91 
95  @NotNull
96  private final Dialogs dialogs;
97 
101  @NotNull
103 
107  @NotNull
109 
113  @NotNull
114  private final Collection<String> optionNames = new HashSet<>();
115 
119  @Nullable
121 
126  @Nullable
128 
135  public DefaultJXCSkin(@NotNull final KeyBindings defaultKeyBindings, @NotNull final OptionManager optionManager, @NotNull final Dialogs dialogs) {
136  this.defaultKeyBindings = defaultKeyBindings;
137  this.optionManager = optionManager;
138  this.dialogs = dialogs;
139  }
140 
141  @NotNull
142  @Override
143  public String getSkinName() {
144  return skinName;
145  }
146 
153  public void setSkinName(@NotNull final String skinName, @NotNull final Resolution minResolution, @NotNull final Resolution maxResolution) {
155  throw new IllegalArgumentException("minimum width must not exceed maximum width");
156  }
158  throw new IllegalArgumentException("minimum height must not exceed maximum height");
159  }
160 
161  this.skinName = skinName;
162  this.minResolution = minResolution;
163  this.maxResolution = maxResolution;
164  }
165 
166  @NotNull
167  @Override
169  return minResolution;
170  }
171 
172  @NotNull
173  @Override
175  return maxResolution;
176  }
177 
178  @Nullable
179  @Override
180  public Gui getDialogQuit() {
181  try {
182  return getDialog("quit");
183  } catch (final JXCSkinException ignored) {
184  return null;
185  }
186  }
187 
188  @Nullable
189  @Override
191  try {
192  return getDialog("disconnect");
193  } catch (final JXCSkinException ignored) {
194  return null;
195  }
196  }
197 
198  @Nullable
199  @Override
201  try {
202  return getDialog("connect");
203  } catch (final JXCSkinException ignored) {
204  return null;
205  }
206  }
207 
208  @NotNull
209  @Override
211  try {
212  return getDialog("keybind");
213  } catch (final JXCSkinException ex) {
214  final AssertionError error = new AssertionError("keybind dialog does not exist");
215  error.initCause(ex);
216  throw error;
217  }
218  }
219 
220  @NotNull
221  @Override
222  public Gui getDialogQuery() {
223  try {
224  return getDialog("query");
225  } catch (final JXCSkinException ex) {
226  final AssertionError error = new AssertionError("query dialog does not exist");
227  error.initCause(ex);
228  throw error;
229  }
230  }
231 
232  @NotNull
233  @Override
234  public Gui getDialogBook(final int bookNo) {
235  try {
236  return getDialog("book");
237  } catch (final JXCSkinException ex) {
238  final AssertionError error = new AssertionError("book dialog does not exist");
239  error.initCause(ex);
240  throw error;
241  }
242  }
243 
244  @NotNull
245  @Override
247  try {
248  return getDialog("main");
249  } catch (final JXCSkinException ex) {
250  final AssertionError error = new AssertionError("main dialog does not exist");
251  error.initCause(ex);
252  throw error;
253  }
254  }
255 
256  @NotNull
257  @Override
259  try {
260  return getDialog("meta");
261  } catch (final JXCSkinException ex) {
262  final AssertionError error = new AssertionError("meta dialog does not exist");
263  error.initCause(ex);
264  throw error;
265  }
266  }
267 
268  @NotNull
269  @Override
271  try {
272  return getDialog("start");
273  } catch (final JXCSkinException ex) {
274  final AssertionError error = new AssertionError("start dialog does not exist");
275  error.initCause(ex);
276  throw error;
277  }
278  }
279 
280  @NotNull
281  @Override
282  public Gui getDialog(@NotNull final String name) throws JXCSkinException {
283  return dialogs.lookup(name);
284  }
285 
286  @NotNull
287  @Override
288  public Iterator<Gui> iterator() {
289  return dialogs.iterator();
290  }
291 
292  @NotNull
293  @Override
294  public CommandList getCommandList(@NotNull final String name) throws JXCSkinException {
295  return definedCommandLists.lookup(name);
296  }
297 
298  @NotNull
299  @Override
300  public Collection<String> getCommandListNames() {
301  return definedCommandLists.getNames();
302  }
303 
304  @NotNull
305  @Override
307  return defaultKeyBindings;
308  }
309 
310  @Override
311  public void attach(@NotNull final TooltipManagerImpl tooltipManager) {
312  //noinspection VariableNotUsedInsideIf
313  if (this.tooltipManager != null) {
314  throw new IllegalStateException("skin is already attached");
315  }
316 
317  this.tooltipManager = tooltipManager;
319 
321  }
322 
323  @Override
324  public void detach() {
325  final TooltipManagerImpl tmpTooltipManager = tooltipManager;
326  tooltipManager = null;
327  if (tmpTooltipManager != null) {
328  tmpTooltipManager.setTooltip(null);
329  }
330 
331  optionNames.forEach(optionManager::removeOption);
332  optionNames.clear();
335  guiElements.clear();
336  }
337 
342  public void insertGuiElement(@NotNull final GUIElement guiElement) {
343  guiElements.add(guiElement);
344  }
345 
350  public void addDialog(@NotNull final String dialogName) {
351  dialogs.addDialog(dialogName);
352  }
353 
358  @Nullable
359  public String getDialogToLoad() {
360  return dialogs.getDialogToLoad();
361  }
362 
369  public void addCommandList(@NotNull final String commandListName, @NotNull final CommandListType commandListType) throws JXCSkinException {
370  final CommandList commandList = new CommandList(commandListType);
371  definedCommandLists.insert(commandListName, commandList);
372  }
373 
378  public void addInitEvent(@NotNull final CommandList commandList) {
379  initEvents.add(commandList);
380  }
381 
389  public void addOption(@NotNull final String optionName, @NotNull final String documentation, @NotNull final Option commandCheckBoxOption) throws JXCSkinException {
390  try {
391  optionManager.addOption(optionName, documentation, commandCheckBoxOption);
392  } catch (final OptionException ex) {
393  throw new JXCSkinException(ex.getMessage(), ex);
394  }
395  optionNames.add(optionName);
396  }
397 
402  public void setTooltipLabel(@Nullable final AbstractLabel tooltipLabel) {
403  this.tooltipLabel = tooltipLabel;
404  }
405 
406  @Nullable
407  @Override
409  return tooltipLabel;
410  }
411 
416  public void addSkinEvent(@NotNull final SkinEvent skinEvent) {
417  skinEvents.add(skinEvent);
418  }
419 
420 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.events.SkinEvent
Interface for events attached to skins.
Definition: SkinEvent.java:29
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialog
Gui getDialog(@NotNull final String name)
Returns a dialog by name.
Definition: DefaultJXCSkin.java:282
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogConnect
Gui getDialogConnect()
Returns the "connection in progress" dialog.
Definition: DefaultJXCSkin.java:200
com.realtime.crossfire.jxclient.gui.label.TooltipManagerImpl.setTooltip
void setTooltip(@Nullable final AbstractLabel tooltip)
Sets the tooltip label.
Definition: TooltipManagerImpl.java:108
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.addOption
void addOption(@NotNull final String optionName, @NotNull final String documentation, @NotNull final Option commandCheckBoxOption)
Add a new option.
Definition: DefaultJXCSkin.java:389
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.minResolution
Resolution minResolution
The minimal resolution.
Definition: DefaultJXCSkin.java:60
com.realtime.crossfire.jxclient.gui.gui.Gui
Combines a list of GUIElements to for a gui.
Definition: Gui.java:49
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.skinName
String skinName
The skin name.
Definition: DefaultJXCSkin.java:54
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getTooltipLabel
AbstractLabel getTooltipLabel()
Returns the AbstractLabel that is used to display tooltips.
Definition: DefaultJXCSkin.java:408
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogKeyBind
Gui getDialogKeyBind()
Returns the key bindings dialog.
Definition: DefaultJXCSkin.java:210
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.optionNames
final Collection< String > optionNames
The defined option names.
Definition: DefaultJXCSkin.java:114
com.realtime.crossfire.jxclient.skin
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.defaultKeyBindings
final KeyBindings defaultKeyBindings
The default key bindings.
Definition: DefaultJXCSkin.java:102
com.realtime.crossfire.jxclient.settings.options.OptionManager.addOption
void addOption(@NotNull final String optionName, @NotNull final String documentation, @NotNull final Option option)
Adds a new option.
Definition: OptionManager.java:65
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.definedCommandLists
final JXCSkinCache< CommandList > definedCommandLists
All defined command lists.
Definition: DefaultJXCSkin.java:78
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.tooltipLabel
AbstractLabel tooltipLabel
The tooltip label or.
Definition: DefaultJXCSkin.java:120
com.realtime.crossfire.jxclient.skin.skin.Dialogs.iterator
Iterator< Gui > iterator()
Definition: Dialogs.java:123
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.optionManager
final OptionManager optionManager
The OptionManager to use.
Definition: DefaultJXCSkin.java:108
com.realtime.crossfire.jxclient.gui.commandlist.CommandListType
The command list type.
Definition: CommandListType.java:29
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getSkinName
String getSkinName()
Returns a short name for the skin.
Definition: DefaultJXCSkin.java:143
com.realtime.crossfire.jxclient.gui.label
Definition: AbstractLabel.java:23
com.realtime.crossfire.jxclient.gui.label.AbstractLabel
Abstract base class for all label classes.
Definition: AbstractLabel.java:43
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getCommandList
CommandList getCommandList(@NotNull final String name)
Returns a named command list.
Definition: DefaultJXCSkin.java:294
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogBook
Gui getDialogBook(final int bookNo)
Returns the popup dialog for readables.
Definition: DefaultJXCSkin.java:234
com.realtime.crossfire.jxclient.gui.commandlist
Definition: CommandList.java:23
com.realtime.crossfire.jxclient.gui.label.TooltipManagerImpl
Manages the tooltip display.
Definition: TooltipManagerImpl.java:38
com.realtime.crossfire.jxclient.gui.gui.GUIElement.dispose
void dispose()
Releases all allocated resources.
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.insertGuiElement
void insertGuiElement(@NotNull final GUIElement guiElement)
Adds a new GUIElement to this skin.
Definition: DefaultJXCSkin.java:342
com.realtime.crossfire.jxclient.skin.skin.JXCSkinCache
Implements a cache for elements identified by name.
Definition: JXCSkinCache.java:40
com.realtime.crossfire.jxclient.gui.keybindings
Definition: InvalidKeyBindingException.java:23
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.setTooltipLabel
void setTooltipLabel(@Nullable final AbstractLabel tooltipLabel)
Sets the AbstractLabel that is used to display tooltips.
Definition: DefaultJXCSkin.java:402
com.realtime.crossfire.jxclient.skin.skin.Dialogs.addDialog
void addDialog(@NotNull final String name)
Creates a new dialog instance.
Definition: Dialogs.java:90
com.realtime.crossfire.jxclient.skin.skin.JXCSkinException
Exception thrown if a skin related problem occurs.
Definition: JXCSkinException.java:31
com.realtime.crossfire.jxclient.settings
Definition: CommandHistory.java:23
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.detach
void detach()
Frees all allocated resources.
Definition: DefaultJXCSkin.java:324
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.addDialog
void addDialog(@NotNull final String dialogName)
Defines a new dialog.
Definition: DefaultJXCSkin.java:350
com.realtime.crossfire.jxclient.gui.keybindings.KeyBindings
Manages a set of key bindings.
Definition: KeyBindings.java:47
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin
Default JXCSkin implementation.
Definition: DefaultJXCSkin.java:48
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.attach
void attach(@NotNull final TooltipManagerImpl tooltipManager)
Attaches this skin to a gui manager.
Definition: DefaultJXCSkin.java:311
com.realtime.crossfire.jxclient.skin.events
Definition: ConnectionStateSkinEvent.java:23
com.realtime.crossfire.jxclient.gui.gui.GUIElement
Interface defining an abstract GUI element.
Definition: GUIElement.java:33
com.realtime.crossfire.jxclient.util.Resolution.getHeight
int getHeight()
Returns the height in pixels.
Definition: Resolution.java:96
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.tooltipManager
TooltipManagerImpl tooltipManager
The TooltipManagerImpl currently attached to or.
Definition: DefaultJXCSkin.java:127
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.guiElements
final Collection< GUIElement > guiElements
All GUI elements.
Definition: DefaultJXCSkin.java:84
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogQuery
Gui getDialogQuery()
Returns the dialog for query text input.
Definition: DefaultJXCSkin.java:222
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogQuit
Gui getDialogQuit()
Returns the "really quit?" dialog.
Definition: DefaultJXCSkin.java:180
com.realtime.crossfire.jxclient.settings.options.OptionManager
Maintains a set of named options.
Definition: OptionManager.java:36
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.skinEvents
final Collection< SkinEvent > skinEvents
All SkinEvents attached to this instance.
Definition: DefaultJXCSkin.java:90
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.addCommandList
void addCommandList(@NotNull final String commandListName, @NotNull final CommandListType commandListType)
Defines a new command list.
Definition: DefaultJXCSkin.java:369
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.iterator
Iterator< Gui > iterator()
Returns all gui instances of this skin.
Definition: DefaultJXCSkin.java:288
com.realtime.crossfire.jxclient.skin.skin.Dialogs.lookup
Gui lookup(@NotNull final String name)
Returns a dialog instance by dialog name.
Definition: Dialogs.java:82
com.realtime.crossfire.jxclient.util.Resolution
Information about JXClient's screen/window resolution.
Definition: Resolution.java:36
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getCommandListNames
Collection< String > getCommandListNames()
Returns the names of all named command lists.
Definition: DefaultJXCSkin.java:300
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogDisconnect
Gui getDialogDisconnect()
Returns the "disconnect from server?" dialog.
Definition: DefaultJXCSkin.java:190
com.realtime.crossfire.jxclient.util
Definition: Codec.java:23
com.realtime.crossfire.jxclient.settings.options.Option
The base class for all options.
Definition: Option.java:33
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.maxResolution
Resolution maxResolution
The maximal resolution.
Definition: DefaultJXCSkin.java:66
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.addSkinEvent
void addSkinEvent(@NotNull final SkinEvent skinEvent)
Records a SkinEvent attached to this instance.
Definition: DefaultJXCSkin.java:416
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.addInitEvent
void addInitEvent(@NotNull final CommandList commandList)
Adds a command list to be executed on "init" events.
Definition: DefaultJXCSkin.java:378
com.realtime.crossfire.jxclient.gui.commandlist.CommandList.execute
void execute()
Execute the command list by calling GUICommand#execute() for each command in order.
Definition: CommandList.java:99
com.realtime.crossfire.jxclient.gui.commandlist.CommandList
A list of GUICommand instances.
Definition: CommandList.java:34
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getMetaInterface
Gui getMetaInterface()
Returns the server selection window.
Definition: DefaultJXCSkin.java:258
com.realtime.crossfire.jxclient.skin.skin.Dialogs
Maintains a set of Gui instances representing dialog windows.
Definition: Dialogs.java:39
com.realtime.crossfire
com.realtime.crossfire.jxclient.settings.options
Definition: CheckBoxOption.java:23
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.initEvents
final Collection< CommandList > initEvents
All "event init" commands in execution order.
Definition: DefaultJXCSkin.java:72
com.realtime
com.realtime.crossfire.jxclient.skin.skin.JXCSkin
Defines a JXClient skin consisting of a main Gui and zero or more dialog Guis.
Definition: JXCSkin.java:42
com
com.realtime.crossfire.jxclient.skin.events.SkinEvent.dispose
void dispose()
Will be called when the skin is disposed.
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getMaxResolution
Resolution getMaxResolution()
Returns the maximal resolution of this skin.
Definition: DefaultJXCSkin.java:174
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getMinResolution
Resolution getMinResolution()
Returns the minimal resolution of this skin.
Definition: DefaultJXCSkin.java:168
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getMainInterface
Gui getMainInterface()
Returns the main window.
Definition: DefaultJXCSkin.java:246
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDialogToLoad
String getDialogToLoad()
Returns one dialog pending loading.
Definition: DefaultJXCSkin.java:359
com.realtime.crossfire.jxclient.skin.skin.Dialogs.getDialogToLoad
String getDialogToLoad()
Returns one dialog pending loading.
Definition: Dialogs.java:110
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.dialogs
final Dialogs dialogs
All defined dialogs.
Definition: DefaultJXCSkin.java:96
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getStartInterface
Gui getStartInterface()
Returns the start window.
Definition: DefaultJXCSkin.java:270
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.setSkinName
void setSkinName(@NotNull final String skinName, @NotNull final Resolution minResolution, @NotNull final Resolution maxResolution)
Sets the skin name.
Definition: DefaultJXCSkin.java:153
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.DefaultJXCSkin
DefaultJXCSkin(@NotNull final KeyBindings defaultKeyBindings, @NotNull final OptionManager optionManager, @NotNull final Dialogs dialogs)
Creates a new instance.
Definition: DefaultJXCSkin.java:135
com.realtime.crossfire.jxclient.util.Resolution.getWidth
int getWidth()
Returns the width in pixels.
Definition: Resolution.java:88
com.realtime.crossfire.jxclient.settings.options.OptionException
Indicates about an incorrect option.
Definition: OptionException.java:31
com.realtime.crossfire.jxclient.skin.skin.DefaultJXCSkin.getDefaultKeyBindings
KeyBindings getDefaultKeyBindings()
Returns the default key bindings for this skin.
Definition: DefaultJXCSkin.java:306