Index: /trunk/src/org/openstreetmap/josm/Main.java =================================================================== --- /trunk/src/org/openstreetmap/josm/Main.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/Main.java (revision 12637) @@ -11,5 +11,4 @@ import java.text.MessageFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -32,7 +31,4 @@ import javax.swing.JComponent; import javax.swing.KeyStroke; -import javax.swing.LookAndFeel; -import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; import org.openstreetmap.josm.actions.JosmAction; @@ -54,5 +50,4 @@ import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; -import org.openstreetmap.josm.gui.preferences.display.LafPreference; import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; @@ -60,5 +55,4 @@ import org.openstreetmap.josm.io.OnlineResource; import org.openstreetmap.josm.io.OsmApi; -import org.openstreetmap.josm.plugins.PluginHandler; import org.openstreetmap.josm.tools.CheckParameterUtil; import org.openstreetmap.josm.tools.I18n; @@ -132,7 +126,7 @@ * The MapFrame. *
- * There should be no need to access this to access any map data. Use {@link #layerManager} instead. + * There should be no need to access this to access any map data. Use {@link MainApplication#getLayerManager} instead. * - * @deprecated Use {@link org.openstreetmap.josm.gui.MainApplication#getMap()} instead + * @deprecated Use {@link MainApplication#getMap()} instead * @see MainPanel */ @@ -142,5 +136,7 @@ /** * The toolbar preference control to register new actions. - */ + * @deprecated Use {@link MainApplication#getToolbar} instead + */ + @Deprecated public static volatile ToolbarPreferences toolbar; @@ -744,59 +740,7 @@ public static void preConstructorInit() { ProjectionPreference.setProjection(); - - String defaultlaf = platform.getDefaultStyle(); - String laf = LafPreference.LAF.get(); - try { - UIManager.setLookAndFeel(laf); - } catch (final NoClassDefFoundError | ClassNotFoundException e) { - // Try to find look and feel in plugin classloaders - Logging.trace(e); - Class> klass = null; - for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) { - try { - klass = cl.loadClass(laf); - break; - } catch (ClassNotFoundException ex) { - Logging.trace(ex); - } - } - if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) { - try { - UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance()); - } catch (ReflectiveOperationException ex) { - Logging.log(Logging.LEVEL_WARN, "Cannot set Look and Feel: " + laf + ": "+ex.getMessage(), ex); - } catch (UnsupportedLookAndFeelException ex) { - Logging.info("Look and Feel not supported: " + laf); - LafPreference.LAF.put(defaultlaf); - Logging.trace(ex); - } - } else { - Logging.info("Look and Feel not found: " + laf); - LafPreference.LAF.put(defaultlaf); - } - } catch (UnsupportedLookAndFeelException e) { - Logging.info("Look and Feel not supported: " + laf); - LafPreference.LAF.put(defaultlaf); - Logging.trace(e); - } catch (InstantiationException | IllegalAccessException e) { - Logging.error(e); - } - toolbar = new ToolbarPreferences(); - - UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); - UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); - UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); - UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); - // Ensures caret color is the same than text foreground color, see #12257 - // See http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html - for (String p : Arrays.asList( - "EditorPane", "FormattedTextField", "PasswordField", "TextArea", "TextField", "TextPane")) { - UIManager.put(p+".caretForeground", UIManager.getColor(p+".foreground")); - } - I18n.translateJavaInternalMessages(); // init default coordinate format - // try { CoordinateFormat.setCoordinateFormat(CoordinateFormat.valueOf(Main.pref.get("coordinates"))); Index: /trunk/src/org/openstreetmap/josm/actions/ExpertToggleAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/ExpertToggleAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/ExpertToggleAction.java (revision 12637) @@ -7,6 +7,6 @@ import java.awt.event.ActionEvent; -import org.openstreetmap.josm.Main; import org.openstreetmap.josm.data.preferences.BooleanProperty; +import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.tools.ListenerList; @@ -100,6 +100,6 @@ ); putValue("toolbar", "expertmode"); - if (Main.toolbar != null) { - Main.toolbar.register(this); + if (MainApplication.getToolbar() != null) { + MainApplication.getToolbar().register(this); } setSelected(PREF_EXPERT.get()); Index: /trunk/src/org/openstreetmap/josm/actions/FullscreenToggleAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/FullscreenToggleAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/FullscreenToggleAction.java (revision 12637) @@ -20,4 +20,5 @@ import org.openstreetmap.josm.Main; +import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.tools.Shortcut; @@ -43,5 +44,5 @@ putValue("help", ht("/Action/FullscreenView")); putValue("toolbar", "fullscreen"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); gd = GraphicsEnvironment.isHeadless() ? null : GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); setSelected(Main.pref.getBoolean("draw.fullscreen", false)); Index: /trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java (revision 12637) @@ -10,4 +10,5 @@ import org.openstreetmap.josm.Main; import org.openstreetmap.josm.data.osm.DataSet; +import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog; import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; @@ -31,5 +32,5 @@ putValue("help", ht("/Action/ObjectHistory")); putValue("toolbar", "action/historyinfo"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); setEnabled(true); } Index: /trunk/src/org/openstreetmap/josm/actions/JosmAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/JosmAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/JosmAction.java (revision 12637) @@ -85,6 +85,6 @@ putValue("toolbar", toolbarId); } - if (registerInToolbar && Main.toolbar != null) { - Main.toolbar.register(this); + if (registerInToolbar && MainApplication.getToolbar() != null) { + MainApplication.getToolbar().register(this); } if (installAdapters) { Index: /trunk/src/org/openstreetmap/josm/actions/MoveAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/MoveAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/MoveAction.java (revision 12637) @@ -97,5 +97,5 @@ putValue("toolbar", "action/move/right"); } - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); } Index: /trunk/src/org/openstreetmap/josm/actions/RestartAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/RestartAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/RestartAction.java (revision 12637) @@ -49,6 +49,6 @@ putValue("help", ht("/Action/Restart")); putValue("toolbar", "action/restart"); - if (Main.toolbar != null) { - Main.toolbar.register(this); + if (MainApplication.getToolbar() != null) { + MainApplication.getToolbar().register(this); } setEnabled(isRestartSupported()); Index: /trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java (revision 12637) @@ -65,5 +65,5 @@ putValue("help", ht("/Action/ShowStatusReport")); putValue("toolbar", "help/showstatusreport"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); } Index: /trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java (revision 12637) @@ -7,8 +7,8 @@ import java.awt.event.KeyEvent; -import org.openstreetmap.josm.Main; import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer; +import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.tools.Shortcut; @@ -31,5 +31,5 @@ ); putValue("toolbar", "wireframe"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); setSelected(MapRendererFactory.getInstance().isWireframeMapRendererActive()); notifySelectedState(); Index: /trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java (revision 12637) @@ -465,5 +465,5 @@ // add custom search button to toolbar preferences - Main.toolbar.addCustomButton(res, -1, false); + MainApplication.getToolbar().addCustomButton(res, -1, false); } Index: /trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java (revision 12637) @@ -53,5 +53,5 @@ super(tr("Imagery offset"), "mapmode/adjustimg", tr("Adjust imagery offset"), null, false, false); putValue("toolbar", "imagery-offset"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); } @@ -271,5 +271,5 @@ for (Object item : dynamicItems) { if (item instanceof JMenuItem) { - Optional.ofNullable(((JMenuItem) item).getAction()).ifPresent(Main.toolbar::unregister); + Optional.ofNullable(((JMenuItem) item).getAction()).ifPresent(MainApplication.getToolbar()::unregister); remove((JMenuItem) item); } else if (item instanceof MenuComponent) { Index: /trunk/src/org/openstreetmap/josm/gui/MainApplication.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/MainApplication.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/MainApplication.java (revision 12637) @@ -46,6 +46,9 @@ import javax.swing.JComponent; import javax.swing.JOptionPane; +import javax.swing.LookAndFeel; import javax.swing.RepaintManager; import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; @@ -74,4 +77,6 @@ import org.openstreetmap.josm.gui.layer.MainLayerManager; import org.openstreetmap.josm.gui.layer.TMSLayer; +import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; +import org.openstreetmap.josm.gui.preferences.display.LafPreference; import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; @@ -98,4 +103,5 @@ import org.openstreetmap.josm.tools.HttpClient; import org.openstreetmap.josm.tools.I18n; +import org.openstreetmap.josm.tools.ImageProvider; import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.OpenBrowser; @@ -127,4 +133,9 @@ */ static MapFrame map; + + /** + * The toolbar preference control to register new actions. + */ + static volatile ToolbarPreferences toolbar; private final MainFrame mainFrame; @@ -237,5 +248,5 @@ } else { // required for running some tests. - panel = new MainPanel(MainApplication.getLayerManager()); + panel = new MainPanel(layerManager); menu = new MainMenu(); } @@ -256,5 +267,5 @@ } // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) - getLayerManager().resetState(); + layerManager.resetState(); super.shutdown(); if (!GraphicsEnvironment.isHeadless()) { @@ -289,5 +300,5 @@ return ((DrawAction) map.mapMode).getInProgressSelection(); } else { - DataSet ds = getLayerManager().getEditDataSet(); + DataSet ds = layerManager.getEditDataSet(); if (ds == null) return null; return ds.getSelected(); @@ -307,5 +318,5 @@ * Returns the main layer manager that is used by the map view. * @return The layer manager. The value returned will never change. - * @since 12636 (as a replacement to {@code MainApplication.getLayerManager()}) + * @since 12636 (as a replacement to {@code Main.getLayerManager()}) */ @SuppressWarnings("deprecation") @@ -324,4 +335,13 @@ public static MapFrame getMap() { return map; + } + + /** + * Returns the toolbar preference control to register new actions. + * @return the toolbar preference control + * @since 12637 (as a replacement to {@code Main.toolbar}) + */ + public static ToolbarPreferences getToolbar() { + return toolbar; } @@ -351,5 +371,5 @@ public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) { final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() -> - SaveLayersDialog.saveUnsavedModifications(MainApplication.getLayerManager().getLayers(), + SaveLayersDialog.saveUnsavedModifications(layerManager.getLayers(), reason != null ? reason : SaveLayersDialog.Reason.EXIT))); if (proceed) { @@ -430,4 +450,5 @@ * @param argArray Command-line arguments */ + @SuppressWarnings("deprecation") public static void main(final String[] argArray) { I18n.init(); @@ -576,4 +597,7 @@ monitor.indeterminateSubTask(tr("Setting defaults")); + setupUIManager(); + toolbar = new ToolbarPreferences(); + Main.toolbar = toolbar; preConstructorInit(); @@ -627,4 +651,55 @@ Logging.info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console"); RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager()); + } + } + + static void setupUIManager() { + String defaultlaf = platform.getDefaultStyle(); + String laf = LafPreference.LAF.get(); + try { + UIManager.setLookAndFeel(laf); + } catch (final NoClassDefFoundError | ClassNotFoundException e) { + // Try to find look and feel in plugin classloaders + Logging.trace(e); + Class> klass = null; + for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) { + try { + klass = cl.loadClass(laf); + break; + } catch (ClassNotFoundException ex) { + Logging.trace(ex); + } + } + if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) { + try { + UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance()); + } catch (ReflectiveOperationException ex) { + Logging.log(Logging.LEVEL_WARN, "Cannot set Look and Feel: " + laf + ": "+ex.getMessage(), ex); + } catch (UnsupportedLookAndFeelException ex) { + Logging.info("Look and Feel not supported: " + laf); + LafPreference.LAF.put(defaultlaf); + Logging.trace(ex); + } + } else { + Logging.info("Look and Feel not found: " + laf); + LafPreference.LAF.put(defaultlaf); + } + } catch (UnsupportedLookAndFeelException e) { + Logging.info("Look and Feel not supported: " + laf); + LafPreference.LAF.put(defaultlaf); + Logging.trace(e); + } catch (InstantiationException | IllegalAccessException e) { + Logging.error(e); + } + + UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); + UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); + UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); + UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); + // Ensures caret color is the same than text foreground color, see #12257 + // See http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html + for (String p : Arrays.asList( + "EditorPane", "FormattedTextField", "PasswordField", "TextArea", "TextField", "TextPane")) { + UIManager.put(p+".caretForeground", UIManager.getColor(p+".foreground")); } } Index: /trunk/src/org/openstreetmap/josm/gui/NotificationManager.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/NotificationManager.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/NotificationManager.java (revision 12637) @@ -122,5 +122,5 @@ } else { x = margin; - y = parentWindow.getHeight() - Main.toolbar.control.getSize().height - size.height - margin; + y = parentWindow.getHeight() - MainApplication.getToolbar().control.getSize().height - size.height - margin; } parentWindow.getLayeredPane().add(currentNotificationPanel, JLayeredPane.POPUP_LAYER, 0); Index: /trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java (revision 12637) @@ -548,5 +548,5 @@ SETTINGS_FACTORIES.add(new BackupPreference.Factory()); SETTINGS_FACTORIES.add(new PluginPreference.Factory()); - SETTINGS_FACTORIES.add(Main.toolbar); + SETTINGS_FACTORIES.add(MainApplication.getToolbar()); SETTINGS_FACTORIES.add(new AudioPreference.Factory()); SETTINGS_FACTORIES.add(new ShortcutPreference.Factory()); Index: /trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java (revision 12637) @@ -68,4 +68,5 @@ import org.openstreetmap.josm.data.imagery.ImageryInfo; import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; +import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; import org.openstreetmap.josm.gui.util.GuiHelper; @@ -502,5 +503,5 @@ t.remove(res); Main.pref.putCollection("toolbar", t); - Main.toolbar.refreshToolbarControl(); + MainApplication.getToolbar().refreshToolbarControl(); } }); @@ -523,5 +524,5 @@ p.setVisible(true); // refresh toolbar to try using changed shortcuts without restart - Main.toolbar.refreshToolbarControl(); + MainApplication.getToolbar().refreshToolbarControl(); } }); @@ -987,5 +988,5 @@ } Main.pref.putCollection("toolbar", t); - Main.toolbar.refreshToolbarControl(); + MainApplication.getToolbar().refreshToolbarControl(); return false; } @@ -1214,5 +1215,5 @@ } Main.pref.putCollection("toolbar", t); - Main.toolbar.refreshToolbarControl(); + MainApplication.getToolbar().refreshToolbarControl(); } Index: /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java (revision 12637) @@ -625,5 +625,5 @@ public void actionPerformed(ActionEvent ae) { String res = getToolbarString(); - Main.toolbar.addCustomButton(res, toolbarIndex, true); + MainApplication.getToolbar().addCustomButton(res, toolbarIndex, true); } } Index: /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java (revision 12637) @@ -7,5 +7,4 @@ import java.awt.event.KeyEvent; -import org.openstreetmap.josm.Main; import org.openstreetmap.josm.actions.JosmAction; import org.openstreetmap.josm.gui.MainApplication; @@ -25,5 +24,5 @@ Shortcut.registerShortcut("preset:search", tr("Search presets"), KeyEvent.VK_F3, Shortcut.DIRECT), false); putValue("toolbar", "presets/search"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); } Index: /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java (revision 12637) @@ -39,5 +39,5 @@ false); putValue("toolbar", "presets/search-objects"); - Main.toolbar.register(this); + MainApplication.getToolbar().register(this); } Index: /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java (revision 12637) @@ -219,5 +219,5 @@ final TaggingPreset preset = getSelectedPreset(); if (preset != null) { - Main.toolbar.addCustomButton(preset.getToolbarString(), -1, false); + MainApplication.getToolbar().addCustomButton(preset.getToolbarString(), -1, false); } } Index: /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java =================================================================== --- /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java (revision 12636) +++ /trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java (revision 12637) @@ -16,4 +16,5 @@ import org.openstreetmap.josm.Main; import org.openstreetmap.josm.data.osm.OsmPrimitive; +import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MenuScroller; import org.openstreetmap.josm.gui.tagging.presets.items.CheckGroup; @@ -62,5 +63,5 @@ for (TaggingPreset tp: taggingPresets) { if (!(tp instanceof TaggingPresetSeparator)) { - Main.toolbar.register(tp); + MainApplication.getToolbar().register(tp); } } Index: /trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java =================================================================== --- /trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java (revision 12636) +++ /trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java (revision 12637) @@ -19,7 +19,7 @@ import org.openstreetmap.josm.data.projection.Projections; import org.openstreetmap.josm.gui.MainApplication; +import org.openstreetmap.josm.gui.MainApplicationTest; import org.openstreetmap.josm.gui.MainPanel; import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer; -import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.io.CertificateAmendment; @@ -201,7 +201,9 @@ * Make sure {@code Main.toolbar} is initialized. */ + @SuppressWarnings("deprecation") public static void initToolbar() { + MainApplicationTest.initToolbar(); if (Main.toolbar == null) { - Main.toolbar = new ToolbarPreferences(); + Main.toolbar = MainApplication.getToolbar(); } } Index: /trunk/test/unit/org/openstreetmap/josm/MainTest.java =================================================================== --- /trunk/test/unit/org/openstreetmap/josm/MainTest.java (revision 12636) +++ /trunk/test/unit/org/openstreetmap/josm/MainTest.java (revision 12637) @@ -13,6 +13,4 @@ import java.util.Collection; import java.util.Map; - -import javax.swing.UIManager; import org.junit.Rule; @@ -81,6 +79,4 @@ Main.preConstructorInit(); assertNotNull(Main.getProjection()); - assertEquals(Main.pref.get("laf", Main.platform.getDefaultStyle()), UIManager.getLookAndFeel().getClass().getCanonicalName()); - assertNotNull(Main.toolbar); } Index: /trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java =================================================================== --- /trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java (revision 12636) +++ /trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java (revision 12637) @@ -19,6 +19,9 @@ import java.util.concurrent.Future; +import javax.swing.UIManager; + import org.junit.Rule; import org.junit.Test; +import org.openstreetmap.josm.Main; import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.data.Version; @@ -26,4 +29,5 @@ import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor; import org.openstreetmap.josm.gui.layer.GpxLayer; +import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; import org.openstreetmap.josm.plugins.PluginHandler; import org.openstreetmap.josm.plugins.PluginHandlerTestIT; @@ -47,4 +51,13 @@ @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") public JOSMTestRules test = new JOSMTestRules().main().https().devAPI().timeout(20000); + + /** + * Make sure {@link MainApplication#toolbar} is initialized. + */ + public static void initToolbar() { + if (MainApplication.toolbar == null) { + MainApplication.toolbar = new ToolbarPreferences(); + } + } @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING") @@ -132,4 +145,13 @@ } + /** + * Unit test of {@link MainApplication#setupUIManager}. + */ + @Test + public void testSetupUIManager() { + MainApplication.setupUIManager(); + assertEquals(Main.pref.get("laf", Main.platform.getDefaultStyle()), UIManager.getLookAndFeel().getClass().getCanonicalName()); + } + private static PluginInformation newPluginInformation(String plugin) throws PluginListParseException { return PluginListParser.createInfo(plugin+".jar", "https://svn.openstreetmap.org/applications/editors/josm/dist/"+plugin+".jar",