1 19 20 package org.netbeans.modules.projectimport.j2seimport.ui; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import javax.swing.JComponent ; 26 import javax.swing.JPanel ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import org.openide.WizardDescriptor; 30 import org.openide.util.NbBundle; 31 32 36 public abstract class BasicPanel extends JPanel { 37 private BasicWizardPanel wiardPanel; 38 private boolean isOK = false; 39 40 public abstract int getPanelIndex(); 41 public abstract String getPanelDescription(); 42 protected abstract void storeWizardData(WizardData data); 43 protected abstract void readWizardData(WizardData data); 44 45 public abstract void validateContent() throws org.openide.WizardValidationException; 46 47 public String getName() { 48 return getPanelDescription(); 49 } 50 51 public final boolean isOK() { 52 return isOK; 53 } 54 55 public final void setValid(boolean valid) { 56 boolean fire = (isOK() != valid); 57 isOK = valid; 58 if (fire) { 59 wiardPanel.fireChange(); 60 } 61 } 62 63 64 public final WizardDescriptor.Panel getWizardPanel() { 65 if (wiardPanel == null) { 66 initPanel(); 67 wiardPanel = new BasicWizardPanel(); 68 } 69 return wiardPanel; 70 } 71 72 final void initPanel() { 73 putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); putClientProperty("WizardPanel_contentSelectedIndex", new Integer (getPanelIndex())); 78 putClientProperty("WizardPanel_contentData", new String [] { getPanelDescription() 80 }); 81 setPreferredSize(new java.awt.Dimension (500, 380)); 82 } 83 84 85 public static class WizardData { 86 private ErrorMessages errorMessages; 87 public final void setErrorMessages(ErrorMessages errorMessages) { 88 this.errorMessages = errorMessages; 89 } 90 91 public final ErrorMessages getErrorMessages() { 92 return errorMessages; 93 } 94 } 95 96 public interface ErrorMessages { 97 void setError(String message); 98 } 99 100 101 private class BasicWizardPanel implements WizardDescriptor.Panel, WizardDescriptor.ValidatingPanel { 102 103 104 private List changeListeners; 105 106 107 public BasicWizardPanel() { 108 } 109 110 public void addChangeListener(ChangeListener l) { 111 if (changeListeners == null) { 112 changeListeners = new ArrayList (2); 113 } 114 changeListeners.add(l); 115 } 116 117 public void removeChangeListener(ChangeListener l) { 118 if (changeListeners != null) { 119 if (changeListeners.remove(l) && changeListeners.isEmpty()) { 120 changeListeners = null; 121 } 122 } 123 } 124 125 public void fireChange() { 126 if (changeListeners != null) { 127 ChangeEvent e = new ChangeEvent (this); 128 for (Iterator i = changeListeners.iterator(); i.hasNext(); ) { 129 ((ChangeListener ) i.next()).stateChanged(e); 130 } 131 } 132 } 133 134 public final void storeSettings(Object settings) { 135 BasicPanel.this.storeWizardData((BasicPanel.WizardData)settings); 136 } 137 138 public final void readSettings(Object settings) { 139 BasicPanel.this.readWizardData((BasicPanel.WizardData)settings); 140 } 141 142 public org.openide.util.HelpCtx getHelp() { 143 return null; 144 } 145 146 147 public java.awt.Component getComponent() { 148 return BasicPanel.this; 149 } 150 151 public boolean isValid() { 152 return BasicPanel.this.isOK(); 153 } 154 155 public void validate() throws org.openide.WizardValidationException { 156 BasicPanel.this.validateContent(); 157 } 158 } 159 160 161 } 162 | Popular Tags |