2 * Copyright 2000-2007 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.util
.ui
;
21 import java
.util
.ArrayList
;
23 public class Layers
extends JLayeredPane
{
25 private final ArrayList
<Component
> myComponents
= new ArrayList
<Component
>();
28 setLayout(new Layout());
31 private class Layout
implements LayoutManager2
{
32 public void addLayoutComponent(Component comp
, Object constraints
) {
33 myComponents
.add(comp
);
36 public float getLayoutAlignmentX(Container target
) {
40 public float getLayoutAlignmentY(Container target
) {
44 public void invalidateLayout(Container target
) {
47 public Dimension
maximumLayoutSize(Container target
) {
50 for (Component each
: myComponents
) {
51 Dimension min
= each
.getMaximumSize();
52 maxWidth
= Math
.min(maxWidth
, min
.width
);
53 maxHeight
= Math
.min(maxHeight
, min
.height
);
55 return new Dimension(maxWidth
, maxHeight
);
58 public void addLayoutComponent(String name
, Component comp
) {
59 myComponents
.add(comp
);
62 public void layoutContainer(Container parent
) {
63 for (Component each
: myComponents
) {
64 each
.setBounds(0, 0, parent
.getWidth() - 1, parent
.getHeight() - 1);
68 public Dimension
minimumLayoutSize(Container parent
) {
71 for (Component each
: myComponents
) {
72 Dimension min
= each
.getMinimumSize();
73 minWidth
= Math
.min(minWidth
, min
.width
);
74 minHeight
= Math
.min(minHeight
, min
.height
);
76 return new Dimension(minWidth
, minHeight
);
79 public Dimension
preferredLayoutSize(Container parent
) {
82 for (Component each
: myComponents
) {
83 Dimension min
= each
.getPreferredSize();
84 prefWidth
= Math
.max(prefWidth
, min
.width
);
85 prefHeight
= Math
.max(prefHeight
, min
.height
);
87 return new Dimension(prefWidth
, prefHeight
);
90 public void removeLayoutComponent(Component comp
) {
91 myComponents
.remove(comp
);