Java Code Examples for org.openide.windows.TopComponent#putClientProperty()

The following examples show how to use org.openide.windows.TopComponent#putClientProperty() . 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: ActionManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void someoneActivated() {
    TopComponent win = TopComponent.getRegistry().getActivated();
    if (LOG.isLoggable(Level.FINER)) {
        String winId;
        if (win == null) {
            winId = "<null>";
        } else {
            String winName = win.getDisplayName();
            if (winName == null) {
                winName = win.getHtmlDisplayName();
            }
            if (winName == null) {
                winName = win.getName();
            }
            if (winName != null) {
                winName = '"' + winName + '"';
            } else {
                winName = "<noname>";
            }
            winId = winName + '(' + win.getClass().getName() + ')';
        }
        LOG.log(Level.FINER, "someoneActivated ({0})", winId);
    }

    if ((win == null) || (win instanceof CloneableEditorSupport.Pane)) {
        return;
    }

    Object key = getActionMapKey();
    ActionMap actionMap = win.getActionMap();

    if ((actionMap.get(key) == null) && activatedOnWindows.add(win)) {
        Action ls = getAction();
        actionMap.put(key, ls);
        win.putClientProperty(getMappedActionKey(),
                new WeakReference<Action>(ls));
    }
}
 
Example 2
Source File: DefaultView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
 public String guessSlideSide (TopComponent comp) {
     String toReturn = Constants.LEFT;
     if (hierarchy.getMaximizedModeView() != null) {
//issue #58562
         toReturn = (String)comp.getClientProperty("lastSlideSide");
         if (toReturn == null) {
             //TODO? now how does one figure on startup with maximazed mode where the editor is?
             toReturn = Constants.LEFT;
         }
     } else {
         Rectangle editorb = hierarchy.getPureEditorAreaBounds();
         Point leftTop = new Point(0, 0);
         SwingUtilities.convertPointToScreen(leftTop, comp);
         if (editorb.x > leftTop.x) {
             toReturn = Constants.LEFT;
             comp.putClientProperty("lastSlideSide", toReturn);
         }
         if ((editorb.x + editorb.width) < leftTop.x) {
             toReturn = Constants.RIGHT;
             comp.putClientProperty("lastSlideSide", toReturn);
         }
         if ((editorb.y + editorb.height) < leftTop.y) {
             toReturn = Constants.BOTTOM;
             comp.putClientProperty("lastSlideSide", toReturn);
         }
     }
     return toReturn;
 }
 
Example 3
Source File: GroupsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static boolean closeAllDocuments() {
    TopComponent[] tcs = WindowManagerImpl.getInstance().getEditorTopComponents();
    for( TopComponent tc : tcs ) {
        if( !Switches.isClosingEnabled(tc) ) {
            continue;
        }
        tc.putClientProperty("inCloseAll", Boolean.TRUE); //NOI18N
        if( !tc.close() ) {
            return false;
        }
    }

    return true;
}
 
Example 4
Source File: DesktopImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test of computeSlideInBounds method, of class DesktopImpl.
 */
public void testComputeSlideInBounds() {
    int ideWidth = 1000;
    int ideHeight = 1000;
    Rectangle splitRootRect = new Rectangle(0,0,ideWidth, ideHeight);
    String side = Constants.LEFT;
    Component slideComponent = new JPanel();
    slideComponent.setBounds(new Rectangle(0,0,100,ideHeight));
    
    Rectangle slideBounds = new Rectangle(0,0,ideWidth/2,ideHeight);
    TopComponent selTc = new TopComponent();
    selTc.setPreferredSize(new Dimension(200,200) );
    
    DesktopImpl instance = new DesktopImpl();
    
    //test default behavior
    Rectangle result = instance.computeSlideInBounds(splitRootRect, side, slideComponent, slideBounds, selTc);
    assertNotNull(result);
    assertEquals( result.width, slideBounds.width);
    assertEquals(result.height, splitRootRect.height);
    
    //now let's test that preferred size is respected
    selTc.putClientProperty(Constants.KEEP_PREFERRED_SIZE_WHEN_SLIDED_IN, Boolean.TRUE);
    result = instance.computeSlideInBounds(splitRootRect, side, slideComponent, slideBounds, selTc);
    assertNotNull(result);
    assertEquals( result.getSize(), selTc.getPreferredSize());
    
    //turn the flag off and test again
    selTc.putClientProperty(Constants.KEEP_PREFERRED_SIZE_WHEN_SLIDED_IN, Boolean.FALSE);
    result = instance.computeSlideInBounds(splitRootRect, side, slideComponent, slideBounds, selTc);
    assertNotNull(result);
    assertEquals( result.width, slideBounds.width);
    assertEquals(result.height, splitRootRect.height);
}
 
