1 2 24 package org.enhydra.tool.common.wizard; 25 26 import org.enhydra.tool.common.ToolException; 28 29 import java.awt.CardLayout ; 31 import java.beans.Beans ; 32 import java.util.Arrays ; 33 import java.util.ArrayList ; 34 import java.util.ResourceBundle ; 35 import javax.swing.JPanel ; 36 import javax.swing.JOptionPane ; 37 38 public class TBWizardDeck extends JPanel { 40 static ResourceBundle res = 41 ResourceBundle.getBundle("org.enhydra.tool.common.Res"); 43 private CardLayout cardLayout = null; 45 private int pageIndex = 0; 46 private TBWizardPage[] pages = new TBWizardPage[0]; 47 48 public TBWizardDeck() { 49 try { 50 jbInit(); 51 } catch (Exception e) { 52 e.printStackTrace(); 53 } 54 } 55 56 60 public void next() { 61 if (!isLastPageShowing()) { 62 TBWizardPage currentPage = pages[pageIndex]; 63 TBWizardPage nextPage = pages[pageIndex +1]; 64 65 try { 66 currentPage.validatePage(); 67 nextPage.preparePage(); 68 cardLayout.next(this); 69 pageIndex++; 70 } catch (ToolException e) { 71 JOptionPane.showMessageDialog(this, e.getMessage(), 72 res.getString("Validation_Error"), 73 JOptionPane.ERROR_MESSAGE); 74 } 75 } 76 } 77 78 protected TBWizardPage[] getPages() { 80 return pages; 81 } 82 83 public int getPageIndex() { 84 return pageIndex; 85 } 86 87 93 protected boolean isFirstPageShowing() { 94 boolean atFirst = (pageIndex == 0); 95 96 return (atFirst); 97 } 98 99 105 protected boolean isLastPageShowing() { 106 return (pageIndex == (pages.length - 1)); 107 } 108 109 113 protected void back() { 114 if (!isFirstPageShowing()) { 115 cardLayout.previous(this); 116 pageIndex--; 117 } 118 } 119 120 126 protected void addWizardPage(TBWizardPage page) { 127 ArrayList list = null; 128 this.add(page, (new String ()) + pages.length); 129 list = new ArrayList (Arrays.asList(pages)); 130 list.add(page); 131 list.trimToSize(); 132 pages = new TBWizardPage[list.size()]; 133 pages = (TBWizardPage[]) list.toArray(pages); 134 list.clear(); 135 } 136 137 protected void removeWizardPage(TBWizardPage page) { 138 ArrayList list = null; 139 list = new ArrayList (Arrays.asList(pages)); 140 if (list.contains(page)) { 141 remove(page); 142 list.remove(page); 143 } 144 list.trimToSize(); 145 pages = new TBWizardPage[list.size()]; 146 pages = (TBWizardPage[]) list.toArray(pages); 147 list.clear(); 148 } 149 150 151 157 private void jbInit() throws Exception { 158 cardLayout = 159 (CardLayout ) Beans.instantiate(getClass().getClassLoader(), 160 CardLayout .class.getName()); 161 this.setLayout(cardLayout); 162 } 163 164 } 165 | Popular Tags |