Java Code Examples for org.openide.windows.WindowManager#getDefault()

The following examples show how to use org.openide.windows.WindowManager#getDefault() . 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: 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 2
Source File: GetLeftEditorAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Perform the action. Sets/unsets maximzed mode. */
 public void actionPerformed(java.awt.event.ActionEvent ev) {
     WindowManager wm = WindowManager.getDefault();
     MultiViewHandler handler = MultiViews.findMultiViewHandler(wm.getRegistry().getActivated());
     if (handler != null) {
         MultiViewPerspective pers = handler.getSelectedPerspective();
         MultiViewPerspective[] all = handler.getPerspectives();
         for (int i = 0; i < all.length; i++) {
             if (pers.getDisplayName().equals(all[i].getDisplayName())) {
                 int newIndex = i != 0 ? i -1 : all.length - 1;
   MultiViewDescription selectedDescr = Accessor.DEFAULT.extractDescription(pers);
   if (selectedDescr instanceof ContextAwareDescription) {
if (((ContextAwareDescription) selectedDescr).isSplitDescription()) {
    newIndex = i > 1 ? i - 2 : all.length - 1;
} else {
    newIndex = i != 0 ? i - 2 : all.length - 2;
}
   }
                 handler.requestActive(all[newIndex]);
   break;
             }
         }
     } else {
         Utilities.disabledActionBeep();
     }
 }
 
Example 3
Source File: GetRightEditorAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Perform the action. Sets/unsets maximzed mode. */
 public void actionPerformed(java.awt.event.ActionEvent ev) {
     WindowManager wm = WindowManager.getDefault();
     MultiViewHandler handler = MultiViews.findMultiViewHandler(wm.getRegistry().getActivated());
     if (handler != null) {
         MultiViewPerspective pers = handler.getSelectedPerspective();
         MultiViewPerspective[] all = handler.getPerspectives();
         for (int i = 0; i < all.length; i++) {
             if (pers.equals(all[i])) {
                 int newIndex = i != all.length  - 1 ? i + 1 : 0;
   MultiViewDescription selectedDescr = Accessor.DEFAULT.extractDescription(pers);
   if (selectedDescr instanceof ContextAwareDescription) {
if (((ContextAwareDescription) selectedDescr).isSplitDescription()) {
    newIndex = i != all.length  - 1 ? i + 2 : 1;
} else {
    newIndex = i != all.length  - 2 ? i + 2 : 0;
}
   }
                 handler.requestActive(all[newIndex]);
   break;
             }
         }
     } else {
         Utilities.disabledActionBeep();
     }
 }
 
Example 4
Source File: RecentViewList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Used to get array for view and for persistence */
public TopComponent [] getTopComponents() {
    List<TopComponent> tcList = new ArrayList<TopComponent>(tcIdList.size());
    WindowManager wm = WindowManager.getDefault();
    for (int i = 0; i < tcIdList.size(); i++) {
        String tcId = tcIdList.get( i );
        TopComponent tc = null;
        Reference<TopComponent> ref = tcCache.get( tcId );
        if( null != ref ) {
            tc = ref.get();
        }
        if( null == tc ) {
            tc = wm.findTopComponent( tcId );
            if( null != tc )
                tcCache.put( tcId, new WeakReference<TopComponent>( tc ) );
        }
        if ((tc != null) && tc.isOpened()) {
            tcList.add(tc);
        }
    }
    return tcList.toArray(new TopComponent[tcList.size()]);
}
 
