made all fields final. Could not resist, sorry
[fedora-idea.git] / util / src / com / intellij / util / ui / Layers.java
blobd3e29193cf296da1a9b305bba6036026c34cab2c
1 /*
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;
19 import javax.swing.*;
20 import java.awt.*;
21 import java.util.ArrayList;
23 public class Layers extends JLayeredPane {
25 private final ArrayList<Component> myComponents = new ArrayList<Component>();
27 public Layers() {
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) {
37 return 0;
40 public float getLayoutAlignmentY(Container target) {
41 return 0;
44 public void invalidateLayout(Container target) {
47 public Dimension maximumLayoutSize(Container target) {
48 int maxWidth = 0;
49 int maxHeight = 0;
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) {
69 int minWidth = 0;
70 int minHeight = 0;
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) {
80 int prefWidth = 0;
81 int prefHeight = 0;
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);