1 2 24 package org.enhydra.tool.common.wizard; 25 26 import org.enhydra.tool.common.ButtonPanel; 28 29 import java.awt.*; 31 import java.awt.event.ActionEvent ; 32 import java.awt.event.ActionListener ; 33 import java.beans.*; 34 import javax.swing.*; 35 36 public class TBWizardButtonPanel extends ButtonPanel { 38 39 private GridBagLayout layoutMain = null; 41 private JPanel panelFiller = null; 42 private JPanel panelLine; 43 private JButton buttonBack = null; 44 private JButton buttonNext = null; 45 private JButton buttonFinish = null; 46 private JButton buttonCancel = null; 47 private JButton buttonHelp = null; 48 private LocalButtonListener buttonListener = null; 49 50 public final static String [] getOptions() { 51 final String [] options = { 52 ButtonPanel.COMMAND_BACK, ButtonPanel.COMMAND_NEXT, 53 ButtonPanel.COMMAND_FINISH, ButtonPanel.COMMAND_CANCEL, 54 ButtonPanel.COMMAND_HELP 55 }; 56 57 return options; 58 } 59 60 public TBWizardButtonPanel() { 61 super(); 62 try { 63 jbInit(); 64 pmInit(); 65 } catch (Exception e) { 66 e.printStackTrace(); 67 } 68 } 69 70 public void removeHelp() { 72 remove(buttonHelp); 73 invalidate(); 74 doLayout(); 75 } 76 77 private void pmInit() { 80 buttonListener = new LocalButtonListener(); 81 82 buttonBack.addActionListener(buttonListener); 84 buttonNext.addActionListener(buttonListener); 85 buttonFinish.addActionListener(buttonListener); 86 buttonCancel.addActionListener(buttonListener); 87 buttonHelp.addActionListener(buttonListener); 88 89 buttonBack.setText(ButtonPanel.COMMAND_BACK); 91 buttonNext.setText(ButtonPanel.COMMAND_NEXT); 92 buttonFinish.setText(ButtonPanel.COMMAND_FINISH); 93 buttonCancel.setText(ButtonPanel.COMMAND_CANCEL); 94 buttonHelp.setText(ButtonPanel.COMMAND_HELP); 95 96 buttonBack.setActionCommand(buttonBack.getText()); 98 buttonNext.setActionCommand(buttonNext.getText()); 99 buttonFinish.setActionCommand(buttonFinish.getText()); 100 buttonCancel.setActionCommand(buttonCancel.getText()); 101 buttonHelp.setActionCommand(buttonHelp.getText()); 102 buttonBack.setMnemonic('B'); 103 buttonNext.setMnemonic('N'); 104 buttonHelp.setMnemonic('H'); 105 buttonFinish.setEnabled(false); 106 buttonBack.setEnabled(false); 107 } 108 109 private void jbInit() throws Exception { 110 layoutMain = 111 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 112 GridBagLayout.class.getName()); 113 panelLine = (JPanel) Beans.instantiate(getClass().getClassLoader(), 114 JPanel.class.getName()); 115 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 116 JPanel.class.getName()); 117 buttonBack = (JButton) Beans.instantiate(getClass().getClassLoader(), 118 JButton.class.getName()); 119 buttonNext = (JButton) Beans.instantiate(getClass().getClassLoader(), 120 JButton.class.getName()); 121 buttonFinish = 122 (JButton) Beans.instantiate(getClass().getClassLoader(), 123 JButton.class.getName()); 124 buttonCancel = 125 (JButton) Beans.instantiate(getClass().getClassLoader(), 126 JButton.class.getName()); 127 buttonHelp = (JButton) Beans.instantiate(getClass().getClassLoader(), 128 JButton.class.getName()); 129 panelLine.setMinimumSize(new Dimension(5, 5)); 130 panelLine.setPreferredSize(new Dimension(5, 5)); 131 panelLine.setBorder(BorderFactory.createEtchedBorder()); 132 133 buttonBack.setText("BACK"); 134 135 buttonNext.setText("NEXT"); 137 buttonFinish.setText("FINISH"); 138 139 buttonCancel.setText("CANCEL"); 141 buttonHelp.setText("HELP"); 142 this.setLayout(layoutMain); 143 this.add(panelLine, new GridBagConstraints(0, 0, 6, 1, 0.0, 0.0 144 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); 145 this.add(panelFiller, 146 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 147 GridBagConstraints.CENTER, 148 GridBagConstraints.BOTH, 149 new Insets(0, 0, 0, 0), 0, 0)); 150 this.add(buttonBack, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 151 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); 152 this.add(buttonNext, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 153 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); 154 this.add(buttonFinish, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 155 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); 156 this.add(buttonCancel, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0 157 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); 158 this.add(buttonHelp, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0 159 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); 160 } 161 162 private class LocalButtonListener implements ActionListener { 163 164 171 public void actionPerformed(ActionEvent e) { 172 Object source = null; 173 ActionEvent event = null; 174 175 source = e.getSource(); 176 if (source == buttonBack) { 177 event = new ActionEvent (buttonBack, ButtonPanel.BACK, 178 buttonBack.getActionCommand()); 179 } else if (source == buttonNext) { 180 event = new ActionEvent (buttonNext, ButtonPanel.NEXT, 181 buttonNext.getActionCommand()); 182 } else if (source == buttonFinish) { 183 event = new ActionEvent (buttonFinish, ButtonPanel.FINISH, 184 buttonFinish.getActionCommand()); 185 } else if (source == buttonCancel) { 186 event = new ActionEvent (buttonCancel, ButtonPanel.CANCEL, 187 buttonCancel.getActionCommand()); 188 } else if (source == buttonHelp) { 189 event = new ActionEvent (buttonHelp, ButtonPanel.HELP, 190 buttonHelp.getActionCommand()); 191 } 192 if (event != null) { 193 notifyActionListeners(event); 194 } 195 } 196 197 } 198 } 199 | Popular Tags |