2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.options.editor;
44
import java.awt.BorderLayout;
45
import java.beans.PropertyChangeListener;
46
import java.util.ArrayList;
47
import java.util.Collection;
48
import javax.swing.JComponent;
49
import javax.swing.JLabel;
50
import javax.swing.JPanel;
51
import javax.swing.JTabbedPane;
52
import javax.swing.border.EmptyBorder;
53
import org.netbeans.spi.options.OptionsPanelController;
54
import org.openide.awt.Mnemonics;
55
import org.openide.util.HelpCtx;
56
import org.openide.util.Lookup;
57
import org.openide.util.LookupEvent;
58
import org.openide.util.LookupListener;
59
import org.openide.util.WeakListeners;
60
import org.openide.util.lookup.Lookups;
64
* Implementation of one panel in Options Dialog.
68
public class FolderBasedController extends OptionsPanelController {
70
private final Lookup.Result<? extends OptionsPanelController> lookupResult;
71
private final LookupListener lookupListener = new LookupListener() {
72
public void resultChanged(LookupEvent ev) {
76
private final HelpCtx helpCtx;
78
private Collection<? extends OptionsPanelController> delegates;
79
private JComponent component;
81
public FolderBasedController(String path, HelpCtx helpCtx) {
82
this.helpCtx = helpCtx;
84
Lookup lookup = Lookups.forPath(path);
85
lookupResult = lookup.lookupResult(OptionsPanelController.class);
86
lookupResult.addLookupListener(WeakListeners.create(
94
public final void update() {
95
Collection<? extends OptionsPanelController> controllers = delegates;
96
for(OptionsPanelController c : controllers) {
101
public final void applyChanges() {
102
Collection<? extends OptionsPanelController> controllers = delegates;
103
for(OptionsPanelController c : controllers) {
108
public final void cancel() {
109
Collection<? extends OptionsPanelController> controllers = delegates;
110
for(OptionsPanelController c : controllers) {
115
public final boolean isValid() {
116
Collection<? extends OptionsPanelController> controllers = delegates;
117
for(OptionsPanelController c : controllers) {
125
public final boolean isChanged() {
126
Collection<? extends OptionsPanelController> controllers = delegates;
127
for(OptionsPanelController c : controllers) {
135
public final HelpCtx getHelpCtx() {
139
public final JComponent getComponent(Lookup masterLookup) {
140
if (component == null) {
141
Collection<JComponent> panels = new ArrayList<JComponent>();
142
Collection<? extends OptionsPanelController> controllers = delegates;
144
for(OptionsPanelController c : controllers) {
145
panels.add(c.getComponent(masterLookup));
148
component = createComponent(panels);
154
protected JComponent createComponent(Collection<? extends JComponent> panels) {
155
return new TabbedPanel(panels);
158
public final void addPropertyChangeListener(PropertyChangeListener l) {
159
Collection<? extends OptionsPanelController> controllers = delegates;
160
for(OptionsPanelController c : controllers) {
161
c.addPropertyChangeListener(l);
165
public final void removePropertyChangeListener(PropertyChangeListener l) {
166
Collection<? extends OptionsPanelController> controllers = delegates;
167
for(OptionsPanelController c : controllers) {
168
c.removePropertyChangeListener(l);
172
private void rebuild() {
173
this.delegates = lookupResult.allInstances();
174
this.component = null;
177
private static final class TabbedPanel extends JPanel {
179
private JTabbedPane tabbedPane = new JTabbedPane();
181
public TabbedPanel(Collection<? extends JComponent> panels) {
182
JLabel label = new JLabel(); // Only for setting tab names
184
for(JComponent p : panels) {
185
p.setBorder(new EmptyBorder(8, 8, 8, 8));
187
String tabName = p.getName();
188
Mnemonics.setLocalizedText(label, tabName);
189
tabbedPane.addTab(label.getText(), p);
191
int idx = Mnemonics.findMnemonicAmpersand(tabName);
192
if (idx != -1 && idx + 1 < tabName.length()) {
193
tabbedPane.setMnemonicAt(tabbedPane.getTabCount() - 1, Character.toUpperCase(tabName.charAt(idx + 1)));
197
setLayout(new BorderLayout());
198
add(tabbedPane, BorderLayout.CENTER);
200
} // End of TabbedPane class