javax.swing.JSplitPane#getClientProperty ( )源码实例Demo

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

源代码1 项目: netbeans   文件: JSplitPaneSupport.java
/** 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;
   }
 
源代码2 项目: netbeans   文件: JSplitPaneSupport.java
/** 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]);	    
   }
              
      }	
  }
 
源代码3 项目: netbeans   文件: JSplitPaneSupport.java
/** 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);
   }
 
源代码4 项目: 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);
   }