1 23 package org.enhydra.kelp.common.dods; 24 25 import org.enhydra.tool.common.ButtonPanel; 27 28 import java.awt.*; 30 import java.awt.event.ActionEvent ; 31 import java.awt.event.ActionListener ; 32 import java.beans.*; 33 import javax.swing.*; 34 35 36 37 public class DodsButtonPanel extends ButtonPanel { 39 private GridBagLayout layoutMain = null; 41 private JButton buttonGenerate = null; 42 private JButton buttonClose = null; 43 private JButton buttonHelp = null; 44 private JButton buttonAbout = null; 45 private LocalButtonListener buttonListener = null; 46 private JPanel panelFiller; 47 49 public static final String [] getOptions() { 50 final String [] options = {ButtonPanel.COMMAND_GENERATE, 51 ButtonPanel.COMMAND_CLOSE, ButtonPanel.COMMAND_HELP, 52 ButtonPanel.COMMAND_ABOUT}; 53 return options; 54 } 55 56 public DodsButtonPanel() { 57 try { 58 jbInit(); 59 pmInit(); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 } 64 65 public void removeHelp() { 67 remove(buttonHelp); 68 invalidate(); 69 doLayout(); 70 } 71 72 private void pmInit() { 75 buttonListener = new LocalButtonListener(); 76 buttonGenerate.addActionListener(buttonListener); 77 buttonClose.addActionListener(buttonListener); 78 buttonAbout.addActionListener(buttonListener); 79 buttonHelp.addActionListener(buttonListener); 80 81 buttonGenerate.setText(ButtonPanel.COMMAND_GENERATE); 82 buttonClose.setText(ButtonPanel.COMMAND_CLOSE); 83 buttonAbout.setText(ButtonPanel.COMMAND_ABOUT); 84 buttonHelp.setText(ButtonPanel.COMMAND_HELP); 85 buttonGenerate.setActionCommand(buttonGenerate.getText()); 87 buttonClose.setActionCommand(buttonClose.getText()); 88 buttonAbout.setActionCommand(buttonAbout.getText()); 89 buttonHelp.setActionCommand(buttonHelp.getText()); 90 buttonClose.requestFocus(); 92 } 93 94 private void jbInit() throws Exception { 95 layoutMain = 96 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 97 GridBagLayout.class.getName()); 98 buttonGenerate = 99 (JButton) Beans.instantiate(getClass().getClassLoader(), 100 JButton.class.getName()); 101 buttonClose = 102 (JButton) Beans.instantiate(getClass().getClassLoader(), 103 JButton.class.getName()); 104 buttonAbout = (JButton) Beans.instantiate(getClass().getClassLoader(), 105 JButton.class.getName()); 106 buttonHelp = (JButton) Beans.instantiate(getClass().getClassLoader(), 107 JButton.class.getName()); 108 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 109 JPanel.class.getName()); 110 buttonGenerate.setText("GENERATE"); 111 buttonClose.setText("CLOSE"); 112 buttonAbout.setText("ABOUT"); 113 buttonHelp.setText("HELP"); 114 this.setLayout(layoutMain); 115 this.add(buttonGenerate, new GridBagConstraints(1, 0, 1, 1, 0.1, 0.0 116 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 20, 5, 2), 0, 0)); 117 this.add(buttonClose, new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0 118 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0)); 119 this.add(buttonHelp, new GridBagConstraints(3, 0, 1, 1, 0.1, 0.0 120 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0)); 121 this.add(buttonAbout, new GridBagConstraints(4, 0, 1, 1, 0.1, 0.0 122 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 2, 5, 2), 0, 0)); 123 this.add(panelFiller, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 124 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 50, 0)); 125 } 126 127 private class LocalButtonListener implements ActionListener { 128 129 136 public void actionPerformed(ActionEvent e) { 137 Object source = null; 138 ActionEvent event = null; 139 140 source = e.getSource(); 141 if (source == buttonGenerate) { 142 event = new ActionEvent (buttonGenerate, 143 ButtonPanel.GENERATE, 144 buttonGenerate.getActionCommand()); 145 146 } else if (source == buttonClose) { 147 event = new ActionEvent (buttonClose, 148 ButtonPanel.CLOSE, 149 buttonClose.getActionCommand()); 150 } else if (source == buttonHelp) { 151 event = new ActionEvent (buttonHelp, ButtonPanel.HELP, 152 buttonHelp.getActionCommand()); 153 } else if (source == buttonAbout) { 154 event = new ActionEvent (buttonAbout, ButtonPanel.ABOUT, 155 buttonAbout.getActionCommand()); 156 } 157 if (event != null) { 158 notifyActionListeners(event); 159 } 160 } 161 162 } 163 164 165 166 } 167 | Popular Tags |