Example 5
Source File: HyperlinkSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void register(final TopComponent tc, final IssueLinker issueLinker) {
    tc.removeContainerListener(regListener);
    tc.addContainerListener(regListener);        
    RequestProcessor.Task task = rp.create(new Runnable() {
        @Override
        public void run() {
            registerChildren(tc, issueLinker);
        }
    });
    tc.putClientProperty(REGISTER_TASK, task);
    task.schedule(1000);
}
 
Example 6
Source File: WorkspaceTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private Object getInternalFrameID(TopComponent topComponent) {
    Object internalFrameID = topComponent.getClientProperty("internalFrameID");
    if (internalFrameID == null) {
        internalFrameID = "IF" + Long.toHexString(new Random().nextLong());
        topComponent.putClientProperty("internalFrameID", internalFrameID);
    }
    return internalFrameID;
}
 
Example 7
Source File: TopComponentSubModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void setSlidingProperty(TopComponent tc) {
    tc.putClientProperty(IS_SLIDING, Boolean.TRUE);
}
 
Example 8
Source File: TopComponentSubModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void clearSlidingProperty(TopComponent tc) {
    tc.putClientProperty(IS_SLIDING, null);
}
 
Example 9
Source File: Central.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean moveTopComponentIntoMode(ModeImpl mode, TopComponent tc, int index) {
    boolean moved = false;
    boolean intoSliding = mode.getKind() == Constants.MODE_KIND_SLIDING;
    boolean intoSeparate = mode.getState() == Constants.MODE_STATE_SEPARATED;
    ModeImpl prevMode = null;
    String tcID = WindowManagerImpl.getInstance().findTopComponentID(tc);
    // XXX
    if(!mode.canContain(tc)) {
        return false;
    }
    TopComponentTracker.getDefault().add( tc, mode );
    for(Iterator it = model.getModes().iterator(); it.hasNext(); ) {
        ModeImpl m = (ModeImpl)it.next();
        if(model.containsModeTopComponent(m, tc)) {
            if (m.getKind() == Constants.MODE_KIND_SLIDING ||
                m.getState() == Constants.MODE_STATE_SEPARATED) {
                prevMode = model.getModeTopComponentPreviousMode(m, tcID);
            } else {
                prevMode = m;
            }
            break;
        }
    }
    int prevIndex = prevMode != null && (intoSliding || intoSeparate) ? prevMode.getOpenedTopComponentsIDs().indexOf( tcID ) : -1;
    if(removeTopComponentFromOtherModes(mode, tc)) {
        moved = true;
    }
    if (index > -1) {
        model.insertModeOpenedTopComponent(mode, tc, index);
    } else {
        model.addModeOpenedTopComponent(mode, tc);
    }
    if (prevMode != null && (intoSliding || intoSeparate)) {
        if( intoSeparate && mode.isPermanent() ) {
            //TC is being moved to a undocked mode so from now it will be
            //groupped with other TCs in that mode
            //so change the previous mode to ensure it docks back into
            //the same mode as other TCs in this mode
            List<String> ids = mode.getTopComponentsIDs();
            if( !ids.isEmpty() ) {
                ModeImpl groupPrevMode = model.getModeTopComponentPreviousMode( mode, ids.get( 0 ) );
                if( null != groupPrevMode ) {
                    prevMode = groupPrevMode;
                }
            }
        }
        // remember previous mode and constraints for precise de-auto-hide
        model.setModeTopComponentPreviousMode(mode, tcID, prevMode, prevIndex);
        model.setModeTopComponentPreviousConstraints(mode, tcID, model.getModeConstraints(prevMode));
    }
    if (!intoSliding) {
        // make the target mode active after dragging..
        model.setActiveMode(mode);
        model.setModeSelectedTopComponent(mode, tc);
    } else {
        sortSlidedOutTopComponentsByPrevModes( mode );
        // don't activate sliding modes, it means the component slides out, that's a bad thing..
        // make some other desktop mode active
        if(prevMode != null && prevMode == getActiveMode() 
               && prevMode.getOpenedTopComponents().isEmpty()) {
            setSomeModeActive();
        }
        // check the drop mode if it was already used, if not, assign it some reasonable size, 
        // according to the current component.
        if (mode.getBounds().width == 0 && mode.getBounds().height == 0) {
            // now we have the sliding mode in initial state
            mode.setBounds(tc.getBounds());
        }            
    }
    //#232061 
    if( null != tc.getClientProperty("windnd_cloned_tc")) {
        tc.putClientProperty("windnd_cloned_tc", null);
        WindowManagerImpl.getInstance().notifyTopComponentOpened(tc);
    }
    return moved;
}
 
Example 10
Source File: Utils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void setOpenedByUser( TopComponent tc, boolean userOpened ) {
    tc.putClientProperty( "userOpened", Boolean.valueOf(userOpened) ); //NOI18N
}
 
Example 11
Source File: Utils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static boolean isOpenedByUser( TopComponent tc ) {
    Object val = tc.getClientProperty( "userOpened" );
    tc.putClientProperty("userOpened", null);
    return null != val && val instanceof Boolean && ((Boolean)val).booleanValue();
}