Changeset 12127 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-05-12T19:53:09+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #14783 - fix NPE when loading early plugins. Restored the static Main.mainPanel, no other choice in order to maintain public listener methods for early plugins

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r12125 r12127  
    203203
    204204    /**
     205     * The same main panel, required to be static for {@code MapFrameListener} handling.
     206     */
     207    protected static MainPanel mainPanel;
     208
     209    /**
    205210     * The file watcher service.
    206211     */
     
    11531158     */
    11541159    public static boolean addAndFireMapFrameListener(MapFrameListener listener) {
    1155         return main.panel.addAndFireMapFrameListener(listener);
     1160        return mainPanel.addAndFireMapFrameListener(listener);
    11561161    }
    11571162
     
    11641169     */
    11651170    public static boolean addMapFrameListener(MapFrameListener listener) {
    1166         return main.panel.addMapFrameListener(listener);
     1171        return mainPanel.addMapFrameListener(listener);
    11671172    }
    11681173
     
    11741179     */
    11751180    public static boolean removeMapFrameListener(MapFrameListener listener) {
    1176         return main.panel.removeMapFrameListener(listener);
     1181        return mainPanel.removeMapFrameListener(listener);
    11771182    }
    11781183
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12125 r12127  
    8888    private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();
    8989
     90    private static ProgramArguments args;
     91    private static boolean skipLoadingPlugins;
     92
    9093    private final MainFrame mainFrame;
    9194
     
    110113    protected void initializeMainWindow() {
    111114        if (mainFrame != null) {
    112             mainFrame.preInitialize();
    113115            panel = mainFrame.getPanel();
    114116            mainFrame.initialize();
     
    208210     */
    209211    public static void main(final String[] argArray) {
     212        // First initializes all stuff that do not require AWT/Swing
     213        mainNoGui(argArray);
     214        // Then initializes all AWT/Swing stuff
     215        mainGui();
     216    }
     217
     218    /**
     219     * Initializes all stuff that do not require AWT/Swing.
     220     * @param argArray Command-line arguments
     221     */
     222    private static void mainNoGui(final String[] argArray) {
    210223        I18n.init();
    211224
    212225        // construct argument table
    213         ProgramArguments args = null;
    214226        try {
    215227            args = new ProgramArguments(argArray);
     
    261273        COMMAND_LINE_ARGS.addAll(Arrays.asList(argArray));
    262274
    263         boolean skipLoadingPlugins = args.hasOption(Option.SKIP_PLUGINS);
     275        skipLoadingPlugins = args.hasOption(Option.SKIP_PLUGINS);
    264276        if (skipLoadingPlugins) {
    265277            Main.info(tr("Plugin loading skipped"));
     
    286298
    287299        Main.platform.afterPrefStartupHook();
    288 
     300    }
     301
     302    /**
     303     * Initializes all AWT/Swing stuff.
     304     */
     305    private static void mainGui() {
    289306        FontsManager.initialize();
    290307
     
    297314                !args.hasOption(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false));
    298315        final MainFrame mainFrame = new MainFrame(contentPanePrivate, geometry);
     316        Main.mainPanel = mainFrame.getPanel();
    299317        Main.parent = mainFrame;
    300318
  • trunk/src/org/openstreetmap/josm/gui/MainFrame.java

    r12125 r12127  
    4949    protected transient WindowGeometry geometry;
    5050    protected int windowState = JFrame.NORMAL;
    51     private MainPanel panel;
     51    private final MainPanel panel;
    5252    private MainMenu menu;
    5353
     
    6868        super();
    6969        this.geometry = geometry;
     70        this.panel = new MainPanel(Main.getLayerManager());
    7071        setContentPane(contentPanePrivate);
    7172    }
    7273
    7374    /**
    74      * Performs pre-initialization required before the call to {@link #initialize()}.
    75      * @since 12125
    76      */
    77     public void preInitialize() {
    78         panel = new MainPanel(Main.getLayerManager());
    79     }
    80 
    81     /**
    8275     * Initializes the content of the window and get the current status panel.
    83      * {@link #preInitialize()} must have been previously called.
    8476     */
    8577    public void initialize() {
     
    138130     * Gets the main panel.
    139131     * @return The main panel.
    140      * @throws IllegalStateException if the main frame has not been initialized yet
    141      * @see #initialize
    142132     * @since 12125
    143133     */
    144134    public MainPanel getPanel() {
    145         if (panel == null) {
    146             throw new IllegalStateException("Not initialized.");
    147         }
    148135        return panel;
    149136    }
Note: See TracChangeset for help on using the changeset viewer.