00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.skin.skin;
00023
00024 import com.realtime.crossfire.jxclient.gui.gui.Gui;
00025 import java.util.HashSet;
00026 import java.util.Iterator;
00027 import java.util.Set;
00028 import org.jetbrains.annotations.NotNull;
00029 import org.jetbrains.annotations.Nullable;
00030
00037 public class Dialogs implements Iterable<Gui> {
00038
00042 @NotNull
00043 private final GuiFactory guiFactory;
00044
00048 @NotNull
00049 private final JXCSkinCache<Gui> dialogs = new JXCSkinCache<Gui>("dialog");
00050
00054 @NotNull
00055 private final Set<String> dialogsToLoad = new HashSet<String>();
00056
00061 public Dialogs(@NotNull final GuiFactory guiFactory) {
00062 this.guiFactory = guiFactory;
00063 }
00064
00071 @NotNull
00072 public Gui lookup(@NotNull final String name) throws JXCSkinException {
00073 return dialogs.lookup(name);
00074 }
00075
00081 @NotNull
00082 public Gui addDialog(@NotNull final String name) {
00083 try {
00084 return dialogs.lookup(name);
00085 } catch (final JXCSkinException ignored) {
00086 final Gui gui = guiFactory.newGui();
00087 try {
00088 dialogs.insert(name, gui);
00089 } catch (final JXCSkinException ex) {
00090 throw new AssertionError(ex);
00091 }
00092 dialogsToLoad.add(name);
00093 return gui;
00094 }
00095 }
00096
00101 @Nullable
00102 public String getDialogToLoad() {
00103 final Iterator<String> it = dialogsToLoad.iterator();
00104 if (!it.hasNext()) {
00105 return null;
00106 }
00107
00108 final String result = it.next();
00109 it.remove();
00110 return result;
00111 }
00112
00116 @NotNull
00117 @Override
00118 public Iterator<Gui> iterator() {
00119 return dialogs.iterator();
00120 }
00121
00122 }