update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / radComponents / XYLayoutManagerImpl.java
blobc9a940a21e590c58c81fe1ac5e3ad0aa7d6812b9
1 /*
2 * Copyright 2000-2009 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.
16 package com.intellij.uiDesigner.radComponents;
18 import com.intellij.uiDesigner.shared.XYLayoutManager;
20 import javax.swing.*;
21 import java.awt.*;
23 /**
24 * @author Anton Katilin
25 * @author Vladimir Kondratyev
27 public final class XYLayoutManagerImpl extends XYLayoutManager {
28 private final Dimension myPreferredSize;
29 private static final Dimension MIN_SIZE = new Dimension(20,20);
31 public XYLayoutManagerImpl(){
32 myPreferredSize = new Dimension();
35 public void setPreferredSize(final Dimension size) {
36 myPreferredSize.setSize(size);
39 public Dimension maximumLayoutSize(final Container container){
40 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
43 public Dimension preferredLayoutSize(final Container container){
44 return myPreferredSize;
47 public void layoutContainer(final Container parent){
50 public Dimension minimumLayoutSize(final Container container){
51 final Container parent = container.getParent();
52 if (!(parent instanceof JComponent)) {
53 return MIN_SIZE;
55 final RadComponent component = (RadComponent)((JComponent)parent).getClientProperty(RadComponent.CLIENT_PROP_RAD_COMPONENT);
56 if (component == null) {
57 return MIN_SIZE;
60 // the following code prevents XYs placed in Grid from being shrunk
61 final RadComponent radParent = component.getParent();
62 if (radParent instanceof RadContainer && (((RadContainer)radParent).getLayoutManager().isGrid())) {
63 return new Dimension(
64 Math.max(myPreferredSize.width, MIN_SIZE.width),
65 Math.max(myPreferredSize.height, MIN_SIZE.height)
68 return MIN_SIZE;