2 * jSite - I18nContainer.java - Copyright © 2007–2014 David Roden
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.i18n;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.List;
27 * Container that collects {@link Runnable}s that change the texts of GUI
28 * components when the current locale has changed.
30 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
32 public class I18nContainer implements Iterable<Runnable> {
34 /** The container singleton. */
35 private static final I18nContainer singleton = new I18nContainer();
37 /** The list of runnables that change texts. */
38 private final List<Runnable> i18nRunnables = Collections.synchronizedList(new ArrayList<Runnable>());
41 * The list of runnables that change texts and run after
42 * {@link #i18nRunnables}.
44 private final List<Runnable> i18nPostRunnables = Collections.synchronizedList(new ArrayList<Runnable>());
47 * Returns the singleton instance.
49 * @return The singleton instance
51 public static I18nContainer getInstance() {
56 * Registers an i18n runnable that is run when the current locale has
60 * The runnable to register
62 public void registerRunnable(Runnable i18nRunnable) {
63 i18nRunnables.add(i18nRunnable);
67 * Registers a {@link Runnable} that changes texts when the current locale
68 * has changed and runs after {@link #i18nRunnables} have run.
70 * @param i18nPostRunnable
71 * The runnable to register
73 public void registerPostRunnable(Runnable i18nPostRunnable) {
74 i18nPostRunnables.add(i18nPostRunnable);
80 * Returns a combined list of {@link #i18nRunnables} and
81 * {@link #i18nPostRunnables}, in that order.
84 public Iterator<Runnable> iterator() {
85 List<Runnable> allRunnables = new ArrayList<Runnable>();
86 allRunnables.addAll(i18nRunnables);
87 allRunnables.addAll(i18nPostRunnables);
88 return allRunnables.iterator();