⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicsplitpaneui.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                }            }            if(insets != null) {                prePrimary += getSizeForPrimaryAxis(insets, true) +		              getSizeForPrimaryAxis(insets, false);		preSecondary += getSizeForSecondaryAxis(insets, true) +		              getSizeForSecondaryAxis(insets, false);            }	    if (axis == 0) {		return new Dimension(prePrimary, preSecondary);	    }	    return new Dimension(preSecondary, prePrimary);        }        /**         * Removes the specified component from our knowledge.         */        public void removeLayoutComponent(Component component) {            for(int counter = 0; counter < 3; counter++) {                if(components[counter] == component) {                    components[counter] = null;                    sizes[counter] = 0;		    doReset = true;                }            }        }        //        // LayoutManager2        //        /**         * Adds the specified component to the layout, using the specified         * constraint object.         * @param comp the component to be added         * @param constraints  where/how the component is added to the layout.         */        public void addLayoutComponent(Component comp, Object constraints) {            if ((constraints == null) || (constraints instanceof String)) {                addLayoutComponent((String)constraints, comp);            } else {                throw new IllegalArgumentException("cannot add to layout: " +                                                   "constraint must be a " +                                                   "string (or null)");            }        }        /**         * Returns the alignment along the x axis.  This specifies how         * the component would like to be aligned relative to other          * components.  The value should be a number between 0 and 1         * where 0 represents alignment along the origin, 1 is aligned         * the furthest away from the origin, 0.5 is centered, etc.         */        public float getLayoutAlignmentX(Container target) {            return 0.0f;        }        /**         * Returns the alignment along the y axis.  This specifies how         * the component would like to be aligned relative to other          * components.  The value should be a number between 0 and 1         * where 0 represents alignment along the origin, 1 is aligned         * the furthest away from the origin, 0.5 is centered, etc.         */        public float getLayoutAlignmentY(Container target) {            return 0.0f;        }        /**         * Does nothing. If the developer really wants to change the         * size of one of the views JSplitPane.resetToPreferredSizes should         * be messaged.         */        public void invalidateLayout(Container c) {        }        /**         * Returns the maximum layout size, which is Integer.MAX_VALUE         * in both directions.         */        public Dimension maximumLayoutSize(Container target) {            return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);        }	//	// New methods.	//        /**         * Marks the receiver so that the next time this instance is         * laid out it'll ask for the preferred sizes.         */        public void resetToPreferredSizes() {	    doReset = true;        }        /**         * Resets the size of the Component at the passed in location.         */        protected void resetSizeAt(int index) {            sizes[index] = 0;	    doReset = true;        }        /**         * Sets the sizes to <code>newSizes</code>.         */        protected void setSizes(int[] newSizes) {            System.arraycopy(newSizes, 0, sizes, 0, 3);        }        /**         * Returns the sizes of the components.         */        protected int[] getSizes() {            int[]         retSizes = new int[3];            System.arraycopy(sizes, 0, retSizes, 0, 3);            return retSizes;        }        /**         * Returns the width of the passed in Components preferred size.         */        protected int getPreferredSizeOfComponent(Component c) {	    return getSizeForPrimaryAxis(c.getPreferredSize());        }        /**         * Returns the width of the passed in Components minimum size.         */        int getMinimumSizeOfComponent(Component c) {	    return getSizeForPrimaryAxis(c.getMinimumSize());        }        /**         * Returns the width of the passed in component.         */        protected int getSizeOfComponent(Component c) {	    return getSizeForPrimaryAxis(c.getSize());        }        /**         * Returns the available width based on the container size and         * Insets.         */        protected int getAvailableSize(Dimension containerSize,                                       Insets insets) {            if(insets == null)                return getSizeForPrimaryAxis(containerSize);            return (getSizeForPrimaryAxis(containerSize) - 		    (getSizeForPrimaryAxis(insets, true) +		     getSizeForPrimaryAxis(insets, false)));        }        /**         * Returns the left inset, unless the Insets are null in which case         * 0 is returned.         */        protected int getInitialLocation(Insets insets) {            if(insets != null)                return getSizeForPrimaryAxis(insets, true);            return 0;        }        /**         * Sets the width of the component c to be size, placing its         * x location at location, y to the insets.top and height         * to the containersize.height less the top and bottom insets.         */        protected void setComponentToSize(Component c, int size,                                          int location, Insets insets,                                          Dimension containerSize) {            if(insets != null) {		if (axis == 0) {		    c.setBounds(location, insets.top, size,				containerSize.height -				(insets.top + insets.bottom));		}		else {		    c.setBounds(insets.left, location, containerSize.width -				(insets.left + insets.right), size);		}            }	    else {                if (axis == 0) {		    c.setBounds(location, 0, size, containerSize.height);		}		else {		    c.setBounds(0, location, containerSize.width, size);		}            }        }	/**	 * If the axis == 0, the width is returned, otherwise the height.	 */	int getSizeForPrimaryAxis(Dimension size) {	    if (axis == 0) {		return size.width;	    }	    return size.height;	}	/**	 * If the axis == 0, the width is returned, otherwise the height.	 */	int getSizeForSecondaryAxis(Dimension size) {	    if (axis == 0) {		return size.height;	    }	    return size.width;	}	/**	 * Returns a particular value of the inset identified by the	 * axis and <code>isTop</code><p>	 *   axis isTop	 *    0    true    - left	 *    0    false   - right	 *    1    true    - top	 *    1    false   - bottom	 */	int getSizeForPrimaryAxis(Insets insets, boolean isTop) {	    if (axis == 0) {		if (isTop) {		    return insets.left;		}		return insets.right;	    }	    if (isTop) {		return insets.top;	    }	    return insets.bottom;	} 	/**	 * Returns a particular value of the inset identified by the	 * axis and <code>isTop</code><p>	 *   axis isTop	 *    0    true    - left	 *    0    false   - right	 *    1    true    - top	 *    1    false   - bottom	 */	int getSizeForSecondaryAxis(Insets insets, boolean isTop) {	    if (axis == 0) {		if (isTop) {		    return insets.top;		}		return insets.bottom;	    }	    if (isTop) {		return insets.left;	    }	    return insets.right;	}         /**         * Determines the components. This should be called whenever         * a new instance of this is installed into an existing         * SplitPane.         */        protected void updateComponents() {            Component comp;            comp = splitPane.getLeftComponent();            if(components[0] != comp) {                components[0] = comp;                if(comp == null) {                    sizes[0] = 0;                } else {                    sizes[0] = -1;                }            }            comp = splitPane.getRightComponent();            if(components[1] != comp) {                components[1] = comp;                if(comp == null) {                    sizes[1] = 0;                } else {                    sizes[1] = -1;                }            }            /* Find the divider. */            Component[] children = splitPane.getComponents();            Component   oldDivider = components[2];            components[2] = null;            for(int counter = children.length - 1; counter >= 0; counter--) {                if(children[counter] != components[0] &&                   children[counter] != components[1] &&                   children[counter] != nonContinuousLayoutDivider) {                    if(oldDivider != children[counter]) {                        components[2] = children[counter];                    } else {                        components[2] = oldDivider;                    }                    break;                }            }            if(components[2] == null) {		sizes[2] = 0;	    }	    else {		sizes[2] = getSizeForPrimaryAxis(components[2].getPreferredSize());	    }        }	/**	 * Resets the size of the first component to <code>leftSize</code>,	 * and the right component to the remainder of the space.	 */	void setDividerLocation(int leftSize, int availableSize) {	    boolean          lValid = (components[0] != null &&				       components[0].isVisible());	    boolean          rValid = (components[1] != null &&				       components[1].isVisible());	    boolean          dValid = (components[2] != null && 				       components[2].isVisible());	    int              max = availableSize;	    if (dValid) {		max -= sizes[2];	    }	    leftSize = Math.max(0, Math.min(leftSize, max));	    if (lValid) {		if (rValid) {		    sizes[0] = leftSize;		    sizes[1] = max - leftSize;		}		else {		    sizes[0] = max;		    sizes[1] = 0;		}	    }	    else if (rValid) {		sizes[1] = max;		sizes[0] = 0;	    }	}	/**	 * Returns an array of the minimum sizes of the components.	 */	int[] getPreferredSizes() {	    int[]         retValue = new int[3];	    for (int counter = 0; counter < 3; counter++) {		if (components[counter] != null &&		    components[counter].isVisible()) {		    retValue[counter] = getPreferredSizeOfComponent			                (components[counter]);		}		else {		    retValue[counter] = -1;		}	    }	    return retValue;	}	/**	 * Returns an array of the minimum sizes of the components.	 */	int[] getMinimumSizes() {	    int[]         retValue = new int[3];	    for (int counter = 0; counter < 2; counter++) {		if (components[counter] != null &&		    components[counter].isVisible()) {		    retValue[counter] = getMinimumSizeOfComponent			                (components[counter]);		}		else {		    retValue[counter] = -1;		}	    }	    retValue[2] = (components[2] != null) ? 		getMinimumSizeOfComponent(components[2]) : -1;	    return retValue;	}	/**	 * Resets the components to their preferred sizes.	 */	void resetToPreferredSizes(int availableSize) {	    // Set the size

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -