source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/DefaultTabPreferenceSetting.java@ 5926

Last change on this file since 5926 was 5632, checked in by Don-vip, 11 years ago

remove forgotten debug code

File size: 4.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences;
3
4import java.awt.Component;
5import java.util.HashMap;
6import java.util.Map;
7
8import javax.swing.JPanel;
9import javax.swing.JScrollPane;
10import javax.swing.JTabbedPane;
11
12import org.openstreetmap.josm.tools.GBC;
13
14public 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 }
99 }
100 }
101 return false;
102 }
103
104 @Override
105 public final void addSubTab(SubPreferenceSetting sub, String title, Component component) {
106 addSubTab(sub, title, component, null);
107 }
108
109 @Override
110 public final void addSubTab(SubPreferenceSetting sub, String title, Component component, String tip) {
111 if (tabpane != null && component != null) {
112 tabpane.addTab(title, null, component, tip);
113 registerSubTab(sub, component);
114 }
115 }
116
117 @Override
118 public final void registerSubTab(SubPreferenceSetting sub, Component component) {
119 if (subSettingMap != null && sub != null && component != null) {
120 subSettingMap.put(sub, component);
121 }
122 }
123
124 @Override
125 public final Component getSubTab(SubPreferenceSetting sub) {
126 return subSettingMap != null ? subSettingMap.get(sub) : null;
127 }
128}
Note: See TracBrowser for help on using the repository browser.