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

📄 grouplayout.java.svn-base

📁 j2me设计的界面包
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
            if (count == 0) {                return 0;            }            if (count == 1) {                return getSpringSize(getSpring(0), axis, type);            }            int size = constrain(operator(getSpringSize(getSpring(0), axis, type),                    getSpringSize(getSpring(1), axis, type)));            for (int counter = 2; counter < count; counter++) {                size = constrain(operator(size, getSpringSize(getSpring(counter),                        axis, type)));            }            return size;        }                Spring getSpring(int index) {            return (Spring)springs.elementAt(index);        }                int getSpringSize(Spring spring, int axis, int type) {            switch(type) {                case MIN_SIZE:                    return spring.getMinimumSize(axis);                case PREF_SIZE:                    return spring.getPreferredSize(axis);                case MAX_SIZE:                    return spring.getMaximumSize(axis);            }            //assert false;            return 0;        }                // Padding        /**         * Adjusts the autopadding springs in this group and its children.         * If <code>insert</code> is true this will insert auto padding         * springs, otherwise this will only adjust the springs that         * comprise auto preferred padding springs.         *         * @param axis the axis of the springs; HORIZONTAL or VERTICAL         * @param leadingPadding List of AutopaddingSprings that occur before         *                       this Group         * @param trailingPadding any trailing autopadding springs are added         *                        to this on exit         * @param leading List of ComponentSprings that occur before this Group         * @param trailing any trailing ComponentSpring are added to this         *                 List         * @param insert Whether or not to insert AutopaddingSprings or just         *               adjust any existing AutopaddingSprings.         */        abstract void insertAutopadding(int axis, Vector leadingPadding,                Vector trailingPadding, Vector leading, Vector trailing,                boolean insert);                /**         * Removes any AutopaddingSprings.         */        void removeAutopadding() {            unset();            for (int counter = springs.size() - 1; counter >= 0; counter--) {                Spring spring = (Spring)springs.elementAt(counter);                if (spring instanceof AutopaddingSpring) {                    if (((AutopaddingSpring)spring).getUserCreated()) {                        ((AutopaddingSpring)spring).reset();                    } else {                        springs.removeElementAt(counter);                    }                } else if (spring instanceof Group) {                    ((Group)spring).removeAutopadding();                }            }        }                void unsetAutopadding() {            // Clear cached pref/min/max.            unset();            for (int counter = springs.size() - 1; counter >= 0; counter--) {                Spring spring = (Spring)springs.elementAt(counter);                if (spring instanceof AutopaddingSpring) {                    ((AutopaddingSpring)spring).unset();                } else if (spring instanceof Group) {                    ((Group)spring).unsetAutopadding();                }            }        }                void calculateAutopadding(int axis) {            for (int counter = springs.size() - 1; counter >= 0; counter--) {                Spring spring = (Spring)springs.elementAt(counter);                if (spring instanceof AutopaddingSpring) {                    // Force size to be reset.                    spring.unset();                    ((AutopaddingSpring)spring).calculatePadding(axis);                } else if (spring instanceof Group) {                    ((Group)spring).calculateAutopadding(axis);                }            }            // Clear cached pref/min/max.            unset();        }                boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) {            for (int i = springs.size() -1; i >= 0; i--) {                Spring spring = (Spring)springs.elementAt(i);                if (!spring.willHaveZeroSize(treatAutopaddingAsZeroSized)) {                    return false;                }            }            return true;        }    }            /**     * A <code>Group</code> that lays out its elements sequentially, one     * after another.  This class has no public constructor, use the     * <code>createSequentialGroup</code> method to create one.     *     * @see #createSequentialGroup()     */    public class SequentialGroup extends Group {        private Spring baselineSpring;                SequentialGroup() {        }                /**         * Adds the specified <code>Group</code> to this         * <code>SequentialGroup</code>         *         * @param group the Group to add         * @return this Group         */        public SequentialGroup add(Group group) {            return (SequentialGroup)addSpring(group);        }                /**         * Adds a <code>Group</code> to this <code>Group</code>.         *         * @param group the <code>Group</code> to add         * @param useAsBaseline whether the specified <code>Group</code> should         *        be used to calculate the baseline for this <code>Group</code>         * @return this <code>Group</code>         */        public SequentialGroup add(boolean useAsBaseline, Group group) {            add(group);            if (useAsBaseline) {                baselineSpring = group;            }            return this;        }                /**         * Adds the specified Component.  If the Component's min/max         * are different from its pref than the component will be resizable.         *         * @param component the Component to add         * @return this <code>SequentialGroup</code>         */        public SequentialGroup add(Component component) {            return add(component, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE);        }                /**         * Adds a <code>Component</code> to this <code>Group</code>.         *         * @param useAsBaseline whether the specified <code>Component</code> should         *        be used to calculate the baseline for this <code>Group</code>         * @param component the <code>Component</code> to add         * @return this <code>Group</code>         */        public SequentialGroup add(boolean useAsBaseline, Component component) {            add(component);            if (useAsBaseline) {                baselineSpring = getSpring(springs.size() - 1);            }            return this;        }        /**         * Adds the specified <code>Component</code>.  Min, pref and max         * can be absolute values, or they can be one of         * <code>DEFAULT_SIZE</code> or <code>PREFERRED_SIZE</code>.  For         * example, the following:         * <pre>         *   add(component, PREFERRED_SIZE, PREFERRED_SIZE, 1000);         * </pre>         * Forces a max of 1000, with the min and preferred equalling that         * of the preferred size of <code>component</code>.         *         * @param component the Component to add         * @param min the minimum size         * @param pref the preferred size         * @param max the maximum size         * @throws IllegalArgumentException if min, pref or max are         *         not positive and not one of PREFERRED_SIZE or DEFAULT_SIZE         * @return this <code>SequentialGroup</code>         */        public SequentialGroup add(Component component, int min, int pref,                int max) {            return (SequentialGroup)addSpring(new ComponentSpring(                    component, min, pref, max));        }                /**         * Adds a <code>Component</code> to this <code>Group</code>         * with the specified size.         *         * @param useAsBaseline whether the specified <code>Component</code> should         *        be used to calculate the baseline for this <code>Group</code>         * @param component the <code>Component</code> to add         * @param min the minimum size or one of <code>DEFAULT_SIZE</code> or         *            <code>PREFERRED_SIZE</code>         * @param pref the preferred size or one of <code>DEFAULT_SIZE</code> or         *            <code>PREFERRED_SIZE</code>         * @param max the maximum size or one of <code>DEFAULT_SIZE</code> or         *            <code>PREFERRED_SIZE</code>         * @return this <code>Group</code>         */        public SequentialGroup add(boolean useAsBaseline,                Component component, int min, int pref, int max) {            add(component, min, pref, max);            if (useAsBaseline) {                baselineSpring = getSpring(springs.size() - 1);            }            return this;        }        /**         * Adds a rigid gap.         *         * @param pref the size of the gap         * @throws IllegalArgumentException if min < 0 or pref < 0 or max < 0         *         or the following is not meant min <= pref <= max         * @return this <code>SequentialGroup</code>         */        public SequentialGroup add(int pref) {            return add(pref, pref, pref);        }                /**         * Adds a gap with the specified size.         *         * @param min the minimum size of the gap, or PREFERRED_SIZE         * @param pref the preferred size of the gap         * @param max the maximum size of the gap, or PREFERRED_SIZE         * @throws IllegalArgumentException if min < 0 or pref < 0 or max < 0         *         or the following is not meant min <= pref <= max         * @return this <code>SequentialGroup</code>         */        public SequentialGroup add(int min, int pref, int max) {            return (SequentialGroup)addSpring(new GapSpring(min, pref, max));        }                /**         * Adds an element representing the preferred gap between the two         * components.         *          * @param comp1 the first component         * @param comp2 the second component         * @param type the type of gap; one of the constants defined by         *        LayoutStyle         * @return this <code>SequentialGroup</code>         * @throws IllegalArgumentException if <code>type</code> is not a         *         valid LayoutStyle constant         * @see LayoutStyle         */        public SequentialGroup addPreferredGap(Component comp1,                Component comp2,                int type) {            return addPreferredGap(comp1, comp2, type, false);        }                /**         * Adds an element representing the preferred gap between the two         * components.         *          * @param comp1 the first component         * @param comp2 the second component         * @param type the type of gap; one of the constants defined by         *        LayoutStyle         * @param canGrow true if the gap can grow if more         *                space is available         * @return this <code>SequentialGroup</code>         * @throws IllegalArgumentException if <code>type</code> is not a         *         valid LayoutStyle constant         * @see LayoutStyle         */        public SequentialGroup addPreferredGap(Component comp1,                Component comp2,                int type, boolean canGrow) {            if (type != LayoutStyle.RELATED &&                    type != LayoutStyle.UNRELATED &&                    type != LayoutStyle.INDENT) {                throw new IllegalArgumentException("Invalid type argument");            }            if (comp1 == null || comp2 == null) {                throw new IllegalArgumentException(                        "Components must be non-null");            }            return (SequentialGroup)addSpring(new PaddingSpring(                    comp1, comp2, type, canGrow));        }        /**         * Adds an element representing the preferred gap between the         * nearest components.  That is, during layout the neighboring         * components are found, and the min, pref and max of this         * element is set based on the preferred gap between the         * components.  If no neighboring components are found the         * min, pref and max are set to 0.         *          * @param type the type of gap; one of the LayoutStyle constants         * @return this SequentialGroup         * @throws IllegalArgumentException if type is not one of         *         <code>LayoutStyle.RELATED</code> or         *         <code>LayoutStyle.UNRELATED</code>         * @see LayoutStyle         */        public SequentialGroup addPreferredGap(int type) {            return addPreferredGap(type, DEFAULT_SIZE, DEFAULT_SIZE);        }                /**         * Adds an element for the preferred gap between the         * nearest components.  That is, during layout the neighboring         * components are found, and the min of this         * element is set based on the preferred gap between the         * components.  If no neighboring components are found the         * min is set to 0.  This method allows you to specify the         * preferred and maximum size by way of the <code>pref</code>         * and <code>max</code> arguments.  These can either be a         * value &gt;= 0, in which case the preferred or max is the max         * of the argument and the preferred gap, of DEFAULT_VALUE in         * which case the value is the same as the preferred gap.         *          * @param type the type of gap; one of LayoutStyle.RELATED or         *        LayoutStyle.UNRELATED         * @param pref the preferred size; one of DEFAULT_SIZE or a value > 0         * @param max the maximum

⌨️ 快捷键说明

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