1 16 17 package org.mc4j.console.connection.create; 18 19 import org.openide.WizardDescriptor; 20 import org.openide.util.NbBundle; 21 22 import javax.swing.event.ChangeEvent ; 23 import javax.swing.event.ChangeListener ; 24 import java.io.IOException ; 25 import java.io.ObjectInputStream ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.NoSuchElementException ; 29 import java.util.Set ; 30 31 36 public class CreateWizardIterator implements WizardDescriptor.Iterator { 37 38 private CreateWizardDescriptor descriptor; 39 40 41 public CreateWizardIterator() { 43 } 44 45 public void setDescriptor(CreateWizardDescriptor descriptor) { 46 this.descriptor = descriptor; 47 48 } 49 50 protected WizardDescriptor.Panel[] createPanels() { 51 return new WizardDescriptor.Panel[] { 52 new CreateVisualPanel(descriptor), 53 new CallCreateVisualPanel(descriptor) 54 }; 55 } 56 57 59 protected String [] createSteps() { 60 return new String [] { 61 "Enter MBean Parameters", 62 "Create MBean" 63 }; 64 } 65 66 68 70 private transient int index = 0; 71 72 protected final int getIndex() { 73 return index; 74 } 75 private transient WizardDescriptor.Panel[] panels = null; 76 protected final WizardDescriptor.Panel[] getPanels() { 77 if (panels == null) { 78 panels = createPanels(); 79 } 80 return panels; 81 } 82 83 85 private transient String [] steps = null; 86 protected final String [] getSteps() { 87 if (steps == null) { 88 steps = createSteps(); 89 } 90 return steps; 91 } 92 93 98 public String name() { 99 return NbBundle.getMessage(CreateWizardIterator.class, "TITLE_x_of_y", 100 new Integer (index + 1), new Integer (getPanels().length)); 101 } 102 103 private boolean showing (int index) throws NoSuchElementException { 104 switch (index) { 105 case 0: 106 return true; 107 case 1: 108 return true; 109 default: 110 throw new NoSuchElementException (); 111 } 112 } 113 public boolean hasNext () { 114 for (int i = index + 1; i < panels.length; i++) { 115 if (showing (i)) { 116 return true; 117 } 118 } 119 return false; 120 } 121 public boolean hasPrevious () { 122 return index > 0; 123 } 124 public void nextPanel () { 125 index++; 126 while (! showing (index)) index++; 127 if (index == 1) { 128 fireChangeEvent (); 130 } 131 } 132 public void previousPanel () { 133 index--; 134 while (! showing (index)) index--; 135 } 136 137 public WizardDescriptor.Panel current() { 138 return getPanels()[index]; 139 } 140 141 149 private transient Set listeners = new HashSet (1); public final void addChangeListener(ChangeListener l) { 151 synchronized (listeners) { 152 listeners.add(l); 153 } 154 } 155 public final void removeChangeListener(ChangeListener l) { 156 synchronized (listeners) { 157 listeners.remove(l); 158 } 159 } 160 protected final void fireChangeEvent() { 161 Iterator it; 162 synchronized (listeners) { 163 it = new HashSet (listeners).iterator(); 164 } 165 ChangeEvent ev = new ChangeEvent (this); 166 while (it.hasNext()) { 167 ((ChangeListener )it.next()).stateChanged(ev); 168 } 169 } 170 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 171 in.defaultReadObject(); 172 listeners = new HashSet (1); 173 } 174 175 176 } 177 | Popular Tags |