1 | |
package org.jtheque.core.managers.view.impl.components; |
2 | |
|
3 | |
import org.jtheque.core.managers.Managers; |
4 | |
import org.jtheque.core.managers.language.ILanguageManager; |
5 | |
import org.jtheque.core.managers.language.TabTitleUpdater; |
6 | |
import org.jtheque.core.managers.view.able.IViewManager; |
7 | |
import org.jtheque.core.managers.view.able.components.TabComponent; |
8 | |
import org.jtheque.core.managers.view.listeners.TabEvent; |
9 | |
import org.jtheque.core.managers.view.listeners.TabListener; |
10 | |
import org.jtheque.utils.collections.CollectionUtils; |
11 | |
|
12 | |
import javax.swing.JComponent; |
13 | |
import javax.swing.JTabbedPane; |
14 | |
import java.io.Serializable; |
15 | |
import java.util.Collections; |
16 | |
import java.util.Comparator; |
17 | |
import java.util.HashMap; |
18 | |
import java.util.List; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public final class MainTabbedPane extends LayerTabbedPane implements TabListener { |
43 | |
|
44 | |
|
45 | |
|
46 | |
public MainTabbedPane() { |
47 | 0 | super(); |
48 | |
|
49 | 0 | setTabPlacement(JTabbedPane.TOP); |
50 | |
|
51 | 0 | List<TabComponent> components = CollectionUtils.copyOf(Managers.getManager(IViewManager.class).getTabComponents()); |
52 | 0 | Collections.sort(components, new PositionComparator()); |
53 | |
|
54 | 0 | Map<JComponent, String> cs = new HashMap<JComponent, String>(components.size()); |
55 | |
|
56 | 0 | for (TabComponent component : components) { |
57 | 0 | addLayeredTab(Managers.getManager(ILanguageManager.class).getMessage(component.getTitleKey()), component.getComponent()); |
58 | 0 | cs.put(component.getComponent(), component.getTitleKey()); |
59 | |
} |
60 | |
|
61 | 0 | Managers.getManager(IViewManager.class).addTabListener(this); |
62 | |
|
63 | 0 | Managers.getManager(ILanguageManager.class).addInternationalizable(new TabTitleUpdater(this, cs)); |
64 | 0 | } |
65 | |
|
66 | |
@Override |
67 | |
public void tabAdded() { |
68 | 0 | if (Managers.getManager(IViewManager.class).isTabMainComponent()) { |
69 | 0 | removeAll(); |
70 | |
|
71 | 0 | List<TabComponent> components = CollectionUtils.copyOf(Managers.getManager(IViewManager.class).getTabComponents()); |
72 | |
|
73 | 0 | Collections.sort(components, new PositionComparator()); |
74 | |
|
75 | 0 | for (TabComponent component : components) { |
76 | 0 | addLayeredTab(Managers.getManager(ILanguageManager.class).getMessage(component.getTitleKey()), component.getComponent()); |
77 | |
} |
78 | |
|
79 | 0 | Managers.getManager(IViewManager.class).refresh(this); |
80 | |
} |
81 | 0 | } |
82 | |
|
83 | |
@Override |
84 | |
public void tabRemoved(TabEvent event) { |
85 | 0 | if (Managers.getManager(IViewManager.class).isTabMainComponent()) { |
86 | 0 | removeTabAt(indexOfTab(Managers.getManager(ILanguageManager.class).getMessage(event.getComponent().getTitleKey()))); |
87 | |
|
88 | 0 | Managers.getManager(IViewManager.class).refresh(this); |
89 | |
} |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 0 | private static final class PositionComparator implements Comparator<TabComponent>, Serializable { |
98 | |
@Override |
99 | |
public int compare(TabComponent component, TabComponent other) { |
100 | 0 | return component.getPosition().compareTo(other.getPosition()); |
101 | |
} |
102 | |
} |
103 | |
} |