Search in sources :

Example 31 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class MaximizeWindowAction method actionPerformed.

/**
 * Perform the action. Sets/unsets maximzed mode.
 */
@Override
public void actionPerformed(java.awt.event.ActionEvent ev) {
    state = !state;
    getMenuItem().setSelected(state);
    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    TopComponent curTC = getTCToWorkWith();
    if (wm.isDocked(curTC)) {
        // inside main window
        ModeImpl mode = (ModeImpl) wm.findMode(curTC);
        String tcID = wm.findTopComponentID(curTC);
        if (mode.getKind() == Constants.MODE_KIND_SLIDING) {
            // maximize/restore slided-in window
            wm.userToggledTopComponentSlideInMaximize(tcID);
        } else if (null != mode) {
            ModeImpl previousMax = wm.getCurrentMaximizedMode();
            if (null != previousMax) {
                if (previousMax.getKind() == Constants.MODE_KIND_EDITOR && mode.getKind() == Constants.MODE_KIND_VIEW) {
                    wm.switchMaximizedMode(mode);
                } else {
                    wm.switchMaximizedMode(null);
                }
            } else {
                wm.switchMaximizedMode(mode);
            }
        } else {
            wm.switchMaximizedMode(null);
        }
    } else {
        // separate windows
        ModeImpl curMax = (ModeImpl) wm.findMode(curTC);
        if (curMax != null) {
            if (curMax.getFrameState() == Frame.NORMAL) {
                curMax.setFrameState(Frame.MAXIMIZED_BOTH);
            } else {
                curMax.setFrameState(Frame.NORMAL);
            }
        }
    }
    updateState();
}
Also used : WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) TopComponent(org.openide.windows.TopComponent)

Example 32 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class MinimizeWindowAction method checkEnabled.

private boolean checkEnabled() {
    TopComponent context = TopComponent.getRegistry().getActivated();
    if (null == context) {
        return false;
    }
    SlideController slideController = (SlideController) SwingUtilities.getAncestorOfClass(SlideController.class, context);
    if (null == slideController)
        return false;
    ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance().findMode(context);
    if (null == mode)
        return false;
    if (WindowManagerImpl.getInstance().isTopComponentMinimized(context))
        return false;
    if (mode.getState() != Constants.MODE_STATE_JOINED)
        return false;
    if (mode.getKind() != Constants.MODE_KIND_VIEW)
        return false;
    return Switches.isTopComponentSlidingEnabled() && Switches.isSlidingEnabled(context);
}
Also used : ModeImpl(org.netbeans.core.windows.ModeImpl) SlideController(org.netbeans.core.windows.view.ui.slides.SlideController) TopComponent(org.openide.windows.TopComponent)

Example 33 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class ResetWindowsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final WindowSystem ws = Lookup.getDefault().lookup(WindowSystem.class);
    if (null == ws) {
        // unsupported window system implementation
        Logger.getLogger(ResetWindowsAction.class.getName()).log(Level.INFO, // NOI18N
        "Reset Windows action does not support custom WindowSystem implementations.");
        return;
    }
    final WindowManagerImpl wm = WindowManagerImpl.getInstance();
    // cancel full-screen mode
    MainWindow.getInstance().setFullScreenMode(false);
    wm.getMainWindow().setExtendedState(JFrame.NORMAL);
    // NOI18N
    TopComponentGroupImpl projectTCGroup = (TopComponentGroupImpl) wm.findTopComponentGroup("OpenedProjects");
    final boolean isProjectsTCGroupOpened = null != projectTCGroup && projectTCGroup.isOpened();
    // get a list of editor windows that should stay open even after the reset
    final TopComponent[] editors = collectEditors();
    // close all other windows just in case they hold some references to editor windows
    wm.closeNonEditorViews();
    // hide the main window to hide some window operations before the actual reset is performed
    wm.getMainWindow().setVisible(false);
    // find an editor window that will be activated after the reset (may be null)
    final TopComponent activeEditor = wm.getArbitrarySelectedEditorTopComponent();
    // make sure that componentHidden() gets called on all opened and selected editors
    // so that they can reset their respective states and/or release some listeners
    wm.deselectEditorTopComponents();
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            // find the local folder that must be deleted
            try {
                FileObject rootFolder = PersistenceManager.getDefault().getRootLocalFolder();
                if (reset && null != rootFolder) {
                    for (FileObject fo : rootFolder.getChildren()) {
                        if (PersistenceManager.COMPS_FOLDER.equals(fo.getName()))
                            // do not delete settings files
                            continue;
                        fo.delete();
                    }
                }
            } catch (IOException ioE) {
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioE);
            }
            // reset the window system
            ws.hide();
            WindowManagerImpl.getInstance().resetModel();
            // keep mappings to TopComponents created so far
            PersistenceManager.getDefault().reset();
            PersistenceHandler.getDefault().clear();
            ws.load();
            ws.show();
            if (isProjectsTCGroupOpened) {
                // NOI18N
                TopComponentGroup tcGroup = wm.findTopComponentGroup("OpenedProjects");
                if (null != tcGroup)
                    tcGroup.open();
            }
            // NOI18N
            ModeImpl editorMode = (ModeImpl) wm.findMode("editor");
            RegistryImpl registry = (RegistryImpl) TopComponent.getRegistry();
            // re-open editor windows that were opened before the reset
            for (int i = 0; i < editors.length && null != editorMode; i++) {
                ModeImpl mode = (ModeImpl) wm.findMode(editors[i]);
                if (null == mode) {
                    RetainLocation retainLocation = editors[i].getClass().getAnnotation(RetainLocation.class);
                    if (null != retainLocation) {
                        String preferedModeName = retainLocation.value();
                        mode = (ModeImpl) wm.findMode(preferedModeName);
                    }
                }
                if (null == mode) {
                    mode = editorMode;
                }
                if (null != mode)
                    mode.addOpenedTopComponentNoNotify(editors[i]);
                // #210380 - do not call componentOpened on the editors
                registry.addTopComponent(editors[i]);
            }
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    Frame mainWindow = wm.getMainWindow();
                    mainWindow.invalidate();
                    mainWindow.repaint();
                }
            });
            // activate some editor window
            if (null != activeEditor) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        activeEditor.requestActive();
                    }
                });
            }
        }
    });
}
Also used : WindowSystem(org.netbeans.core.WindowSystem) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) RetainLocation(org.openide.windows.RetainLocation) IOException(java.io.IOException) TopComponentGroup(org.openide.windows.TopComponentGroup) TopComponentGroupImpl(org.netbeans.core.windows.TopComponentGroupImpl) RegistryImpl(org.netbeans.core.windows.RegistryImpl) FileObject(org.openide.filesystems.FileObject) TopComponent(org.openide.windows.TopComponent)

