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.awt.AWTError;
023: import java.awt.Component;
024: import java.awt.Container;
025: import java.awt.Dimension;
026: import java.awt.LayoutManager2;
027: import java.io.Serializable;
028:
029: import org.apache.harmony.x.swing.internal.nls.Messages;
030:
031: public class OverlayLayout implements LayoutManager2, Serializable {
032:
033: private final Container target;
034: transient private final LayoutParameters layoutParams;
035:
036: public OverlayLayout(final Container target) {
037: this .target = target;
038: layoutParams = new LayoutParameters(target,
039: LayoutParameters.MIXED_ALIGNMENT);
040: }
041:
042: public void addLayoutComponent(final Component component,
043: final Object constraints) {
044: invalidateLayout(target);
045: }
046:
047: public Dimension preferredLayoutSize(final Container target) {
048: checkTarget(target);
049: layoutParams.calculateLayoutParameters();
050:
051: return layoutParams.preferredSize;
052: }
053:
054: public Dimension minimumLayoutSize(final Container target) {
055: checkTarget(target);
056: layoutParams.calculateLayoutParameters();
057:
058: return layoutParams.minimumSize;
059: }
060:
061: public Dimension maximumLayoutSize(final Container target) {
062: checkTarget(target);
063: layoutParams.calculateLayoutParameters();
064:
065: return layoutParams.maximumSize;
066: }
067:
068: public void addLayoutComponent(final String name,
069: final Component component) {
070: invalidateLayout(target);
071: }
072:
073: public void invalidateLayout(final Container target) {
074: checkTarget(target);
075: layoutParams.invalidate();
076: }
077:
078: public float getLayoutAlignmentY(final Container target) {
079: checkTarget(target);
080: layoutParams.calculateLayoutParameters();
081:
082: return layoutParams.alignmentY;
083: }
084:
085: public float getLayoutAlignmentX(final Container target) {
086: checkTarget(target);
087: layoutParams.calculateLayoutParameters();
088:
089: return layoutParams.alignmentX;
090: }
091:
092: public void removeLayoutComponent(final Component component) {
093: invalidateLayout(target);
094: }
095:
096: public void layoutContainer(final Container target) {
097: checkTarget(target);
098: layoutParams.layoutTarget();
099: }
100:
101: /**
102: * Checks if we want to deal with the same target that was mentioned in constructor
103: *
104: * @param target
105: */
106: private void checkTarget(final Container target) {
107: if (this .target != target) {
108: throw new AWTError(Messages.getString("swing.err.03")); //$NON-NLS-1$
109: }
110: }
111:
112: }
|