1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 /* 23 * SelectPathPanel.java 24 * 25 * Created on February 12, 2003 26 */ 27 28 package org.openoffice.netbeans.modules.office.wizard; 29 30 import java.awt.Component; 31 import java.util.HashSet; 32 import java.util.Iterator; 33 import java.util.Set; 34 import javax.swing.event.ChangeEvent; 35 import javax.swing.event.ChangeListener; 36 37 import org.openide.WizardDescriptor; 38 import org.openide.util.HelpCtx; 39 import org.openide.util.NbBundle; 40 41 import org.openoffice.netbeans.modules.office.options.OfficeSettings; 42 import org.openoffice.idesupport.OfficeInstallation; 43 import org.openoffice.idesupport.SVersionRCFile; 44 45 /** A single panel descriptor for a wizard. 46 * You probably want to make a wizard iterator to hold it. 47 * 48 * @author tomaso 49 */ 50 public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel */ { 51 52 /** The visual component that displays this panel. 53 * If you need to access the component from this class, 54 * just use getComponent(). 55 */ 56 private SelectPathVisualPanel component; 57 private OfficeInstallation office; 58 59 /** Create the wizard panel descriptor. */ SelectPathPanel()60 public SelectPathPanel() { 61 office = OfficeSettings.getDefault().getOfficeDirectory(); 62 63 if (office == null) { 64 try { 65 office = SVersionRCFile.createInstance().getDefaultVersion(); 66 } 67 catch (java.io.IOException ioe) {} 68 } 69 } 70 71 // Get the visual component for the panel. In this template, the component 72 // is kept separate. This can be more efficient: if the wizard is created 73 // but never displayed, or not all panels are displayed, it is better to 74 // create only those which really need to be visible. getComponent()75 public Component getComponent() { 76 if (component == null) { 77 component = new SelectPathVisualPanel(this); 78 } 79 return component; 80 } 81 getHelp()82 public HelpCtx getHelp() { 83 // Show no Help button for this panel: 84 return HelpCtx.DEFAULT_HELP; 85 // If you have context help: 86 // return new HelpCtx(SelectPathPanel.class); 87 } 88 isValid()89 public boolean isValid() { 90 // If it is always OK to press Next or Finish, then: 91 return true; 92 // If it depends on some condition (form filled out...), then: 93 // return someCondition(); 94 // and when this condition changes (last form field filled in...) then: 95 // fireChangeEvent(); 96 // and uncomment the complicated stuff below. 97 } 98 99 // public final void addChangeListener(ChangeListener l) {} 100 // public final void removeChangeListener(ChangeListener l) {} 101 102 private final Set listeners = new HashSet(1); // Set<ChangeListener> addChangeListener(ChangeListener l)103 public final void addChangeListener(ChangeListener l) { 104 synchronized (listeners) { 105 listeners.add(l); 106 } 107 } removeChangeListener(ChangeListener l)108 public final void removeChangeListener(ChangeListener l) { 109 synchronized (listeners) { 110 listeners.remove(l); 111 } 112 } fireChangeEvent()113 protected final void fireChangeEvent() { 114 Iterator it; 115 synchronized (listeners) { 116 it = new HashSet(listeners).iterator(); 117 } 118 ChangeEvent ev = new ChangeEvent(this); 119 while (it.hasNext()) { 120 ((ChangeListener)it.next()).stateChanged(ev); 121 } 122 } 123 setSelectedPath(OfficeInstallation oi)124 public void setSelectedPath(OfficeInstallation oi) { 125 this.office = oi; 126 fireChangeEvent(); 127 } 128 getSelectedPath()129 public OfficeInstallation getSelectedPath() { 130 return office; 131 } 132 133 // You can use a settings object to keep track of state. 134 // Normally the settings object will be the WizardDescriptor, 135 // so you can use WizardDescriptor.getProperty & putProperty 136 // to store information entered by the user. readSettings(Object settings)137 public void readSettings(Object settings) { 138 } 139 storeSettings(Object settings)140 public void storeSettings(Object settings) { 141 WizardDescriptor wiz = (WizardDescriptor)settings; 142 wiz.putProperty(InstallationPathDescriptor.PROP_INSTALLPATH, office); 143 } 144 } 145