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-2007 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: package org.netbeans.modules.java.source.tasklist;
042:
043: import java.beans.PropertyChangeListener;
044: import java.beans.PropertyChangeSupport;
045: import javax.swing.JComponent;
046: import javax.swing.SwingUtilities;
047: import javax.swing.event.ChangeEvent;
048: import javax.swing.event.ChangeListener;
049: import org.netbeans.spi.options.AdvancedOption;
050: import org.netbeans.spi.options.OptionsPanelController;
051: import org.openide.util.HelpCtx;
052: import org.openide.util.Lookup;
053: import org.openide.util.NbBundle;
054:
055: /**
056: *
057: * @author Jan Lahoda
058: */
059: public class TasklistOptions extends AdvancedOption {
060:
061: public TasklistOptions() {
062: }
063:
064: public String getDisplayName() {
065: return NbBundle
066: .getMessage(TasklistOptions.class, "DN_Tasklist");// "Java Tasklist - Temporary settings";
067: }
068:
069: public String getTooltip() {
070: return NbBundle
071: .getMessage(TasklistOptions.class, "TP_Tasklist");// "Java Tasklist - Temporary settings";
072: }
073:
074: public OptionsPanelController create() {
075: return new TasklistOptionsPanelController();
076: }
077:
078: private static class TasklistOptionsPanelController extends
079: OptionsPanelController implements ChangeListener {
080:
081: private TasklistOptionsPanel panel;
082: private PropertyChangeSupport pcs = new PropertyChangeSupport(
083: this );
084:
085: public void update() {
086: assert SwingUtilities.isEventDispatchThread();
087: if (panel == null) {
088: getComponent(null);//XXX: should not happen
089: }
090:
091: panel.setDependenciesEnabled(TasklistSettings
092: .isDependencyTrackingEnabled());
093: panel.setBadgesEnabled(TasklistSettings.isBadgesEnabled());
094: panel.setTasklistEnabled(TasklistSettings
095: .isTasklistEnabled());
096:
097: }
098:
099: public void applyChanges() {
100: if (panel == null)
101: return;
102:
103: TasklistSettings.setTasklistsEnabled(panel
104: .getTasklistEnabled());
105: TasklistSettings.setDependencyTrackingEnabled(panel
106: .getDependenciesEnabled());
107: TasklistSettings.setBadgesEnabled(panel.getBadgesEnabled());
108:
109: }
110:
111: public void cancel() {
112: if (panel == null)
113: return;
114: panel.setTasklistEnabled(TasklistSettings
115: .isTasklistEnabled());
116: panel.setDependenciesEnabled(TasklistSettings
117: .isDependencyTrackingEnabled());
118: panel.setBadgesEnabled(TasklistSettings.isBadgesEnabled());
119: }
120:
121: public boolean isValid() {
122: return true;
123: }
124:
125: public boolean isChanged() {
126: if (panel == null)
127: return false;
128:
129: return TasklistSettings.isTasklistEnabled() != panel
130: .getTasklistEnabled()
131: || TasklistSettings.isDependencyTrackingEnabled() != panel
132: .getDependenciesEnabled()
133: || TasklistSettings.isBadgesEnabled() != panel
134: .getBadgesEnabled();
135: }
136:
137: public JComponent getComponent(Lookup masterLookup) {
138: if (panel == null) {
139: panel = new TasklistOptionsPanel();
140: panel.addChangeListener(this );
141: }
142: return panel;
143: }
144:
145: public HelpCtx getHelpCtx() {
146: return new HelpCtx("netbeans.optionsDialog.java.tasklist");
147: }
148:
149: public void addPropertyChangeListener(PropertyChangeListener l) {
150: pcs.addPropertyChangeListener(l);
151: }
152:
153: public void removePropertyChangeListener(
154: PropertyChangeListener l) {
155: pcs.removePropertyChangeListener(l);
156: }
157:
158: public void stateChanged(ChangeEvent e) {
159: pcs.firePropertyChange(PROP_CHANGED, null, null);
160: }
161:
162: }
163: }
|