Java Code Examples for javax.swing.JSplitPane#getClientProperty()

The following examples show how to use javax.swing.JSplitPane#getClientProperty() . 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
/** Removes all components from given real container.
    * @param container instance of a real container to be cleared
    * @param containerDelegate effective container delegate of the container
    *        (e.g. like content pane of JFrame)
    * @return whether it was possible to clear the container (some containers
    *         may not support this)
    */
   @Override
   public boolean clearContainer(Container container,
                                 Container containerDelegate)
   {

// don't remove components which are a default part of JSplitPane

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

if(left != null) {
    // left/top component has already been set -> remove it
    removeComponentFromContainer(container, containerDelegate, splitPane.getLeftComponent());
}
if(right != null) {
    // right/bottom component has already been set -> remove it
    removeComponentFromContainer(container, containerDelegate, splitPane.getRightComponent());
}

       return true;
   }
 
Example 2
Source File: JSplitPaneSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Adds real components to given container (according to layout
   * constraints stored for the components).
   * @param container instance of a real container to be added to
   * @param containerDelegate effective container delegate of the container
   * @param components components to be added
   * @param index position at which to add the components to container
   */
  @Override
  public void addComponentsToContainer(Container container,
                                       Container containerDelegate,
                                       Component[] components,
                                       int index)
  {
      if (!(container instanceof JSplitPane))
          return;	
	
      for (int i=0; i < components.length; i++) {	    	    
   JSplitPane splitPane = (JSplitPane) container;
   
          int descPos = convertPosition(getConstraints(i + index));
          if (descPos == 0) {
if(splitPane.getClientProperty(LEFT_TOP_BUTTON)==null) {	    
    // store the defaul swing button, so we can fall back to it 
    // if component[i] will be removed later...
    splitPane.putClientProperty(LEFT_TOP_BUTTON, splitPane.getLeftComponent());  
} 
splitPane.setLeftComponent(components[i]);
   } 
   else if (descPos == 1) {
if(splitPane.getClientProperty(RIGHT_BOTTOM_BUTTON)==null) {
    // store the defaul swing button, so we can fall back to it 
    // if component[i] will be removed later...
    splitPane.putClientProperty(RIGHT_BOTTOM_BUTTON, splitPane.getRightComponent());	    	    	    
} 							    				
splitPane.setRightComponent(components[i]);	    
   }
              
      }	
  }
 
Example 3
Source File: JSplitPaneSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Removes a real component from a real container.
    * @param container instance of a real container
    * @param containerDelegate effective container delegate of the container
    * @param component component to be removed
    * @return whether it was possible to remove the component (some containers
    *         may not support removing individual components reasonably)
    */
   @Override
   public boolean removeComponentFromContainer(Container container,
                                               Container containerDelegate,
                                               Component component)
   {
if( !(containerDelegate instanceof JSplitPane) ) {
    return false; // should not happen
}	

JSplitPane splitPane = (JSplitPane) containerDelegate;

if( component == splitPane.getLeftComponent() ) { 
    if( super.removeComponentFromContainer(container, containerDelegate, component) ) {
	JButton left = (JButton) splitPane.getClientProperty(LEFT_TOP_BUTTON);
	if( left != null ) {
	    // fall back to the default swing setting
	    splitPane.setLeftComponent(left);
	    splitPane.putClientProperty(LEFT_TOP_BUTTON, null);
	}	
	return true;
    }
} else if ( component == splitPane.getRightComponent() ) {    
    if( super.removeComponentFromContainer(container, containerDelegate, component) ) {
	JButton right = (JButton) splitPane.getClientProperty(RIGHT_BOTTOM_BUTTON);
	if( right != null ) {
	    // fall back to the default swing setting		    
	    splitPane.setRightComponent(right);		    
	    splitPane.putClientProperty(RIGHT_BOTTOM_BUTTON, null);
	}	
	return true;
    }
}

       return super.removeComponentFromContainer(container, containerDelegate, component);
   }
 
Example 4
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);
   }