Crossfire JXClient, Trunk
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-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 
27 import java.util.Collection;
28 import java.util.HashSet;
29 import java.util.Iterator;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
32 
39 public class Dialogs implements Iterable<Gui> {
40 
44  @NotNull
45  private final GuiFactory guiFactory;
46 
50  @NotNull
51  private final GuiManager guiManager;
52 
56  @NotNull
57  private final JXCSkinCache<Gui> dialogs = new JXCSkinCache<>("dialog");
58 
62  @NotNull
63  private final Collection<String> dialogsToLoad = new HashSet<>();
64 
70  public Dialogs(@NotNull final GuiFactory guiFactory, @NotNull final GuiManager guiManager) {
71  this.guiFactory = guiFactory;
72  this.guiManager = guiManager;
73  }
74 
81  @NotNull
82  public Gui lookup(@NotNull final String name) throws JXCSkinException {
83  return dialogs.lookup(name);
84  }
85 
90  public void addDialog(@NotNull final String name) {
91  try {
92  dialogs.lookup(name);
93  } catch (final JXCSkinException ignored) {
94  final Gui gui = guiFactory.newGui(name);
95  try {
96  dialogs.insert(name, gui);
97  } catch (final JXCSkinException ex) {
98  throw new AssertionError(ex);
99  }
100  dialogsToLoad.add(name);
101  guiManager.addDialog(name, gui);
102  }
103  }
104 
109  @Nullable
110  public String getDialogToLoad() {
111  final Iterator<String> it = dialogsToLoad.iterator();
112  if (!it.hasNext()) {
113  return null;
114  }
115 
116  final String result = it.next();
117  it.remove();
118  return result;
119  }
120 
121  @NotNull
122  @Override
123  public Iterator<Gui> iterator() {
124  return dialogs.iterator();
125  }
126 
127 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.skin.skin.Dialogs.guiFactory
final GuiFactory guiFactory
Definition: Dialogs.java:45
com.realtime.crossfire.jxclient.skin.skin.GuiFactory.newGui
Gui newGui(@NotNull final String name)
Definition: GuiFactory.java:68
com.realtime.crossfire.jxclient.gui.gui.Gui
Definition: Gui.java:49
com.realtime.crossfire.jxclient.window
Definition: DialogStateParser.java:23
com.realtime.crossfire.jxclient.skin.skin.GuiFactory
Definition: GuiFactory.java:41
com.realtime.crossfire.jxclient.skin.skin.JXCSkinException
Definition: JXCSkinException.java:31
com.realtime.crossfire.jxclient.skin.skin.Dialogs.iterator
Iterator< Gui > iterator()
Definition: Dialogs.java:123
com.realtime.crossfire.jxclient.skin.skin.Dialogs.lookup
Gui lookup(@NotNull final String name)
Definition: Dialogs.java:82
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.skin.skin.JXCSkinCache
Definition: JXCSkinCache.java:40
com.realtime.crossfire.jxclient.skin.skin.Dialogs.dialogsToLoad
final Collection< String > dialogsToLoad
Definition: Dialogs.java:63
com.realtime.crossfire.jxclient.gui.gui
Definition: AbstractGUIElement.java:23
com.realtime.crossfire.jxclient.skin.skin.Dialogs.addDialog
void addDialog(@NotNull final String name)
Definition: Dialogs.java:90
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.skin.skin.Dialogs
Definition: Dialogs.java:39
com.realtime.crossfire.jxclient.skin.skin.Dialogs.Dialogs
Dialogs(@NotNull final GuiFactory guiFactory, @NotNull final GuiManager guiManager)
Definition: Dialogs.java:70
com.realtime.crossfire.jxclient.skin.skin.Dialogs.dialogs
final JXCSkinCache< Gui > dialogs
Definition: Dialogs.java:57
com.realtime.crossfire.jxclient.window.GuiManager.addDialog
void addDialog(@NotNull final String name, @NotNull final Gui dialog)
Definition: GuiManager.java:435
com.realtime.crossfire.jxclient.skin.skin.Dialogs.guiManager
final GuiManager guiManager
Definition: Dialogs.java:51
com.realtime.crossfire.jxclient.window.GuiManager
Definition: GuiManager.java:63
com.realtime.crossfire.jxclient.skin.skin.Dialogs.getDialogToLoad
String getDialogToLoad()
Definition: Dialogs.java:110