Ignore:
Timestamp:
2017-08-24T23:29:01+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate Main.toolbar. Replacement: gui.MainApplication.getToolbar()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12636 r12637  
    4646import javax.swing.JComponent;
    4747import javax.swing.JOptionPane;
     48import javax.swing.LookAndFeel;
    4849import javax.swing.RepaintManager;
    4950import javax.swing.SwingUtilities;
     51import javax.swing.UIManager;
     52import javax.swing.UnsupportedLookAndFeelException;
    5053
    5154import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
     
    7477import org.openstreetmap.josm.gui.layer.MainLayerManager;
    7578import org.openstreetmap.josm.gui.layer.TMSLayer;
     79import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
     80import org.openstreetmap.josm.gui.preferences.display.LafPreference;
    7681import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
    7782import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;
     
    98103import org.openstreetmap.josm.tools.HttpClient;
    99104import org.openstreetmap.josm.tools.I18n;
     105import org.openstreetmap.josm.tools.ImageProvider;
    100106import org.openstreetmap.josm.tools.Logging;
    101107import org.openstreetmap.josm.tools.OpenBrowser;
     
    127133     */
    128134    static MapFrame map;
     135
     136    /**
     137     * The toolbar preference control to register new actions.
     138     */
     139    static volatile ToolbarPreferences toolbar;
    129140
    130141    private final MainFrame mainFrame;
     
    237248        } else {
    238249            // required for running some tests.
    239             panel = new MainPanel(MainApplication.getLayerManager());
     250            panel = new MainPanel(layerManager);
    240251            menu = new MainMenu();
    241252        }
     
    256267        }
    257268        // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
    258         getLayerManager().resetState();
     269        layerManager.resetState();
    259270        super.shutdown();
    260271        if (!GraphicsEnvironment.isHeadless()) {
     
    289300            return ((DrawAction) map.mapMode).getInProgressSelection();
    290301        } else {
    291             DataSet ds = getLayerManager().getEditDataSet();
     302            DataSet ds = layerManager.getEditDataSet();
    292303            if (ds == null) return null;
    293304            return ds.getSelected();
     
    307318     * Returns the main layer manager that is used by the map view.
    308319     * @return The layer manager. The value returned will never change.
    309      * @since 12636 (as a replacement to {@code MainApplication.getLayerManager()})
     320     * @since 12636 (as a replacement to {@code Main.getLayerManager()})
    310321     */
    311322    @SuppressWarnings("deprecation")
     
    324335    public static MapFrame getMap() {
    325336        return map;
     337    }
     338
     339    /**
     340     * Returns the toolbar preference control to register new actions.
     341     * @return the toolbar preference control
     342     * @since 12637 (as a replacement to {@code Main.toolbar})
     343     */
     344    public static ToolbarPreferences getToolbar() {
     345        return toolbar;
    326346    }
    327347
     
    351371    public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) {
    352372        final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() ->
    353                 SaveLayersDialog.saveUnsavedModifications(MainApplication.getLayerManager().getLayers(),
     373                SaveLayersDialog.saveUnsavedModifications(layerManager.getLayers(),
    354374                        reason != null ? reason : SaveLayersDialog.Reason.EXIT)));
    355375        if (proceed) {
     
    430450     * @param argArray Command-line arguments
    431451     */
     452    @SuppressWarnings("deprecation")
    432453    public static void main(final String[] argArray) {
    433454        I18n.init();
     
    576597
    577598        monitor.indeterminateSubTask(tr("Setting defaults"));
     599        setupUIManager();
     600        toolbar = new ToolbarPreferences();
     601        Main.toolbar = toolbar;
    578602        preConstructorInit();
    579603
     
    627651            Logging.info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console");
    628652            RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
     653        }
     654    }
     655
     656    static void setupUIManager() {
     657        String defaultlaf = platform.getDefaultStyle();
     658        String laf = LafPreference.LAF.get();
     659        try {
     660            UIManager.setLookAndFeel(laf);
     661        } catch (final NoClassDefFoundError | ClassNotFoundException e) {
     662            // Try to find look and feel in plugin classloaders
     663            Logging.trace(e);
     664            Class<?> klass = null;
     665            for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) {
     666                try {
     667                    klass = cl.loadClass(laf);
     668                    break;
     669                } catch (ClassNotFoundException ex) {
     670                    Logging.trace(ex);
     671                }
     672            }
     673            if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) {
     674                try {
     675                    UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance());
     676                } catch (ReflectiveOperationException ex) {
     677                    Logging.log(Logging.LEVEL_WARN, "Cannot set Look and Feel: " + laf + ": "+ex.getMessage(), ex);
     678                } catch (UnsupportedLookAndFeelException ex) {
     679                    Logging.info("Look and Feel not supported: " + laf);
     680                    LafPreference.LAF.put(defaultlaf);
     681                    Logging.trace(ex);
     682                }
     683            } else {
     684                Logging.info("Look and Feel not found: " + laf);
     685                LafPreference.LAF.put(defaultlaf);
     686            }
     687        } catch (UnsupportedLookAndFeelException e) {
     688            Logging.info("Look and Feel not supported: " + laf);
     689            LafPreference.LAF.put(defaultlaf);
     690            Logging.trace(e);
     691        } catch (InstantiationException | IllegalAccessException e) {
     692            Logging.error(e);
     693        }
     694
     695        UIManager.put("OptionPane.okIcon", ImageProvider.get("ok"));
     696        UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon"));
     697        UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel"));
     698        UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon"));
     699        // Ensures caret color is the same than text foreground color, see #12257
     700        // See http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html
     701        for (String p : Arrays.asList(
     702                "EditorPane", "FormattedTextField", "PasswordField", "TextArea", "TextField", "TextPane")) {
     703            UIManager.put(p+".caretForeground", UIManager.getColor(p+".foreground"));
    629704        }
    630705    }
Note: See TracChangeset for help on using the changeset viewer.