1 7 8 package org.jdesktop.jdnc.markup; 9 10 import java.awt.Component ; 11 12 import java.util.logging.Level ; 13 14 import javax.swing.*; 15 16 import java.net.URL ; 17 import java.net.MalformedURLException ; 18 19 import junit.framework.TestCase; 20 21 import org.jdesktop.jdnc.markup.ElementTypes; 22 23 import net.openmarkup.ObjectRealizer; 24 import net.openmarkup.Scribe; 25 26 import org.jdesktop.swing.actions.AbstractActionExt; 27 import org.jdesktop.swing.JXRootPane; 28 29 public class ActionsTest extends TestCase { 30 31 private ObjectRealizer realizer; 32 33 protected void setUp() { 34 realizer = RealizerUnitTest.createObjectRealizer(); 35 realizer.add(ElementTypes.get()); 36 } 37 38 protected void tearDown() { 39 realizer = null; 40 } 41 42 45 public void testActionAttributes() throws Exception { 46 URL url = RealizerUnitTest.class.getResource("resources/action1.xml"); 47 assertNotNull(url); 48 49 Object obj = realizer.getObject(url); 50 assertNotNull(obj); 51 assertTrue(obj instanceof Action); 52 53 Action action = (Action)obj; 54 55 assertEquals("find", action.getValue(Action.ACTION_COMMAND_KEY)); 56 assertEquals("Find", action.getValue(Action.NAME)); 57 assertEquals("Find an item", action.getValue(Action.SHORT_DESCRIPTION)); 58 assertEquals("Find an item", action.getValue(Action.LONG_DESCRIPTION)); 59 assertTrue(((AbstractActionExt)action).isStateAction()); 60 assertEquals("find-group", action.getValue(AbstractActionExt.GROUP)); 61 assertEquals(new Integer ('F'), action.getValue(Action.MNEMONIC_KEY)); 62 63 assertNotNull(action.getValue(Action.SMALL_ICON)); 64 assertTrue(action.getValue(Action.SMALL_ICON) instanceof Icon); 65 assertTrue(action.getValue(AbstractActionExt.LARGE_ICON) instanceof Icon); 66 assertTrue(action.getValue(Action.ACCELERATOR_KEY) instanceof KeyStroke); 67 } 68 69 73 public void testActionIcons() throws Exception { 74 URL url = RealizerUnitTest.class.getResource("resources/action0.xml"); 75 assertNotNull(url); 76 77 Object obj = realizer.getObject(url); 78 assertNotNull(obj); 79 assertTrue(obj instanceof Action); 80 81 Action action = (Action)obj; 82 83 Icon icon = (Icon)action.getValue(Action.SMALL_ICON); 84 assertNotNull("Icon should not be null: " + icon, icon); 85 assertTrue(icon instanceof Icon); 86 87 icon = (Icon)action.getValue(AbstractActionExt.LARGE_ICON); 88 assertNotNull("Icon should not be null: " + icon, icon); 89 assertTrue(icon instanceof Icon); 90 91 } 92 93 96 public void testActionIcons2() throws Exception { 97 URL url = RealizerUnitTest.class.getResource("resources/action6.xml"); 98 assertNotNull(url); 99 100 Object obj = realizer.getObject(url); 101 assertNotNull(obj); 102 assertTrue(obj instanceof Action); 103 104 Action action = (Action)obj; 105 106 Icon icon = (Icon)action.getValue(Action.SMALL_ICON); 107 assertNull("Icon should be null: " + icon, icon); 108 icon = (Icon)action.getValue(AbstractActionExt.LARGE_ICON); 109 assertNull("Icon should be null: " + icon, icon); 110 } 111 112 116 public void testToolBarCreate() throws Exception { 117 URL url = RealizerUnitTest.class.getResource("resources/action2.xml"); 118 assertNotNull(url); 119 120 Object obj = realizer.getObject(url); 121 assertNotNull(obj); 122 assertTrue(obj.getClass().toString() + " is not a JRootPane", 123 obj instanceof JRootPane); 124 125 JXRootPane root = (JXRootPane)obj; 126 JToolBar toolbar = root.getToolBar(); 127 128 assertTrue(toolbar.getComponentCount() == 4); 129 130 Component comp = toolbar.getComponent(3); 131 assertNotNull(comp); 132 assertTrue(comp.getClass().toString() + " is not a JToggleButton", 133 comp instanceof JToggleButton); 134 } 135 136 140 public void testMenuBarCreate() throws Exception { 141 URL url = RealizerUnitTest.class.getResource("resources/action4.xml"); 142 assertNotNull(url); 143 144 Object obj = realizer.getObject(url); 145 assertNotNull(obj); 146 assertTrue(obj.getClass().toString() + " is not a JRootPane", 147 obj instanceof JRootPane); 148 149 JXRootPane root = (JXRootPane)obj; 150 JMenuBar menubar = root.getJMenuBar(); 151 assertNotNull(menubar); 152 assertTrue(menubar.getComponentCount() == 3); 153 154 } 155 } 156 | Popular Tags |