X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fi18n%2FI18nContainer.java;fp=src%2Fmain%2Fjava%2Fde%2Ftodesbaum%2Fjsite%2Fi18n%2FI18nContainer.java;h=9683dd3bad46108517a91c965b9e75dea974b852;hb=38bdc433e50669e8244a63b5af59e597f88f1d29;hp=0000000000000000000000000000000000000000;hpb=f14b9fbe6d88e23920b10a75ebeba4d38390301b;p=jSite.git diff --git a/src/main/java/de/todesbaum/jsite/i18n/I18nContainer.java b/src/main/java/de/todesbaum/jsite/i18n/I18nContainer.java new file mode 100644 index 0000000..9683dd3 --- /dev/null +++ b/src/main/java/de/todesbaum/jsite/i18n/I18nContainer.java @@ -0,0 +1,91 @@ +/* + * jSite - I18nContainer.java - Copyright © 2007–2012 David Roden + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package de.todesbaum.jsite.i18n; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * Container that collects {@link Runnable}s that change the texts of GUI + * components when the current locale has changed. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + */ +public class I18nContainer implements Iterable { + + /** The container singleton. */ + private static final I18nContainer singleton = new I18nContainer(); + + /** The list of runnables that change texts. */ + private final List i18nRunnables = Collections.synchronizedList(new ArrayList()); + + /** + * The list of runnables that change texts and run after + * {@link #i18nRunnables}. + */ + private final List i18nPostRunnables = Collections.synchronizedList(new ArrayList()); + + /** + * Returns the singleton instance. + * + * @return The singleton instance + */ + public static I18nContainer getInstance() { + return singleton; + } + + /** + * Registers an i18n runnable that is run when the current locale has + * changed. + * + * @param i18nRunnable + * The runnable to register + */ + public void registerRunnable(Runnable i18nRunnable) { + i18nRunnables.add(i18nRunnable); + } + + /** + * Registers a {@link Runnable} that changes texts when the current locale + * has changed and runs after {@link #i18nRunnables} have run. + * + * @param i18nPostRunnable + * The runnable to register + */ + public void registerPostRunnable(Runnable i18nPostRunnable) { + i18nPostRunnables.add(i18nPostRunnable); + } + + /** + * {@inheritDoc} + *

+ * Returns a combined list of {@link #i18nRunnables} and + * {@link #i18nPostRunnables}, in that order. + */ + @Override + public Iterator iterator() { + List allRunnables = new ArrayList(); + allRunnables.addAll(i18nRunnables); + allRunnables.addAll(i18nPostRunnables); + return allRunnables.iterator(); + } + +}