| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TabTitleUpdater |
|
| 2.5;2.5 |
| 1 | package org.jtheque.core.managers.language; | |
| 2 | ||
| 3 | import org.jtheque.core.managers.Managers; | |
| 4 | ||
| 5 | import javax.swing.JComponent; | |
| 6 | import javax.swing.JTabbedPane; | |
| 7 | import java.util.HashMap; | |
| 8 | import java.util.Map; | |
| 9 | import java.util.Map.Entry; | |
| 10 | ||
| 11 | /* | |
| 12 | * This file is part of JTheque. | |
| 13 | * | |
| 14 | * JTheque is free software: you can redistribute it and/or modify | |
| 15 | * it under the terms of the GNU General Public License as published by | |
| 16 | * the Free Software Foundation, either version 3 of the License. | |
| 17 | * | |
| 18 | * JTheque is distributed in the hope that it will be useful, | |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | * GNU General Public License for more details. | |
| 22 | * | |
| 23 | * You should have received a copy of the GNU General Public License | |
| 24 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 25 | */ | |
| 26 | ||
| 27 | /** | |
| 28 | * A tab title updater to keep the tab title up to date with the current locale. | |
| 29 | * | |
| 30 | * @author Baptiste Wicht | |
| 31 | */ | |
| 32 | public final class TabTitleUpdater implements Internationalizable { | |
| 33 | private final JTabbedPane tab; | |
| 34 | private final Map<JComponent, String> components; | |
| 35 | ||
| 36 | /** | |
| 37 | * Construct a new TabTitleUpdater. | |
| 38 | * | |
| 39 | * @param tab The tabbed pane. | |
| 40 | * @param components The components of the tabbed pane. | |
| 41 | */ | |
| 42 | public TabTitleUpdater(JTabbedPane tab, Map<JComponent, String> components) { | |
| 43 | 0 | super(); |
| 44 | ||
| 45 | 0 | this.tab = tab; |
| 46 | 0 | this.components = new HashMap<JComponent, String>(components); |
| 47 | 0 | } |
| 48 | ||
| 49 | @Override | |
| 50 | public void refreshText() { | |
| 51 | 0 | for (Entry<JComponent, String> entry : components.entrySet()) { |
| 52 | 0 | for (int i = 0; i < tab.getTabCount(); i++) { |
| 53 | 0 | if (entry.getKey().equals(tab.getTabComponentAt(i))) { |
| 54 | 0 | tab.setTitleAt(i, Managers.getManager(ILanguageManager.class).getMessage(entry.getValue())); |
| 55 | ||
| 56 | 0 | break; |
| 57 | } | |
| 58 | } | |
| 59 | } | |
| 60 | 0 | } |
| 61 | } |