1 7 package org.enhydra.base.tool; 8 9 import java.awt.event.ActionEvent ; 10 import java.awt.event.ActionListener ; 11 12 import javax.swing.JPanel ; 13 14 import javax.swing.AbstractAction ; 15 import javax.swing.JLabel ; 16 import javax.swing.JCheckBox ; 17 import javax.swing.JComboBox ; 18 import javax.swing.JOptionPane ; 19 import javax.swing.JTextField ; 20 21 27 public class AdaptorConfigurationPanel extends JPanel { 28 29 private JLabel headLabel = null; 30 private JLabel authenticationLabel = null; 31 private JComboBox authenticationCombo = null; 32 private JCheckBox httpAdaptor = null; 33 private JLabel httpAdaptorLabel = null; 34 private JTextField httpAdaptorText = null; 35 private JCheckBox rmiAdaptor = null; 36 private JLabel rmiAdaptorLabel = null; 37 private JTextField rmiAdaptorText = null; 38 41 public AdaptorConfigurationPanel() { 42 super(); 43 initialize(); 44 } 45 50 private void initialize() { 51 headLabel = new JLabel (); 52 authenticationLabel = new JLabel (); 53 httpAdaptorLabel = new JLabel (); 54 rmiAdaptorLabel = new JLabel (); 55 this.setPreferredSize(new java.awt.Dimension (300,150)); 56 this.setSize(300, 150); 57 headLabel.setText(""); 58 headLabel.setPreferredSize(new java.awt.Dimension (300,25)); 59 headLabel.setName("headLabel"); 60 authenticationLabel.setText("Adaptor Authentication Level:"); 61 authenticationLabel.setName("authenticationLabel"); 62 httpAdaptorLabel.setText("Port:"); 63 httpAdaptorLabel.setPreferredSize(new java.awt.Dimension (30,16)); 64 httpAdaptorLabel.setName("httpAdaptorLabel"); 65 rmiAdaptorLabel.setText("Port:"); 66 rmiAdaptorLabel.setPreferredSize(new java.awt.Dimension (30,16)); 67 this.add(headLabel, null); 68 this.add(authenticationLabel, null); 69 this.add(getAuthenticationCombo(), null); 70 this.add(getHttpAdaptor(), null); 71 this.add(httpAdaptorLabel, null); 72 this.add(getHttpAdaptorText(), null); 73 this.add(getRmiAdaptor(), null); 74 this.add(rmiAdaptorLabel, null); 75 this.add(getRmiAdaptorText(), null); 76 } 77 82 private JComboBox getAuthenticationCombo() { 83 if (authenticationCombo == null) { 84 authenticationCombo = new JComboBox (); 85 authenticationCombo.setPreferredSize(new java.awt.Dimension (115,25)); 86 authenticationCombo.setName("authenticationCombo"); 87 authenticationCombo.addItem("none"); 88 authenticationCombo.addItem("basic"); 89 authenticationCombo.addItem("digest"); 90 authenticationCombo.setSelectedIndex(0); 91 } 92 return authenticationCombo; 93 } 94 99 private JCheckBox getHttpAdaptor() { 100 if (httpAdaptor == null) { 101 httpAdaptor = new JCheckBox (); 102 httpAdaptor.setName("httpAdaptor"); 103 httpAdaptor.setPreferredSize(new java.awt.Dimension (175,21)); 104 httpAdaptor.setText("HTTP Adaptor"); 105 httpAdaptor.setSelected(true); 106 httpAdaptor.addActionListener(new CustomActionListener()); 107 } 108 return httpAdaptor; 109 } 110 115 private JTextField getHttpAdaptorText() { 116 if (httpAdaptorText == null) { 117 httpAdaptorText = new JTextField (); 118 httpAdaptorText.setPreferredSize(new java.awt.Dimension (75,20)); 119 httpAdaptorText.setName("httpAdaptorText"); 120 httpAdaptorText.setText("9050"); 121 } 122 return httpAdaptorText; 123 } 124 129 private JCheckBox getRmiAdaptor() { 130 if (rmiAdaptor == null) { 131 rmiAdaptor = new JCheckBox (); 132 rmiAdaptor.setName("rmiAdaptor"); 133 rmiAdaptor.setPreferredSize(new java.awt.Dimension (175,21)); 134 rmiAdaptor.setSelected(true); 135 rmiAdaptor.setText("RMI/JRMP Adaptor"); 136 rmiAdaptor.addActionListener(new CustomActionListener()); 137 } 138 return rmiAdaptor; 139 } 140 145 private JTextField getRmiAdaptorText() { 146 if (rmiAdaptorText == null) { 147 rmiAdaptorText = new JTextField (); 148 rmiAdaptorText.setName("rmiAdaptorText"); 149 rmiAdaptorText.setPreferredSize(new java.awt.Dimension (75,20)); 150 rmiAdaptorText.setText("1099"); 151 } 152 return rmiAdaptorText; 153 } 154 155 public void setHttpPort (String port){ 156 getHttpAdaptorText().setText(port); 157 } 158 159 public String getHttpPort (){ 160 return getHttpAdaptorText().getText(); 161 } 162 163 public void setRmiPort (String port){ 164 getRmiAdaptorText().setText(port); 165 } 166 167 public String getRmiPort (){ 168 return getRmiAdaptorText().getText(); 169 } 170 171 public void setHttpChecked (boolean selected){ 172 getHttpAdaptor().setSelected(selected); 173 174 httpAdaptorLabel.setEnabled(getHttpAdaptor().isSelected()); 175 getHttpAdaptorText().setEnabled(getHttpAdaptor().isSelected()); 176 } 177 178 public boolean getHttpChecked (){ 179 return getHttpAdaptor().isSelected(); 180 } 181 182 public void setRmiChecked (boolean selected){ 183 getRmiAdaptor().setSelected(selected); 184 185 rmiAdaptorLabel.setEnabled(getRmiAdaptor().isSelected()); 186 getRmiAdaptorText().setEnabled(getRmiAdaptor().isSelected()); 187 } 188 189 public boolean getRmiChecked (){ 190 return getRmiAdaptor().isSelected(); 191 } 192 193 public void setComboSelection (String select){ 194 getAuthenticationCombo().setSelectedItem(select); 195 } 196 197 public String getComboSelection (){ 198 return (String )getAuthenticationCombo().getSelectedItem(); 199 } 200 201 private class CustomAction extends AbstractAction { 202 public void actionPerformed(ActionEvent ae) { 203 String command = ae.getActionCommand(); 204 if ("HTTP Adaptor".equals(command)) { 205 httpAdaptorLabel.setEnabled(getHttpAdaptor().isSelected()); 206 getHttpAdaptorText().setEnabled(getHttpAdaptor().isSelected()); 207 } else if ("RMI/JRMP Adaptor".equals(command)) { 208 rmiAdaptorLabel.setEnabled(getRmiAdaptor().isSelected()); 209 getRmiAdaptorText().setEnabled(getRmiAdaptor().isSelected()); 210 } 211 } 212 } 213 214 private class CustomActionListener implements ActionListener { 215 216 protected AbstractAction action; 217 218 public CustomActionListener() { 219 action = new CustomAction(); 220 } 221 222 public void actionPerformed(ActionEvent e) { 223 action.actionPerformed(e); 224 } 225 } 226 227 public boolean checkEntries (){ 228 boolean valid = true; 229 if (httpAdaptor.isSelected()){ 230 if ("".equals(httpAdaptorText.getText())||httpAdaptorText.getText()==null){ 231 displayErrorMessage("Http Adaptor Port"); 232 valid = false; 233 } else { 234 try { 235 int temp = Integer.parseInt(httpAdaptorText.getText()); 236 } catch (NumberFormatException ex){ 237 displayErrorMessage("Http Adaptor Port"); 238 valid = false; 239 } 240 } 241 } 242 243 if (rmiAdaptor.isSelected()){ 244 if ("".equals(rmiAdaptorText.getText())||rmiAdaptorText.getText()==null){ 245 displayErrorMessage("RMI/JRMP Adaptor Port"); 246 valid = false; 247 } else { 248 try { 249 int temp = Integer.parseInt(rmiAdaptorText.getText()); 250 } catch (NumberFormatException ex){ 251 displayErrorMessage("RMI/JRMP Adaptor Port"); 252 valid = false; 253 } 254 } 255 } 256 return valid; 257 } 258 259 private void displayErrorMessage(String field){ 260 JOptionPane.showMessageDialog(null, "Check '"+field+"' Field Setting!", "Enhydra Configuration Tool - Houston, we have a problem!", 261 JOptionPane.ERROR_MESSAGE); 262 } 263 } 264 | Popular Tags |