org.openide.windows.Mode Java Examples

The following examples show how to use org.openide.windows.Mode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyboardPopupSwitcher.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to process given <code>KeyEvent</code> and returns true is event
 * was successfully processed/consumed.
 */
public static boolean processShortcut(KeyEvent kev) {
    WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    // don't perform when focus is dialog
    if (!wmi.getMainWindow().isFocused() &&
        !WindowManagerImpl.isSeparateWindow(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow())) {
        return false;
    }

    if( Boolean.getBoolean("netbeans.winsys.ctrltab.editoronly") ) { //NOI18N
        Mode activeMode = wmi.getActiveMode();
        if( !wmi.isEditorMode(activeMode) )
            return false;
    }

    return doProcessShortcut( kev );
}
 
Example #2
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    WorkspaceTopComponent workspaceTopComponent = FloatIntoWorkspaceAction.promptForWorkspaces();
    if (workspaceTopComponent != null) {
        workspaceTopComponent.requestActive();
        Mode mode = WindowManager.getDefault().findMode(window);
        if (mode != null) {
            TopComponent[] topComponents = WindowManager.getDefault().getOpenedTopComponents(mode);
            for (TopComponent topComponent : topComponents) {
                if (!(topComponent instanceof WorkspaceTopComponent)) {
                    workspaceTopComponent.addTopComponent(topComponent);
                }
            }
        }
    }
}
 
Example #3
Source File: TileUtilities.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Opens a top component in the given mode.
 *
 * @param topComponent The top component to open.
 * @param modeName     The mode's name.
 * @return {@code true} on success.
 */
