@SuppressWarnings("restriction") public static void enableAppleFullscreen(JFrame window) { window.pack(); window.setVisible(true); setAutoRequestFocus(window, true); if (javaVersion() == 7) { // work around bug in java 7 where top bar space is blank unless undecorated FullScreenUtilities.addFullScreenListenerTo( window, new FullScreenAdapter() { boolean working = false; @Override public void windowEnteredFullScreen(AppEvent.FullScreenEvent e) { if (working) { working = false; return; } ; if (!((JFrame) e.getWindow()).isUndecorated()) { working = true; Application.getApplication().requestToggleFullScreen(e.getWindow()); } } @Override public void windowExitedFullScreen(AppEvent.FullScreenEvent e) { if (working) { e.getWindow().dispose(); ((JFrame) e.getWindow()).setUndecorated(true); e.getWindow().pack(); e.getWindow().setVisible(true); Application.getApplication().requestToggleFullScreen(e.getWindow()); return; } ; if (((JFrame) e.getWindow()).isUndecorated()) { e.getWindow().dispose(); ((JFrame) e.getWindow()).setUndecorated(false); e.getWindow().setVisible(true); } } }); } FullScreenUtilities.setWindowCanFullScreen(window, true); }
public SheetMessage( final Window owner, final String title, final String message, final Icon icon, final String[] buttons, final DialogWrapper.DoNotAskOption doNotAskOption, final String defaultButton, final String focusedButton) { myWindow = new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL); myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE); myWindow.addWindowListener( new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { super.windowActivated(e); } }); myParent = owner; myWindow.setUndecorated(true); myWindow.setBackground(Gray.TRANSPARENT); myController = new SheetController( this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton); imageHeight = 0; registerMoveResizeHandler(); myWindow.setFocusable(true); myWindow.setFocusableWindowState(true); if (SystemInfo.isJavaVersionAtLeast("1.7")) { myWindow.setSize(myController.SHEET_NC_WIDTH, 0); setWindowOpacity(0.0f); myWindow.addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { super.componentShown(e); setWindowOpacity(1.0f); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); } }); } else { myWindow.setModal(true); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); setPositionRelativeToParent(); } startAnimation(true); restoreFullscreenButton = couldBeInFullScreen(); if (restoreFullscreenButton) { FullScreenUtilities.setWindowCanFullScreen(myParent, false); } LaterInvocator.enterModal(myWindow); myWindow.setVisible(true); LaterInvocator.leaveModal(myWindow); }
public MacMainFrameDecorator(@NotNull final IdeFrameImpl frame, final boolean navBar) { myFrame = frame; final ID window = MacUtil.findWindowForTitle(frame.getTitle()); if (window == null) return; if (CURRENT_SETTER == null) { CURRENT_SETTER = navBar ? NAVBAR_SETTER : TOOLBAR_SETTER; CURRENT_GETTER = navBar ? NAVBAR_GETTER : TOOLBAR_GETTER; SHOWN = CURRENT_GETTER.fun(null); } UISettings.getInstance().addUISettingsListener(this, this); final ID pool = invoke("NSAutoreleasePool", "new"); int v = UNIQUE_COUNTER.incrementAndGet(); if (Patches.APPLE_BUG_ID_10514018) { frame.addWindowListener( new WindowAdapter() { @Override public void windowDeiconified(WindowEvent e) { if (e.getWindow() == frame && frame.getState() == Frame.ICONIFIED) { frame.setState(Frame.NORMAL); } } }); } try { if (SystemInfo.isMacOSLion) { if (!FULL_SCREEN_AVAILABLE) return; FullScreenUtilities.addFullScreenListenerTo( frame, new FullScreenAdapter() { @Override public void windowEnteredFullScreen(AppEvent.FullScreenEvent event) { myInFullScreen = true; JRootPane rootPane = frame.getRootPane(); if (rootPane != null) rootPane.putClientProperty(FULL_SCREEN, Boolean.TRUE); if (Patches.APPLE_BUG_ID_10207064) { // fix problem with bottom empty bar // it seems like the title is still visible in fullscreen but the window itself // shifted up for titlebar height // and the size of the frame is still calculated to be the height of the screen // which is wrong // so just add these titlebar height to the frame height once again Timer timer = new Timer( 300, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { frame.setSize( frame.getWidth(), frame.getHeight() + frame.getInsets().top); } }); } }); timer.setRepeats(false); timer.start(); } } @Override public void windowExitedFullScreen(AppEvent.FullScreenEvent event) { myInFullScreen = false; frame.storeFullScreenStateIfNeeded(false); JRootPane rootPane = frame.getRootPane(); if (rootPane != null) rootPane.putClientProperty(FULL_SCREEN, null); } }); } else { // toggle toolbar String className = "IdeaToolbar" + v; final ID ownToolbar = Foundation.allocateObjcClassPair(Foundation.getObjcClass("NSToolbar"), className); Foundation.registerObjcClassPair(ownToolbar); ID toolbar = invoke( invoke(className, "alloc"), "initWithIdentifier:", Foundation.nsString(className)); Foundation.cfRetain(toolbar); invoke(toolbar, "setVisible:", 0); // hide native toolbar by default Foundation.addMethod( ownToolbar, Foundation.createSelector("setVisible:"), SET_VISIBLE_CALLBACK, "v*"); Foundation.addMethod(ownToolbar, Foundation.createSelector("isVisible"), IS_VISIBLE, "B*"); invoke(window, "setToolbar:", toolbar); invoke(window, "setShowsToolbarButton:", 1); } } finally { invoke(pool, "release"); } }
public SheetMessage( final Window owner, final String title, final String message, final Icon icon, final String[] buttons, final DialogWrapper.DoNotAskOption doNotAskOption, final String defaultButton, final String focusedButton) { final Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); final Component recentFocusOwner = activeWindow == null ? null : activeWindow.getMostRecentFocusOwner(); WeakReference<Component> beforeShowFocusOwner = new WeakReference<Component>(recentFocusOwner); maximizeIfNeeded(owner); myWindow = new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL); myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE); myWindow.addWindowListener( new WindowAdapter() { @Override public void windowActivated(@NotNull WindowEvent e) { super.windowActivated(e); } }); myParent = owner; myWindow.setUndecorated(true); myWindow.setBackground(Gray.TRANSPARENT); myController = new SheetController( this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton); imageHeight = 0; registerMoveResizeHandler(); myWindow.setFocusable(true); myWindow.setFocusableWindowState(true); if (SystemInfo.isJavaVersionAtLeast("1.7")) { myWindow.setSize(myController.SHEET_NC_WIDTH, 0); setWindowOpacity(0.0f); myWindow.addComponentListener( new ComponentAdapter() { @Override public void componentShown(@NotNull ComponentEvent e) { super.componentShown(e); setWindowOpacity(1.0f); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); } }); } else { myWindow.setModal(true); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); setPositionRelativeToParent(); } startAnimation(true); restoreFullScreenButton = couldBeInFullScreen(); if (restoreFullScreenButton) { FullScreenUtilities.setWindowCanFullScreen(myParent, false); } LaterInvocator.enterModal(myWindow); myWindow.setVisible(true); LaterInvocator.leaveModal(myWindow); Component focusCandidate = beforeShowFocusOwner.get(); if (focusCandidate == null) { focusCandidate = IdeFocusManager.getGlobalInstance() .getLastFocusedFor(IdeFocusManager.getGlobalInstance().getLastFocusedFrame()); } // focusCandidate is null if a welcome screen is closed and ide frame is not opened. // this is ok. We set focus correctly on our frame activation. if (focusCandidate != null) { focusCandidate.requestFocus(); } }
private void init(FolderPanel leftFolderPanel, FolderPanel rightFolderPanel) { // Set the window icon setWindowIcon(); if (OsFamily.MAC_OS_X.isCurrent()) { // Lion Fullscreen support FullScreenUtilities.setWindowCanFullScreen(this, true); } // Enable window resize setResizable(true); // The toolbar should have no inset, this is why it is left out of the insetsPane JPanel contentPane = new JPanel(new BorderLayout()); setContentPane(contentPane); // Initializes the folder panels and file tables. this.leftFolderPanel = leftFolderPanel; this.rightFolderPanel = rightFolderPanel; leftTable = leftFolderPanel.getFileTable(); rightTable = rightFolderPanel.getFileTable(); activeTable = leftTable; // Create the toolbar and corresponding panel wrapping it, and show it only if it hasn't been // disabled in the // preferences. // Note: Toolbar.setVisible() has to be called no matter if Toolbar is visible or not, in order // for it to be // properly initialized this.toolbar = new ToolBar(this); this.toolbarPanel = ToolbarMoreButton.wrapToolBar(toolbar); this.toolbarPanel.setVisible( MuConfigurations.getPreferences() .getVariable(MuPreference.TOOLBAR_VISIBLE, MuPreferences.DEFAULT_TOOLBAR_VISIBLE)); contentPane.add(toolbarPanel, BorderLayout.NORTH); JPanel insetsPane = new JPanel(new BorderLayout()) { // Add an x=3,y=3 gap around content pane @Override public Insets getInsets() { return new Insets(0, 3, 3, 3); // No top inset } }; // Below the toolbar there is the pane with insets contentPane.add(insetsPane, BorderLayout.CENTER); // Listen to location change events to display the current folder in the window's title leftFolderPanel.getLocationManager().addLocationListener(this); rightFolderPanel.getLocationManager().addLocationListener(this); // Create menu bar (has to be created after toolbar) MainMenuBar menuBar = new MainMenuBar(this); setJMenuBar(menuBar); // Create the split pane that separates folder panels and allows to resize how much space is // allocated to the // both of them. The split orientation is loaded from and saved to the preferences. // Note: the vertical/horizontal terminology used in muCommander is just the opposite of the one // used // in JSplitPane which is anti-natural / confusing. splitPane = new ProportionalSplitPane( this, MuConfigurations.getSnapshot() .getVariable( MuSnapshot.getSplitOrientation(0), MuSnapshot.DEFAULT_SPLIT_ORIENTATION) .equals(MuSnapshot.VERTICAL_SPLIT_ORIENTATION) ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT, false, MainFrame.this.leftFolderPanel, MainFrame.this.rightFolderPanel) { // We don't want any extra space around split pane @Override public Insets getInsets() { return new Insets(0, 0, 0, 0); } }; // Remove any default border the split pane has splitPane.setBorder(null); // Adds buttons that allow to collapse and expand the split pane in both directions splitPane.setOneTouchExpandable(true); // Disable all the JSPlitPane accessibility shortcuts that are registered by default, as some of // them // conflict with default mucommander action shortcuts (e.g. F6 and F8) splitPane.disableAccessibilityShortcuts(); // Split pane will be given any extra space insetsPane.add(splitPane, BorderLayout.CENTER); // Add a 2-pixel gap between the file table and status bar YBoxPanel southPanel = new YBoxPanel(); southPanel.addSpace(2); // Add status bar this.statusBar = new StatusBar(this); southPanel.add(statusBar); // Show command bar only if it hasn't been disabled in the preferences this.commandBar = new CommandBar(this); // Note: CommandBar.setVisible() has to be called no matter if CommandBar is visible or not, in // order for it to be properly initialized this.commandBar.setVisible( MuConfigurations.getPreferences() .getVariable( MuPreference.COMMAND_BAR_VISIBLE, MuPreferences.DEFAULT_COMMAND_BAR_VISIBLE)); southPanel.add(commandBar); insetsPane.add(southPanel, BorderLayout.SOUTH); // Perform CloseAction when the user asked the window to close setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { ActionManager.performAction(CloseWindowAction.Descriptor.ACTION_ID, MainFrame.this); } }); ActionKeymap.registerActions(this); // Fire table change events on registered ActivePanelListener instances, to notify of the intial // active table. fireActivePanelChanged(activeTable.getFolderPanel()); // Set the custom FocusTraversalPolicy that manages focus for both FolderPanel and their // subcomponents. setFocusTraversalPolicy(new CustomFocusTraversalPolicy()); }