--- a/core.windows/manifest.mf Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/manifest.mf Tue Nov 23 17:48:26 2010 +0100 @@ -6,5 +6,5 @@ OpenIDE-Module-Recommends: org.netbeans.core.windows.nativeaccess.NativeWindowSystem AutoUpdate-Show-In-Client: false AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 2.23 +OpenIDE-Module-Specification-Version: 2.24 --- a/core.windows/src/org/netbeans/core/windows/actions/ResetWindowsAction.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/actions/ResetWindowsAction.java Tue Nov 23 17:48:26 2010 +0100 @@ -79,6 +79,7 @@ @ActionReference(position = 3000, path = "Menu/Window") public class ResetWindowsAction implements ActionListener { + @Override public void actionPerformed(ActionEvent e) { final WindowSystem ws = Lookup.getDefault().lookup( WindowSystem.class ); if( null == ws ) { @@ -90,10 +91,8 @@ final WindowManagerImpl wm = WindowManagerImpl.getInstance(); - if( wm.getMainWindow() instanceof MainWindow ) { - //cancel full-screen mode - ((MainWindow) wm.getMainWindow()).setFullScreenMode( false ); - } + //cancel full-screen mode + MainWindow.getInstance().setFullScreenMode(false); wm.getMainWindow().setExtendedState( JFrame.NORMAL ); @@ -116,6 +115,7 @@ wm.deselectEditorTopComponents(); SwingUtilities.invokeLater( new Runnable() { + @Override public void run() { //find the local folder that must be deleted FileObject rootFolder = FileUtil.getConfigFile( PersistenceManager.ROOT_LOCAL_FOLDER ); @@ -150,6 +150,7 @@ editorMode.addOpenedTopComponentNoNotify(editors[i]); } SwingUtilities.invokeLater( new Runnable() { + @Override public void run() { Frame mainWindow = wm.getMainWindow(); mainWindow.invalidate(); @@ -159,6 +160,7 @@ //activate some editor window if( null != activeEditor ) { SwingUtilities.invokeLater( new Runnable() { + @Override public void run() { activeEditor.requestActive(); } --- a/core.windows/src/org/netbeans/core/windows/actions/ToggleFullScreenAction.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/actions/ToggleFullScreenAction.java Tue Nov 23 17:48:26 2010 +0100 @@ -74,6 +74,7 @@ public ToggleFullScreenAction() { addPropertyChangeListener( new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { if( Action.ACCELERATOR_KEY.equals(evt.getPropertyName()) ) { synchronized( ToggleFullScreenAction.this ) { @@ -86,12 +87,14 @@ }); } + @Override public JComponent[] getMenuPresenters() { createItems(); updateState(); return menuItems; } + @Override public JComponent[] synchMenuPresenters(JComponent[] items) { updateState(); return menuItems; @@ -112,8 +115,7 @@ synchronized( this ) { createItems(); menuItems[0].setSelected(null != frame - && (frame instanceof MainWindow) - && ((MainWindow)frame).isFullScreenMode()); + && MainWindow.getInstance().isFullScreenMode()); } } @@ -129,22 +131,25 @@ } /** Perform the action. Sets/unsets maximzed mode. */ + @Override public void actionPerformed(java.awt.event.ActionEvent ev) { - MainWindow frame = (MainWindow)WindowManager.getDefault().getMainWindow(); - frame.setFullScreenMode( !frame.isFullScreenMode() ); + MainWindow mainWindow = MainWindow.getInstance(); + mainWindow.setFullScreenMode( !mainWindow.isFullScreenMode() ); } + @Override public String getName() { return NbBundle.getMessage(ToggleFullScreenAction.class, "CTL_ToggleFullScreenAction"); } + @Override public HelpCtx getHelpCtx() { return new HelpCtx(ToggleFullScreenAction.class); } @Override public boolean isEnabled() { - return WindowManager.getDefault().getMainWindow() instanceof MainWindow; + return WindowManager.getDefault().getMainWindow() == MainWindow.getInstance().getFrame(); } } --- a/core.windows/src/org/netbeans/core/windows/view/DefaultView.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/view/DefaultView.java Tue Nov 23 17:48:26 2010 +0100 @@ -100,7 +100,7 @@ // XXX public Frame getMainWindow() { - return hierarchy.getMainWindow(); + return hierarchy.getMainWindow().getFrame(); } public Component getEditorAreaComponent() { @@ -186,7 +186,7 @@ return; } } - + // Process all event types. for(int i = 0; i < viewEvents.length; i++) { ViewEvent viewEvent = viewEvents[i]; @@ -520,6 +520,8 @@ // }, AWTEvent.FOCUS_EVENT_MASK); hierarchy.getMainWindow().initializeComponents(); + + JFrame frame = hierarchy.getMainWindow().getFrame(); // Init toolbar. ToolbarPool.getDefault().setConfiguration(wsa.getToolbarConfigurationName()); @@ -569,7 +571,7 @@ // XXX PENDING if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { // Ignore when main window is maximized. - if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) { + if(frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { if (DEBUG) { debugLog("do updateMainWindowBoundsSeparatedHelp"); } --- a/core.windows/src/org/netbeans/core/windows/view/ViewHierarchy.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/view/ViewHierarchy.java Tue Nov 23 17:48:26 2010 +0100 @@ -59,8 +59,11 @@ import java.lang.ref.WeakReference; import java.util.*; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import org.netbeans.core.windows.Debug; +import org.netbeans.core.windows.WindowManagerImpl; import org.openide.windows.TopComponent; /** @@ -124,19 +127,33 @@ public MainWindow getMainWindow() { if (mainWindow == null) { - mainWindow = new MainWindow(); + JFrame mainFrame = null; + for( Frame f : Frame.getFrames() ) { + if( f instanceof JFrame ) { + JFrame frame = (JFrame)f; + if( "NbMainWindow".equals(frame.getName())) { //NOI18N + mainFrame = frame; + break; + } + } + } + if( null == mainFrame ) { + mainFrame = new JFrame(); + } + Logger.getLogger(MainWindow.class.getName()).log(Level.FINE, "Installing MainWindow into " + mainFrame); //NOI18N + mainWindow = MainWindow.install(mainFrame); } return mainWindow; } public void installMainWindowListeners() { - mainWindow.addComponentListener(mainWindowListener); - mainWindow.addWindowStateListener(mainWindowListener); + mainWindow.getFrame().addComponentListener(mainWindowListener); + mainWindow.getFrame().addWindowStateListener(mainWindowListener); } public void uninstallMainWindowListeners() { - mainWindow.removeComponentListener(mainWindowListener); - mainWindow.removeWindowStateListener(mainWindowListener); + mainWindow.getFrame().removeComponentListener(mainWindowListener); + mainWindow.getFrame().removeWindowStateListener(mainWindowListener); } /** Updates the view hierarchy according to new structure. */ @@ -598,17 +615,18 @@ } public void updateMainWindowBounds(WindowSystemAccessor wsa) { + JFrame frame = mainWindow.getFrame(); if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { - mainWindow.setBounds(wsa.getMainWindowBoundsJoined()); + frame.setBounds(wsa.getMainWindowBoundsJoined()); } else { // #45832 clear the desktop when going to SDI, setMainWindowDesktop(null); // invalidate to recalculate the main window's preffered size.. - mainWindow.invalidate(); - mainWindow.setBounds(wsa.getMainWindowBoundsSeparated()); + frame.invalidate(); + frame.setBounds(wsa.getMainWindowBoundsSeparated()); } // #38146 So the updateSplit works with correct size. - mainWindow.validate(); + frame.validate(); // PENDING consider better handling this event so there is not doubled // validation (one in MainWindow - needs to be provided here) and this as second one. } @@ -815,6 +833,7 @@ private EditorAreaFrame createEditorAreaFrame() { final EditorAreaFrame frame = new EditorAreaFrame(); frame.addComponentListener(new ComponentAdapter() { + @Override public void componentResized(ComponentEvent evt) { if(frame.getExtendedState() == Frame.MAXIMIZED_BOTH) { // Ignore changes when the frame is in maximized state. @@ -823,6 +842,7 @@ controller.userResizedEditorArea(frame.getBounds()); } + @Override public void componentMoved(ComponentEvent evt) { if(frame.getExtendedState() == Frame.MAXIMIZED_BOTH) { // Ignore changes when the frame is in maximized state. @@ -834,6 +854,7 @@ frame.setWindowActivationListener(controller); frame.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent evt) { closeEditorModes(); } @@ -923,7 +944,7 @@ } public void updateUI() { - SwingUtilities.updateComponentTreeUI(mainWindow); + SwingUtilities.updateComponentTreeUI(mainWindow.getFrame()); if(editorAreaFrame != null) { SwingUtilities.updateComponentTreeUI(editorAreaFrame); } @@ -946,6 +967,7 @@ return s; } + @Override public String toString() { return dumpElement(desktop.getSplitRoot(), 0) + "\nseparateViews=" + separateModeViews.keySet(); // NOI18N } --- a/core.windows/src/org/netbeans/core/windows/view/dnd/WindowDnDManager.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/view/dnd/WindowDnDManager.java Tue Nov 23 17:48:26 2010 +0100 @@ -496,7 +496,7 @@ private TopComponentDroppable findMainWindowDroppable( Point location, int kind, TopComponent transfer) { - MainWindow mainWindow = (MainWindow)WindowManagerImpl.getInstance().getMainWindow(); + JFrame mainWindow = (JFrame)WindowManagerImpl.getInstance().getMainWindow(); if (!ZOrderManager.getInstance().isOnTop(mainWindow, location)) { return null; @@ -635,7 +635,7 @@ /** Indicates whether the cursor is around center panel of main window. * In that case is needed also to provide a drop. */ static boolean isAroundCenterPanel(Point location) { - Component desktop = ((MainWindow)WindowManagerImpl.getInstance().getMainWindow()).getDesktop(); + Component desktop = MainWindow.getInstance().getDesktop(); if(desktop == null) { return false; } @@ -683,7 +683,7 @@ /** Indicates whether the cursor is around center panel of main window. * In that case is needed also to provide a drop. */ static boolean isNearEdge(Point location, ViewAccessor viewAccessor) { - Component desktop = ((MainWindow)WindowManagerImpl.getInstance().getMainWindow()).getDesktop(); + Component desktop = MainWindow.getInstance().getDesktop(); if(desktop == null) { return false; } @@ -1155,7 +1155,7 @@ /** Implements TopComponentDroppable. */ public Component getDropComponent() { - return ((MainWindow)WindowManagerImpl.getInstance().getMainWindow()).getDesktop(); + return MainWindow.getInstance().getDesktop(); } /** Implements TopComponentDroppable. */ --- a/core.windows/src/org/netbeans/core/windows/view/ui/MainWindow.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/view/ui/MainWindow.java Tue Nov 23 17:48:26 2010 +0100 @@ -82,9 +82,12 @@ * * @author Ian Formanek, Petr Hamernik */ -public final class MainWindow extends JFrame { +public final class MainWindow { /** generated Serialized Version UID */ static final long serialVersionUID = -1160791973145645501L; + + private final JFrame frame; + private static JMenuBar mainMenuBar; /** Desktop. */ @@ -101,43 +104,32 @@ private Lookup.Result saveResult; private Lookup.Result dobResult; private LookupListener saveListener; + + private static MainWindow theInstance; /** Constructs main window. */ - public MainWindow() { - if( "Aqua".equals(UIManager.getLookAndFeel().getID()) - && null == System.getProperty("apple.awt.brushMetalLook") ) //NOI18N - getRootPane().putClientProperty("apple.awt.brushMetalLook", Boolean.TRUE); //NOI18N + private MainWindow(JFrame frame) { + this.frame = frame; } - - /** Overrides superclass method, adds help context to the new root pane. */ - @Override - protected void setRootPane(JRootPane root) { - super.setRootPane(root); - if(root != null) { - HelpCtx.setHelpIDString( - root, new HelpCtx(MainWindow.class).getHelpID()); + + public static MainWindow install( JFrame frame ) { + synchronized( MainWindow.class ) { + if( null != theInstance ) { + Logger.getLogger(MainWindow.class.getName()).log(Level.INFO, "Installing MainWindow again, existing frame is: " + theInstance.frame); //NOI18N + } + theInstance = new MainWindow(frame); + return theInstance; } - //Optimization related to jdk bug 4939857 - on pre 1.5 jdk's an - //extra repaint is caused by the search for an opaque component up - //to the component root. Post 1.5, root pane will automatically be - //opaque. - root.setOpaque(true); - if (Utilities.isWindows()) { - // use glass pane that will not cause repaint/revalidate of parent when set visible - // is called (when setting wait cursor in ModuleActions) #40689 - JComponent c = new JPanel() { - @Override - public void setVisible(boolean flag) { - if (flag != isVisible ()) { - super.setVisible(flag); - } - } - }; - c.setName(root.getName()+".nbGlassPane"); // NOI18N - c.setVisible(false); - ((JPanel)c).setOpaque(false); - root.setGlassPane(c); + } + + public static MainWindow getInstance() { + synchronized( MainWindow.class ) { + if( null == theInstance ) { + Logger.getLogger(MainWindow.class.getName()).log(Level.INFO, "Accessing uninitialized MainWindow, using dummy JFrame instead." ); //NOI18N + theInstance = new MainWindow(new JFrame()); + } + return theInstance; } } @@ -155,23 +147,38 @@ } inited = true; + JPanel contentPane = new JPanel(new BorderLayout()) { + @Override + public void paint(Graphics g) { + super.paint(g); + Logger.getLogger(MainWindow.class.getName()).log(Level.FINE, + "Paint method of main window invoked normally."); //NOI18N + // XXX is this only needed by obsolete #24291 hack, or now needed independently? + WindowManagerImpl.getInstance().mainWindowPainted(); + } + + }; + frame.setContentPane(contentPane); + init(); + + initRootPane(); // initialize frame - initFrameIcons(this); + initFrameIcons(frame); initListeners(); - setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - getAccessibleContext().setAccessibleDescription( + frame.getAccessibleContext().setAccessibleDescription( NbBundle.getBundle(MainWindow.class).getString("ACSD_MainWindow")); - setJMenuBar(mainMenuBar); + frame.setJMenuBar(mainMenuBar); if (!Constants.NO_TOOLBARS) { JComponent tb = getToolbarComponent(); - getContentPane().add(tb, BorderLayout.NORTH); + frame.getContentPane().add(tb, BorderLayout.NORTH); } if(!Constants.SWITCH_STATUSLINE_IN_MENUBAR) { @@ -207,33 +214,34 @@ decoratePanel (statusLinePanel, false); statusLinePanel.setName("statusLine"); //NOI18N - getContentPane().add (statusLinePanel, BorderLayout.SOUTH); + frame.getContentPane().add (statusLinePanel, BorderLayout.SOUTH); } else { // custom status line provided JComponent status = getCustomStatusLine(); if (status != null) { - getContentPane().add(status, BorderLayout.SOUTH); + frame.getContentPane().add(status, BorderLayout.SOUTH); } } } - getContentPane().add(getDesktopPanel(), BorderLayout.CENTER); + frame.getContentPane().add(getDesktopPanel(), BorderLayout.CENTER); //#38810 start - focusing the main window in case it's not active and the menu is // selected.. MenuSelectionManager.defaultManager().addChangeListener(new ChangeListener(){ + @Override public void stateChanged(ChangeEvent e) { MenuElement[] elems = MenuSelectionManager.defaultManager().getSelectedPath(); if (elems != null && elems.length > 0) { - if (elems[0] == getJMenuBar()) { - if (!isActive()) { - toFront(); + if (elems[0] == frame.getJMenuBar()) { + if (!frame.isActive()) { + frame.toFront(); } } } } }); //#38810 end - setTitle(NbBundle.getMessage(MainWindow.class, "CTL_MainWindow_Title_No_Project", System.getProperty("netbeans.buildnumber"))); + frame.setTitle(NbBundle.getMessage(MainWindow.class, "CTL_MainWindow_Title_No_Project", System.getProperty("netbeans.buildnumber"))); if (Utilities.getOperatingSystem() == Utilities.OS_MAC) { //Show a "save dot" in the close button if a modified file is //being edited @@ -243,10 +251,11 @@ dobResult = Utilities.actionsGlobalContext().lookupResult (DataObject.class); if( null != saveResult && null != dobResult ) { saveListener = new LookupListener() { + @Override public void resultChanged(LookupEvent ev) { if (ev.getSource() == saveResult) { boolean modified = saveResult.allItems().size() > 0; - getRootPane().putClientProperty ("Window.documentModified", //NOI18N + frame.getRootPane().putClientProperty ("Window.documentModified", //NOI18N modified ? Boolean.TRUE : Boolean.FALSE); } else if (ev.getSource() == dobResult) { int count = dobResult.allItems().size(); @@ -256,14 +265,14 @@ FileObject file = dob.getPrimaryFile(); File f = FileUtil.toFile(file); if (f != null) { - getRootPane().putClientProperty("Window.documentFile", f); //NOI18N + frame.getRootPane().putClientProperty("Window.documentFile", f); //NOI18N break; } //Fall through case 0 : //Fall through default : - getRootPane().putClientProperty("Window.documentFile", null); //NOI18N + frame.getRootPane().putClientProperty("Window.documentFile", null); //NOI18N } } } @@ -315,14 +324,66 @@ } return some ? icons : null; } + + protected void initRootPane() { + JRootPane root = frame.getRootPane(); + if( null == root ) + return; + if( "Aqua".equals(UIManager.getLookAndFeel().getID()) + && null == System.getProperty("apple.awt.brushMetalLook") ) //NOI18N + root.putClientProperty("apple.awt.brushMetalLook", Boolean.TRUE); //NOI18N + HelpCtx.setHelpIDString( + root, new HelpCtx(MainWindow.class).getHelpID()); + if (Utilities.isWindows()) { + // use glass pane that will not cause repaint/revalidate of parent when set visible + // is called (when setting wait cursor in ModuleActions) #40689 + JComponent c = new JPanel() { + @Override + public void setVisible(boolean flag) { + if (flag != isVisible ()) { + super.setVisible(flag); + } + } + }; + c.setName(root.getName()+".nbGlassPane"); // NOI18N + c.setVisible(false); + ((JPanel)c).setOpaque(false); + root.setGlassPane(c); + } + } + + + //delegate some JFrame methods for convenience + + public void setBounds(Rectangle bounds) { + frame.setBounds(bounds); + } + + public void setExtendedState(int extendedState) { + frame.setExtendedState(extendedState); + } + + public void setVisible(boolean visible) { + frame.setVisible(visible); + } + + public int getExtendedState() { + return frame.getExtendedState(); + } + + public JMenuBar getJMenuBar() { + return frame.getJMenuBar(); + } static private class StatusLineElementsListener implements LookupListener { private JPanel decoratingPanel; StatusLineElementsListener (JPanel decoratingPanel) { this.decoratingPanel = decoratingPanel; } + @Override public void resultChanged (LookupEvent ev) { SwingUtilities.invokeLater (new Runnable () { + @Override public void run () { decoratePanel (decoratingPanel, false); } @@ -352,7 +413,7 @@ } private void initListeners() { - addWindowListener (new WindowAdapter() { + frame.addWindowListener (new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { LifecycleManager.getDefault().exit(); @@ -362,7 +423,7 @@ public void windowActivated (WindowEvent evt) { // #19685. Cancel foreigner popup when // activated main window. - org.netbeans.core.windows.RegistryImpl.cancelMenu(MainWindow.this); + org.netbeans.core.windows.RegistryImpl.cancelMenu(frame); } } ); @@ -475,12 +536,12 @@ } if( null != forcedBounds ) { bounds = new Rectangle( forcedBounds ); - setPreferredSize( bounds.getSize() ); + frame.setPreferredSize( bounds.getSize() ); forcedBounds = null; } if(!bounds.isEmpty()) { - setBounds(bounds); + frame.setBounds(bounds); } } @@ -510,10 +571,10 @@ if(desktop != null) { getDesktopPanel().add(desktop, BorderLayout.CENTER); } - invalidate(); - validate(); + frame.invalidate(); + frame.validate(); - repaint(); + frame.repaint(); } // XXX PENDING used in DnD only. @@ -539,7 +600,7 @@ // XXX /** Gets bounds of main window without the dektop component. */ public Rectangle getPureMainWindowBounds() { - Rectangle bounds = getBounds(); + Rectangle bounds = frame.getBounds(); // XXX Substract the desktop height, we know the pure main window // is always at the top, the width is same. @@ -551,15 +612,6 @@ return bounds; } - @Override - public void paint(Graphics g) { - super.paint(g); - Logger.getLogger(MainWindow.class.getName()).log(Level.FINE, - "Paint method of main window invoked normally."); //NOI18N - // XXX is this only needed by obsolete #24291 hack, or now needed independently? - WindowManagerImpl.getInstance().mainWindowPainted(); - } - // Full Screen Mode private boolean isFullScreenMode = false; private Rectangle restoreBounds; @@ -575,22 +627,22 @@ } isSwitchingFullScreenMode = true; if( !isFullScreenMode ) { - restoreExtendedState = getExtendedState(); - restoreBounds = getBounds(); - isUndecorated = isUndecorated(); - windowDecorationStyle = getRootPane().getWindowDecorationStyle(); + restoreExtendedState = frame.getExtendedState(); + restoreBounds = frame.getBounds(); + isUndecorated = frame.isUndecorated(); + windowDecorationStyle = frame.getRootPane().getWindowDecorationStyle(); } isFullScreenMode = fullScreenMode; if( Utilities.isWindows() ) - setVisible( false ); + frame.setVisible( false ); else WindowManagerImpl.getInstance().setVisible(false); - dispose(); + frame.dispose(); - setUndecorated( isFullScreenMode || isUndecorated ); + frame.setUndecorated( isFullScreenMode || isUndecorated ); // Added to support Custom Look and Feel with Decorations - getRootPane().setWindowDecorationStyle( isFullScreenMode ? JRootPane.NONE : windowDecorationStyle ); + frame.getRootPane().setWindowDecorationStyle( isFullScreenMode ? JRootPane.NONE : windowDecorationStyle ); final String toolbarConfigName = ToolbarPool.getDefault().getConfiguration(); if( null != toolbarConfigName ) { @@ -602,16 +654,16 @@ final boolean updateBounds = ( !isFullScreenMode );//&& restoreExtendedState != JFrame.MAXIMIZED_BOTH ); GraphicsDevice device = null; - Graphics gc = getGraphics(); + Graphics gc = frame.getGraphics(); if( gc instanceof Graphics2D ) { GraphicsConfiguration conf = ((Graphics2D)gc).getDeviceConfiguration(); if( null != conf ) device = conf.getDevice(); } if( null != device && device.isFullScreenSupported() ) { - device.setFullScreenWindow( isFullScreenMode ? this : null ); + device.setFullScreenWindow( isFullScreenMode ? frame : null ); } else { - setExtendedState( isFullScreenMode ? JFrame.MAXIMIZED_BOTH : restoreExtendedState ); + frame.setExtendedState( isFullScreenMode ? JFrame.MAXIMIZED_BOTH : restoreExtendedState ); } if( updateBounds || (isFullScreenMode() && !Utilities.isWindows()) ) { @@ -623,15 +675,16 @@ } } if( Utilities.isWindows() ) { - setVisible( true ); + frame.setVisible( true ); SwingUtilities.invokeLater( new Runnable() { + @Override public void run() { - invalidate(); - validate(); - repaint(); + frame.invalidate(); + frame.validate(); + frame.repaint(); if( updateBounds ) { - setPreferredSize( restoreBounds.getSize() ); - setBounds( restoreBounds ); + frame.setPreferredSize( restoreBounds.getSize() ); + frame.setBounds( restoreBounds ); } ToolbarPool.getDefault().setConfiguration( toolbarConfigName ); isSwitchingFullScreenMode = false; @@ -640,10 +693,11 @@ } else { WindowManagerImpl.getInstance().setVisible(true); SwingUtilities.invokeLater( new Runnable() { + @Override public void run() { - invalidate(); - validate(); - repaint(); + frame.invalidate(); + frame.validate(); + frame.repaint(); ToolbarPool.getDefault().setConfiguration( toolbarConfigName ); isSwitchingFullScreenMode = false; } @@ -655,6 +709,10 @@ return isFullScreenMode; } + public JFrame getFrame() { + return frame; + } + private static class HeavyWeightPopupFactory extends PopupFactory { @Override --- a/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarConfiguration.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/src/org/netbeans/core/windows/view/ui/toolbars/ToolbarConfiguration.java Tue Nov 23 17:48:26 2010 +0100 @@ -151,8 +151,7 @@ } private void fillToolbarsMenu (JComponent menu, boolean isContextMenu) { - Frame frame = WindowManager.getDefault().getMainWindow(); - boolean fullScreen = (frame instanceof MainWindow) && ((MainWindow)frame).isFullScreenMode(); + boolean fullScreen = MainWindow.getInstance().isFullScreenMode(); Map name2constr = collectAllConstraints(); // generate list of available toolbars --- a/core.windows/test/unit/src/org/netbeans/core/windows/view/ui/CustomMenuBarTest.java Thu Nov 18 15:43:46 2010 -0500 +++ a/core.windows/test/unit/src/org/netbeans/core/windows/view/ui/CustomMenuBarTest.java Tue Nov 23 17:48:26 2010 +0100 @@ -88,7 +88,7 @@ //Verify that test layer was added to default filesystem assertNotNull(FileUtil.getConfigFile("LookAndFeel/MenuBar.instance")); - MainWindow mw = (MainWindow) WindowManager.getDefault().getMainWindow(); + MainWindow mw = MainWindow.getInstance(); mw.initializeComponents(); assertEquals(mw.getJMenuBar(), createMenuBar()); IDEInitializer.removeLayers(); @@ -101,18 +101,18 @@ //Verify that test layer was added to default filesystem assertNotNull(FileUtil.getConfigFile("LookAndFeel/StatusLine.instance")); - MainWindow mw = (MainWindow) WindowManager.getDefault().getMainWindow(); + MainWindow mw = MainWindow.getInstance(); mw.initializeComponents(); - assertTrue(findComponent(mw, createStatusLine())); + assertTrue(findComponent(mw.getFrame(), createStatusLine())); IDEInitializer.removeLayers(); } public void testNoToolbar() throws Exception { - MainWindow mw = (MainWindow) WindowManager.getDefault().getMainWindow(); + MainWindow mw = MainWindow.getInstance(); mw.initializeComponents(); ToolbarPool tp = ToolbarPool.getDefault(); - assertTrue(!findComponent(mw, tp)); + assertTrue(!findComponent(mw.getFrame(), tp)); } private static boolean findComponent(Container cont, Component comp) { --- a/openide.windows/apichanges.xml Thu Nov 18 15:43:46 2010 -0500 +++ a/openide.windows/apichanges.xml Tue Nov 23 17:48:26 2010 +0100 @@ -50,6 +50,22 @@ Window System API + + + Reuse existing JFrame instance (if any) as IDE's main window. + + + + + + When window system loads it checks for existing Frames (java.awt.Frame.getFrames()) and + if there is a JFrame whose name is "NbMainWindow" then it is reused as the main window. + Main menu, toolbars and content pane will be put into this existing JFrame. + If there isn't such a JFrame instance then a new empty JFrame is created + and used for the main window - the same way as before this change. + + + --- a/openide.windows/manifest.mf Thu Nov 18 15:43:46 2010 -0500 +++ a/openide.windows/manifest.mf Tue Nov 23 17:48:26 2010 +0100 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.windows -OpenIDE-Module-Specification-Version: 6.35 +OpenIDE-Module-Specification-Version: 6.36 OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties AutoUpdate-Essential-Module: true