Example 34 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class ResizeModeAction method updateEnabled.

private void updateEnabled() {
    ModeImpl contextMode = getModeToWorkWith();
    if (null == contextMode || contextMode.getKind() == Constants.MODE_KIND_EDITOR || contextMode.getState() == Constants.MODE_STATE_SEPARATED || null == contextMode.getSelectedTopComponent()) {
        setEnabled(false);
        return;
    }
    Component c = contextMode.getSelectedTopComponent();
    MultiSplitPane splitPane = (MultiSplitPane) SwingUtilities.getAncestorOfClass(MultiSplitPane.class, c);
    if (null == splitPane) {
        setEnabled(false);
        return;
    }
    setEnabled(true);
}
Also used : ModeImpl(org.netbeans.core.windows.ModeImpl) MultiSplitPane(org.netbeans.core.windows.view.ui.MultiSplitPane) TopComponent(org.openide.windows.TopComponent) Component(java.awt.Component)

Example 35 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class SwitchToRecentDocumentAction method actionPerformed.

/**
 * Perform the action. Sets/unsets maximzed mode.
 */
public void actionPerformed(java.awt.event.ActionEvent ev) {
    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    String[] ids = wm.getRecentViewIDList();
    if (ids.length == 0) {
        return;
    }
    for (int i = 0; i < ids.length; i++) {
        String tcId = ids[i];
        ModeImpl mode = (ModeImpl) wm.findModeForOpenedID(tcId);
        if (mode == null) {
            continue;
        }
        if (mode.getKind() == Constants.MODE_KIND_EDITOR) {
            // #37030 Unmaximize other mode if needed.
            if (mode != wm.getCurrentMaximizedMode()) {
                wm.switchMaximizedMode(null);
            }
            TopComponent tc = wm.findTopComponent(tcId);
            if (null != tc) {
                tc.requestActive();
                break;
            }
        }
    }
}
Also used : WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) TopComponent(org.openide.windows.TopComponent)

Aggregations

ModeImpl (org.netbeans.core.windows.ModeImpl)60 TopComponent (org.openide.windows.TopComponent)35 WindowManagerImpl (org.netbeans.core.windows.WindowManagerImpl)22 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)3 List (java.util.List)3 FileObject (org.openide.filesystems.FileObject)3 Component (java.awt.Component)2 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 BackingStoreException (java.util.prefs.BackingStoreException)2 Preferences (java.util.prefs.Preferences)2 WindowSystem (org.netbeans.core.WindowSystem)2 ModeStructureSnapshot (org.netbeans.core.windows.ModeStructureSnapshot)2 TopComponentTracker (org.netbeans.core.windows.TopComponentTracker)2 MultiSplitPane (org.netbeans.core.windows.view.ui.MultiSplitPane)2 TabActionEvent (org.netbeans.swing.tabcontrol.event.TabActionEvent)2 NbPreferences (org.openide.util.NbPreferences)2