Crossfire JXClient, Trunk  R20561
SkinLoader.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.main;
23 
50 import java.awt.Component;
51 import java.io.File;
52 import org.jetbrains.annotations.NotNull;
53 import org.jetbrains.annotations.Nullable;
54 
59 public class SkinLoader {
60 
64  @NotNull
66 
70  @NotNull
72 
76  @NotNull
78 
82  @NotNull
83  private final SmoothFaces smoothFaces;
84 
88  @NotNull
90 
94  @NotNull
96 
100  @Nullable
101  private final Resolution resolution;
102 
106  @NotNull
107  private final Macros macros;
108 
112  @NotNull
114 
118  @NotNull
120 
124  @NotNull
126 
130  @NotNull
132 
136  @NotNull
137  private final CommandQueue commandQueue;
138 
142  @NotNull
143  private final JXCSkinLoader skinLoader;
144 
148  @NotNull
150 
154  @NotNull
155  private final Shortcuts shortcuts;
156 
175  public SkinLoader(@NotNull final CommandCallback commandCallback, @NotNull final MetaserverModel metaserverModel, @Nullable final Resolution resolution, @NotNull final Macros macros, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final CrossfireServerConnection server, @NotNull final GuiStateManager guiStateManager, @NotNull final TooltipManager tooltipManager, @NotNull final CommandQueue commandQueue, @NotNull final JXCSkinLoader skinLoader, @NotNull final CommandExecutor commandExecutor, @NotNull final Shortcuts shortcuts, @NotNull final CharacterModel characterModel, @NotNull final SmoothFaces smoothFaces, @NotNull final GUICommandFactory guiCommandFactory) {
176  this.commandCallback = commandCallback;
177  this.metaserverModel = metaserverModel;
178  this.resolution = resolution;
179  this.macros = macros;
180  this.windowRenderer = windowRenderer;
181  this.server = server;
182  this.guiStateManager = guiStateManager;
183  this.tooltipManager = tooltipManager;
184  this.commandQueue = commandQueue;
185  this.skinLoader = skinLoader;
186  this.commandExecutor = commandExecutor;
187  this.shortcuts = shortcuts;
188  this.characterModel = characterModel;
189  this.smoothFaces = smoothFaces;
190  this.guiCommandFactory = guiCommandFactory;
191  }
192 
199  @NotNull
200  public JXCSkin loadSkin(@NotNull final String skinName) throws JXCSkinException {
201  // check for skin in directory
202  final File dir = new File(skinName);
203  final JXCSkinSource skinSource = dir.exists() && dir.isDirectory() ? new JXCSkinDirSource(dir) : new JXCSkinClassSource("com/realtime/crossfire/jxclient/skins/"+skinName);
204  final GuiFactory guiFactory = new GuiFactory(guiCommandFactory);
205  final GUIElementListener elementListener = new GUIElementListener() {
206 
207  @Override
208  public void raiseDialog(@NotNull final Component component) {
209  final Gui gui = GuiUtils.getGui(component);
210  if (gui != null) {
211  windowRenderer.raiseDialog(gui);
212  }
213  }
214 
215  @Override
216  public void activeChanged(@NotNull final ActivatableGUIElement element, final boolean active) {
217  final Gui gui = GuiUtils.getGui(element);
218  if (gui != null) {
219  gui.setActiveElement(element, active);
220  }
221  }
222 
223  @Override
224  public boolean isActive(@NotNull final ActivatableGUIElement element) {
225  final Gui gui = GuiUtils.getGui(element);
226  return gui != null && gui.isActiveElement(element);
227  }
228 
229  };
230 
231  final JXCSkin skin = skinLoader.load(skinSource, server, guiStateManager, tooltipManager, windowRenderer, elementListener, metaserverModel, characterModel, commandQueue, shortcuts, commandExecutor, currentSpellManager, commandCallback, macros, guiFactory, smoothFaces);
232  if (resolution != null) {
233  if (skin.getMinResolution().getWidth() > resolution.getWidth() || skin.getMinResolution().getHeight() > resolution.getHeight()) {
234  throw new JXCSkinException("resolution "+resolution+" is not supported by this skin");
235  }
236  if (resolution.getWidth() > skin.getMaxResolution().getWidth() || resolution.getHeight() > skin.getMaxResolution().getHeight()) {
237  throw new JXCSkinException("resolution "+resolution+" is not supported by this skin");
238  }
239  }
240 
241  return skin;
242  }
243 
244 }
final JXCWindowRenderer windowRenderer
The JXCWindowRenderer for this window.
static Gui getGui(@NotNull final Component element)
Returns the Gui an element is part of.
Definition: GuiUtils.java:91
JXCSkin loadSkin(@NotNull final String skinName)
Loads a skin file.
Combines a list of GUIElements to for a gui.
Definition: Gui.java:43
JXCSkin load(@NotNull final JXCSkinSource skinSource, @NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final GuiStateManager guiStateManager, @NotNull final TooltipManager tooltipManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final GUIElementListener elementListener, @NotNull final MetaserverModel metaserverModel, @NotNull final CharacterModel characterModel, @NotNull final CommandQueue commandQueue, @NotNull final Shortcuts shortcuts, @NotNull final CommandExecutor commandExecutor, @NotNull final CurrentSpellManager currentSpellManager, @NotNull final CommandCallback commandCallback, @NotNull final Macros macros, @NotNull final GuiFactory guiFactory, @NotNull final SmoothFaces smoothFaces)
Loads the skin from its external representation.
final CommandQueue commandQueue
The CommandQueue instance.
final SmoothFaces smoothFaces
The SmoothFaces.
Definition: SkinLoader.java:83
boolean isActiveElement(@Nullable final ActivatableGUIElement activeElement)
Returns whether a given gui element is the active element of this dialog.
Definition: Gui.java:345
SkinLoader(@NotNull final CommandCallback commandCallback, @NotNull final MetaserverModel metaserverModel, @Nullable final Resolution resolution, @NotNull final Macros macros, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final CrossfireServerConnection server, @NotNull final GuiStateManager guiStateManager, @NotNull final TooltipManager tooltipManager, @NotNull final CommandQueue commandQueue, @NotNull final JXCSkinLoader skinLoader, @NotNull final CommandExecutor commandExecutor, @NotNull final Shortcuts shortcuts, @NotNull final CharacterModel characterModel, @NotNull final SmoothFaces smoothFaces, @NotNull final GUICommandFactory guiCommandFactory)
Creates a new instance.
Parser for loading JXCSkin instances from JXCSkinSources.
final CurrentSpellManager currentSpellManager
The CurrentSpellManager instance for this window.
Definition: SkinLoader.java:95
final Shortcuts shortcuts
The Shortcuts instance.
final JXCSkinLoader skinLoader
The JXCSkinLoader instance.
final CharacterModel characterModel
The CharacterModel instance for this window.
Definition: SkinLoader.java:77
Manages image information ("faces") needed to display the map view, items, and spell icons...
Resolution getMaxResolution()
Returns the maximal resolution of this skin.
int getWidth()
Returns the width in pixels.
Definition: Resolution.java:87
Defines a JXClient skin consisting of a main Gui and zero or more dialog Guis.
Definition: JXCSkin.java:40
int getHeight()
Returns the height in pixels.
Definition: Resolution.java:95
final CommandExecutor commandExecutor
The CommandExecutor instance.
Manages macro expansion in command strings.
Definition: Macros.java:37
A GUIElement that can be set to active or inactive.
final TooltipManager tooltipManager
The TooltipManager instance.
Factory for creating Gui instances.
Definition: GuiFactory.java:34
final MetaserverModel metaserverModel
The MetaserverModel instance for this window.
Definition: SkinLoader.java:71
void setActiveElement(@NotNull final ActivatableGUIElement activeElement, final boolean active)
Sets the gui element owning the focus.
Definition: Gui.java:303
Utility class for Gui related functions.
Definition: GuiUtils.java:35
Interface for providers of JXCSkin sources.
Interface that defines callback functions needed by commands.
Factory for creating GUICommand instances from string representation.
Maintains the character list for an account.
final CrossfireServerConnection server
The CrossfireServerConnection to use.
Exception thrown if a skin related problem occurs.
final Resolution resolution
The size of the client area.
final GuiStateManager guiStateManager
The GuiStateManager instance.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Maintains the pending (ncom) commands sent to the server.
Information about JXClient's screen/window resolution.
Definition: Resolution.java:35
Loader for JXCSkins and attaching them to the client.
Definition: SkinLoader.java:59
void raiseDialog(@NotNull final Gui dialog)
Raises an already opened dialog.
final Macros macros
The Macros instance.
final GUICommandFactory guiCommandFactory
The GUICommandFactory for creating commands.
Definition: SkinLoader.java:89
A JXCSkinSource that loads via the class loader.
final CommandCallback commandCallback
The CommandCallback instance.
Definition: SkinLoader.java:65
Maintains smoothing information received from the Crossfire server.
Resolution getMinResolution()
Returns the minimal resolution of this skin.