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
.jgoodies
.forms
.layout
.ColumnSpec
;
20 import com
.jgoodies
.forms
.layout
.ConstantSize
;
21 import com
.jgoodies
.forms
.layout
.FormLayout
;
22 import com
.jgoodies
.forms
.layout
.CellConstraints
;
23 import com
.intellij
.uiDesigner
.core
.GridConstraints
;
24 import junit
.framework
.TestCase
;
31 public class RadFormLayoutManagerTest
extends TestCase
{
32 private RadFormLayoutManager myManager
;
33 private RadContainer myContainer
;
34 private FormLayout myLayout
;
36 public void setUp() throws Exception
{
38 myManager
= new RadFormLayoutManager();
39 myContainer
= new RadContainer(null, "grid");
40 myContainer
.setLayoutManager(myManager
);
41 myLayout
= (FormLayout
) myContainer
.getLayout();
44 public void testAddComponent() {
45 RadComponent c
= newComponent(0, 0, 1, 1);
46 myContainer
.addComponent(c
);
47 CellConstraints cc
= myLayout
.getConstraints(c
.getDelegee());
48 assertEquals(1, cc
.gridX
);
49 assertEquals(1, cc
.gridY
);
50 assertEquals(1, cc
.gridWidth
);
51 assertEquals(1, cc
.gridHeight
);
54 private RadComponent
newComponent(final int row
, final int column
, final int rowSpan
, final int colSpan
) {
55 RadComponent c
= new RadAtomicComponent(null, JLabel
.class, "1");
56 c
.setCustomLayoutConstraints(new CellConstraints(1, 1, CellConstraints
.DEFAULT
, CellConstraints
.DEFAULT
));
57 c
.getConstraints().restore(new GridConstraints(row
, column
, rowSpan
, colSpan
, GridConstraints
.ANCHOR_CENTER
, GridConstraints
.FILL_BOTH
,
58 GridConstraints
.SIZEPOLICY_CAN_GROW
, GridConstraints
.SIZEPOLICY_CAN_GROW
,
63 public void testInsertColumn() {
64 myManager
.insertGridCells(myContainer
, 0, false, false, true);
65 assertEquals(3, myManager
.getGridColumnCount(myContainer
));
68 public void testResizeColumn() {
69 myManager
.processCellResized(myContainer
, false, 0, 210);
70 final ColumnSpec spec
= myLayout
.getColumnSpec(1);
71 assertTrue(spec
.getSize() instanceof ConstantSize
);
72 ConstantSize cSize
= (ConstantSize
) spec
.getSize();
73 assertEquals(210, cSize
.getPixelSize(myContainer
.getDelegee()));
76 public void testMoveColumnRight() {
77 myManager
.insertGridCells(myContainer
, 0, false, false, true);
78 final ConstantSize colSize
= new ConstantSize(17, ConstantSize
.MM
);
79 myLayout
.setColumnSpec(1, new ColumnSpec(colSize
));
80 RadComponent c
= newComponent(0, 0, 1, 1);
81 myContainer
.addComponent(c
);
82 myManager
.processCellsMoved(myContainer
, false, new int[] { 0 }, 3);
83 assertEquals(colSize
, myLayout
.getColumnSpec(3).getSize());
84 assertEquals(3, myLayout
.getConstraints(c
.getDelegee()).gridX
);
87 public void testMoveColumnLeft() {
88 myManager
.insertGridCells(myContainer
, 0, false, false, true);
89 final ConstantSize colSize
= new ConstantSize(17, ConstantSize
.MM
);
90 myLayout
.setColumnSpec(3, new ColumnSpec(colSize
));
91 RadComponent c
= newComponent(0, 2, 1, 1);
92 myContainer
.addComponent(c
);
93 myManager
.processCellsMoved(myContainer
, false, new int[] { 2 }, 0);
94 assertEquals(colSize
, myLayout
.getColumnSpec(1).getSize());
95 assertEquals(1, myLayout
.getConstraints(c
.getDelegee()).gridX
);
98 public void testMoveMultipleColumnsRight() {
99 myManager
.insertGridCells(myContainer
, 0, false, false, true);
100 myManager
.insertGridCells(myContainer
, 0, false, false, true);
101 final ConstantSize colSize1
= new ConstantSize(17, ConstantSize
.MM
);
102 final ConstantSize colSize2
= new ConstantSize(19, ConstantSize
.MM
);
103 myLayout
.setColumnSpec(1, new ColumnSpec(colSize1
));
104 myLayout
.setColumnSpec(3, new ColumnSpec(colSize2
));
105 RadComponent c1
= newComponent(0, 0, 1, 1);
106 myContainer
.addComponent(c1
);
107 RadComponent c2
= newComponent(0, 2, 1, 1);
108 myContainer
.addComponent(c2
);
109 myManager
.processCellsMoved(myContainer
, false, new int[] { 0, 2 }, 5);
110 assertEquals(colSize1
, myLayout
.getColumnSpec(3).getSize());
111 assertEquals(colSize2
, myLayout
.getColumnSpec(5).getSize());
112 assertEquals(3, myLayout
.getConstraints(c1
.getDelegee()).gridX
);
113 assertEquals(5, myLayout
.getConstraints(c2
.getDelegee()).gridX
);