001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing.tree;
021:
022: import java.awt.Rectangle;
023:
024: public class VariableHeightLayoutCacheTest extends
025: AbstractLayoutCacheTest {
026: @Override
027: protected void setUp() throws Exception {
028: super .setUp();
029: cache = new VariableHeightLayoutCache();
030: defaultRowValue = cache.getRowForPath(null);
031: }
032:
033: @Override
034: protected void tearDown() throws Exception {
035: super .tearDown();
036: }
037:
038: /*
039: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.VariableHeightLayoutCache()'
040: */
041: @Override
042: public void testLayoutCache() {
043: assertFalse(cache.rootVisible);
044: assertNull(cache.nodeDimensions);
045: assertEquals(0, cache.rowHeight);
046: assertNull(cache.treeModel);
047: assertNull(cache.treeSelectionModel);
048: }
049:
050: /*
051: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.setRootVisible(boolean)'
052: */
053: @Override
054: public void testSetRootVisible() {
055: super .testSetRootVisible();
056: int height = 1111;
057: cache.setRowHeight(height);
058: TreeModel model = new UndefaultTreeModel(root);
059: root.add(node1);
060: root.add(node2);
061: cache.setModel(model);
062: cache.setNodeDimensions(dimensions2);
063: if (isHarmony()) {
064: assertEquals(new Rectangle(0, -1111, 100, 1111), cache
065: .getBounds(rootPath, null));
066: } else {
067: assertEquals(new Rectangle(0, -1, 100, 1111), cache
068: .getBounds(rootPath, null));
069: }
070: assertEquals(new Rectangle(10, 0 * height, 100, height), cache
071: .getBounds(path1, null));
072: assertEquals(new Rectangle(10, 1 * height, 100, height), cache
073: .getBounds(path2, null));
074: cache.setRootVisible(true);
075: assertEquals(new Rectangle(0, 0, 100, 1111), cache.getBounds(
076: rootPath, null));
077: assertEquals(new Rectangle(10, 1 * height, 100, height), cache
078: .getBounds(path1, null));
079: assertEquals(new Rectangle(10, 2 * height, 100, height), cache
080: .getBounds(path2, null));
081: }
082:
083: /*
084: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.setRowHeight(int)'
085: */
086: @Override
087: public void testSetRowHeight() {
088: cache.setRowHeight(100);
089: assertEquals(100, cache.getRowHeight());
090: cache.setRowHeight(200);
091: assertEquals(200, cache.getRowHeight());
092: cache.setRowHeight(-1);
093: assertEquals(-1, cache.getRowHeight());
094: }
095:
096: /*
097: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.getPreferredHeight()'
098: */
099: @Override
100: public void testGetPreferredHeight() {
101: int height = 1111;
102: TreeModel model = new UndefaultTreeModel(root);
103: root.add(node1);
104: root.add(node2);
105: cache.setRowHeight(height);
106: assertEquals(0, cache.getPreferredHeight());
107: cache.setModel(model);
108: assertEquals(2222, cache.getPreferredHeight());
109: cache.setRowHeight(-100);
110: assertEquals(0, cache.getPreferredHeight());
111: cache.setRowHeight(height);
112: cache.setNodeDimensions(dimensions3);
113: assertEquals(2222, cache.getPreferredHeight());
114: cache.setRootVisible(true);
115: assertEquals(3333, cache.getPreferredHeight());
116: cache.setRowHeight(-100);
117: assertEquals(6000, cache.getPreferredHeight());
118: cache.setRootVisible(false);
119: if (isHarmony()) {
120: assertEquals(3000, cache.getPreferredHeight());
121: } else {
122: assertEquals(5000, cache.getPreferredHeight());
123: }
124: }
125:
126: /*
127: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.getPreferredWidth(Rectangle)'
128: */
129: @Override
130: public void testGetPreferredWidth() {
131: int height = 1111;
132: TreeModel model = new DefaultTreeModel(root);
133: root.add(node1);
134: root.add(node2);
135: node1.add(node3);
136: node1.add(node4);
137: node2.add(node5);
138: node2.add(node6);
139: cache.setRowHeight(height);
140: assertEquals(0, cache.getPreferredWidth(null));
141: cache.setModel(model);
142: assertEquals(0, cache.getPreferredWidth(null));
143: cache.setRowHeight(-100);
144: assertEquals(0, cache.getPreferredWidth(null));
145: cache.setNodeDimensions(dimensions2);
146: assertEquals(110, cache.getPreferredWidth(new Rectangle(0, 0,
147: 0, 0)));
148: assertEquals(20, cache.getPreferredHeight());
149: assertEquals(110, cache.getPreferredWidth(new Rectangle(0,
150: 3010, 10, 10)));
151: cache.setRootVisible(true);
152: assertEquals(110, cache.getPreferredWidth(new Rectangle(0, 0,
153: 50, 100)));
154: cache.setExpandedState(path1, true);
155: if (!isHarmony()) {
156: assertEquals(120, cache.getPreferredWidth(new Rectangle(0,
157: 0, 0, 0)));
158: } else {
159: assertEquals(100, cache.getPreferredWidth(new Rectangle(0,
160: 0, 0, 0)));
161: }
162: assertEquals(120, cache.getPreferredWidth(null));
163: cache.setExpandedState(path1, false);
164: cache.setExpandedState(path2, true);
165: if (!isHarmony()) {
166: assertEquals(120, cache.getPreferredWidth(new Rectangle(0,
167: 0, 0, 0)));
168: } else {
169: assertEquals(100, cache.getPreferredWidth(new Rectangle(0,
170: 0, 0, 0)));
171: }
172: assertEquals(120, cache.getPreferredWidth(null));
173: }
174:
175: /*
176: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.getBounds(TreePath, Rectangle)'
177: */
178: public void testGetBounds() {
179: int height = 1111;
180: cache.setRowHeight(height);
181: TreeModel model = new UndefaultTreeModel(root);
182: root.add(node1);
183: root.add(node2);
184: node1.add(node3);
185: node1.add(node4);
186: node2.add(node5);
187: node2.add(node6);
188: cache.setModel(model);
189: cache.setExpandedState(rootPath, false);
190: assertNull(cache.getBounds(path1, new Rectangle()));
191: cache.setExpandedState(path1, true);
192: cache.setExpandedState(path2, true);
193: cache.setRowHeight(10);
194: if (isHarmony()) {
195: assertEquals(new Rectangle(0, -10, 0, 10), cache.getBounds(
196: rootPath, null));
197: } else {
198: assertEquals(new Rectangle(0, -1, 0, 10), cache.getBounds(
199: rootPath, null));
200: }
201: assertEquals(new Rectangle(0, 0, 0, 10), cache.getBounds(path1,
202: null));
203: assertEquals(new Rectangle(0, 30, 0, 10), cache.getBounds(
204: path2, null));
205: assertEquals(new Rectangle(0, 50, 0, 10), cache.getBounds(
206: path26, null));
207: cache.setRowHeight(-10);
208: assertEquals(new Rectangle(0, 0, 0, 0), cache.getBounds(path1,
209: null));
210: assertEquals(new Rectangle(0, 0, 0, 0), cache.getBounds(path2,
211: null));
212: assertEquals(new Rectangle(0, 0, 0, 0), cache.getBounds(path26,
213: null));
214: cache.setNodeDimensions(dimensions1);
215: assertEquals(new Rectangle(root.hashCode(), 0, 0, 1), cache
216: .getBounds(rootPath, null));
217: assertEquals(new Rectangle(node1.hashCode(), 0, 1, 1), cache
218: .getBounds(path1, null));
219: assertEquals(new Rectangle(node2.hashCode(), 1, 1, 1), cache
220: .getBounds(path2, null));
221: // assertEquals(new Rectangle(0, 1, 0, 0), cache.getBounds(path13, null));
222: // assertEquals(new Rectangle(0, 1, 0, 0), cache.getBounds(path14, null));
223: // assertEquals(new Rectangle(0, 2, 0, 0), cache.getBounds(path25, null));
224: // assertEquals(new Rectangle(0, 2, 0, 0), cache.getBounds(path26, null));
225: cache.setRowHeight(-110);
226: cache.setNodeDimensions(dimensions3);
227: assertEquals(new Rectangle(0, 0, 20, 2000), cache.getBounds(
228: rootPath, null));
229: assertEquals(new Rectangle(10000, 0, 10, 1000), cache
230: .getBounds(path1, null));
231: assertEquals(new Rectangle(10000, 6000, 40, 4000), cache
232: .getBounds(path2, null));
233: assertEquals(new Rectangle(20000, 1000, 20, 2000), cache
234: .getBounds(path13, null));
235: assertEquals(new Rectangle(20000, 3000, 30, 3000), cache
236: .getBounds(path14, null));
237: assertEquals(new Rectangle(20000, 10000, 50, 5000), cache
238: .getBounds(path25, null));
239: assertEquals(new Rectangle(20000, 15000, 60, 6000), cache
240: .getBounds(path26, null));
241: cache.setModel(null);
242: assertNull(cache.getBounds(path1, null));
243: }
244:
245: /*
246: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.getPathClosestTo(int, int)'
247: */
248: public void testGetPathClosestTo() {
249: int height = 10;
250: cache.setRowHeight(height);
251: TreeModel model = new UndefaultTreeModel(root);
252: root.add(node1);
253: root.add(node2);
254: node1.add(node3);
255: node1.add(node4);
256: node2.add(node5);
257: node2.add(node6);
258: assertNull(cache.getPathClosestTo(-100, -100));
259: assertNull(cache.getPathClosestTo(0, 0));
260: assertNull(cache.getPathClosestTo(100, 100));
261: cache.setModel(model);
262: cache.setExpandedState(rootPath, false);
263: assertNull(cache.getPathClosestTo(-100, -100));
264: assertNull(cache.getPathClosestTo(0, 0));
265: assertNull(cache.getPathClosestTo(100, 100));
266: cache.setRootVisible(true);
267: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
268: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
269: assertEquals(rootPath, cache.getPathClosestTo(100, 100));
270: cache.setExpandedState(rootPath, true);
271: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
272: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
273: assertEquals(path2, cache.getPathClosestTo(100, 100));
274: cache.setExpandedState(path1, true);
275: cache.setExpandedState(path2, true);
276: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
277: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
278: assertEquals(path13, cache.getPathClosestTo(0, 20));
279: assertEquals(path2, cache.getPathClosestTo(0, 40));
280: assertEquals(path26, cache.getPathClosestTo(0, 60));
281: assertEquals(path26, cache.getPathClosestTo(0, 80));
282: assertEquals(rootPath, cache.getPathClosestTo(120, 0));
283: assertEquals(path13, cache.getPathClosestTo(120, 20));
284: assertEquals(path2, cache.getPathClosestTo(120, 40));
285: assertEquals(path26, cache.getPathClosestTo(120, 60));
286: assertEquals(path26, cache.getPathClosestTo(120, 80));
287: cache.setRowHeight(-100);
288: cache.setNodeDimensions(dimensions2);
289: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
290: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
291: assertEquals(path26, cache.getPathClosestTo(100, 100));
292: cache.setModel(model);
293: cache.setRootVisible(false);
294: cache.setExpandedState(rootPath, false);
295: assertNull(cache.getPathClosestTo(-100, -100));
296: assertNull(cache.getPathClosestTo(0, 0));
297: assertNull(cache.getPathClosestTo(100, 100));
298: cache.setRootVisible(true);
299: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
300: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
301: assertEquals(rootPath, cache.getPathClosestTo(100, 100));
302: cache.setExpandedState(rootPath, true);
303: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
304: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
305: assertEquals(path2, cache.getPathClosestTo(100, 100));
306: cache.setExpandedState(path1, true);
307: cache.setExpandedState(path2, true);
308: assertEquals(rootPath, cache.getPathClosestTo(-100, -100));
309: assertEquals(rootPath, cache.getPathClosestTo(0, 0));
310: assertEquals(path13, cache.getPathClosestTo(0, 20));
311: assertEquals(path2, cache.getPathClosestTo(0, 40));
312: assertEquals(path26, cache.getPathClosestTo(0, 60));
313: assertEquals(path26, cache.getPathClosestTo(0, 80));
314: assertEquals(rootPath, cache.getPathClosestTo(120, 0));
315: assertEquals(path13, cache.getPathClosestTo(120, 20));
316: assertEquals(path2, cache.getPathClosestTo(120, 40));
317: assertEquals(path26, cache.getPathClosestTo(120, 60));
318: assertEquals(path26, cache.getPathClosestTo(120, 80));
319: cache.setModel(null);
320: assertNull(cache.getPathClosestTo(0, 0));
321: }
322:
323: /*
324: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.invalidatePathBounds(TreePath)'
325: */
326: public void testInvalidatePathBounds() {
327: }
328:
329: /*
330: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.invalidateSizes()'
331: */
332: @Override
333: public void testInvalidateSizes() {
334: // super.testInvalidateSizes();
335: }
336:
337: /*
338: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.treeNodesChanged(TreeModelEvent)'
339: */
340: @Override
341: public void testTreeNodesChanged() {
342: super .testTreeNodesChanged();
343: }
344:
345: /*
346: * Test method for 'javax.swing.tree.VariableHeightLayoutCache.setNodeDimensions(NodeDimensions)'
347: */
348: public void testSetNodeDimensionsNodeDimensions() {
349: }
350:
351: @Override
352: public void testIsFixedRowHeight() {
353: assertFalse(cache.isFixedRowHeight());
354: }
355: }
|