1 19 20 package org.netbeans.core.windows.view.ui; 21 22 import javax.swing.JSplitPane ; 23 import javax.swing.JWindow ; 24 import org.netbeans.junit.NbTestCase; 25 26 31 public class MultiSplitPaneTest extends NbTestCase { 32 33 private static int DIVIDER_SIZE = 10; 34 private MultiSplitPane split; 35 private JWindow testWindow; 36 37 public MultiSplitPaneTest(String testName) { 38 super(testName); 39 } 40 41 protected boolean runInEQ () { 42 return true; 43 } 44 45 protected void setUp() throws Exception { 46 split = new MultiSplitPane(); 47 split.setDividerSize( DIVIDER_SIZE ); 48 49 testWindow = new JWindow (); 50 testWindow.setVisible( true ); 51 } 53 54 protected void resizeSplit( int orientation, int splitSize, int nonResizingSize ) { 55 if( orientation == JSplitPane.HORIZONTAL_SPLIT ) 56 split.setSize( splitSize, nonResizingSize ); 57 else 58 split.setSize( nonResizingSize, splitSize ); 59 testWindow.getContentPane().add( split ); 60 split.validate(); 61 } 62 63 protected void checkNonSplitSizes( int expectedSize, TestViewElement[] views ) { 64 for( int i=0; i<views.length; i++ ) { 65 assertEquals( "Invalid non-split size for view " + i, expectedSize, views[i].getNonSplitSize() ); 66 } 67 } 68 69 public void testProportionalResize2ChildrenHorizontal() { 70 doTestProportionalResize2Children( JSplitPane.HORIZONTAL_SPLIT ); 71 } 72 73 public void testProportionalResize2ChildrenVertical() { 74 doTestProportionalResize2Children( JSplitPane.VERTICAL_SPLIT ); 75 } 76 77 protected void doTestProportionalResize2Children( int orientation ) { 78 TestViewElement[] views = new TestViewElement[2]; 79 double[] splitWeights = new double[2]; 80 81 views[0] = new TestViewElement( orientation, 0.0 ); 82 splitWeights[0] = 0.5; 83 views[1] = new TestViewElement( orientation, 0.0 ); 84 splitWeights[1] = 0.5; 85 86 split.setChildren( orientation, views, splitWeights ); 87 88 resizeSplit( orientation, 200+DIVIDER_SIZE, 200 ); 90 assertEquals( 100, views[0].getSizeInSplit() ); 91 assertEquals( 100, views[1].getSizeInSplit() ); 92 checkNonSplitSizes( 200, views ); 94 95 resizeSplit( orientation, 100+DIVIDER_SIZE, 300 ); 97 assertEquals( 50, views[0].getSizeInSplit() ); 98 assertEquals( 50, views[1].getSizeInSplit() ); 99 checkNonSplitSizes( 300, views ); 100 101 views[0].setMinSize( 10 ); 103 views[1].setMinSize( 10 ); 104 resizeSplit( orientation, 0, 100 ); 105 assertEquals( 10, views[0].getSizeInSplit() ); 106 assertEquals( 10, views[1].getSizeInSplit() ); 107 checkNonSplitSizes( 100, views ); 108 } 109 110 public void testProportionalResize5ChildrenHorizontal() { 111 doTestProportionalResize5Children( JSplitPane.HORIZONTAL_SPLIT ); 112 } 113 114 public void testProportionalResize5ChildrenVertical() { 115 doTestProportionalResize5Children( JSplitPane.VERTICAL_SPLIT ); 116 } 117 118 protected void doTestProportionalResize5Children( int orientation ) { 119 TestViewElement[] views = new TestViewElement[5]; 120 double[] splitWeights = new double[5]; 121 122 views[0] = new TestViewElement( orientation, 0.0 ); 123 splitWeights[0] = 0.1; 124 views[1] = new TestViewElement( orientation, 0.0 ); 125 splitWeights[1] = 0.1; 126 views[2] = new TestViewElement( orientation, 0.0 ); 127 splitWeights[2] = 0.1; 128 views[3] = new TestViewElement( orientation, 0.0 ); 129 splitWeights[3] = 0.1; 130 views[4] = new TestViewElement( orientation, 0.0 ); 131 splitWeights[4] = 0.6; 132 133 split.setChildren( orientation, views, splitWeights ); 134 135 resizeSplit( orientation, 1000+4*DIVIDER_SIZE, 200 ); 137 assertEquals( 100, views[0].getSizeInSplit() ); 138 assertEquals( 100, views[1].getSizeInSplit() ); 139 assertEquals( 100, views[2].getSizeInSplit() ); 140 assertEquals( 100, views[3].getSizeInSplit() ); 141 assertEquals( 600, views[4].getSizeInSplit() ); 142 checkNonSplitSizes( 200, views ); 144 145 resizeSplit( orientation, 100+4*DIVIDER_SIZE, 300 ); 147 assertEquals( 10, views[0].getSizeInSplit() ); 148 assertEquals( 10, views[1].getSizeInSplit() ); 149 assertEquals( 10, views[2].getSizeInSplit() ); 150 assertEquals( 10, views[3].getSizeInSplit() ); 151 assertEquals( 60, views[4].getSizeInSplit() ); 152 checkNonSplitSizes( 300, views ); 153 154 views[0].setMinSize( 10 ); 156 views[1].setMinSize( 10 ); 157 views[2].setMinSize( 10 ); 158 views[3].setMinSize( 10 ); 159 views[4].setMinSize( 10 ); 160 resizeSplit( orientation, 0, 100 ); 161 assertEquals( 10, views[0].getSizeInSplit() ); 162 assertEquals( 10, views[1].getSizeInSplit() ); 163 assertEquals( 10, views[2].getSizeInSplit() ); 164 assertEquals( 10, views[3].getSizeInSplit() ); 165 assertEquals( 10, views[4].getSizeInSplit() ); 166 checkNonSplitSizes( 100, views ); 167 } 168 169 170 public void testEqualResizeWeightsHorizontal() { 171 doTestEqualResizeWeights( JSplitPane.HORIZONTAL_SPLIT ); 172 } 173 174 public void testEqualResizeWeightsVertical() { 175 doTestEqualResizeWeights( JSplitPane.VERTICAL_SPLIT ); 176 } 177 178 protected void doTestEqualResizeWeights( int orientation ) { 179 TestViewElement[] views = new TestViewElement[4]; 180 double[] splitWeights = new double[4]; 181 182 views[0] = new TestViewElement( orientation, 0.25 ); 183 splitWeights[0] = 1.0; 184 views[1] = new TestViewElement( orientation, 0.25 ); 185 splitWeights[1] = 1.0; 186 views[2] = new TestViewElement( orientation, 0.25 ); 187 splitWeights[2] = 1.0; 188 views[3] = new TestViewElement( orientation, 0.25 ); 189 splitWeights[3] = 1.0; 190 191 split.setChildren( orientation, views, splitWeights ); 192 193 resizeSplit( orientation, 1000+3*DIVIDER_SIZE, 200 ); 195 assertEquals( 250, views[0].getSizeInSplit() ); 196 assertEquals( 250, views[1].getSizeInSplit() ); 197 assertEquals( 250, views[2].getSizeInSplit() ); 198 assertEquals( 250, views[3].getSizeInSplit() ); 199 checkNonSplitSizes( 200, views ); 201 202 resizeSplit( orientation, 100+3*DIVIDER_SIZE, 300 ); 204 assertEquals( 25, views[0].getSizeInSplit() ); 205 assertEquals( 25, views[1].getSizeInSplit() ); 206 assertEquals( 25, views[2].getSizeInSplit() ); 207 assertEquals( 25, views[3].getSizeInSplit() ); 208 checkNonSplitSizes( 300, views ); 209 210 views[0].setMinSize( 10 ); 212 views[1].setMinSize( 10 ); 213 views[2].setMinSize( 10 ); 214 views[3].setMinSize( 10 ); 215 resizeSplit( orientation, 0, 100 ); 216 assertEquals( 10, views[0].getSizeInSplit() ); 217 assertEquals( 10, views[1].getSizeInSplit() ); 218 assertEquals( 10, views[2].getSizeInSplit() ); 219 assertEquals( 10, views[3].getSizeInSplit() ); 220 checkNonSplitSizes( 100, views ); 221 } 222 223 public void testDifferentResizeWeightsHorizontal() { 224 doTestDifferentResizeWeights( JSplitPane.HORIZONTAL_SPLIT ); 225 } 226 227 public void testDifferentResizeWeightsVertical() { 228 doTestDifferentResizeWeights( JSplitPane.VERTICAL_SPLIT ); 229 } 230 231 protected void doTestDifferentResizeWeights( int orientation ) { 232 TestViewElement[] views = new TestViewElement[4]; 233 double[] splitWeights = new double[4]; 234 235 views[0] = new TestViewElement( orientation, 0.2 ); splitWeights[0] = 1.0; 237 views[1] = new TestViewElement( orientation, 0.2 ); splitWeights[1] = 1.0; 239 views[2] = new TestViewElement( orientation, 0.5 ); splitWeights[2] = 1.0; 241 views[3] = new TestViewElement( orientation, 0.5 ); splitWeights[3] = 1.0; 243 244 split.setChildren( orientation, views, splitWeights ); 245 246 resizeSplit( orientation, 100+3*DIVIDER_SIZE, 200 ); 248 assertEquals( 25, views[0].getSizeInSplit() ); 249 assertEquals( 25, views[1].getSizeInSplit() ); 250 assertEquals( 25, views[2].getSizeInSplit() ); 251 assertEquals( 25, views[3].getSizeInSplit() ); 252 checkNonSplitSizes( 200, views ); 254 255 resizeSplit( orientation, 1000+3*DIVIDER_SIZE, 300 ); 257 assertEquals( 115, views[0].getSizeInSplit() ); assertEquals( 115, views[1].getSizeInSplit() ); assertEquals( 385, views[2].getSizeInSplit() ); assertEquals( 385, views[3].getSizeInSplit() ); checkNonSplitSizes( 300, views ); 262 263 resizeSplit( orientation, 100+3*DIVIDER_SIZE, 300 ); 265 assertEquals( 12, views[0].getSizeInSplit() ); assertEquals( 12, views[1].getSizeInSplit() ); assertEquals( 39, views[2].getSizeInSplit() ); assertEquals( 37, views[3].getSizeInSplit() ); checkNonSplitSizes( 300, views ); 270 271 views[0].setMinSize( 10 ); 273 views[1].setMinSize( 10 ); 274 views[2].setMinSize( 10 ); 275 views[3].setMinSize( 10 ); 276 resizeSplit( orientation, 0, 100 ); 277 assertEquals( 10, views[0].getSizeInSplit() ); 278 assertEquals( 10, views[1].getSizeInSplit() ); 279 assertEquals( 10, views[2].getSizeInSplit() ); 280 assertEquals( 10, views[3].getSizeInSplit() ); 281 checkNonSplitSizes( 100, views ); 282 } 283 } 284 | Popular Tags |