synthsplitpaneui.java

来自「java jdk 1.4的源码」· Java 代码 · 共 2,043 行 · 第 1/5 页

JAVA
2,043
字号
        /**         * Adds the component at place.  Place must be one of         * JSplitPane.LEFT, RIGHT, TOP, BOTTOM, or null (for the         * divider).         */        public void addLayoutComponent(String place, Component component) {            boolean isValid = true;            if(place != null) {                if(place.equals(JSplitPane.DIVIDER)) {                    /* Divider. */                    components[2] = component;                    sizes[2] = getSizeForPrimaryAxis(component.						     getPreferredSize());                } else if(place.equals(JSplitPane.LEFT) ||                          place.equals(JSplitPane.TOP)) {                    components[0] = component;                    sizes[0] = 0;                } else if(place.equals(JSplitPane.RIGHT) ||                          place.equals(JSplitPane.BOTTOM)) {                    components[1] = component;                    sizes[1] = 0;                } else if(!place.equals(                                    SynthSplitPaneUI.NON_CONTINUOUS_DIVIDER))                    isValid = false;            } else {                isValid = false;            }            if(!isValid)                throw new IllegalArgumentException("cannot add to layout: " +                    "unknown constraint: " +                    place);	    doReset = true;        }        /**         * Returns the minimum size needed to contain the children.         * The width is the sum of all the childrens min widths and         * the height is the largest of the childrens minimum heights.         */        public Dimension minimumLayoutSize(Container container) {            int         minPrimary = 0;            int         minSecondary = 0;            Insets      insets = splitPane.getInsets();            for (int counter=0; counter<3; counter++) {                if(components[counter] != null) {                    Dimension   minSize = components[counter].getMinimumSize();		    int         secSize = getSizeForSecondaryAxis(minSize);                    minPrimary += getSizeForPrimaryAxis(minSize);                    if(secSize > minSecondary)                        minSecondary = secSize;                }            }            if(insets != null) {                minPrimary += getSizeForPrimaryAxis(insets, true) +		              getSizeForPrimaryAxis(insets, false);		minSecondary += getSizeForSecondaryAxis(insets, true) +		              getSizeForSecondaryAxis(insets, false);            }	    if (axis == 0) {		return new Dimension(minPrimary, minSecondary);	    }	    return new Dimension(minSecondary, minPrimary);        }        /**         * Returns the preferred size needed to contain the children.         * The width is the sum of all the childrens preferred widths and         * the height is the largest of the childrens preferred heights.         */        public Dimension preferredLayoutSize(Container container) {            int         prePrimary = 0;            int         preSecondary = 0;            Insets      insets = splitPane.getInsets();            for(int counter = 0; counter < 3; counter++) {                if(components[counter] != null) {		    Dimension   preSize = components[counter].			                  getPreferredSize();		    int         secSize = getSizeForSecondaryAxis(preSize);                    prePrimary += getSizeForPrimaryAxis(preSize);                    if(secSize > preSecondary)                        preSecondary = secSize;                }            }            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;                }            }

⌨️ 快捷键说明

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