1 2 24 package org.enhydra.tool.common.wizard; 25 26 import org.enhydra.tool.common.event.FirstFocusEvent; 28 import org.enhydra.tool.common.event.FirstFocusListener; 29 import org.enhydra.tool.common.DialogHandler; 30 import org.enhydra.tool.common.ButtonPanel; 31 import org.enhydra.tool.common.InnerPanel; 32 import org.enhydra.tool.common.DialogPanel; 33 import org.enhydra.tool.common.SwingUtil; 34 import org.enhydra.tool.common.event.HelpEvent; 35 import org.enhydra.tool.common.event.HelpListener; 36 37 import javax.swing.*; 39 import javax.swing.border.*; 40 import java.awt.*; 41 import java.awt.event.ActionEvent ; 42 import java.awt.event.ActionListener ; 43 import java.io.File ; 44 import java.beans.*; 45 import java.lang.ref.WeakReference ; 46 import java.util.ArrayList ; 47 import java.util.Arrays ; 48 import java.util.ResourceBundle ; 49 50 61 abstract public class TBWizard extends DialogHandler 62 implements FirstFocusListener { 63 static ResourceBundle res = 65 ResourceBundle.getBundle("org.enhydra.tool.common.Res"); 67 69 private TBWizardButtonPanel buttonPanel; 70 private TBWizardInnerPanel innerPanel; 71 private TBWizardButtonListener buttonListener; 72 private WeakReference backRef = null; 73 private WeakReference nextRef = null; 74 private WeakReference finishRef = null; 75 76 82 public TBWizard() { 83 super(); 84 innerPanel = new TBWizardInnerPanel(); 85 buttonPanel = new TBWizardButtonPanel(); 86 innerPanel.addFirstFocusListener(this); 87 } 88 89 public void onFirstFocus(FirstFocusEvent event) { 91 refreshButtons(); 92 } 93 94 97 protected void clearAll() { 98 super.clearAll(); 99 if (backRef != null) { 100 backRef.clear(); 101 } 102 if (nextRef != null) { 103 nextRef.clear(); 104 } 105 if (finishRef != null) { 106 finishRef.clear(); 107 } 108 innerPanel = null; 109 buttonPanel = null; 110 backRef = null; 111 nextRef = null; 112 finishRef = null; 113 } 114 115 public TBWizardDeck getDeck() { 116 return innerPanel.getDeck(); 117 } 118 119 public void setDeck(TBWizardDeck d) { 120 innerPanel.setDeck(d); 121 } 122 123 public ActionListener createButtonListener() { 125 return (new TBWizardButtonListener(this)); 126 } 127 128 public ButtonPanel getButtonPanel() { 130 return buttonPanel; 131 } 132 133 public InnerPanel getInnerPanel() { 134 return innerPanel; 135 } 136 137 public void setLargeIcon(Icon icon) { 138 innerPanel.setLargeIcon(icon); 139 } 140 141 public Icon getLargeIcon() { 142 return innerPanel.getLargeIcon(); 143 } 144 145 152 public void addWizardPage(TBWizardPage page) { 153 innerPanel.addWizardPage(page); 154 } 155 156 public void back() { 157 innerPanel.getDeck().back(); 158 refreshButtons(); 159 } 160 161 public void next() { 162 innerPanel.getDeck().next(); 163 refreshButtons(); 164 } 165 166 public void finish() { 167 setOption(JOptionPane.OK_OPTION); 168 super.closeWindow(); 169 } 170 171 public void cancel() { 172 setOption(JOptionPane.CANCEL_OPTION); 173 super.closeWindow(); 174 } 175 176 private Component getNext() { 179 Component comp = null; 180 181 if (nextRef == null) { 182 comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(), 183 ButtonPanel.COMMAND_NEXT); 184 if (comp != null) { 185 nextRef = new WeakReference (comp); 186 } 187 } else { 188 comp = (Component) nextRef.get(); 189 } 190 return comp; 191 } 192 193 private Component getBack() { 194 Component comp = null; 195 196 if (backRef == null) { 197 comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(), 198 ButtonPanel.COMMAND_BACK); 199 if (comp != null) { 200 backRef = new WeakReference (comp); 201 } 202 } else { 203 comp = (Component) backRef.get(); 204 } 205 return comp; 206 } 207 208 private Component getFinish() { 209 Component comp = null; 210 211 if (finishRef == null) { 212 comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(), 213 ButtonPanel.COMMAND_FINISH); 214 if (comp != null) { 215 finishRef = new WeakReference (comp); 216 } 217 } else { 218 comp = (Component) finishRef.get(); 219 } 220 return comp; 221 } 222 223 public void refreshButtons() { 224 Component back = null; 225 Component next = null; 226 Component finish = null; 227 boolean backEnable = true; 228 boolean nextEnable = true; 229 boolean finishEnable = true; 230 231 back = getBack(); 232 next = getNext(); 233 finish = getFinish(); 234 if (innerPanel.getDeck().isLastPageShowing()) { 235 nextEnable = false; 236 } 237 if (innerPanel.getDeck().isFirstPageShowing()) { 238 backEnable = false; 239 finishEnable = false; 240 } 241 if (back != null) { 242 back.setEnabled(backEnable); 243 } 244 if (next != null) { 245 next.setEnabled(nextEnable); 246 } 247 if (finish != null) { 248 finish.setEnabled(finishEnable); 249 } 250 } 251 252 } 253 | Popular Tags |