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

Last change on this file since 13146 was 12620, checked in by Don-vip, 7 years ago

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

  • Property svn:eol-style set to native
File size: 4.2 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;
13import org.openstreetmap.josm.tools.Logging;
14
15/**
16 * Abstract base class for {@link TabPreferenceSetting} implementations.
17 *
18 * Support for common functionality, like icon, title and adding a tab ({@link SubPreferenceSetting}).
19 */
20public abstract class DefaultTabPreferenceSetting extends DefaultPreferenceSetting implements TabPreferenceSetting {
21
22 private final String iconName;
23 private final String description;
24 private final String title;
25 private final JTabbedPane tabpane;
26 private final Map<SubPreferenceSetting, Component> subSettingMap;
27
28 /**
29 * Constructs a new {@code DefaultTabPreferenceSetting}.
30 */
31 public DefaultTabPreferenceSetting() {
32 this(null, null, null);
33 }
34
35 public DefaultTabPreferenceSetting(String iconName, String title, String description) {
36 this(iconName, title, description, false);
37 }
38
39 public DefaultTabPreferenceSetting(String iconName, String title, String description, boolean isExpert) {
40 this(iconName, title, description, isExpert, null);
41 }
42
43 public DefaultTabPreferenceSetting(String iconName, String title, String description, boolean isExpert, JTabbedPane tabpane) {
44 super(isExpert);
45 this.iconName = iconName;
46 this.description = description;
47 this.title = title;
48 this.tabpane = tabpane;
49 this.subSettingMap = tabpane != null ? new HashMap<>() : null;
50 }
51
52 @Override
53 public String getIconName() {
54 return iconName;
55 }
56
57 @Override
58 public String getTooltip() {
59 if (getDescription() != null) {
60 return "<html>"+getDescription()+"</html>";
61 } else {
62 return null;
63 }
64 }
65
66 @Override
67 public String getDescription() {
68 return description;
69 }
70
71 @Override
72 public String getTitle() {
73 return title;
74 }
75
76 /**
77 * Get the inner tab pane, if any.
78 * @return The JTabbedPane contained in this tab preference settings, or null if none is set.
79 * @since 5631
80 */
81 public final JTabbedPane getTabPane() {
82 return tabpane;
83 }
84
85 protected final void createPreferenceTabWithScrollPane(PreferenceTabbedPane gui, JPanel panel) {
86 GBC a = GBC.eol().insets(-5, 0, 0, 0);
87 a.anchor = GBC.EAST;
88
89 JScrollPane scrollPane = new JScrollPane(panel);
90 scrollPane.setBorder(null);
91
92 JPanel tab = gui.createPreferenceTab(this);
93 tab.add(scrollPane, GBC.eol().fill(GBC.BOTH));
94 tab.add(GBC.glue(0, 10), a);
95 }
96
97 @Override
98 public boolean selectSubTab(SubPreferenceSetting subPref) {
99 if (tabpane != null && subPref != null) {
100 Component tab = getSubTab(subPref);
101 if (tab != null) {
102 try {
103 tabpane.setSelectedComponent(tab);
104 return true;
105 } catch (IllegalArgumentException e) {
106 // Ignore exception and return false below
107 Logging.debug(Logging.getErrorMessage(e));
108 }
109 }
110 }
111 return false;
112 }
113
114 @Override
115 public final void addSubTab(SubPreferenceSetting sub, String title, Component component) {
116 addSubTab(sub, title, component, null);
117 }
118
119 @Override
120 public final void addSubTab(SubPreferenceSetting sub, String title, Component component, String tip) {
121 if (tabpane != null && component != null) {
122 tabpane.addTab(title, null, component, tip);
123 registerSubTab(sub, component);
124 }
125 }
126
127 @Override
128 public final void registerSubTab(SubPreferenceSetting sub, Component component) {
129 if (subSettingMap != null && sub != null && component != null) {
130 subSettingMap.put(sub, component);
131 }
132 }
133
134 @Override
135 public final Component getSubTab(SubPreferenceSetting sub) {
136 return subSettingMap != null ? subSettingMap.get(sub) : null;
137 }
138}
Note: See TracBrowser for help on using the repository browser.