Java Code Examples for javax.swing.JSplitPane#TOP

The following examples show how to use javax.swing.JSplitPane#TOP . 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: JSplitPaneSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;	
}
 
Example 2
Source File: JSplitPaneSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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];
}
 
Example 3
Source File: JSplitPaneSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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);
   }