1 19 package org.netbeans.modules.xml.core.wizard; 20 21 import java.util.*; 22 import java.beans.*; 23 24 import javax.swing.*; 25 import javax.swing.event.*; 26 27 import org.openide.*; 28 import org.openide.util.HelpCtx; 29 import java.net.URL ; 30 31 41 public abstract class AbstractPanel extends JPanel implements Customizer { 42 43 44 private static final long serialVersionUID =508989667995691L; 45 46 49 protected DocumentModel model; 50 51 private WizardStep step; 53 54 57 protected abstract void updateModel(); 58 59 62 protected abstract void initView(); 63 64 67 protected abstract void updateView(); 68 69 70 71 73 public void setObject(Object model) { 74 if ( not(model instanceof DocumentModel) ) { 75 throw new IllegalArgumentException ("DocumentModel class expected."); } 77 78 this.model = (DocumentModel) model; 79 initView(); 80 } 81 82 public void addPropertyChangeListener(PropertyChangeListener p1) { 83 } 84 85 public void removePropertyChangeListener(PropertyChangeListener p1) { 86 } 87 88 protected static boolean not(boolean expr) { 89 return ! expr; 90 } 91 92 97 protected final WizardStep getStep() { 98 if (step == null) throw new IllegalStateException ("new WizardStep(this) have not been called!"); 99 return step; 100 } 101 102 106 public static class WizardStep implements WizardDescriptor.Panel { 107 108 private final AbstractPanel peer; 109 private Vector listeners = new Vector(); 110 private final ChangeEvent EVENT = new ChangeEvent(this); 111 private boolean valid = true; 112 113 public WizardStep(AbstractPanel peer) { 114 if (peer == null) throw new NullPointerException (); 115 this.peer = peer; 116 peer.step = this; 117 } 118 119 public java.awt.Component getComponent() { 120 return peer; 121 } 122 123 public void readSettings(Object settings) { 124 peer.updateView(); 125 } 126 127 130 public final HelpCtx getHelp() { 131 return HelpCtx.DEFAULT_HELP; 136 } 137 138 public void addChangeListener(javax.swing.event.ChangeListener l) { 139 listeners.add(l); 140 } 141 142 public void storeSettings(Object settings) { 143 peer.updateModel(); 144 } 145 146 public boolean isValid() { 147 return valid; 148 } 149 150 protected final void setValid(boolean valid) { 151 152 if (this.valid == valid) return; 153 154 this.valid = valid; 155 156 synchronized (listeners) { 157 Iterator it = listeners.iterator(); 158 while (it.hasNext()) { 159 ChangeListener next = (ChangeListener) it.next(); 160 next.stateChanged(EVENT); 161 } 162 } 163 } 164 165 public void removeChangeListener(ChangeListener l) { 166 listeners.remove(l); 167 } 168 } 169 170 } 171 | Popular Tags |