1 23 package org.enhydra.kelp.common.xmlc; 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 public class XMLCButtonPanel extends ButtonPanel { 37 38 private GridBagLayout layoutMain; 40 private JButton buttonCompile = null; 41 private JButton buttonClose = null; 42 private JButton buttonHelp = null; 43 private JButton buttonAbout = null; 44 private JPanel panelFiller = null; 45 private LocalButtonListener buttonListener = null; 46 47 public final static String [] getOptions() { 48 final String [] options = { 49 ButtonPanel.COMMAND_COMPILE, ButtonPanel.COMMAND_CLOSE, 50 ButtonPanel.COMMAND_HELP, ButtonPanel.COMMAND_ABOUT 51 }; 52 53 return options; 54 } 55 56 public XMLCButtonPanel() { 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 buttonCompile.addActionListener(buttonListener); 77 buttonClose.addActionListener(buttonListener); 78 buttonAbout.addActionListener(buttonListener); 79 buttonHelp.addActionListener(buttonListener); 80 buttonCompile.setText(ButtonPanel.COMMAND_COMPILE); 81 buttonClose.setText(ButtonPanel.COMMAND_CLOSE); 82 buttonAbout.setText(ButtonPanel.COMMAND_ABOUT); 83 buttonHelp.setText(ButtonPanel.COMMAND_HELP); 84 85 buttonCompile.setActionCommand(buttonCompile.getText()); 87 buttonClose.setActionCommand(buttonClose.getText()); 88 buttonAbout.setActionCommand(buttonAbout.getText()); 89 buttonHelp.setActionCommand(buttonHelp.getText()); 90 } 91 92 private void jbInit() throws Exception { 93 layoutMain = 94 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 95 GridBagLayout.class.getName()); 96 buttonCompile = 97 (JButton) Beans.instantiate(getClass().getClassLoader(), 98 JButton.class.getName()); 99 buttonClose = (JButton) Beans.instantiate(getClass().getClassLoader(), 100 JButton.class.getName()); 101 buttonAbout = (JButton) Beans.instantiate(getClass().getClassLoader(), 102 JButton.class.getName()); 103 buttonHelp = (JButton) Beans.instantiate(getClass().getClassLoader(), 104 JButton.class.getName()); 105 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 106 JPanel.class.getName()); 107 buttonCompile.setText("COMPILE"); 108 buttonCompile.setEnabled(false); 109 buttonClose.setText("CLOSE"); 110 buttonAbout.setText("ABOUT"); 111 buttonHelp.setText("HELP"); 112 this.setLayout(layoutMain); 113 this.add(buttonCompile, 114 new GridBagConstraints(2, 0, 1, 1, 0.1, 0.0, 115 GridBagConstraints.CENTER, 116 GridBagConstraints.NONE, 117 new Insets(5, 0, 5, 5), 0, 0)); 118 this.add(buttonClose, 119 new GridBagConstraints(3, 0, 1, 1, 0.1, 0.0, 120 GridBagConstraints.CENTER, 121 GridBagConstraints.NONE, 122 new Insets(5, 5, 5, 5), 0, 0)); 123 this.add(buttonAbout, 124 new GridBagConstraints(5, 0, 1, 1, 0.1, 0.0, 125 GridBagConstraints.CENTER, 126 GridBagConstraints.NONE, 127 new Insets(5, 5, 5, 5), 0, 0)); 128 this.add(buttonHelp, 129 new GridBagConstraints(4, 0, 1, 1, 0.1, 0.0, 130 GridBagConstraints.CENTER, 131 GridBagConstraints.NONE, 132 new Insets(5, 5, 5, 5), 0, 0)); 133 this.add(panelFiller, 134 new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 135 GridBagConstraints.CENTER, 136 GridBagConstraints.HORIZONTAL, 137 new Insets(0, 0, 0, 0), 50, 0)); 138 } 139 140 private class LocalButtonListener implements ActionListener { 141 142 149 public void actionPerformed(ActionEvent e) { 150 Object source = null; 151 ActionEvent event = null; 152 153 source = e.getSource(); 154 if (source == buttonCompile) { 155 event = new ActionEvent (buttonCompile, ButtonPanel.COMPILE, 156 buttonCompile.getActionCommand()); 157 } else if (source == buttonClose) { 158 event = new ActionEvent (buttonClose, ButtonPanel.CLOSE, 159 buttonClose.getActionCommand()); 160 } else if (source == buttonHelp) { 161 event = new ActionEvent (buttonHelp, ButtonPanel.HELP, 162 buttonHelp.getActionCommand()); 163 } else if (source == buttonAbout) { 164 event = new ActionEvent (buttonAbout, ButtonPanel.ABOUT, 165 buttonAbout.getActionCommand()); 166 } 167 if (event != null) { 168 notifyActionListeners(event); 169 } 170 } 171 172 } 173 } 174 | Popular Tags |