Crossfire JXClient, Trunk  R20561
Dialogs.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.skin.skin;
23 
26 import java.util.Collection;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
38 public class Dialogs implements Iterable<Gui> {
39 
43  @NotNull
44  private final GuiFactory guiFactory;
45 
49  @NotNull
50  private final GuiManager guiManager;
51 
55  @NotNull
56  private final JXCSkinCache<Gui> dialogs = new JXCSkinCache<>("dialog");
57 
61  @NotNull
62  private final Collection<String> dialogsToLoad = new HashSet<>();
63 
69  public Dialogs(@NotNull final GuiFactory guiFactory, @NotNull final GuiManager guiManager) {
70  this.guiFactory = guiFactory;
71  this.guiManager = guiManager;
72  }
73 
80  @NotNull
81  public Gui lookup(@NotNull final String name) throws JXCSkinException {
82  return dialogs.lookup(name);
83  }
84 
90  @NotNull
91  public Gui addDialog(@NotNull final String name) {
92  try {
93  return dialogs.lookup(name);
94  } catch (final JXCSkinException ignored) {
95  final Gui gui = guiFactory.newGui();
96  try {
97  dialogs.insert(name, gui);
98  } catch (final JXCSkinException ex) {
99  throw new AssertionError(ex);
100  }
101  dialogsToLoad.add(name);
102  guiManager.addDialog(name, gui);
103  return gui;
104  }
105  }
106 
111  @Nullable
112  public String getDialogToLoad() {
113  final Iterator<String> it = dialogsToLoad.iterator();
114  if (!it.hasNext()) {
115  return null;
116  }
117 
118  final String result = it.next();
119  it.remove();
120  return result;
121  }
122 
126  @NotNull
127  @Override
128  public Iterator<Gui> iterator() {
129  return dialogs.iterator();
130  }
131 
132 }
String getDialogToLoad()
Returns one dialog pending loading.
Definition: Dialogs.java:112
final GuiFactory guiFactory
The GuiFactory for creating new Gui instances.
Definition: Dialogs.java:44
Combines a list of GUIElements to for a gui.
Definition: Gui.java:43
Gui addDialog(@NotNull final String name)
Creates a new dialog instance.
Definition: Dialogs.java:91
final GuiManager guiManager
The GuiManager to add dialogs to.
Definition: Dialogs.java:50
Dialogs(@NotNull final GuiFactory guiFactory, @NotNull final GuiManager guiManager)
Creates a new instance.
Definition: Dialogs.java:69
void addDialog(@NotNull final String name, @NotNull final Gui dialog)
Adds a dialog for name based lookup.
Iterator< T > iterator()
Returns all stored values.
Gui lookup(@NotNull final String name)
Returns a dialog instance by dialog name.
Definition: Dialogs.java:81
final Collection< String > dialogsToLoad
Names of pending skin files.
Definition: Dialogs.java:62
Factory for creating Gui instances.
Definition: GuiFactory.java:34
void insert(@NotNull final String name, @NotNull final T t)
Adds a new element to the cache.
Maintains the application&#39;s main GUI state.
Definition: GuiManager.java:60
Gui newGui()
Creates a new Gui instance.
Definition: GuiFactory.java:54
final JXCSkinCache< Gui > dialogs
The existing dialogs.
Definition: Dialogs.java:56
Implements a cache for elements identified by name.
Exception thrown if a skin related problem occurs.
Maintains a set of Gui instances representing dialog windows.
Definition: Dialogs.java:38
T lookup(@NotNull final String name)
Looks up an element by name.