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.api.options;
043:
044: import java.awt.Image;
045: import java.beans.PropertyChangeEvent;
046: import java.beans.PropertyChangeListener;
047: import java.util.Arrays;
048: import java.util.Collection;
049: import java.util.HashSet;
050: import javax.swing.Icon;
051: import javax.swing.ImageIcon;
052: import javax.swing.JComponent;
053: import javax.swing.JLabel;
054: import javax.swing.SwingUtilities;
055: import junit.framework.TestCase;
056: import org.netbeans.spi.options.OptionsCategory;
057: import org.netbeans.spi.options.OptionsPanelController;
058: import org.openide.util.HelpCtx;
059: import org.openide.util.Lookup;
060: import org.openide.util.Utilities;
061:
062: /**
063: */
064: public final class RegisteredCategory extends OptionsCategory {
065: private static Icon icon;
066: private static PropertyChangeListener propertyChangeListener;
067: private Collection<String> calls = new HashSet<String>();
068:
069: public void setInvalid() {
070: propertyChangeListener.propertyChange(new PropertyChangeEvent(
071: this , OptionsPanelController.PROP_VALID, null, null));
072: }
073:
074: public void helpChanged() {
075: propertyChangeListener
076: .propertyChange(new PropertyChangeEvent(this ,
077: OptionsPanelController.PROP_HELP_CTX, null,
078: null));
079: }
080:
081: public Icon getIcon() {
082: if (icon == null) {
083: Image image = Utilities
084: .loadImage("org/netbeans/modules/options/resources/generalOptions.png");
085: icon = new ImageIcon(image);
086: }
087: return icon;
088: }
089:
090: public String getCategoryName() {
091: return "CTL_General_Options";
092: }
093:
094: public String getTitle() {
095: return "CTL_General_Options_Title";
096: }
097:
098: public String getDescription() {
099: return "CTL_General_Options_Description";
100: }
101:
102: public void assertThreadingForAllCallsWereTested() {
103: TestCase.assertTrue(calls.contains("update()"));
104: TestCase.assertTrue(calls.contains("cancel()"));
105: TestCase.assertTrue(calls.contains("isValid()"));
106: TestCase.assertTrue(calls.contains("getLookup()"));
107: TestCase.assertTrue(calls.contains("getComponent()"));
108: TestCase.assertTrue(calls.contains("applyChanges()"));
109:
110: }
111:
112: public OptionsPanelController create() {
113: return new OptionsPanelController() {
114:
115: public void update() {
116: TestCase.assertTrue(SwingUtilities
117: .isEventDispatchThread());
118: calls.add("update()");
119: }
120:
121: public void applyChanges() {
122: TestCase.assertTrue(SwingUtilities
123: .isEventDispatchThread());
124: TestCase.assertTrue(calls.contains("update()"));
125: calls.add("applyChanges()");
126: }
127:
128: public void cancel() {
129: TestCase.assertTrue(SwingUtilities
130: .isEventDispatchThread());
131: TestCase.assertTrue(calls.contains("update()"));
132: calls.add("cancel()");
133: }
134:
135: public boolean isValid() {
136: TestCase.assertTrue(SwingUtilities
137: .isEventDispatchThread());
138: calls.add("isValid()");
139: return true;
140: }
141:
142: public boolean isChanged() {
143: return false;
144: }
145:
146: public HelpCtx getHelpCtx() {
147: return null;
148: }
149:
150: public Lookup getLookup() {
151: TestCase.assertFalse(SwingUtilities
152: .isEventDispatchThread());
153: calls.add("getLookup()");
154: return super .getLookup();
155: }
156:
157: public JComponent getComponent(Lookup masterLookup) {
158: TestCase.assertTrue(SwingUtilities
159: .isEventDispatchThread());
160: calls.add("getComponent()");
161: return new JLabel();
162: }
163:
164: public void addPropertyChangeListener(
165: PropertyChangeListener l) {
166: propertyChangeListener = l;
167: }
168:
169: public void removePropertyChangeListener(
170: PropertyChangeListener l) {
171: propertyChangeListener = null;
172: }
173: };
174: }
175: }
|