1 19 20 package org.netbeans.spi.palette; 21 22 import java.beans.BeanInfo ; 23 import org.netbeans.modules.palette.Category; 24 import org.netbeans.modules.palette.Item; 25 import org.netbeans.modules.palette.Model; 26 import org.netbeans.modules.palette.Settings; 27 import org.openide.filesystems.FileObject; 28 import org.openide.nodes.Node; 29 30 34 public class SettingsTest extends AbstractPaletteTestHid { 35 36 public SettingsTest(String testName) { 37 super(testName); 38 } 39 40 public void testItemVisible() throws Exception { 41 FileObject item1 = getItemFile( categoryNames[0], itemNames[0][0] ); 42 FileObject item2 = getItemFile( categoryNames[0], itemNames[0][1] ); 43 FileObject item3 = getItemFile( categoryNames[0], itemNames[0][2] ); 44 45 item2.setAttribute( PaletteController.ATTR_IS_VISIBLE, new Boolean (false) ); 46 item3.setAttribute( PaletteController.ATTR_IS_VISIBLE, new Boolean (true) ); 47 48 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 49 Settings settings = pc.getSettings(); 50 Model model = pc.getModel(); 51 Category[] categories = model.getCategories(); 52 Item[] items = categories[0].getItems(); 53 54 assertTrue( "Items are visible by default", settings.isVisible( items[0] ) ); 55 assertTrue( !settings.isVisible( items[1] ) ); 56 assertTrue( settings.isVisible( items[2] ) ); 57 58 settings.setVisible( items[0], false ); 59 settings.setVisible( items[1], true ); 60 settings.setVisible( items[2], false ); 61 62 assertTrue( !settings.isVisible( items[0] ) ); 63 assertTrue( settings.isVisible( items[1] ) ); 64 assertTrue( !settings.isVisible( items[2] ) ); 65 } 66 67 public void testCategoryVisible() throws Exception { 68 FileObject cat1 = getCategoryFile( categoryNames[0] ); 69 FileObject cat2 = getCategoryFile( categoryNames[1] ); 70 FileObject cat3 = getCategoryFile( categoryNames[2] ); 71 72 cat2.setAttribute( PaletteController.ATTR_IS_VISIBLE, new Boolean (false) ); 73 cat3.setAttribute( PaletteController.ATTR_IS_VISIBLE, new Boolean (true) ); 74 75 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 76 Settings settings = pc.getSettings(); 77 Model model = pc.getModel(); 78 Category[] categories = model.getCategories(); 79 80 assertTrue( "Categories are visible by default", settings.isVisible( categories[0] ) ); 81 assertTrue( !settings.isVisible( categories[1] ) ); 82 assertTrue( settings.isVisible( categories[2] ) ); 83 84 settings.setVisible( categories[0], false ); 85 settings.setVisible( categories[1], true ); 86 settings.setVisible( categories[2], false ); 87 88 assertTrue( !settings.isVisible( categories[0] ) ); 89 assertTrue( settings.isVisible( categories[1] ) ); 90 assertTrue( !settings.isVisible( categories[2] ) ); 91 } 92 93 public void testCategoryReadonly() throws Exception { 94 FileObject cat1 = getCategoryFile( categoryNames[0] ); 95 FileObject cat2 = getCategoryFile( categoryNames[1] ); 96 FileObject cat3 = getCategoryFile( categoryNames[2] ); 97 98 cat2.setAttribute( PaletteController.ATTR_IS_READONLY, new Boolean (true) ); 99 cat3.setAttribute( PaletteController.ATTR_IS_READONLY, new Boolean (false) ); 100 101 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 102 Model model = pc.getModel(); 103 Category[] categories = model.getCategories(); 104 105 Node node1 = (Node)categories[0].getLookup().lookup( Node.class ); 106 Node node2 = (Node)categories[1].getLookup().lookup( Node.class ); 107 Node node3 = (Node)categories[2].getLookup().lookup( Node.class ); 108 109 assertTrue( "Categories removable by default", node1.canDestroy() ); 110 assertTrue( !node2.canDestroy() ); 111 assertTrue( node3.canDestroy() ); 112 } 113 114 public void testItemReadonly() throws Exception { 115 FileObject item1 = getItemFile( categoryNames[0], itemNames[0][0] ); 116 FileObject item2 = getItemFile( categoryNames[0], itemNames[0][1] ); 117 FileObject item3 = getItemFile( categoryNames[0], itemNames[0][2] ); 118 119 item2.setAttribute( PaletteController.ATTR_IS_READONLY, new Boolean (true) ); 120 item3.setAttribute( PaletteController.ATTR_IS_READONLY, new Boolean (false) ); 121 122 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 123 Model model = pc.getModel(); 124 Item[] items = model.getCategories()[0].getItems(); 125 126 Node node1 = (Node)items[0].getLookup().lookup( Node.class ); 127 Node node2 = (Node)items[1].getLookup().lookup( Node.class ); 128 Node node3 = (Node)items[2].getLookup().lookup( Node.class ); 129 130 assertTrue( "Items removable by default", node1.canDestroy() ); 131 assertTrue( !node2.canDestroy() ); 132 assertTrue( node3.canDestroy() ); 133 } 134 135 public void testCategoryExpanded() throws Exception { 136 FileObject cat1 = getCategoryFile( categoryNames[0] ); 137 FileObject cat2 = getCategoryFile( categoryNames[1] ); 138 FileObject cat3 = getCategoryFile( categoryNames[2] ); 139 140 cat2.setAttribute( PaletteController.ATTR_IS_EXPANDED, new Boolean (true) ); 141 cat3.setAttribute( PaletteController.ATTR_IS_EXPANDED, new Boolean (false) ); 142 143 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 144 Settings settings = pc.getSettings(); 145 Model model = pc.getModel(); 146 Category[] categories = model.getCategories(); 147 148 assertTrue( "Categories are collapsed by default", !settings.isExpanded( categories[0] ) ); 149 assertTrue( settings.isExpanded( categories[1] ) ); 150 assertTrue( !settings.isExpanded( categories[2] ) ); 151 152 settings.setExpanded( categories[0], true ); 153 settings.setExpanded( categories[1], false ); 154 settings.setExpanded( categories[2], true ); 155 156 assertTrue( settings.isExpanded( categories[0] ) ); 157 assertTrue( !settings.isExpanded( categories[1] ) ); 158 assertTrue( settings.isExpanded( categories[2] ) ); 159 } 160 161 public void testShowItemNamesTrue() throws Exception { 162 paletteRootFolder.setAttribute( PaletteController.ATTR_SHOW_ITEM_NAMES, new Boolean (true) ); 163 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 164 Settings settings = pc.getSettings(); 165 166 assertTrue( settings.getShowItemNames() ); 167 168 settings.setShowItemNames( false ); 169 170 assertTrue( !settings.getShowItemNames() ); 171 } 172 173 public void testShowItemNamesFalse() throws Exception { 174 paletteRootFolder.setAttribute( PaletteController.ATTR_SHOW_ITEM_NAMES, new Boolean (false) ); 175 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 176 Settings settings = pc.getSettings(); 177 178 assertTrue( !settings.getShowItemNames() ); 179 180 settings.setShowItemNames( true ); 181 182 assertTrue( settings.getShowItemNames() ); 183 } 184 185 public void testShowItemNamesDefault() throws Exception { 186 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 187 Settings settings = pc.getSettings(); 188 189 assertTrue( "ShowItemNames is on by default", settings.getShowItemNames() ); 190 } 191 192 public void testIconSizeDefault() throws Exception { 193 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 194 Settings settings = pc.getSettings(); 195 196 assertEquals( "Small icons are default", BeanInfo.ICON_COLOR_16x16, settings.getIconSize() ); 197 } 198 199 public void testIconSizeCustom() throws Exception { 200 paletteRootFolder.setAttribute( PaletteController.ATTR_ICON_SIZE, new Integer (123) ); 201 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 202 Settings settings = pc.getSettings(); 203 204 assertEquals( 123, settings.getIconSize() ); 205 206 settings.setIconSize( 321 ); 207 208 assertEquals( 321, settings.getIconSize() ); 209 } 210 211 public void testItemWidthDefault() throws Exception { 212 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 213 Settings settings = pc.getSettings(); 214 215 assertEquals( "No item width is specified by default", -1, settings.getItemWidth() ); 216 } 217 218 public void testItemWidthCustom() throws Exception { 219 paletteRootFolder.setAttribute( PaletteController.ATTR_ITEM_WIDTH, new Integer (123) ); 220 PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); 221 Settings settings = pc.getSettings(); 222 223 assertEquals( 123, settings.getItemWidth() ); 224 } 225 } 226 | Popular Tags |