1 19 package org.netbeans.modules.xml.tools.generator; 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 39 public abstract class SAXGeneratorAbstractPanel extends JPanel implements Customizer { 40 41 42 private static final long serialVersionUID =5089896677680825691L; 43 44 private WizardStep step; 46 47 50 protected SAXGeneratorModel model; 51 52 53 public SAXGeneratorAbstractPanel() { 54 } 55 56 public static final class WizardStep implements WizardDescriptor.Panel { 57 58 private SAXGeneratorAbstractPanel peer; 59 private Class peerClass; 60 private Object bean; 61 private Integer index; 62 63 private Vector listeners = new Vector(); 64 private final ChangeEvent EVENT = new ChangeEvent(this); 65 private boolean valid = true; 66 67 70 public WizardStep(Class peerClass) { 71 if (SAXGeneratorAbstractPanel.class.isAssignableFrom(peerClass) == false) { 72 throw new IllegalArgumentException ("SAXGeneratorAbstractPanel required. Got " + peerClass); 73 } 74 this.peerClass = peerClass; 75 } 76 77 public java.awt.Component getComponent() { 78 return getPeer(); 79 } 80 81 private SAXGeneratorAbstractPanel getPeer() { 82 if (peer == null) { 83 try { 84 if (bean == null) throw new IllegalStateException (); 87 if (index == null) throw new IllegalStateException (); 88 peer = (SAXGeneratorAbstractPanel) peerClass.newInstance(); 89 peer.step = this; 90 peer.setObject(bean); 91 peer.putClientProperty("WizardPanel_contentSelectedIndex", index); } catch (InstantiationException ex) { 93 throw new IllegalStateException (); 94 } catch (IllegalAccessException ex) { 95 throw new IllegalStateException (); 96 } 97 } 98 return peer; 99 } 100 101 void setBean(Object bean) { 102 this.bean = bean; 103 } 104 105 void setIndex(int index) { 106 this.index = new Integer (index); 107 } 108 109 public void readSettings(java.lang.Object p1) { 110 getPeer().updateView(); 111 } 112 113 116 public HelpCtx getHelp() { 117 return null; 119 } 120 121 public void addChangeListener(javax.swing.event.ChangeListener l) { 122 listeners.add(l); 123 } 124 125 public void storeSettings(java.lang.Object p1) { 126 getPeer().updateModel(); 127 } 128 129 public boolean isValid() { 130 return valid; 131 } 132 133 void setValid(boolean valid) { 134 135 if (this.valid == valid) return; 136 137 this.valid = valid; 138 139 synchronized (listeners) { 140 Iterator it = listeners.iterator(); 141 while (it.hasNext()) { 142 ChangeListener next = (ChangeListener) it.next(); 143 next.stateChanged(EVENT); 144 } 145 } 146 } 147 148 public void removeChangeListener(javax.swing.event.ChangeListener l) { 149 listeners.remove(l); 150 } 151 } 152 153 154 157 protected final void setValid(boolean valid) { 158 if (step != null) step.setValid(valid); 159 } 160 161 164 protected abstract void updateModel(); 165 166 169 protected abstract void initView(); 170 171 174 protected abstract void updateView(); 175 176 177 public void setObject(java.lang.Object peer) { 178 if ( not(peer instanceof SAXGeneratorModel) ) { 179 throw new IllegalArgumentException ("SAXGeneratorModel class expected."); } 181 182 model = (SAXGeneratorModel) peer; 183 initView(); 184 } 185 186 public void addPropertyChangeListener(java.beans.PropertyChangeListener p1) { 187 } 188 189 public void removePropertyChangeListener(java.beans.PropertyChangeListener p1) { 190 } 191 192 protected final boolean not (boolean expr) { 193 return ! expr; 194 } 195 196 } 197 | Popular Tags |