001: package abbot.editor;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import java.util.*;
006:
007: import junit.extensions.abbot.*;
008:
009: public class CompactHierarchyTest extends ComponentTestFixture {
010:
011: private CompactHierarchy hierarchy;
012:
013: protected void setUp() {
014: hierarchy = new CompactHierarchy(getHierarchy());
015: }
016:
017: public void testElideScrollPaneChildren() {
018: Object[][] data = { { "one", "two" }, { "three", "four" } };
019: String[] columns = { "one", "two" };
020: JTable table = new JTable(data, columns);
021: JScrollPane sp = new JScrollPane(table);
022: showFrame(sp);
023: Collection kids = hierarchy.getComponents(sp);
024: assertEquals("Scroll pane should show two children", 2, kids
025: .size());
026: assertTrue("One child should be the table header", kids
027: .contains(table.getTableHeader()));
028: assertTrue("One child should be the table", kids
029: .contains(table));
030: }
031:
032: public void testElidePopups() {
033: JLabel label = new JLabel(getName());
034: JFrame f = new JFrame(getName());
035: f.getContentPane().add(label);
036: showWindow(f, new Dimension(200, 200));
037: JPopupMenu light = new JPopupMenu();
038: light.add(new JMenuItem("item"));
039: JPopupMenu heavy = new JPopupMenu();
040: for (int i = 0; i < 10; i++) {
041: heavy.add(new JMenuItem("item " + i));
042: }
043:
044: showPopup(light, label);
045: assertEquals("LW Popup parent should be its invoker", label,
046: hierarchy.getParent(light));
047: Collection kids = hierarchy.getComponents(label);
048: assertEquals("Label should have LW popup child: " + kids, 1,
049: kids.size());
050: assertEquals("Label child should be the LW popup", light, kids
051: .iterator().next());
052: // Normally, a heavyweight popup will be a child of the frame's
053: // layered pane. Make sure it's not represented that way
054: kids = hierarchy.getComponents(f.getLayeredPane());
055: assertEquals("Frame should have a single child: " + kids, f
056: .getContentPane(), kids.iterator().next());
057:
058: showPopup(heavy, label);
059: assertEquals("HW Popup parent should be its invoker", label,
060: hierarchy.getParent(heavy));
061: kids = hierarchy.getComponents(label);
062: assertEquals("Label should have HW popup child: " + kids, 1,
063: kids.size());
064: assertEquals("Label child should be the HW popup", heavy, kids
065: .iterator().next());
066: // Normally, a heavyweight popup will be a sub-window of the frame
067: // Make sure it's not represented that way
068: kids = hierarchy.getComponents(f);
069: assertEquals("Frame should have a single child: " + kids, f
070: .getContentPane(), kids.iterator().next());
071: }
072:
073: public void testElideMenuContents() {
074: JMenuBar mb = new JMenuBar();
075: JMenu menu = new JMenu("file");
076: JMenuItem item = new JMenuItem("open");
077: menu.add(item);
078: mb.add(menu);
079: JFrame f = new JFrame(getName());
080: f.setJMenuBar(mb);
081: showWindow(f);
082:
083: Collection kids = hierarchy.getComponents(menu);
084: assertEquals("Menu should have one child: " + kids, 1, kids
085: .size());
086: assertEquals("Menu child should be menu item", item, kids
087: .iterator().next());
088: }
089:
090: public void testElideRootPaneContainer() {
091: JFrame f = (JFrame) showFrame(new JLabel(getName()));
092:
093: Collection kids = hierarchy.getComponents(f);
094: assertEquals("Frame should have a single child: " + kids, 1,
095: kids.size());
096: assertEquals("Content pane should appear as child of frame", f
097: .getContentPane(), kids.iterator().next());
098: }
099:
100: public CompactHierarchyTest(String name) {
101: super (name);
102: }
103:
104: public static void main(String[] args) {
105: TestHelper.runTests(args, CompactHierarchyTest.class);
106: }
107: }
|