public static boolean openInMode(TopComponent topComponent, String modeName) {
    Mode mode = WindowManager.getDefault().findMode(modeName);
    if (mode != null) {
        if (!Arrays.asList(mode.getTopComponents()).contains(topComponent)) {
            if (mode.dockInto(topComponent)) {
                topComponent.open();
                return true;
            }
        } else {
            topComponent.open();
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: NewWorkspaceAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    String defaultName = WindowUtilities.getUniqueTitle(Bundle.VAL_NewWorkspaceActionValue(),
                                                        WorkspaceTopComponent.class);
    NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine(Bundle.LBL_NewWorkspaceActionName(),
                                                                  Bundle.CTL_NewWorkspaceActionName());
    d.setInputText(defaultName);
    Object result = DialogDisplayer.getDefault().notify(d);
    if (NotifyDescriptor.OK_OPTION.equals(result)) {
        WorkspaceTopComponent workspaceTopComponent = new WorkspaceTopComponent(d.getInputText());
        Mode editor = WindowManager.getDefault().findMode("editor");
        Assert.notNull(editor, "editor");
        editor.dockInto(workspaceTopComponent);
        workspaceTopComponent.open();
        workspaceTopComponent.requestActive();
    }
}
 
Example #5
Source File: DefaultSplitContainer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean supportsKind(TopComponentDraggable transfer) {
    if( transfer.isModeTransfer() ) {
        ModeView mv = getModeView();
        Mode mode = WindowManagerImpl.getInstance().findMode( mv.getTopComponents().get( 0 ) );
        if( mode.getName().equals( transfer.getMode().getName() ) )
            return false;
    }
    if(transfer.isAllowedToMoveAnywhere()) {
        return true;
    }
    
    boolean isNonEditor = transfer.getKind() == Constants.MODE_KIND_VIEW || transfer.getKind() == Constants.MODE_KIND_SLIDING;
    boolean thisIsNonEditor = getKind() == Constants.MODE_KIND_VIEW || getKind() == Constants.MODE_KIND_SLIDING;

    return (isNonEditor == thisIsNonEditor);

}
 
Example #6
Source File: ActionUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static void cloneWindow(TopComponent tc) {
    if(tc instanceof TopComponent.Cloneable) {
        TopComponent clone = ((TopComponent.Cloneable)tc).cloneComponent();
        int openIndex = -1;
        Mode m = findMode(tc);
        if( null != m ) {
            TopComponent[] tcs = m.getTopComponents();
            for( int i=0; i<tcs.length; i++ ) {
                if( tcs[i] == tc ) {
                    openIndex = i + 1;
                    break;
                }
            }
            if( openIndex >= tcs.length )
                openIndex = -1;
        }
        if( openIndex >= 0 ) {
            clone.openAtTabPosition(openIndex);
        } else {
            clone.open();
        }
        clone.requestActive();
    }
}
 
Example #7
Source File: LaoutPreviewTopComponent.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
static void showLaoutPreview(JPanel panel, String name) {
    WindowManager wm = WindowManager.getDefault();
    TopComponent topComponent = wm.findTopComponent("LaoutPreviewTopComponent"); // NOI18N
    if (topComponent == null) {
        topComponent = new LaoutPreviewTopComponent();
    }
    if (topComponent instanceof LaoutPreviewTopComponent) {
        if (!topComponent.isOpened()) {
            Mode mode = wm.findMode("commonpalette");
            if (mode != null) {
                mode.dockInto(topComponent);
            }
            topComponent.removeAll();
            if (panel != null) {
                topComponent.add(panel);
            }
            topComponent.updateUI();
            topComponent.setName("Laout Preview [" + name + "]");
            topComponent.setToolTipText("Laout Preview [" + name + "]");
            topComponent.open();
        }
    }

}
 
Example #8
Source File: GraphViewerImplementation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void view(InputGraph graph, boolean clone) {

    if (!clone) {
        WindowManager manager = WindowManager.getDefault();
        for (Mode m : manager.getModes()) {
            for (TopComponent t : manager.getOpenedTopComponents(m)) {
                if (t instanceof EditorTopComponent) {
                    EditorTopComponent etc = (EditorTopComponent) t;
                    if (etc.getModel().getGroup().getGraphs().contains(graph)) {
                        etc.getModel().selectGraph(graph);
                        t.requestActive();
                        return;
                    }
                }
            }
        }
    }

    Diagram diagram = Diagram.createDiagram(graph, Settings.get().get(Settings.NODE_TEXT, Settings.NODE_TEXT_DEFAULT));
    EditorTopComponent tc = new EditorTopComponent(diagram);
    tc.open();
    tc.requestActive();
}
 
Example #9
Source File: DesignView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    BIG: for (Mode m : WindowManager.getDefault().getModes()) {
        boolean found = false;
        for (TopComponent topComponent : m.getTopComponents()) {
            if (topComponent instanceof DesignViewComponent) {
                found = true;
                continue;
            }
            topComponent.close();
        }
        if (!found) {
            final DesignViewComponent mc = new DesignViewComponent();
            m.dockInto(mc);
            mc.open();
        }
    }
}
 
Example #10
Source File: AnalysisResultTopComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static synchronized AnalysisResultTopComponent findInstance() {
    TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
    if (win instanceof AnalysisResultTopComponent) {
        return (AnalysisResultTopComponent) win;
    }
    if (win == null) {
        Logger.getLogger(AnalysisResultTopComponent.class.getName()).warning(
                "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
    } else {
        Logger.getLogger(AnalysisResultTopComponent.class.getName()).warning(
                "There seem to be multiple components with the '" + PREFERRED_ID +
                "' ID. That is a potential source of errors and unexpected behavior.");
    }
    
    AnalysisResultTopComponent result = new AnalysisResultTopComponent();
    Mode outputMode = WindowManager.getDefault().findMode("output");
    
    if (outputMode != null) {
        outputMode.dockInto(result);
    }
    return result;
}
 
Example #11
Source File: KnockoutTCController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the Knockout top component group.
 * 
 * @param koVersion version of Knockout used by the inspected page.
 */
private void openKnockoutTCGroup(final String koVersion) {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            TopComponentGroup group = getKnockoutTCGroup();
            KnockoutTC knockoutTC = (KnockoutTC)getKnockoutTC();
            knockoutTC.knockoutUsed(pageModel, koVersion);
            Mode mode = WindowManager.getDefault().findMode(knockoutTC);
            TopComponent selectedTC = mode.getSelectedTopComponent();
            group.open();
            if (selectedTC != null) {
                // When the group is opened then Knockout view jumps
                // to front by default. We don't want this.
                // CSS Styles view is more important probably.
                // This call moves the original TC from the same
                // mode to front.
                selectedTC.requestVisible();
            }
        }
    });
}
 
Example #12
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the file selected in the editor.
 * 
 * @return file selected in the editor.
 */
private static FileObject selectedEditorFile() {
    WindowManager manager = WindowManager.getDefault();
    TopComponent.Registry registry = manager.getRegistry();
    TopComponent active = registry.getActivated();
    if ((active == null) || !manager.isOpenedEditorTopComponent(active)) {
        active = null;
        for (Mode mode : manager.getModes()) {
            if (manager.isEditorMode(mode)) {
                active = mode.getSelectedTopComponent();
                if (active != null) {
                    break;
                }
            }
        }
    }
    FileObject selectedFile = null;
    if (active != null) {
        selectedFile = active.getLookup().lookup(FileObject.class);
    }
    return selectedFile;
}
 
Example #13
Source File: AttachWindowAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Uses Central.userDroppedTopComponents(ModeImpl mode, TopComponentDraggable draggable, String side)
 * to attach source TopComponent to target Mode according to sideConstant
 * value.
 * @param sourceTc source TopComponent
 * @param mode target mode
 * @param sideConstant side constant
 */
