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
.uiDesigner
.core
.GridLayoutManager
;
20 import com
.intellij
.uiDesigner
.core
.GridConstraints
;
21 import com
.intellij
.uiDesigner
.snapShooter
.SnapshotContext
;
24 import java
.awt
.LayoutManager
;
25 import java
.awt
.GridLayout
;
26 import java
.awt
.Insets
;
31 public class RadSwingGridLayoutManager
extends RadGridLayoutManager
{
32 private int myLastRow
= 0;
33 private int myLastColumn
= 0;
36 public void createSnapshotLayout(final SnapshotContext context
,
37 final JComponent parent
,
38 final RadContainer container
,
39 final LayoutManager layout
) {
40 GridLayout gridLayout
= (GridLayout
) layout
;
42 int ncomponents
= parent
.getComponentCount();
43 int nrows
= gridLayout
.getRows();
44 int ncols
= gridLayout
.getColumns();
47 ncols
= (ncomponents
+ nrows
- 1) / nrows
;
49 nrows
= (ncomponents
+ ncols
- 1) / ncols
;
52 container
.setLayout(new GridLayoutManager(nrows
, ncols
,
53 new Insets(0, 0, 0, 0),
54 gridLayout
.getHgap(), gridLayout
.getVgap(),
60 public void addSnapshotComponent(final JComponent parent
,
61 final JComponent child
,
62 final RadContainer container
,
63 final RadComponent component
) {
64 GridLayoutManager grid
= (GridLayoutManager
) container
.getLayout();
65 component
.getConstraints().setRow(myLastRow
);
66 component
.getConstraints().setColumn(myLastColumn
);
67 component
.getConstraints().setFill(GridConstraints
.FILL_BOTH
);
68 if (myLastColumn
== grid
.getColumnCount()-1) {
75 container
.addComponent(component
);