001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing;
021:
022: import java.io.Serializable;
023:
024: import org.apache.harmony.x.swing.SizeRequirementsHelper;
025:
026: public class SizeRequirements implements Serializable {
027:
028: private static final int[] EMPTY_ARRAY = new int[0];
029:
030: public int minimum;
031: public int preferred;
032: public int maximum;
033: public float alignment;
034:
035: public SizeRequirements(final int min, final int pref,
036: final int max, final float a) {
037: minimum = min;
038: preferred = pref;
039: maximum = max;
040: alignment = a;
041: }
042:
043: public SizeRequirements() {
044: this (0, 0, 0, 0.5f);
045: }
046:
047: SizeRequirements(final float a) {
048: this (0, 0, 0, a);
049: }
050:
051: public String toString() {
052: return "[" + minimum + "," + preferred + "," + maximum + "]@"
053: + alignment;
054: }
055:
056: public static SizeRequirements getTiledSizeRequirements(
057: final SizeRequirements[] children) {
058:
059: return SizeRequirementsHelper.getTiledSizeRequirements(
060: children, null);
061: }
062:
063: public static SizeRequirements getAlignedSizeRequirements(
064: final SizeRequirements[] children) {
065:
066: return SizeRequirementsHelper.getAlignedSizeRequirements(
067: children, null, false);
068: }
069:
070: public static void calculateTiledPositions(final int allocated,
071: final SizeRequirements total,
072: final SizeRequirements[] children, final int[] offsets,
073: final int[] spans, final boolean normal) {
074:
075: SizeRequirements totalRequirements = SizeRequirementsHelper
076: .getTiledSizeRequirements(children, total);
077:
078: SizeRequirementsHelper.calculateTiledPositions(allocated,
079: totalRequirements, children, offsets, spans, normal);
080: }
081:
082: public static void calculateAlignedPositions(final int allocated,
083: final SizeRequirements total,
084: final SizeRequirements[] children, final int[] offsets,
085: final int[] spans, final boolean normal) {
086:
087: SizeRequirementsHelper.calculateAlignedPositions(allocated,
088: total, children, offsets, spans, normal);
089: }
090:
091: public static void calculateTiledPositions(final int allocated,
092: final SizeRequirements total,
093: final SizeRequirements[] children, final int[] offsets,
094: final int[] spans) {
095: calculateTiledPositions(allocated, total, children, offsets,
096: spans, true);
097: }
098:
099: public static void calculateAlignedPositions(final int allocated,
100: final SizeRequirements total,
101: final SizeRequirements[] children, final int[] offsets,
102: final int[] spans) {
103:
104: calculateAlignedPositions(allocated, total, children, offsets,
105: spans, true);
106: }
107:
108: public static int[] adjustSizes(final int delta,
109: final SizeRequirements[] children) {
110: return EMPTY_ARRAY;
111: }
112:
113: void set(final int min, final int pref, final int max, final float a) {
114: minimum = min;
115: preferred = pref;
116: maximum = max;
117: alignment = a;
118: }
119:
120: void reset() {
121: minimum = 0;
122: preferred = 0;
123: maximum = 0;
124: alignment = 0.5f;
125: }
126:
127: }
|