private static void attachTopComponent(TopComponent sourceTc, Mode mode, String sideConstant) {
    try {
        Class<?> centralClass = classForName("org.netbeans.core.windows.Central");
        Class<?> tcdClass = classForName("org.netbeans.core.windows.view.dnd.TopComponentDraggable");
        Class<?> modeImplClass = classForName("org.netbeans.core.windows.ModeImpl");
        Method attachMethod = centralClass.getMethod("userDroppedTopComponents", modeImplClass, tcdClass, String.class);
        Method getCentralMethod = WindowManager.getDefault().getClass().getDeclaredMethod("getCentral", (Class<?>[]) null);
        getCentralMethod.setAccessible(true);
        Object centralInstance = getCentralMethod.invoke(WindowManager.getDefault(), (Object[]) null);
        Constructor<?> tcdConstructor = tcdClass.getDeclaredConstructor(TopComponent.class);
        tcdConstructor.setAccessible(true);
        Object tcdInstance = tcdConstructor.newInstance(sourceTc);
        attachMethod.setAccessible(true);
        attachMethod.invoke(centralInstance, mode, tcdInstance, sideConstant);
    } catch (Exception e) {
        throw new JemmyException("Cannot attach TopComponent.", e);
    }
}
 
Example #14
Source File: MonitorAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void openTransactionView() {

	TransactionView tv = TransactionView.getInstance(); 
        WindowManager wm = WindowManager.getDefault();
	Mode mode = wm.findMode(tv);
        
        if(mode == null) {
            mode = wm.findMode("output"); // NOI18N
            if(mode != null) {
                mode.dockInto(tv);
            }
        }
	tv.open();
        tv.requestVisible();
        tv.requestActive();        
    }
 
Example #15
Source File: MaximizeWindowAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Performs Maximize Window by IDE API on given top component operator 
 * which is activated before the action.
 * @param tco top component operator which should be activated and maximized
 */
public void performAPI(final TopComponentOperator tco) {
    tco.makeComponentVisible();
    // run in dispatch thread
    tco.getQueueTool().invokeSmoothly(new Runnable() {

        @Override
        public void run() {
            WindowManager wm = WindowManager.getDefault();
            TopComponent tc = (TopComponent) tco.getSource();
            Mode mode = wm.findMode(tc);
            if (mode == null) {
                throw new JemmyException("Mode not found for " + tc);
            }
            AttachWindowAction.callWindowManager("switchMaximizedMode", mode);
        }
    });
}
 
Example #16
Source File: EditorTopComponent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static EditorTopComponent getActive() {
    Set<? extends Mode> modes = WindowManager.getDefault().getModes();
    for (Mode m : modes) {
        TopComponent tc = m.getSelectedTopComponent();
        if (tc instanceof EditorTopComponent) {
            return (EditorTopComponent) tc;
        }
    }
    return null;
}
 
Example #17
Source File: ExplorerTopComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void open() {
    if (needsDocking()) {
        Mode mode = WindowManager.getDefault().findMode("explorer"); // NOI18N
        if (mode != null) mode.dockInto(this);
    }
    super.open();
}
 
Example #18
Source File: EditorTopComponent.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static EditorTopComponent getActive() {
    Set<? extends Mode> modes = WindowManager.getDefault().getModes();
    for (Mode m : modes) {
        TopComponent tc = m.getSelectedTopComponent();
        if (tc instanceof EditorTopComponent) {
            return (EditorTopComponent) tc;
        }
    }
    return null;
}
 
Example #19
Source File: SnapshotsWindowUI.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void open() {
    WindowManager wmanager = WindowManager.getDefault();
    if (wmanager.findMode(this) == null) { // needs docking
        Mode _mode = wmanager.findMode(Bundle.SnapshotsWindowUI_mode());
        if (_mode != null) _mode.dockInto(this);
    }
    super.open();
}
 
Example #20
Source File: AddWatchAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void openWatchesView() {
    // open watches view
    TopComponent watchesView = WindowManager.getDefault().findTopComponent("watchesView"); // NOI18N
    if (watchesView != null && watchesView.isOpened()) {
        Mode mw = WindowManager.getDefault().findMode(watchesView);
        if (mw != null && mw.getSelectedTopComponent() == watchesView) {
            return ; // Watches is already selected
        }
    }
    String viewName = VariablesViewButtons.isWatchesViewNested() ? "localsView" : "watchesView";
    ViewActions.openComponent (viewName, false).requestVisible();
}
 
Example #21
Source File: TextEditorComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
    */
   private void dockIntoEditorMode () {
// dock into editor mode if possible        
       Workspace current = WindowManager.getDefault().getCurrentWorkspace();
       Mode editorMode = current.findMode (CloneableEditorSupport.EDITOR_MODE);
       if ( editorMode != null ) {
           editorMode.dockInto (this);
       }        
   }
 
