001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.spi.palette;
043:
044: import java.beans.BeanInfo;
045: import org.netbeans.modules.palette.Category;
046: import org.netbeans.modules.palette.Item;
047: import org.netbeans.modules.palette.Model;
048: import org.netbeans.modules.palette.Settings;
049: import org.openide.filesystems.FileObject;
050: import org.openide.nodes.Node;
051:
052: /**
053: *
054: * @author S. Aubrecht
055: */
056: public class SettingsTest extends AbstractPaletteTestHid {
057:
058: public SettingsTest(String testName) {
059: super (testName);
060: }
061:
062: public void testItemVisible() throws Exception {
063: FileObject item1 = getItemFile(categoryNames[0],
064: itemNames[0][0]);
065: FileObject item2 = getItemFile(categoryNames[0],
066: itemNames[0][1]);
067: FileObject item3 = getItemFile(categoryNames[0],
068: itemNames[0][2]);
069:
070: item2.setAttribute(PaletteController.ATTR_IS_VISIBLE,
071: new Boolean(false));
072: item3.setAttribute(PaletteController.ATTR_IS_VISIBLE,
073: new Boolean(true));
074:
075: PaletteController pc = PaletteFactory.createPalette(
076: getRootFolderName(), new DummyActions());
077: Settings settings = pc.getSettings();
078: Model model = pc.getModel();
079: Category[] categories = model.getCategories();
080: Item[] items = categories[0].getItems();
081:
082: assertTrue("Items are visible by default", settings
083: .isVisible(items[0]));
084: assertTrue(!settings.isVisible(items[1]));
085: assertTrue(settings.isVisible(items[2]));
086:
087: settings.setVisible(items[0], false);
088: settings.setVisible(items[1], true);
089: settings.setVisible(items[2], false);
090:
091: assertTrue(!settings.isVisible(items[0]));
092: assertTrue(settings.isVisible(items[1]));
093: assertTrue(!settings.isVisible(items[2]));
094: }
095:
096: public void testCategoryVisible() throws Exception {
097: FileObject cat1 = getCategoryFile(categoryNames[0]);
098: FileObject cat2 = getCategoryFile(categoryNames[1]);
099: FileObject cat3 = getCategoryFile(categoryNames[2]);
100:
101: cat2.setAttribute(PaletteController.ATTR_IS_VISIBLE,
102: new Boolean(false));
103: cat3.setAttribute(PaletteController.ATTR_IS_VISIBLE,
104: new Boolean(true));
105:
106: PaletteController pc = PaletteFactory.createPalette(
107: getRootFolderName(), new DummyActions());
108: Settings settings = pc.getSettings();
109: Model model = pc.getModel();
110: Category[] categories = model.getCategories();
111:
112: assertTrue("Categories are visible by default", settings
113: .isVisible(categories[0]));
114: assertTrue(!settings.isVisible(categories[1]));
115: assertTrue(settings.isVisible(categories[2]));
116:
117: settings.setVisible(categories[0], false);
118: settings.setVisible(categories[1], true);
119: settings.setVisible(categories[2], false);
120:
121: assertTrue(!settings.isVisible(categories[0]));
122: assertTrue(settings.isVisible(categories[1]));
123: assertTrue(!settings.isVisible(categories[2]));
124: }
125:
126: public void testCategoryReadonly() throws Exception {
127: FileObject cat1 = getCategoryFile(categoryNames[0]);
128: FileObject cat2 = getCategoryFile(categoryNames[1]);
129: FileObject cat3 = getCategoryFile(categoryNames[2]);
130:
131: cat2.setAttribute(PaletteController.ATTR_IS_READONLY,
132: new Boolean(true));
133: cat3.setAttribute(PaletteController.ATTR_IS_READONLY,
134: new Boolean(false));
135:
136: PaletteController pc = PaletteFactory.createPalette(
137: getRootFolderName(), new DummyActions());
138: Model model = pc.getModel();
139: Category[] categories = model.getCategories();
140:
141: Node node1 = (Node) categories[0].getLookup()
142: .lookup(Node.class);
143: Node node2 = (Node) categories[1].getLookup()
144: .lookup(Node.class);
145: Node node3 = (Node) categories[2].getLookup()
146: .lookup(Node.class);
147:
148: assertTrue("Categories removable by default", node1
149: .canDestroy());
150: assertTrue(!node2.canDestroy());
151: assertTrue(node3.canDestroy());
152: }
153:
154: public void testItemReadonly() throws Exception {
155: FileObject item1 = getItemFile(categoryNames[0],
156: itemNames[0][0]);
157: FileObject item2 = getItemFile(categoryNames[0],
158: itemNames[0][1]);
159: FileObject item3 = getItemFile(categoryNames[0],
160: itemNames[0][2]);
161:
162: item2.setAttribute(PaletteController.ATTR_IS_READONLY,
163: new Boolean(true));
164: item3.setAttribute(PaletteController.ATTR_IS_READONLY,
165: new Boolean(false));
166:
167: PaletteController pc = PaletteFactory.createPalette(
168: getRootFolderName(), new DummyActions());
169: Model model = pc.getModel();
170: Item[] items = model.getCategories()[0].getItems();
171:
172: Node node1 = (Node) items[0].getLookup().lookup(Node.class);
173: Node node2 = (Node) items[1].getLookup().lookup(Node.class);
174: Node node3 = (Node) items[2].getLookup().lookup(Node.class);
175:
176: assertTrue("Items removable by default", node1.canDestroy());
177: assertTrue(!node2.canDestroy());
178: assertTrue(node3.canDestroy());
179: }
180:
181: public void testCategoryExpanded() throws Exception {
182: FileObject cat1 = getCategoryFile(categoryNames[0]);
183: FileObject cat2 = getCategoryFile(categoryNames[1]);
184: FileObject cat3 = getCategoryFile(categoryNames[2]);
185:
186: cat2.setAttribute(PaletteController.ATTR_IS_EXPANDED,
187: new Boolean(true));
188: cat3.setAttribute(PaletteController.ATTR_IS_EXPANDED,
189: new Boolean(false));
190:
191: PaletteController pc = PaletteFactory.createPalette(
192: getRootFolderName(), new DummyActions());
193: Settings settings = pc.getSettings();
194: Model model = pc.getModel();
195: Category[] categories = model.getCategories();
196:
197: assertTrue("Categories are collapsed by default", !settings
198: .isExpanded(categories[0]));
199: assertTrue(settings.isExpanded(categories[1]));
200: assertTrue(!settings.isExpanded(categories[2]));
201:
202: settings.setExpanded(categories[0], true);
203: settings.setExpanded(categories[1], false);
204: settings.setExpanded(categories[2], true);
205:
206: assertTrue(settings.isExpanded(categories[0]));
207: assertTrue(!settings.isExpanded(categories[1]));
208: assertTrue(settings.isExpanded(categories[2]));
209: }
210:
211: public void testShowItemNamesTrue() throws Exception {
212: paletteRootFolder.setAttribute(
213: PaletteController.ATTR_SHOW_ITEM_NAMES, new Boolean(
214: true));
215: PaletteController pc = PaletteFactory.createPalette(
216: getRootFolderName(), new DummyActions());
217: Settings settings = pc.getSettings();
218:
219: assertTrue(settings.getShowItemNames());
220:
221: settings.setShowItemNames(false);
222:
223: assertTrue(!settings.getShowItemNames());
224: }
225:
226: public void testShowItemNamesFalse() throws Exception {
227: paletteRootFolder.setAttribute(
228: PaletteController.ATTR_SHOW_ITEM_NAMES, new Boolean(
229: false));
230: PaletteController pc = PaletteFactory.createPalette(
231: getRootFolderName(), new DummyActions());
232: Settings settings = pc.getSettings();
233:
234: assertTrue(!settings.getShowItemNames());
235:
236: settings.setShowItemNames(true);
237:
238: assertTrue(settings.getShowItemNames());
239: }
240:
241: public void testShowItemNamesDefault() throws Exception {
242: PaletteController pc = PaletteFactory.createPalette(
243: getRootFolderName(), new DummyActions());
244: Settings settings = pc.getSettings();
245:
246: assertTrue("ShowItemNames is on by default", settings
247: .getShowItemNames());
248: }
249:
250: public void testIconSizeDefault() throws Exception {
251: PaletteController pc = PaletteFactory.createPalette(
252: getRootFolderName(), new DummyActions());
253: Settings settings = pc.getSettings();
254:
255: assertEquals("Small icons are default",
256: BeanInfo.ICON_COLOR_16x16, settings.getIconSize());
257: }
258:
259: public void testIconSizeCustom() throws Exception {
260: paletteRootFolder.setAttribute(
261: PaletteController.ATTR_ICON_SIZE, new Integer(123));
262: PaletteController pc = PaletteFactory.createPalette(
263: getRootFolderName(), new DummyActions());
264: Settings settings = pc.getSettings();
265:
266: assertEquals(123, settings.getIconSize());
267:
268: settings.setIconSize(321);
269:
270: assertEquals(321, settings.getIconSize());
271: }
272:
273: public void testItemWidthDefault() throws Exception {
274: PaletteController pc = PaletteFactory.createPalette(
275: getRootFolderName(), new DummyActions());
276: Settings settings = pc.getSettings();
277:
278: assertEquals("No item width is specified by default", -1,
279: settings.getItemWidth());
280: }
281:
282: public void testItemWidthCustom() throws Exception {
283: paletteRootFolder.setAttribute(
284: PaletteController.ATTR_ITEM_WIDTH, new Integer(123));
285: PaletteController pc = PaletteFactory.createPalette(
286: getRootFolderName(), new DummyActions());
287: Settings settings = pc.getSettings();
288:
289: assertEquals(123, settings.getItemWidth());
290: }
291: }
|