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


Ignore:
Timestamp:
2017-05-12T01:28:59+02:00 (7 years ago)
Author:
Don-vip
Message:

see #14741 - rework initialization of Main.Panel so that it is done after PlatformHook.preStartupHook, as any other Swing code

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

Legend:

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

    r12119 r12125  
    6565import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    6666import org.openstreetmap.josm.data.validation.OsmValidator;
    67 import org.openstreetmap.josm.gui.MainFrame;
    6867import org.openstreetmap.josm.gui.MainMenu;
    6968import org.openstreetmap.josm.gui.MainPanel;
     
    198197
    199198    /**
     199     * The main panel.
     200     * @since 12125
     201     */
     202    public MainPanel panel;
     203
     204    /**
    200205     * The file watcher service.
    201206     */
     
    213218    @Deprecated
    214219    public static int logLevel = 3;
    215 
    216     /**
    217      * The real main panel. This field may be removed any time and made private to {@link MainFrame}
    218      * @see #panel
    219      */
    220     protected static final MainPanel mainPanel = new MainPanel(getLayerManager());
    221220
    222221    /**
     
    491490    protected Main() {
    492491        setInstance(this);
    493         mainPanel.addMapFrameListener((o, n) -> redoUndoListener.commandChanged(0, 0));
    494492    }
    495493
     
    579577    /**
    580578     * Called once at startup to initialize the main window content.
    581      * Should set {@link #menu}
     579     * Should set {@link #menu} and {@link #panel}
    582580     */
    583581    protected abstract void initializeMainWindow();
     
    716714
    717715    /**
    718      * Global panel.
    719      */
    720     public static final JPanel panel = mainPanel;
    721 
    722     private final CommandQueueListener redoUndoListener = (queueSize, redoSize) -> {
     716     * Listener that sets the enabled state of undo/redo menu entries.
     717     */
     718    protected final CommandQueueListener redoUndoListener = (queueSize, redoSize) -> {
    723719            menu.undo.setEnabled(queueSize > 0);
    724720            menu.redo.setEnabled(redoSize > 0);
     
    770766        toolbar = new ToolbarPreferences();
    771767        contentPanePrivate.updateUI();
    772         panel.updateUI();
    773768
    774769        UIManager.put("OptionPane.okIcon", ImageProvider.get("ok"));
     
    11581153     */
    11591154    public static boolean addAndFireMapFrameListener(MapFrameListener listener) {
    1160         return mainPanel.addAndFireMapFrameListener(listener);
     1155        return main.panel.addAndFireMapFrameListener(listener);
    11611156    }
    11621157
     
    11691164     */
    11701165    public static boolean addMapFrameListener(MapFrameListener listener) {
    1171         return mainPanel.addMapFrameListener(listener);
     1166        return main.panel.addMapFrameListener(listener);
    11721167    }
    11731168
     
    11791174     */
    11801175    public static boolean removeMapFrameListener(MapFrameListener listener) {
    1181         return mainPanel.removeMapFrameListener(listener);
     1176        return main.panel.removeMapFrameListener(listener);
    11821177    }
    11831178
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r11654 r12125  
    198198        JMenu subMenu = Main.main.menu.imagerySubMenu;
    199199        int heightUnrolled = 30*(getItemCount()+subMenu.getItemCount());
    200         if (heightUnrolled < Main.panel.getHeight()) {
     200        if (heightUnrolled < Main.main.panel.getHeight()) {
    201201            // add all items of submenu if they will fit on screen
    202202            int n = subMenu.getItemCount();
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r11925 r12125  
    8888    private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();
    8989
    90     private MainFrame mainFrame;
     90    private final MainFrame mainFrame;
    9191
    9292    /**
     
    109109    @Override
    110110    protected void initializeMainWindow() {
    111         mainPanel.reAddListeners();
    112111        if (mainFrame != null) {
     112            mainFrame.preInitialize();
     113            panel = mainFrame.getPanel();
    113114            mainFrame.initialize();
    114 
    115115            menu = mainFrame.getMenu();
    116116        } else {
    117117            // required for running some tests.
     118            panel = new MainPanel(Main.getLayerManager());
    118119            menu = new MainMenu();
    119120        }
     121        panel.addMapFrameListener((o, n) -> redoUndoListener.commandChanged(0, 0));
     122        panel.reAddListeners();
    120123    }
    121124
  • trunk/src/org/openstreetmap/josm/gui/MainFrame.java

    r11905 r12125  
    4949    protected transient WindowGeometry geometry;
    5050    protected int windowState = JFrame.NORMAL;
     51    private MainPanel panel;
    5152    private MainMenu menu;
    5253
     
    7172
    7273    /**
     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    /**
    7382     * Initializes the content of the window and get the current status panel.
     83     * {@link #preInitialize()} must have been previously called.
    7484     */
    7585    public void initialize() {
     
    98108        refreshTitle();
    99109
    100         getContentPane().add(Main.panel, BorderLayout.CENTER);
     110        getContentPane().add(panel, BorderLayout.CENTER);
    101111        menu.initialize();
    102112    }
     
    115125     * Gets the main menu used for this window.
    116126     * @return The main menu.
     127     * @throws IllegalStateException if the main frame has not been initialized yet
     128     * @see #initialize
    117129     */
    118130    public MainMenu getMenu() {
     
    121133        }
    122134        return menu;
     135    }
     136
     137    /**
     138     * Gets the main panel.
     139     * @return The main panel.
     140     * @throws IllegalStateException if the main frame has not been initialized yet
     141     * @see #initialize
     142     * @since 12125
     143     */
     144    public MainPanel getPanel() {
     145        if (panel == null) {
     146            throw new IllegalStateException("Not initialized.");
     147        }
     148        return panel;
    123149    }
    124150
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java

    r11746 r12125  
    7171     */
    7272    public void pasteOn(OsmDataLayer editLayer, EastNorth mPosition, Transferable transferable) {
    73         importData(new TransferSupport(Main.panel, transferable), editLayer, mPosition);
     73        importData(new TransferSupport(Main.main.panel, transferable), editLayer, mPosition);
    7474    }
    7575
     
    8080    public void pasteTags(Collection<? extends OsmPrimitive> primitives) {
    8181        Transferable transferable = ClipboardUtils.getClipboardContent();
    82         importTags(new TransferSupport(Main.panel, transferable), primitives);
     82        importTags(new TransferSupport(Main.main.panel, transferable), primitives);
    8383    }
    8484
Note: See TracChangeset for help on using the changeset viewer.