Example #22
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private TopComponent dockInternalFrame(JInternalFrame internalFrame) {
    TopComponent topComponent = closeInternalFrame(internalFrame, true);

    Mode mode = WindowManager.getDefault().findMode("editor");
    mode.dockInto(topComponent);
    if (!topComponent.isOpened()) {
        topComponent.open();
    }

    return topComponent;
}
 
Example #23
Source File: PaletteSwitchTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initViewTopComponent( TopComponent tc ) throws IOException {
    Mode viewMode = WindowManagerImpl.getInstance().findMode( "unitTestViewMode" );
    if( null == viewMode ) {
        viewMode = WindowManagerImpl.getInstance().createMode( "unitTestViewMode", Constants.MODE_KIND_VIEW, Constants.MODE_STATE_JOINED, false, new SplitConstraint[0] );
    }
    viewMode.dockInto(tc);
}
 
Example #24
Source File: PaletteSwitchTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initEditorTopComponent( TopComponent tc ) throws IOException {
    Mode editorMode = WindowManagerImpl.getInstance().findMode( "unitTestEditorMode" );
    if( null == editorMode ) {
        editorMode = WindowManagerImpl.getInstance().createMode( "unitTestEditorMode", Constants.MODE_KIND_EDITOR, Constants.MODE_STATE_JOINED, false, new SplitConstraint[0] );
    }
    editorMode.dockInto(tc);
}
 
Example #25
Source File: CssStylesTCController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the CssStylesTC TopComponent is opened but does not initialize it.
 */
private boolean isCSSStylesTCOpened() {
    WindowManager wm = WindowManager.getDefault();
    for(Mode mode : wm.getModes()) {
        if(CssStylesTCController.CSS_TC_MODE.equals(mode.getName())) {
            for(TopComponent tc : wm.getOpenedTopComponents(mode)) {
                if(tc instanceof CssStylesTC) {
                    return true;
                }
            }
            break;
        }
    }
    return false;
}
 
Example #26
Source File: VerifierSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the TC in the output mode and activates it.
 */
public void showInMode() {
    if (!isOpened()) {
        Mode mode = WindowManager.getDefault().findMode("output"); // NOI18N
        if (mode != null) {
            mode.dockInto(this);
        }
    }
    open();
    requestVisible();
    requestActive();
}
 
Example #27
Source File: DocumentWindowManager.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Opens a document window.
 * <p>
 * Document windows are initially opened in the NetBeans {@code "editor"} mode which
 * is the central panel of the main frame.
 *
 * @param documentWindow The document window to be opened.
 * @return {@code true} on success
 */
public boolean openWindow(DocumentWindow documentWindow) {
    TopComponent topComponent = documentWindow.getTopComponent();
    WorkspaceTopComponent workspaceTopComponent = WorkspaceTopComponent.findShowingInstance();
    if (workspaceTopComponent != null) {
        workspaceTopComponent.addTopComponent(topComponent);
        return true;
    }
    Mode editor = WindowManager.getDefault().findMode("editor");
    if (editor.dockInto(topComponent)) {
        topComponent.open();
        return true;
    }
    return false;
}
 
Example #28
Source File: SnapUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Opens a new window in SNAP Desktop.
 *
 * @param window The window which must must be an instance of {@link TopComponent}.
 * @param location The location where the window should appear when it is first opened.
 *                 Possible docking areas are
 *                 "explorer" (upper left), "navigator" (lower left), "properties" (upper right),
 *                 "output" (bottom). You may choose "floating" to not dock the window at all. Note
 *                 that this mode requires explicitly setting the window's position and size.
 * @param requestActive {@code true} if a request will be made to activate the window after opening it.
 */
public static void openWindow(TopComponent window, String location, boolean requestActive) {
    WindowManager.getDefault().invokeWhenUIReady(() -> {
        Mode mode = WindowManager.getDefault().findMode(location);
        if (mode != null) {
            mode.dockInto(window);
        }
        window.open();
        if (requestActive) {
            window.requestActive();
        }
    });
}
 
Example #29
Source File: VerifierSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the TC in the output mode and activates it.
 */
public void showInMode() {
    if (!isOpened()) {
        Mode mode = WindowManager.getDefault().findMode("output"); // NOI18N
        if (mode != null) {
            mode.dockInto(this);
        }
    }
    open();
    requestVisible();
    requestActive();
}
 
Example #30
Source File: DeveloperHtmlBrowserComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void open() {
    WindowManager wm = WindowManager.getDefault();
    Mode mode = wm.findMode( this );
    if( null == mode && !Boolean.getBoolean("webpreview.document") ) { //NOI18N
        mode = wm.findMode("webpreview"); //NOI18N
        if( null != mode ) {
            mode.dockInto( this );
        }
    }
    super.open();
}