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.apache.tools.ant.module.wizards.shortcut;
043:
044: import java.awt.Component;
045: import java.util.ArrayList;
046: import java.util.List;
047: import java.util.NoSuchElementException;
048: import javax.swing.JComponent;
049: import javax.swing.event.ChangeListener;
050: import org.openide.WizardDescriptor;
051: import org.openide.filesystems.Repository;
052: import org.openide.loaders.DataFolder;
053: import org.openide.util.ChangeSupport;
054: import org.openide.util.NbBundle;
055:
056: final class ShortcutIterator implements
057: WizardDescriptor.Iterator<ShortcutWizard> {
058:
059: ShortcutIterator() {
060: }
061:
062: // You should define what panels you want to use here:
063:
064: private List<WizardDescriptor.Panel<ShortcutWizard>> createPanels() {
065: List<WizardDescriptor.Panel<ShortcutWizard>> _panels = new ArrayList<WizardDescriptor.Panel<ShortcutWizard>>();
066: _panels.add(new IntroPanel.IntroWizardPanel());
067: _panels.add(new SelectFolderPanel.SelectFolderWizardPanel(
068: NbBundle.getMessage(ShortcutIterator.class,
069: "SI_LBL_select_menu_to_add_to"), NbBundle
070: .getMessage(ShortcutIterator.class,
071: "SI_TEXT_menu_locn"), NbBundle
072: .getMessage(ShortcutIterator.class,
073: "SI_LBL_display_name_for_menu"),
074: DataFolder.findFolder(Repository.getDefault()
075: .getDefaultFileSystem().findResource("Menu")), // NOI18N
076: true, ShortcutWizard.PROP_FOLDER_MENU));
077: _panels.add(new SelectFolderPanel.SelectFolderWizardPanel(
078: NbBundle.getMessage(ShortcutIterator.class,
079: "SI_LBL_select_toolbar"),
080: NbBundle.getMessage(ShortcutIterator.class,
081: "SI_TEXT_toolbar_locn"), NbBundle.getMessage(
082: ShortcutIterator.class,
083: "SI_LBL_display_name_for_toolbar"), DataFolder
084: .findFolder(Repository.getDefault()
085: .getDefaultFileSystem().findResource(
086: "Toolbars")), // NOI18N
087: false, ShortcutWizard.PROP_FOLDER_TOOL));
088: _panels
089: .add(new SelectKeyboardShortcutPanel.SelectKeyboardShortcutWizardPanel());
090: _panels
091: .add(new CustomizeScriptPanel.CustomizeScriptWizardPanel());
092: return _panels;
093: }
094:
095: // And the list of step names:
096:
097: private String[] createSteps() {
098: return new String[] {
099: NbBundle.getMessage(ShortcutIterator.class,
100: "SI_LBL_choose_options"),
101: NbBundle.getMessage(ShortcutIterator.class,
102: "SI_LBL_add_to_menu"),
103: NbBundle.getMessage(ShortcutIterator.class,
104: "SI_LBL_add_to_toolbar"),
105: NbBundle.getMessage(ShortcutIterator.class,
106: "SI_LBL_make_keyboard_shortcut"),
107: NbBundle.getMessage(ShortcutIterator.class,
108: "SI_LBL_cust_script"), };
109: }
110:
111: private transient int index;
112: private transient List<WizardDescriptor.Panel<ShortcutWizard>> panels;
113: private transient ShortcutWizard wiz;
114:
115: // You can keep a reference to the TemplateWizard which can
116: // provide various kinds of useful information such as
117: // the currently selected target name.
118: // Also the panels will receive wiz as their "settings" object.
119: void initialize(ShortcutWizard wiz) {
120: this .wiz = wiz;
121: index = 0;
122: panels = createPanels();
123: // #44409: make sure IntroWizardPanel knows about wiz
124: // XXX workaround should no longer be necessary...
125: ((IntroPanel.IntroWizardPanel) panels.get(0)).initialize(wiz);
126: // Make sure list of steps is accurate.
127: String[] steps = createSteps();
128: for (int i = 0; i < panels.size(); i++) {
129: Component c = panels.get(i).getComponent();
130: if (steps[i] == null) {
131: // Default step name to component name of panel.
132: // Mainly useful for getting the name of the target
133: // chooser to appear in the list of steps.
134: steps[i] = c.getName();
135: }
136: if (c instanceof JComponent) { // assume Swing components
137: JComponent jc = (JComponent) c;
138: // Step #.
139: jc.putClientProperty(
140: "WizardPanel_contentSelectedIndex", i); // NOI18N
141: // Step name (actually the whole list for reference).
142: jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
143: }
144: }
145: }
146:
147: // --- WizardDescriptor.Iterator METHODS: ---
148:
149: public String name() {
150: return NbBundle.getMessage(ShortcutIterator.class,
151: "TITLE_x_of_y", index + 1, panels.size());
152: }
153:
154: boolean showing(String prop) {
155: Boolean s = (Boolean) wiz.getProperty(prop);
156: return (s == null) || s.booleanValue();
157: }
158:
159: private boolean showing(int index) throws NoSuchElementException {
160: switch (index) {
161: case 0:
162: return true;
163: case 1:
164: return showing(ShortcutWizard.PROP_SHOW_MENU);
165: case 2:
166: return showing(ShortcutWizard.PROP_SHOW_TOOL);
167: case 3:
168: return showing(ShortcutWizard.PROP_SHOW_KEYB);
169: case 4:
170: return showing(ShortcutWizard.PROP_SHOW_CUST);
171: default:
172: throw new NoSuchElementException();
173: }
174: }
175:
176: public boolean hasNext() {
177: for (int i = index + 1; i < panels.size(); i++) {
178: if (showing(i)) {
179: return true;
180: }
181: }
182: return false;
183: }
184:
185: public boolean hasPrevious() {
186: return index > 0;
187: }
188:
189: public void nextPanel() throws NoSuchElementException {
190: if (!hasNext()) {
191: throw new NoSuchElementException();
192: }
193: index++;
194: while (!showing(index))
195: index++;
196: if (index == 1) {
197: // User finished intro panel, list of panels may have changed:
198: fireChangeEvent();
199: }
200: }
201:
202: public void previousPanel() throws NoSuchElementException {
203: if (!hasPrevious()) {
204: throw new NoSuchElementException();
205: }
206: index--;
207: while (!showing(index))
208: index--;
209: }
210:
211: public WizardDescriptor.Panel<ShortcutWizard> current() {
212: return panels.get(index);
213: }
214:
215: private transient ChangeSupport cs = new ChangeSupport(this );
216:
217: public final void addChangeListener(ChangeListener l) {
218: cs.addChangeListener(l);
219: }
220:
221: public final void removeChangeListener(ChangeListener l) {
222: cs.removeChangeListener(l);
223: }
224:
225: protected final void fireChangeEvent() {
226: cs.fireChange();
227: }
228:
229: }
|