01: package abbot.editor;
02:
03: import java.awt.*;
04: import javax.swing.*;
05: import javax.swing.plaf.*;
06:
07: import junit.extensions.abbot.*;
08:
09: /** Verify operation of LookAndFeelPreserver, and ScriptModel interactions. */
10:
11: public class LookAndFeelPreserverTest extends ComponentTestFixture {
12:
13: private String alternate;
14:
15: protected void setUp() throws Exception {
16: LookAndFeel laf = UIManager.getLookAndFeel();
17: UIManager.LookAndFeelInfo[] infos = UIManager
18: .getInstalledLookAndFeels();
19: for (int i = 0; i < infos.length; i++) {
20: String cname = infos[i].getClassName();
21: if (!laf.getClass().getName().equals(cname)) {
22: alternate = cname;
23: return;
24: }
25: }
26: throw new RuntimeException("No alternate LAF available");
27: }
28:
29: public void testPreserveGlobalLAFChange() throws Exception {
30: JFrame f = new JFrame(getName());
31: new LookAndFeelPreserver(f);
32:
33: JLabel label = new JLabel(getName());
34: f.getContentPane().add(label);
35: LabelUI ui = label.getUI();
36: UIManager.setLookAndFeel(alternate);
37: Frame[] frames = Frame.getFrames();
38: for (int i = 0; i < frames.length; i++) {
39: SwingUtilities.updateComponentTreeUI(frames[i]);
40: }
41:
42: getRobot().waitForIdle();
43: LabelUI ui2 = label.getUI();
44: assertEquals("UI should revert after attempt at global change",
45: ui, ui2);
46: }
47:
48: public void testPreserveWithinHierarchy() throws Exception {
49: JFrame f = new JFrame(getName());
50: new LookAndFeelPreserver(f);
51:
52: JLabel label = new JLabel("original LAF");
53: f.getContentPane().add(label);
54: LabelUI ui = label.getUI();
55: UIManager.setLookAndFeel(alternate);
56:
57: JLabel label2 = new JLabel("LAF changed");
58: f.getContentPane().add(label2);
59:
60: getRobot().waitForIdle();
61: LabelUI ui2 = label2.getUI();
62: assertEquals(
63: "Should use original LAF for new hierarchy members",
64: ui, ui2);
65: }
66:
67: /** Construct a test case with the given name. */
68: public LookAndFeelPreserverTest(String name) {
69: super (name);
70: }
71:
72: /** Run the default test suite. */
73: public static void main(String[] args) {
74: TestHelper.runTests(args, LookAndFeelPreserverTest.class);
75: }
76: }
|