1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import javax.swing.JPanel;
|
---|
9 | import javax.swing.JScrollPane;
|
---|
10 | import javax.swing.JTabbedPane;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.tools.GBC;
|
---|
13 |
|
---|
14 | public abstract class DefaultTabPreferenceSetting extends DefaultPreferenceSetting implements TabPreferenceSetting {
|
---|
15 |
|
---|
16 | private final String iconName;
|
---|
17 | private final String description;
|
---|
18 | private final String title;
|
---|
19 | private final JTabbedPane tabpane;
|
---|
20 | private final Map<SubPreferenceSetting, Component> subSettingMap;
|
---|
21 |
|
---|
22 | public DefaultTabPreferenceSetting() {
|
---|
23 | this(null, null, null);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public DefaultTabPreferenceSetting(String iconName, String title, String description) {
|
---|
27 | this(iconName, title, description, false);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public DefaultTabPreferenceSetting(String iconName, String title, String description, boolean isExpert) {
|
---|
31 | this(iconName, title, description, isExpert, null);
|
---|
32 | }
|
---|
33 |
|
---|
34 | public DefaultTabPreferenceSetting(String iconName, String title, String description, boolean isExpert, JTabbedPane tabpane) {
|
---|
35 | super(isExpert);
|
---|
36 | this.iconName = iconName;
|
---|
37 | this.description = description;
|
---|
38 | this.title = title;
|
---|
39 | this.tabpane = tabpane;
|
---|
40 | this.subSettingMap = tabpane != null ? new HashMap<SubPreferenceSetting, Component>() : null;
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public String getIconName() {
|
---|
45 | return iconName;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public String getTooltip() {
|
---|
50 | if (getDescription() != null) {
|
---|
51 | return "<html>"+getDescription()+"</html>";
|
---|
52 | } else {
|
---|
53 | return null;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public String getDescription() {
|
---|
59 | return description;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public String getTitle() {
|
---|
64 | return title;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Get the inner tab pane, if any.
|
---|
69 | * @return The JTabbedPane contained in this tab preference settings, or null if none is set.
|
---|
70 | * @since 5631
|
---|
71 | */
|
---|
72 | public final JTabbedPane getTabPane() {
|
---|
73 | return tabpane;
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected final void createPreferenceTabWithScrollPane(PreferenceTabbedPane gui, JPanel panel) {
|
---|
77 | GBC a = GBC.eol().insets(-5,0,0,0);
|
---|
78 | a.anchor = GBC.EAST;
|
---|
79 |
|
---|
80 | JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
81 | scrollPane.setBorder(null);
|
---|
82 |
|
---|
83 | JPanel tab = gui.createPreferenceTab(this);
|
---|
84 | tab.add(scrollPane, GBC.eol().fill(GBC.BOTH));
|
---|
85 | tab.add(GBC.glue(0,10), a);
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public boolean selectSubTab(SubPreferenceSetting subPref) {
|
---|
90 | if (tabpane != null && subPref != null) {
|
---|
91 | Component tab = getSubTab(subPref);
|
---|
92 | if (tab != null) {
|
---|
93 | try {
|
---|
94 | tabpane.setSelectedComponent(tab);
|
---|
95 | return true;
|
---|
96 | } catch (IllegalArgumentException e) {
|
---|
97 | // Ignore exception and return false below
|
---|
98 | e.printStackTrace();
|
---|
99 | System.out.println(tabpane.getTabCount());
|
---|
100 | for (int i = 0; i < tabpane.getTabCount() ; i++) {
|
---|
101 | System.out.println(tabpane.getComponentAt(i));
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Override
|
---|
110 | public final void addSubTab(SubPreferenceSetting sub, String title, Component component) {
|
---|
111 | addSubTab(sub, title, component, null);
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Override
|
---|
115 | public final void addSubTab(SubPreferenceSetting sub, String title, Component component, String tip) {
|
---|
116 | if (tabpane != null && component != null) {
|
---|
117 | tabpane.addTab(title, null, component, tip);
|
---|
118 | registerSubTab(sub, component);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | @Override
|
---|
123 | public final void registerSubTab(SubPreferenceSetting sub, Component component) {
|
---|
124 | if (subSettingMap != null && sub != null && component != null) {
|
---|
125 | subSettingMap.put(sub, component);
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | @Override
|
---|
130 | public final Component getSubTab(SubPreferenceSetting sub) {
|
---|
131 | return subSettingMap != null ? subSettingMap.get(sub) : null;
|
---|
132 | }
|
---|
133 | }
|
---|