|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4210354 |
| 27 | + * @summary Tests whether method FixedHeightLayoutCache.getBounds returns bad Rectangle |
| 28 | + * @run main bug4210354 |
| 29 | + */ |
| 30 | + |
| 31 | +import java.awt.Rectangle; |
| 32 | + |
| 33 | +import javax.swing.tree.AbstractLayoutCache; |
| 34 | +import javax.swing.tree.DefaultMutableTreeNode; |
| 35 | +import javax.swing.tree.DefaultTreeModel; |
| 36 | +import javax.swing.tree.FixedHeightLayoutCache; |
| 37 | +import javax.swing.tree.TreePath; |
| 38 | + |
| 39 | +public class bug4210354 { |
| 40 | + static class DummyNodeDimensions extends AbstractLayoutCache.NodeDimensions { |
| 41 | + private final Rectangle rectangle; |
| 42 | + |
| 43 | + public DummyNodeDimensions(Rectangle r) { |
| 44 | + rectangle = r; |
| 45 | + } |
| 46 | + public Rectangle getNodeDimensions(Object value, int row, int depth, |
| 47 | + boolean expanded, Rectangle bounds) { |
| 48 | + return rectangle; |
| 49 | + } |
| 50 | + |
| 51 | + /* create the TreeModel of depth 1 with specified num of children */ |
| 52 | + public DefaultTreeModel getTreeModelILike(int childrenCount) { |
| 53 | + DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); |
| 54 | + for (int i = 0; i < childrenCount; i++) { |
| 55 | + DefaultMutableTreeNode child = |
| 56 | + new DefaultMutableTreeNode("root.child" + i); |
| 57 | + root.insert(child, i); |
| 58 | + } |
| 59 | + return new DefaultTreeModel(root); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + public void init() { |
| 64 | + int x = 1, y = 2, dx = 3, dy = 4, h = 3; |
| 65 | + DummyNodeDimensions dim = new DummyNodeDimensions(new Rectangle(x, y, dx, dy)); |
| 66 | + FixedHeightLayoutCache fhlc = new FixedHeightLayoutCache(); |
| 67 | + fhlc.setModel(dim.getTreeModelILike(3)); |
| 68 | + fhlc.setRootVisible(true); |
| 69 | + fhlc.setNodeDimensions(dim); |
| 70 | + fhlc.setRowHeight(h); |
| 71 | + int row = 0; |
| 72 | + TreePath path = fhlc.getPathForRow(row); |
| 73 | + Rectangle r = fhlc.getBounds(path, new Rectangle()); |
| 74 | + Rectangle r2 = new Rectangle(x, row * h, dx, h); |
| 75 | + if (r.width != r2.width) { |
| 76 | + throw new RuntimeException("FixedHeightLayoutCache.getBounds returns bad Rectangle"); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + public static void main(String[] args) throws Exception { |
| 81 | + bug4210354 b = new bug4210354(); |
| 82 | + b.init(); |
| 83 | + } |
| 84 | +} |
1 commit comments
openjdk-notifier[bot] commentedon Jan 30, 2024
Review
Issues