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.
17 package com
.intellij
.uiDesigner
.radComponents
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.uiDesigner
.XmlWriter
;
21 import com
.intellij
.uiDesigner
.SwingProperties
;
22 import com
.intellij
.uiDesigner
.inspections
.FormInspectionUtil
;
23 import com
.intellij
.uiDesigner
.lw
.IProperty
;
24 import com
.intellij
.uiDesigner
.designSurface
.ComponentDropLocation
;
25 import com
.intellij
.uiDesigner
.designSurface
.NoDropLocation
;
26 import com
.intellij
.uiDesigner
.propertyInspector
.Property
;
27 import com
.intellij
.uiDesigner
.snapShooter
.SnapshotContext
;
28 import com
.intellij
.util
.IncorrectOperationException
;
29 import org
.jetbrains
.annotations
.NotNull
;
30 import org
.jetbrains
.annotations
.Nullable
;
36 * Design-time support for a layout manager.
40 public abstract class RadLayoutManager
{
42 * Returns the name of the layout manager. If null is returned, the layout manager property is not
45 * @return the layout manager name.
47 @Nullable public abstract String
getName();
49 @Nullable public LayoutManager
createLayout() {
53 public void changeContainerLayout(RadContainer container
) throws IncorrectOperationException
{
54 ensureChildrenVisible(container
);
55 container
.setLayoutManager(this);
58 public abstract void writeChildConstraints(final XmlWriter writer
, final RadComponent child
);
60 public void writeLayout(final XmlWriter writer
, final RadContainer radContainer
) {
63 @NotNull public ComponentDropLocation
getDropLocation(RadContainer container
, @Nullable final Point location
) {
64 return NoDropLocation
.INSTANCE
;
67 public abstract void addComponentToContainer(final RadContainer container
, final RadComponent component
, final int index
);
69 public void removeComponentFromContainer(final RadContainer container
, final RadComponent component
) {
70 container
.getDelegee().remove(component
.getDelegee());
73 public boolean isSwitchedToChild(RadContainer container
, RadComponent child
) {
77 public boolean switchContainerToChild(RadContainer container
, RadComponent child
) {
81 public Property
[] getContainerProperties(final Project project
) {
82 return Property
.EMPTY_ARRAY
;
85 public Property
[] getComponentProperties(final Project project
, final RadComponent component
) {
86 return Property
.EMPTY_ARRAY
;
89 public void addSnapshotComponent(final JComponent parent
,
90 final JComponent child
,
91 final RadContainer container
,
92 final RadComponent component
) {
93 throw new UnsupportedOperationException("Layout manager " + this + " does not support adding snapshot components");
96 public void createSnapshotLayout(final SnapshotContext context
,
97 final JComponent parent
,
98 final RadContainer container
,
99 final LayoutManager layout
) {
102 public boolean isIndexed() {
106 public boolean isGrid() {
110 public boolean areChildrenExclusive() {
114 public void setChildDragging(RadComponent child
, boolean dragging
) {
115 child
.getDelegee().setVisible(!dragging
);
118 public boolean canMoveComponent(RadComponent c
, int rowDelta
, int colDelta
, final int rowSpanDelta
, final int colSpanDelta
) {
122 public void moveComponent(RadComponent c
, int rowDelta
, int colDelta
, final int rowSpanDelta
, final int colSpanDelta
) {
125 protected static void ensureChildrenVisible(final RadContainer container
) {
126 if (container
.getLayoutManager().areChildrenExclusive()) {
127 // ensure that components which were hidden by previous layout are visible (IDEADEV-16077)
128 for(RadComponent child
: container
.getComponents()) {
129 final IProperty property
= FormInspectionUtil
.findProperty(child
, SwingProperties
.VISIBLE
);
130 if (property
== null || property
.getPropertyValue(child
) == Boolean
.TRUE
) {
131 child
.getDelegee().setVisible(true);