Example 5
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 6
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 7
Source File: CSSStylesPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean cssFileFocused() {
    WindowManager manager = WindowManager.getDefault();
    Frame mainWindow = manager.getMainWindow();
    if (mainWindow.isActive()) {
        TopComponent.Registry registry = manager.getRegistry();
        TopComponent activeTC = registry.getActivated();
        if (activeTC != null) {
            if (activeTC instanceof CssStylesTC) {
                return true;
            }
            if (manager.isOpenedEditorTopComponent(activeTC)) {
                FileObject fob = activeTC.getLookup().lookup(FileObject.class);
                if ((fob != null) && "text/css".equals(fob.getMIMEType())) { // NOI18N
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 8
Source File: FormEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void checkFormGroupVisibility() {
    // when active TopComponent changes, check if we should open or close
    // the form editor group of windows (Inspector, Palette, Properties)
    WindowManager wm = WindowManager.getDefault();
    final TopComponentGroup group = wm.findTopComponentGroup("form"); // NOI18N
    if (group == null)
        return; // group not found (should not happen)
    
    boolean designerSelected = false;
    Iterator it = wm.getModes().iterator();
    while (it.hasNext()) {
        Mode mode = (Mode) it.next();
        TopComponent selected = mode.getSelectedTopComponent();
        if (getSelectedElementType(selected) == FORM_ELEMENT_INDEX) {
            designerSelected = true;
            break;
        }
    }

    if (designerSelected && !Boolean.TRUE.equals(groupVisible)) {
        // Bug 116008: calling group.open() first time may cause hiding the
        // FormDesigner (some winsys multiview initialization mess), calling
        // this method again and hiding the group. By setting the groupVisible
        // to false we make the re-entrant call effectively do nothing.
        groupVisible = Boolean.FALSE;
        group.open();
        groupVisible = Boolean.TRUE;
        final TopComponentGroup paletteGroup = wm.findTopComponentGroup( "commonpalette" ); // NOI18N
        if( null != paletteGroup ) {
            paletteGroup.open();
        }
    }
    else if (!designerSelected && !Boolean.FALSE.equals(groupVisible)) {
        group.close();
        groupVisible = Boolean.FALSE;
    }
}
 
Example 9
Source File: ProjectOpenedHookImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void projectOpened() {
    final CssPreprocessorsListener cssSupport = project.getLookup().lookup(CssPreprocessorsListener.class);
    if (cssSupport != null) {
        CssPreprocessors.getDefault().addCssPreprocessorsListener(cssSupport);
    }

    WindowManager windowManager = WindowManager.getDefault();
    windowManager.addWindowSystemListener(WeakListeners.create(WindowSystemListener.class, windowSystemListener, windowManager));

}
 
Example 10
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 11
Source File: ProfilerWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void open() {
    WindowManager windowManager = WindowManager.getDefault();
    if (windowManager.findMode(this) == null) { // needs docking
        Mode mode = windowManager.findMode(Bundle.ProfilerWindow_mode());
        if (mode != null) mode.dockInto(this);
    }
    super.open();
}
 
Example 12
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 13
Source File: LaoutPreviewTopComponent.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
static void hideLaoutPreview() {
    WindowManager wm = WindowManager.getDefault();
    TopComponent topComponent = wm.findTopComponent("LaoutPreviewTopComponent"); // NOI18N
    if (null != topComponent) {
        topComponent.removeAll();
        topComponent.close();
    }
}
 
Example 14
Source File: PaletteTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void showPalette() {
    WindowManager wm = WindowManager.getDefault();
    TopComponent palette = wm.findTopComponent("CommonPalette"); // NOI18N
    if (null == palette) {
        Logger.getLogger(PaletteSwitch.class.getName()).log(Level.INFO, "Cannot find CommonPalette component."); // NOI18N

        //for unit-testing
        palette = getDefault();
    }
    if (!palette.isOpened()) {
        palette.open();
    }
}
 
Example 15
Source File: TileUtilities.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Counts the currently opened top components in modes of kind "editor".
 *
 * @return The number of currently opened top components in modes of kind "editor"
 */
public static int countOpenEditorWindows() {
    int count = 0;
    WindowManager wm = WindowManager.getDefault();
    Set<TopComponent> opened = wm.getRegistry().getOpened();
    for (TopComponent openedWindow : opened) {
        if (wm.isEditorTopComponent(openedWindow)) {
            count++;
        }
    }
    return count;
}
 
Example 16
Source File: TopComponentCreationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test saving of TopComponent with persistence type
 * TopComponent.PERSISTENCE_ALWAYS.
 */
public void testSavePersistentTopComponent () throws Exception {
    WindowManager wm = WindowManager.getDefault();
    
    Mode m = wm.findMode("explorer");
    assertNotNull("Mode explorer must be present", m);
    
    TopComponent tc = Component00.getDefault();
    m.dockInto(tc);
    tc.open();
    
    String res = "Windows2Local/Modes/explorer/"
    + wm.findTopComponentID(tc) + ".wstcref";
    //Check that persistent, opened TC is saved ie. wstcref file is created
    PersistenceHandler.getDefault().save();
    //Check wstcref file was created
    assertNotNull(FileUtil.getConfigFile(res));
    deleteLocalData();
    //Check wstcref file was deleted
    assertNull(FileUtil.getConfigFile(res));
    
    //Check that persistent, closed TC is saved ie. wstcref file is created
    tc.close();
    PersistenceHandler.getDefault().save();        
    //Check wstcref file was created
    assertNotNull(FileUtil.getConfigFile(res));
    deleteLocalData();
    //Check wstcref file was deleted
    assertNull(FileUtil.getConfigFile(res));
}
 
Example 17
Source File: RecentViewList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Fills list of weak references with TCs that are in given
 * input list but are not yet contained in list of weak references.
 */
private void fillList(Set<TopComponent> openedTCs) {
    tcCache.clear();
    WindowManager wm = WindowManager.getDefault();
    for (TopComponent curTC: openedTCs) {
        String id = wm.findTopComponentID( curTC );
        if( !tcIdList.contains( id ) ) {
            if( tcIdList.size() > 1 )
                tcIdList.add( 1, id );
            else
                tcIdList.add( id );
        }
        tcCache.put( id, new WeakReference<TopComponent>( curTC ) );
    }
}
 
Example 18
Source File: ProfilerWindow.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void open() {
    WindowManager windowManager = WindowManager.getDefault();
    if (windowManager.findMode(this) == null) { // needs docking
        Mode mode = windowManager.findMode(Bundle.ProfilerWindow_mode());
        if (mode != null) mode.dockInto(this);
    }
    super.open();
}
 
Example 19
Source File: WindowManagerModeTest.java    From netbeans with Apache License 2.0 3 votes vote down vote up
public void testUpdateModeConstraints() {
    
    WindowManager wm = WindowManager.getDefault();
    assertNotNull(wm);
    
    boolean updated = wm.updateModeConstraintsFromXml(editorModeXml);
    
    assertTrue("Should have found and updated the editor Mode", updated);
}
 
Example 20
Source File: WindowManagerModeTest.java    From netbeans with Apache License 2.0 3 votes vote down vote up
public void testCreateAndRemoveAnonymousMode() {

        WindowManager wm = WindowManager.getDefault();
        assertNotNull(wm);

        Mode mode = wm.createModeFromXml(anonymousModeXml);
        assertNotNull("Anonymous Mode should have been created", mode);
        
        assertEquals("Anonymous Mode should be find-able", mode, wm.findMode(mode.getName()));

        assertTrue("Anonymous Mode should have been removed", wm.removeMode(mode));
    }