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

📄 basicsplitpaneui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    @Deprecated    protected int getDividerBorderSize() {        return 1;    }    /**     * LayoutManager for JSplitPanes that have an orientation of     * HORIZONTAL_SPLIT.     */    public class BasicHorizontalLayoutManager implements LayoutManager2    {        /* left, right, divider. (in this exact order) */        protected int[]         sizes;        protected Component[]   components;	/** Size of the splitpane the last time laid out. */	private int             lastSplitPaneSize;	/** True if resetToPreferredSizes has been invoked. */	private boolean         doReset;	/** Axis, 0 for horizontal, or 1 for veritcal. */	private int             axis;	BasicHorizontalLayoutManager() {	    this(0);	}        BasicHorizontalLayoutManager(int axis) {	    this.axis = axis;            components = new Component[3];            components[0] = components[1] = components[2] = null;            sizes = new int[3];        }	//	// LayoutManager	//	/**         * Does the actual layout.         */        public void layoutContainer(Container container) {            Dimension   containerSize = container.getSize();            // If the splitpane has a zero size then no op out of here.            // If we execute this function now, we're going to cause ourselves            // much grief.            if (containerSize.height <= 0 || containerSize.width <= 0 ) {		lastSplitPaneSize = 0;                return;            }	    int         spDividerLocation = splitPane.getDividerLocation();            Insets      insets = splitPane.getInsets();	    int         availableSize = getAvailableSize(containerSize,							 insets);	    int         newSize = getSizeForPrimaryAxis(containerSize);	    int         beginLocation = getDividerLocation(splitPane);	    int         dOffset = getSizeForPrimaryAxis(insets, true);	    Dimension   dSize = (components[2] == null) ? null :		                 components[2].getPreferredSize();	    if ((doReset && !dividerLocationIsSet) || spDividerLocation < 0) {		resetToPreferredSizes(availableSize);	    }	    else if (lastSplitPaneSize <= 0 ||		     availableSize == lastSplitPaneSize || !painted ||		     (dSize != null &&		      getSizeForPrimaryAxis(dSize) != sizes[2])) {		if (dSize != null) {		    sizes[2] = getSizeForPrimaryAxis(dSize);		}		else {		    sizes[2] = 0;		}		setDividerLocation(spDividerLocation - dOffset, availableSize);		dividerLocationIsSet = false;	    }	    else if (availableSize != lastSplitPaneSize) {		distributeSpace(availableSize - lastSplitPaneSize,                                getKeepHidden());	    }	    doReset = false;	    dividerLocationIsSet = false;	    lastSplitPaneSize = availableSize;            // Reset the bounds of each component            int nextLocation = getInitialLocation(insets);	    int counter = 0;            while (counter < 3) {                if (components[counter] != null &&		    components[counter].isVisible()) {                    setComponentToSize(components[counter], sizes[counter],                                       nextLocation, insets, containerSize);                    nextLocation += sizes[counter];                }                switch (counter) {                case 0:                    counter = 2;                    break;                case 2:                    counter = 1;                    break;                case 1:                    counter = 3;                    break;                }            }	    if (painted) {		// This is tricky, there is never a good time for us		// to push the value to the splitpane, painted appears to		// the best time to do it. What is really needed is		// notification that layout has completed.		int      newLocation = getDividerLocation(splitPane);		if (newLocation != (spDividerLocation - dOffset)) {		    int  lastLocation = splitPane.getLastDividerLocation();		    ignoreDividerLocationChange = true;		    try {			splitPane.setDividerLocation(newLocation);			// This is not always needed, but is rather tricky			// to determine when... The case this is needed for			// is if the user sets the divider location to some			// bogus value, say 0, and the actual value is 1, the			// call to setDividerLocation(1) will preserve the			// old value of 0, when we really want the divider			// location value  before the call. This is needed for			// the one touch buttons.			splitPane.setLastDividerLocation(lastLocation);		    } finally {			ignoreDividerLocationChange = false;		    }		}	    }        }        /**         * 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(                                    BasicSplitPaneUI.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,

⌨️ 快捷键说明

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