javax.swing.JSplitPane#RIGHT源码实例Demo

下面列出了javax.swing.JSplitPane#RIGHT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: JSplitPaneSupport.java
private String findFreePosition() {
    int leftTop = 0, rightBottom = 0;
    int orientation = JSplitPane.HORIZONTAL_SPLIT;
	
    for (int i=0, n=getComponentCount(); i < n; i++) {
        LayoutConstraints constraints = getConstraints(i);
        if (!(constraints instanceof SplitConstraints))
            continue;

        int constrPos = convertPosition(constraints);
        if (constrPos == 0)
            leftTop++;
        else if (constrPos == 1)
            rightBottom++;
    }

    if (leftTop == 0 || leftTop < rightBottom)
        return orientation == JSplitPane.HORIZONTAL_SPLIT ?
            JSplitPane.LEFT : JSplitPane.TOP;
    else 
        return orientation == JSplitPane.HORIZONTAL_SPLIT ?
            JSplitPane.RIGHT : JSplitPane.BOTTOM;	
}
 
源代码2 项目: netbeans   文件: JSplitPaneSupport.java
/** This method is used for scanning code structures and recognizing
 * components added to containers and their constraints. It's called from
 * initialize method. When a relevant code statement is found, then the
 * CodeExpression of component is get and added to component, and also the
 * layout constraints information is read.
 * @param statement CodeStatement to be tested if it contains relevant code
 * @param componentCode CodeGroup to be filled with all component code
 * @return CodeExpression representing found component; null if the
 *         statement is not relevant
 */
@Override
protected CodeExpression readComponentCode(CodeStatement statement,
                                           CodeGroup componentCode)
{
    CodeExpression[] params = statement.getStatementParameters();
    if (params.length != 1)
        return null;

    String position = null;
    Object connectingObject = statement.getMetaObject();
    if (getSimpleAddMethod().equals(connectingObject)) {
        position = getComponentCount() == 0 ? JSplitPane.LEFT : JSplitPane.RIGHT;
    } else if (getSetLeftComponentMethod().equals(connectingObject)) {
        position = JSplitPane.LEFT;
    } else if (getSetRightComponentMethod().equals(connectingObject)) {
        position = JSplitPane.RIGHT;
    } else if (getSetTopComponentMethod().equals(connectingObject)) {
        position = JSplitPane.TOP;
    } else if (getSetBottomComponentMethod().equals(connectingObject)) {
        position = JSplitPane.BOTTOM;
    }

    SplitConstraints constr = new SplitConstraints(position);
    getConstraintsList().add(constr);

    componentCode.addStatement(statement);

    return params[0];
}
 
源代码3 项目: netbeans   文件: JSplitPaneSupport.java
/** This method calculates layout constraints for a component dragged
    * over a container (or just for mouse cursor being moved over container,
    * without any component).
    * @param container instance of a real container over/in which the
    *        component is dragged
    * @param containerDelegate effective container delegate of the container
    * @param component the real component being dragged, not needed here
    * @param index position (index) of the component in its container;
    *        not needed here
    * @param posInCont position of mouse in the container
    * @param posInComp position of mouse in the dragged component; not needed
    * @return new LayoutConstraints object corresponding to the position of
    *         the component in the container
    */
   @Override
   public LayoutConstraints getNewConstraints(Container container,
                                              Container containerDelegate,
                                              Component component,
                                              int index,
                                              Point posInCont,
                                              Point posInComp)
   {
       if (!(container instanceof JSplitPane))
           return null;

       JSplitPane splitPane = (JSplitPane) container;
       Dimension sz = splitPane.getSize();
       int orientation = splitPane.getOrientation();

JButton left  = (JButton) splitPane.getClientProperty(LEFT_TOP_BUTTON);
JButton right = (JButton) splitPane.getClientProperty(RIGHT_BOTTOM_BUTTON);

       if ( (left == null && right == null) || 
     (left != null && right != null) ) 
{	    	    
    String freePosition;        	    
           if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
               if (posInCont.x <= sz.width / 2) 
                   freePosition = JSplitPane.LEFT;
	else 
                   freePosition = JSplitPane.RIGHT;
           }
           else {				
               if (posInCont.y <= sz.height / 2) 
                   freePosition = JSplitPane.TOP;		
	else 
                   freePosition = JSplitPane.BOTTOM;
           }
           assistantParams = freePosition;
    return new SplitConstraints(freePosition);
}

       assistantParams = findFreePosition();
return new SplitConstraints(assistantParams);
   }