source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java@ 15856

Last change on this file since 15856 was 15856, checked in by Don-vip, 4 years ago

fix #18711 - Bold font for tab subtitles in preferences dialog

  • Property svn:eol-style set to native
File size: 26.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.Container;
8import java.awt.Font;
9import java.awt.GridBagLayout;
10import java.awt.event.MouseWheelEvent;
11import java.awt.event.MouseWheelListener;
12import java.util.ArrayList;
13import java.util.Collection;
14import java.util.Collections;
15import java.util.HashSet;
16import java.util.Iterator;
17import java.util.LinkedList;
18import java.util.List;
19import java.util.NoSuchElementException;
20import java.util.Objects;
21import java.util.Set;
22import java.util.function.Predicate;
23import java.util.stream.IntStream;
24
25import javax.swing.BorderFactory;
26import javax.swing.Icon;
27import javax.swing.ImageIcon;
28import javax.swing.JLabel;
29import javax.swing.JOptionPane;
30import javax.swing.JPanel;
31import javax.swing.JScrollPane;
32import javax.swing.JTabbedPane;
33import javax.swing.event.ChangeEvent;
34import javax.swing.event.ChangeListener;
35
36import org.openstreetmap.josm.actions.ExpertToggleAction;
37import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener;
38import org.openstreetmap.josm.actions.RestartAction;
39import org.openstreetmap.josm.gui.HelpAwareOptionPane;
40import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
41import org.openstreetmap.josm.gui.MainApplication;
42import org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference;
43import org.openstreetmap.josm.gui.preferences.audio.AudioPreference;
44import org.openstreetmap.josm.gui.preferences.display.ColorPreference;
45import org.openstreetmap.josm.gui.preferences.display.DisplayPreference;
46import org.openstreetmap.josm.gui.preferences.display.DrawingPreference;
47import org.openstreetmap.josm.gui.preferences.display.LafPreference;
48import org.openstreetmap.josm.gui.preferences.display.LanguagePreference;
49import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
50import org.openstreetmap.josm.gui.preferences.map.BackupPreference;
51import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;
52import org.openstreetmap.josm.gui.preferences.map.MapPreference;
53import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
54import org.openstreetmap.josm.gui.preferences.plugin.PluginPreference;
55import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
56import org.openstreetmap.josm.gui.preferences.remotecontrol.RemoteControlPreference;
57import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreference;
58import org.openstreetmap.josm.gui.preferences.server.OverpassServerPreference;
59import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
60import org.openstreetmap.josm.gui.preferences.server.ServerAccessPreference;
61import org.openstreetmap.josm.gui.preferences.shortcut.ShortcutPreference;
62import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
63import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference;
64import org.openstreetmap.josm.gui.preferences.validator.ValidatorTestsPreference;
65import org.openstreetmap.josm.gui.util.GuiHelper;
66import org.openstreetmap.josm.plugins.PluginDownloadTask;
67import org.openstreetmap.josm.plugins.PluginHandler;
68import org.openstreetmap.josm.plugins.PluginInformation;
69import org.openstreetmap.josm.tools.CheckParameterUtil;
70import org.openstreetmap.josm.tools.GBC;
71import org.openstreetmap.josm.tools.ImageProvider;
72import org.openstreetmap.josm.tools.Logging;
73import org.openstreetmap.josm.tools.Utils;
74import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
75
76/**
77 * The preference settings.
78 *
79 * @author imi
80 */
81public final class PreferenceTabbedPane extends JTabbedPane implements ExpertModeChangeListener, ChangeListener {
82
83 private final class PluginDownloadAfterTask implements Runnable {
84 private final PluginPreference preference;
85 private final PluginDownloadTask task;
86 private final Set<PluginInformation> toDownload;
87
88 private PluginDownloadAfterTask(PluginPreference preference, PluginDownloadTask task,
89 Set<PluginInformation> toDownload) {
90 this.preference = preference;
91 this.task = task;
92 this.toDownload = toDownload;
93 }
94
95 @Override
96 public void run() {
97 boolean requiresRestart = false;
98
99 for (PreferenceSetting setting : settingsInitialized) {
100 if (setting.ok()) {
101 requiresRestart = true;
102 }
103 }
104
105 // build the messages. We only display one message, including the status information from the plugin download task
106 // and - if necessary - a hint to restart JOSM
107 //
108 StringBuilder sb = new StringBuilder();
109 sb.append("<html>");
110 if (task != null && !task.isCanceled()) {
111 PluginHandler.refreshLocalUpdatedPluginInfo(task.getDownloadedPlugins());
112 sb.append(PluginPreference.buildDownloadSummary(task));
113 }
114 if (requiresRestart) {
115 sb.append(tr("You have to restart JOSM for some settings to take effect."));
116 sb.append("<br/><br/>");
117 sb.append(tr("Would you like to restart now?"));
118 }
119 sb.append("</html>");
120
121 // display the message, if necessary
122 //
123 if (requiresRestart) {
124 final ButtonSpec[] options = RestartAction.getButtonSpecs();
125 if (0 == HelpAwareOptionPane.showOptionDialog(
126 MainApplication.getMainFrame(),
127 sb.toString(),
128 tr("Restart"),
129 JOptionPane.INFORMATION_MESSAGE,
130 null, /* no special icon */
131 options,
132 options[0],
133 null /* no special help */
134 )) {
135 MainApplication.getMenu().restart.actionPerformed(null);
136 }
137 } else if (task != null && !task.isCanceled()) {
138 JOptionPane.showMessageDialog(
139 MainApplication.getMainFrame(),
140 sb.toString(),
141 tr("Warning"),
142 JOptionPane.WARNING_MESSAGE
143 );
144 }
145
146 // load the plugins that can be loaded at runtime
147 List<PluginInformation> newPlugins = preference.getNewlyActivatedPlugins();
148 if (newPlugins != null) {
149 Collection<PluginInformation> downloadedPlugins = null;
150 if (task != null && !task.isCanceled()) {
151 downloadedPlugins = task.getDownloadedPlugins();
152 }
153 List<PluginInformation> toLoad = new ArrayList<>();
154 for (PluginInformation pi : newPlugins) {
155 if (toDownload.contains(pi) && downloadedPlugins != null && !downloadedPlugins.contains(pi)) {
156 continue; // failed download
157 }
158 if (pi.canloadatruntime) {
159 toLoad.add(pi);
160 }
161 }
162 // check if plugin dependences can also be loaded
163 Collection<PluginInformation> allPlugins = new HashSet<>(toLoad);
164 allPlugins.addAll(PluginHandler.getPlugins());
165 boolean removed;
166 do {
167 removed = false;
168 Iterator<PluginInformation> it = toLoad.iterator();
169 while (it.hasNext()) {
170 if (!PluginHandler.checkRequiredPluginsPreconditions(null, allPlugins, it.next(), requiresRestart)) {
171 it.remove();
172 removed = true;
173 }
174 }
175 } while (removed);
176
177 if (!toLoad.isEmpty()) {
178 PluginHandler.loadPlugins(PreferenceTabbedPane.this, toLoad, null);
179 }
180 }
181
182 if (MainApplication.getMainFrame() != null) {
183 MainApplication.getMainFrame().repaint();
184 }
185 }
186 }
187
188 /**
189 * Allows PreferenceSettings to do validation of entered values when ok was pressed.
190 * If data is invalid then event can return false to cancel closing of preferences dialog.
191 * @since 10600 (functional interface)
192 */
193 @FunctionalInterface
194 public interface ValidationListener {
195 /**
196 *
197 * @return True if preferences can be saved
198 */
199 boolean validatePreferences();
200 }
201
202 private interface PreferenceTab {
203 TabPreferenceSetting getTabPreferenceSetting();
204
205 Component getComponent();
206 }
207
208 public static final class PreferencePanel extends JPanel implements PreferenceTab {
209 private final transient TabPreferenceSetting preferenceSetting;
210
211 private PreferencePanel(TabPreferenceSetting preferenceSetting) {
212 super(new GridBagLayout());
213 CheckParameterUtil.ensureParameterNotNull(preferenceSetting);
214 this.preferenceSetting = preferenceSetting;
215 buildPanel();
216 }
217
218 private void buildPanel() {
219 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
220 add(buildHtmlPanel(preferenceSetting.getTitle(), Font.BOLD),
221 GBC.eol().insets(0, 5, 0, 10).anchor(GBC.NORTHWEST).fill(GBC.HORIZONTAL));
222 add(buildHtmlPanel(preferenceSetting.getDescription(), Font.ITALIC),
223 GBC.eol().insets(5, 0, 5, 20).fill(GBC.HORIZONTAL));
224 }
225
226 private static JLabel buildHtmlPanel(String text, int fontStyle) {
227 JLabel label = new JLabel("<html>" + text + "</html>");
228 label.setFont(label.getFont().deriveFont(fontStyle));
229 return label;
230 }
231
232 @Override
233 public TabPreferenceSetting getTabPreferenceSetting() {
234 return preferenceSetting;
235 }
236
237 @Override
238 public Component getComponent() {
239 return this;
240 }
241 }
242
243 public static final class PreferenceScrollPane extends JScrollPane implements PreferenceTab {
244 private final transient TabPreferenceSetting preferenceSetting;
245
246 private PreferenceScrollPane(Component view, TabPreferenceSetting preferenceSetting) {
247 super(view);
248 this.preferenceSetting = preferenceSetting;
249 }
250
251 private PreferenceScrollPane(PreferencePanel preferencePanel) {
252 this(preferencePanel.getComponent(), preferencePanel.getTabPreferenceSetting());
253 }
254
255 @Override
256 public TabPreferenceSetting getTabPreferenceSetting() {
257 return preferenceSetting;
258 }
259
260 @Override
261 public Component getComponent() {
262 return this;
263 }
264 }
265
266 // all created tabs
267 private final transient List<PreferenceTab> tabs = new ArrayList<>();
268 private static final Collection<PreferenceSettingFactory> SETTINGS_FACTORIES = new LinkedList<>();
269 private static final PreferenceSettingFactory ADVANCED_PREFERENCE_FACTORY = new AdvancedPreference.Factory();
270 private final transient List<PreferenceSetting> settings = new ArrayList<>();
271
272 // distinct list of tabs that have been initialized (we do not initialize tabs until they are displayed to speed up dialog startup)
273 private final transient List<PreferenceSetting> settingsInitialized = new ArrayList<>();
274
275 final transient List<ValidationListener> validationListeners = new ArrayList<>();
276
277 /**
278 * Add validation listener to currently open preferences dialog. Calling to removeValidationListener is not necessary, all listeners will
279 * be automatically removed when dialog is closed
280 * @param validationListener validation listener to add
281 */
282 public void addValidationListener(ValidationListener validationListener) {
283 validationListeners.add(validationListener);
284 }
285
286 /**
287 * Construct a PreferencePanel for the preference settings. Layout is GridBagLayout
288 * and a centered title label and the description are added.
289 * @param caller Preference settings, that display a top level tab
290 * @return The created panel ready to add other controls.
291 */
292 public PreferencePanel createPreferenceTab(TabPreferenceSetting caller) {
293 return createPreferenceTab(caller, false);
294 }
295
296 /**
297 * Construct a PreferencePanel for the preference settings. Layout is GridBagLayout
298 * and a centered title label and the description are added.
299 * @param caller Preference settings, that display a top level tab
300 * @param inScrollPane if <code>true</code> the added tab will show scroll bars
301 * if the panel content is larger than the available space
302 * @return The created panel ready to add other controls.
303 */
304 public PreferencePanel createPreferenceTab(TabPreferenceSetting caller, boolean inScrollPane) {
305 CheckParameterUtil.ensureParameterNotNull(caller, "caller");
306 PreferencePanel p = new PreferencePanel(caller);
307
308 PreferenceTab tab = p;
309 if (inScrollPane) {
310 PreferenceScrollPane sp = new PreferenceScrollPane(p);
311 tab = sp;
312 }
313 tabs.add(tab);
314 return p;
315 }
316
317 private void selectTabBy(Predicate<TabPreferenceSetting> predicate) {
318 IntStream.range(0, getTabCount())
319 .filter(i -> getComponentAt(i) instanceof PreferenceTab
320 && predicate.test(((PreferenceTab) getComponentAt(i)).getTabPreferenceSetting()))
321 .findFirst()
322 .ifPresent(this::setSelectedIndex);
323 }
324
325 /**
326 * Selects a {@link TabPreferenceSetting} by its icon name
327 * @param name the icon name
328 */
329 public void selectTabByName(String name) {
330 Objects.requireNonNull(name);
331 selectTabBy(tps -> Objects.equals(name, tps.getIconName()));
332 }
333
334 /**
335 * Selects a {@link TabPreferenceSetting} by class
336 * @param clazz preferences tab class
337 */
338 public void selectTabByPref(Class<? extends TabPreferenceSetting> clazz) {
339 selectTabBy(clazz::isInstance);
340 }
341
342 /**
343 * Selects a {@link SubPreferenceSetting} by class
344 * @param clazz sub preferences tab class
345 * @return true if the specified preference settings have been selected, false otherwise.
346 */
347 public boolean selectSubTabByPref(Class<? extends SubPreferenceSetting> clazz) {
348 try {
349 final SubPreferenceSetting sub = getSetting(clazz);
350 final TabPreferenceSetting tab = sub.getTabPreferenceSetting(this);
351 selectTabBy(tps -> tps.equals(tab));
352 return tab.selectSubTab(sub);
353 } catch (NoSuchElementException ignore) {
354 return false;
355 }
356 }
357
358 /**
359 * Returns the {@code DisplayPreference} object.
360 * @return the {@code DisplayPreference} object.
361 */
362 public DisplayPreference getDisplayPreference() {
363 return getSetting(DisplayPreference.class);
364 }
365
366 /**
367 * Returns the {@code MapPreference} object.
368 * @return the {@code MapPreference} object.
369 */
370 public MapPreference getMapPreference() {
371 return getSetting(MapPreference.class);
372 }
373
374 /**
375 * Returns the {@code PluginPreference} object.
376 * @return the {@code PluginPreference} object.
377 */
378 public PluginPreference getPluginPreference() {
379 return getSetting(PluginPreference.class);
380 }
381
382 /**
383 * Returns the {@code ImageryPreference} object.
384 * @return the {@code ImageryPreference} object.
385 */
386 public ImageryPreference getImageryPreference() {
387 return getSetting(ImageryPreference.class);
388 }
389
390 /**
391 * Returns the {@code ShortcutPreference} object.
392 * @return the {@code ShortcutPreference} object.
393 */
394 public ShortcutPreference getShortcutPreference() {
395 return getSetting(ShortcutPreference.class);
396 }
397
398 /**
399 * Returns the {@code ServerAccessPreference} object.
400 * @return the {@code ServerAccessPreference} object.
401 * @since 6523
402 */
403 public ServerAccessPreference getServerPreference() {
404 return getSetting(ServerAccessPreference.class);
405 }
406
407 /**
408 * Returns the {@code ValidatorPreference} object.
409 * @return the {@code ValidatorPreference} object.
410 * @since 6665
411 */
412 public ValidatorPreference getValidatorPreference() {
413 return getSetting(ValidatorPreference.class);
414 }
415
416 /**
417 * Saves preferences.
418 */
419 public void savePreferences() {
420 // create a task for downloading plugins if the user has activated, yet not downloaded, new plugins
421 final PluginPreference preference = getPluginPreference();
422 if (preference != null) {
423 final Set<PluginInformation> toDownload = preference.getPluginsScheduledForUpdateOrDownload();
424 final PluginDownloadTask task;
425 if (toDownload != null && !toDownload.isEmpty()) {
426 task = new PluginDownloadTask(this, toDownload, tr("Download plugins"));
427 } else {
428 task = null;
429 }
430
431 // this is the task which will run *after* the plugins are downloaded
432 final Runnable continuation = new PluginDownloadAfterTask(preference, task, toDownload);
433
434 if (task != null) {
435 // if we have to launch a plugin download task we do it asynchronously, followed
436 // by the remaining "save preferences" activities run on the Swing EDT.
437 MainApplication.worker.submit(task);
438 MainApplication.worker.submit(() -> GuiHelper.runInEDT(continuation));
439 } else {
440 // no need for asynchronous activities. Simply run the remaining "save preference"
441 // activities on this thread (we are already on the Swing EDT
442 continuation.run();
443 }
444 }
445 }
446
447 /**
448 * If the dialog is closed with Ok, the preferences will be stored to the preferences-
449 * file, otherwise no change of the file happens.
450 */
451 public PreferenceTabbedPane() {
452 super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
453 super.addMouseWheelListener(new WheelListener(this));
454 super.getModel().addChangeListener(this);
455 ExpertToggleAction.addExpertModeChangeListener(this);
456 }
457
458 public void buildGui() {
459 Collection<PreferenceSettingFactory> factories = new ArrayList<>(SETTINGS_FACTORIES);
460 factories.addAll(PluginHandler.getPreferenceSetting());
461 factories.add(ADVANCED_PREFERENCE_FACTORY);
462
463 for (PreferenceSettingFactory factory : factories) {
464 if (factory != null) {
465 PreferenceSetting setting = factory.createPreferenceSetting();
466 if (setting != null) {
467 settings.add(setting);
468 }
469 }
470 }
471 addGUITabs(false);
472 }
473
474 private void addGUITabsForSetting(Icon icon, TabPreferenceSetting tps) {
475 for (PreferenceTab tab : tabs) {
476 if (tab.getTabPreferenceSetting().equals(tps)) {
477 insertGUITabsForSetting(icon, tps, getTabCount());
478 }
479 }
480 }
481
482 private int insertGUITabsForSetting(Icon icon, TabPreferenceSetting tps, int index) {
483 int position = index;
484 for (PreferenceTab tab : tabs) {
485 if (tab.getTabPreferenceSetting().equals(tps)) {
486 insertTab(null, icon, tab.getComponent(), tps.getTooltip(), position++);
487 }
488 }
489 return position - 1;
490 }
491
492 private void addGUITabs(boolean clear) {
493 boolean expert = ExpertToggleAction.isExpert();
494 Component sel = getSelectedComponent();
495 if (clear) {
496 removeAll();
497 }
498 // Inspect each tab setting
499 for (PreferenceSetting setting : settings) {
500 if (setting instanceof TabPreferenceSetting) {
501 TabPreferenceSetting tps = (TabPreferenceSetting) setting;
502 if (expert || !tps.isExpert()) {
503 // Get icon
504 String iconName = tps.getIconName();
505 ImageIcon icon = null;
506
507 if (iconName != null && !iconName.isEmpty()) {
508 icon = ImageProvider.get("preferences", iconName, ImageProvider.ImageSizes.SETTINGS_TAB);
509 }
510 if (settingsInitialized.contains(tps)) {
511 // If it has been initialized, add corresponding tab(s)
512 addGUITabsForSetting(icon, tps);
513 } else {
514 // If it has not been initialized, create an empty tab with only icon and tooltip
515 addTab(null, icon, new PreferencePanel(tps), tps.getTooltip());
516 }
517 }
518 } else if (!(setting instanceof SubPreferenceSetting)) {
519 Logging.warn("Ignoring preferences "+setting);
520 }
521 }
522 if (sel != null) {
523 int index = indexOfComponent(sel);
524 if (index > -1) {
525 setSelectedIndex(index);
526 }
527 }
528 }
529
530 @Override
531 public void expertChanged(boolean isExpert) {
532 addGUITabs(true);
533 }
534
535 /**
536 * Returns a list of all preferences settings
537 * @return a list of all preferences settings
538 */
539 public List<PreferenceSetting> getSettings() {
540 return Collections.unmodifiableList(settings);
541 }
542
543 /**
544 * Returns the preferences setting for the given class
545 * @param clazz the preference setting class
546 * @param <T> the preference setting type
547 * @return the preferences setting for the given class
548 * @throws NoSuchElementException if there is no such value
549 */
550 public <T extends PreferenceSetting> T getSetting(Class<? extends T> clazz) {
551 return Utils.filteredCollection(settings, clazz).iterator().next();
552 }
553
554 static {
555 // order is important!
556 SETTINGS_FACTORIES.add(new DisplayPreference.Factory());
557 SETTINGS_FACTORIES.add(new DrawingPreference.Factory());
558 SETTINGS_FACTORIES.add(new ColorPreference.Factory());
559 SETTINGS_FACTORIES.add(new LafPreference.Factory());
560 SETTINGS_FACTORIES.add(new LanguagePreference.Factory());
561 SETTINGS_FACTORIES.add(new ServerAccessPreference.Factory());
562 SETTINGS_FACTORIES.add(new AuthenticationPreference.Factory());
563 SETTINGS_FACTORIES.add(new ProxyPreference.Factory());
564 SETTINGS_FACTORIES.add(new OverpassServerPreference.Factory());
565 SETTINGS_FACTORIES.add(new MapPreference.Factory());
566 SETTINGS_FACTORIES.add(new ProjectionPreference.Factory());
567 SETTINGS_FACTORIES.add(new MapPaintPreference.Factory());
568 SETTINGS_FACTORIES.add(new TaggingPresetPreference.Factory());
569 SETTINGS_FACTORIES.add(new BackupPreference.Factory());
570 SETTINGS_FACTORIES.add(new PluginPreference.Factory());
571 SETTINGS_FACTORIES.add(MainApplication.getToolbar());
572 SETTINGS_FACTORIES.add(new AudioPreference.Factory());
573 SETTINGS_FACTORIES.add(new ShortcutPreference.Factory());
574 SETTINGS_FACTORIES.add(new ValidatorPreference.Factory());
575 SETTINGS_FACTORIES.add(new ValidatorTestsPreference.Factory());
576 SETTINGS_FACTORIES.add(new ValidatorTagCheckerRulesPreference.Factory());
577 SETTINGS_FACTORIES.add(new RemoteControlPreference.Factory());
578 SETTINGS_FACTORIES.add(new ImageryPreference.Factory());
579 }
580
581 /**
582 * This mouse wheel listener reacts when a scroll is carried out over the
583 * tab strip and scrolls one tab/down or up, selecting it immediately.
584 */
585 static final class WheelListener implements MouseWheelListener {
586
587 final JTabbedPane tabbedPane;
588
589 WheelListener(JTabbedPane tabbedPane) {
590 this.tabbedPane = tabbedPane;
591 }
592
593 @Override
594 public void mouseWheelMoved(MouseWheelEvent wev) {
595 // Ensure the cursor is over the tab strip
596 if (tabbedPane.indexAtLocation(wev.getPoint().x, wev.getPoint().y) < 0)
597 return;
598
599 // Get currently selected tab && ensure the new tab index is sound
600 int newTab = Utils.clamp(tabbedPane.getSelectedIndex() + wev.getWheelRotation(),
601 0, tabbedPane.getTabCount() - 1);
602
603 tabbedPane.setSelectedIndex(newTab);
604 }
605 }
606
607 @Override
608 public void stateChanged(ChangeEvent e) {
609 int index = getSelectedIndex();
610 Component sel = getSelectedComponent();
611 if (index > -1 && sel instanceof PreferenceTab) {
612 PreferenceTab tab = (PreferenceTab) sel;
613 TabPreferenceSetting preferenceSettings = tab.getTabPreferenceSetting();
614 if (!settingsInitialized.contains(preferenceSettings)) {
615 try {
616 getModel().removeChangeListener(this);
617 preferenceSettings.addGui(this);
618 // Add GUI for sub preferences
619 for (PreferenceSetting setting : settings) {
620 if (setting instanceof SubPreferenceSetting) {
621 addSubPreferenceSetting(preferenceSettings, (SubPreferenceSetting) setting);
622 }
623 }
624 Icon icon = getIconAt(index);
625 remove(index);
626 if (index <= insertGUITabsForSetting(icon, preferenceSettings, index)) {
627 setSelectedIndex(index);
628 }
629 } catch (SecurityException ex) {
630 Logging.error(ex);
631 } catch (RuntimeException ex) { // NOPMD
632 // allow to change most settings even if e.g. a plugin fails
633 BugReportExceptionHandler.handleException(ex);
634 } finally {
635 settingsInitialized.add(preferenceSettings);
636 getModel().addChangeListener(this);
637 }
638 }
639 Container ancestor = getTopLevelAncestor();
640 if (ancestor instanceof PreferenceDialog) {
641 ((PreferenceDialog) ancestor).setHelpContext(preferenceSettings.getHelpContext());
642 }
643 }
644 }
645
646 private void addSubPreferenceSetting(TabPreferenceSetting preferenceSettings, SubPreferenceSetting sps) {
647 if (sps.getTabPreferenceSetting(this) == preferenceSettings) {
648 try {
649 sps.addGui(this);
650 } catch (SecurityException ex) {
651 Logging.error(ex);
652 } catch (RuntimeException ex) { // NOPMD
653 BugReportExceptionHandler.handleException(ex);
654 } finally {
655 settingsInitialized.add(sps);
656 }
657 }
658 }
659}
Note: See TracBrowser for help on using the repository browser.