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.JCheckBox ; 16 import javax.swing.JLabel ; 17 import javax.swing.JOptionPane ; 18 import javax.swing.JTextField ; 19 20 26 public class ConnectorConfigurationPanel extends JPanel { 27 28 private JCheckBox httpConnector = null; 29 30 private JLabel httpConnectorLabel = null; 31 32 private JTextField httpConnectorText = null; 33 34 private JCheckBox sslHTTPConnector = null; 35 36 private JLabel sslHTTPConnectorLabel = null; 37 38 private JTextField sslHTTPConnectorText = null; 39 40 private JCheckBox ajpConnector = null; 41 42 private JLabel ajpConnectorLabel = null; 43 44 private JTextField ajpConnectorText = null; 45 46 private JCheckBox directorConnector = null; 47 48 private JLabel directorConnectorLabel = null; 49 50 private JTextField directorConnectorText = null; 51 52 private JLabel head = null; 53 56 public ConnectorConfigurationPanel() { 57 super(); 58 initialize(); 59 } 60 61 66 private void initialize() { 67 head = new JLabel (); 68 httpConnectorLabel = new JLabel (); 69 sslHTTPConnectorLabel = new JLabel (); 70 ajpConnectorLabel = new JLabel (); 71 directorConnectorLabel = new JLabel (); 72 this.setPreferredSize(new java.awt.Dimension (300, 150)); 73 this.setSize(300, 150); 74 httpConnectorLabel.setText("Port:"); 75 httpConnectorLabel.setPreferredSize(new java.awt.Dimension (30, 16)); 76 httpConnectorLabel.setName("httpConnectorLabel"); 77 sslHTTPConnectorLabel.setText("Port:"); 78 sslHTTPConnectorLabel.setPreferredSize(new java.awt.Dimension (30, 16)); 79 sslHTTPConnectorLabel.setName("sslHTTPConnectorLabel"); 80 ajpConnectorLabel.setText("Port:"); 81 ajpConnectorLabel.setPreferredSize(new java.awt.Dimension (30, 16)); 82 ajpConnectorLabel.setName("ajpConnectorLabel"); 83 directorConnectorLabel.setText("Port:"); 84 directorConnectorLabel.setPreferredSize(new java.awt.Dimension (30, 16)); 85 directorConnectorLabel.setName("directorConnectorLabel"); 86 head.setText(""); 87 head.setName("head"); 88 head.setPreferredSize(new java.awt.Dimension (300,10)); 89 this.add(head, null); 90 this.add(getHttpConnector(), null); 91 this.add(httpConnectorLabel, null); 92 this.add(getHttpConnectorText(), null); 93 this.add(getSslHTTPConnector(), null); 94 this.add(sslHTTPConnectorLabel, null); 95 this.add(getSslHTTPConnectorText(), null); 96 this.add(getAjpConnector(), null); 97 this.add(ajpConnectorLabel, null); 98 this.add(getAjpConnectorText(), null); 99 this.add(getDirectorConnector(), null); 100 this.add(directorConnectorLabel, null); 101 this.add(getDirectorConnectorText(), null); 102 } 103 104 109 private JCheckBox getHttpConnector() { 110 if (httpConnector == null) { 111 httpConnector = new JCheckBox (); 112 httpConnector.setSelected(true); 113 httpConnector.setText("non-SSL HTTP Connector"); 114 httpConnector.setName("httpConnector"); 115 httpConnector.setPreferredSize(new java.awt.Dimension (175, 24)); 116 httpConnector.addActionListener(new CustomActionListener()); 117 } 118 return httpConnector; 119 } 120 121 126 private JTextField getHttpConnectorText() { 127 if (httpConnectorText == null) { 128 httpConnectorText = new JTextField (); 129 httpConnectorText.setPreferredSize(new java.awt.Dimension (75, 20)); 130 httpConnectorText.setName("httpConnectorText"); 131 httpConnectorText.setText("8080"); 132 } 133 return httpConnectorText; 134 } 135 136 141 private JCheckBox getSslHTTPConnector() { 142 if (sslHTTPConnector == null) { 143 sslHTTPConnector = new JCheckBox (); 144 sslHTTPConnector.setText("SSL HTTP Connector"); 145 sslHTTPConnector.setPreferredSize(new java.awt.Dimension (175, 24)); 146 sslHTTPConnector.setSelected(true); 147 sslHTTPConnector.setName("sslHTTPConnector"); 148 sslHTTPConnector.addActionListener(new CustomActionListener()); 149 } 150 return sslHTTPConnector; 151 } 152 153 158 private JTextField getSslHTTPConnectorText() { 159 if (sslHTTPConnectorText == null) { 160 sslHTTPConnectorText = new JTextField (); 161 sslHTTPConnectorText 162 .setPreferredSize(new java.awt.Dimension (75, 20)); 163 sslHTTPConnectorText.setName("sslHTTPConnectorText"); 164 sslHTTPConnectorText.setText("8443"); 165 } 166 return sslHTTPConnectorText; 167 } 168 169 174 private JCheckBox getAjpConnector() { 175 if (ajpConnector == null) { 176 ajpConnector = new JCheckBox (); 177 ajpConnector.setSelected(true); 178 ajpConnector.setText("AJP Connector"); 179 ajpConnector.setName("ajpConnector"); 180 ajpConnector.setPreferredSize(new java.awt.Dimension (175, 24)); 181 ajpConnector.addActionListener(new CustomActionListener()); 182 } 183 return ajpConnector; 184 } 185 186 191 private JTextField getAjpConnectorText() { 192 if (ajpConnectorText == null) { 193 ajpConnectorText = new JTextField (); 194 ajpConnectorText.setPreferredSize(new java.awt.Dimension (75, 20)); 195 ajpConnectorText.setName("ajpConnectorLabel"); 196 ajpConnectorText.setText("9009"); 197 } 198 return ajpConnectorText; 199 } 200 201 206 private JCheckBox getDirectorConnector() { 207 if (directorConnector == null) { 208 directorConnector = new JCheckBox (); 209 directorConnector.setSelected(true); 210 directorConnector.setText("Director Connector"); 211 directorConnector.setName("directorConnector"); 212 directorConnector.setPreferredSize(new java.awt.Dimension (175, 24)); 213 directorConnector.addActionListener(new CustomActionListener()); 214 } 215 return directorConnector; 216 } 217 218 223 private JTextField getDirectorConnectorText() { 224 if (directorConnectorText == null) { 225 directorConnectorText = new JTextField (); 226 directorConnectorText.setPreferredSize(new java.awt.Dimension (75, 227 20)); 228 directorConnectorText.setName("directorConnectorText"); 229 directorConnectorText.setText("9003"); 230 } 231 return directorConnectorText; 232 } 233 234 public boolean checkEntries (){ 235 boolean valid = true; 236 if (httpConnector.isSelected()){ 237 if ("".equals(httpConnectorText.getText())||httpConnectorText.getText()==null){ 238 displayErrorMessage("non-SSL Http Connector Port"); 239 valid = false; 240 } else { 241 try { 242 int temp = Integer.parseInt(httpConnectorText.getText()); 243 } catch (NumberFormatException ex){ 244 displayErrorMessage("non-SSL Http Connector Port"); 245 valid = false; 246 } 247 } 248 } 249 250 if (sslHTTPConnector.isSelected()){ 251 if ("".equals(sslHTTPConnectorText.getText())||sslHTTPConnectorText.getText()==null){ 252 displayErrorMessage("SSL Http Connector Port"); 253 valid = false; 254 } else { 255 try { 256 int temp = Integer.parseInt(sslHTTPConnectorText.getText()); 257 } catch (NumberFormatException ex){ 258 displayErrorMessage("SSL Http Connector Port"); 259 valid = false; 260 } 261 } 262 } 263 264 if (ajpConnector.isSelected()){ 265 if ("".equals(ajpConnectorText.getText())||ajpConnectorText.getText()==null){ 266 displayErrorMessage("AJP Connector Port"); 267 valid = false; 268 } else { 269 try { 270 int temp = Integer.parseInt(ajpConnectorText.getText()); 271 } catch (NumberFormatException ex){ 272 displayErrorMessage("AJP Connector Port"); 273 valid = false; 274 } 275 } 276 } 277 278 if (directorConnector.isSelected()){ 279 if ("".equals(directorConnectorText.getText())||directorConnectorText.getText()==null){ 280 displayErrorMessage("Director Connector Port"); 281 valid = false; 282 } else { 283 try { 284 int temp = Integer.parseInt(directorConnectorText.getText()); 285 } catch (NumberFormatException ex){ 286 displayErrorMessage("Director Connector Port"); 287 valid = false; 288 } 289 } 290 } 291 return valid; 292 } 293 294 private void displayErrorMessage(String field){ 295 JOptionPane.showMessageDialog(null, "Check '"+field+"' Field Setting!", "Enhydra Configuration Tool - Houston, we have a problem!", 296 JOptionPane.ERROR_MESSAGE); 297 } 298 299 public void setHttpPort (String port){ 300 getHttpConnectorText().setText(port); 301 } 302 303 public String getHttpPort (){ 304 return getHttpConnectorText().getText(); 305 } 306 307 public void setSslHttpPort (String port){ 308 getSslHTTPConnectorText().setText(port); 309 } 310 311 public String getSslHttpPort (){ 312 return getSslHTTPConnectorText().getText(); 313 } 314 315 public void setAjpPort (String port){ 316 getAjpConnectorText().setText(port); 317 } 318 319 public String getAjpPort (){ 320 return getAjpConnectorText().getText(); 321 } 322 323 public void setDirectorPort (String port){ 324 getDirectorConnectorText().setText(port); 325 } 326 327 public String getDirectorPort (){ 328 return getDirectorConnectorText().getText(); 329 } 330 331 public void setHttpChecked (boolean selected){ 332 getHttpConnector().setSelected(selected); 333 334 httpConnectorLabel.setEnabled(getHttpConnector().isSelected()); 335 getHttpConnectorText().setEnabled(getHttpConnector().isSelected()); 336 } 337 338 public boolean getHttpChecked (){ 339 return getHttpConnector().isSelected(); 340 } 341 342 public void setSslHttpChecked (boolean selected){ 343 getSslHTTPConnector().setSelected(selected); 344 345 sslHTTPConnectorLabel.setEnabled(getSslHTTPConnector().isSelected()); 346 getSslHTTPConnectorText().setEnabled( 347 getSslHTTPConnector().isSelected()); 348 } 349 350 public boolean getSslHttpChecked (){ 351 return getSslHTTPConnector().isSelected(); 352 } 353 354 public void setAjpChecked (boolean selected){ 355 getAjpConnector().setSelected(selected); 356 357 ajpConnectorLabel.setEnabled(getAjpConnector().isSelected()); 358 getAjpConnectorText() 359 .setEnabled(getAjpConnector().isSelected()); 360 } 361 362 public boolean getAjpChecked (){ 363 return getAjpConnector().isSelected(); 364 } 365 366 public void setDirectorChecked (boolean selected){ 367 getDirectorConnector().setSelected(selected); 368 369 directorConnectorLabel.setEnabled(getDirectorConnector().isSelected()); 370 getDirectorConnectorText().setEnabled( 371 getDirectorConnector().isSelected()); 372 } 373 374 public boolean getDirectorChecked (){ 375 return getDirectorConnector().isSelected(); 376 } 377 378 private class CustomAction extends AbstractAction { 379 public void actionPerformed(ActionEvent ae) { 380 String command = ae.getActionCommand(); 381 if ("non-SSL HTTP Connector".equals(command)) { 382 httpConnectorLabel.setEnabled(getHttpConnector().isSelected()); 383 getHttpConnectorText().setEnabled(getHttpConnector().isSelected()); 384 } else if ("SSL HTTP Connector".equals(command)) { 385 sslHTTPConnectorLabel.setEnabled(getSslHTTPConnector().isSelected()); 386 getSslHTTPConnectorText().setEnabled( 387 getSslHTTPConnector().isSelected()); 388 } else if ("AJP Connector".equals(command)) { 389 ajpConnectorLabel.setEnabled(getAjpConnector().isSelected()); 390 getAjpConnectorText() 391 .setEnabled(getAjpConnector().isSelected()); 392 } else if ("Director Connector".equals(command)) { 393 directorConnectorLabel.setEnabled(getDirectorConnector().isSelected()); 394 getDirectorConnectorText().setEnabled( 395 getDirectorConnector().isSelected()); 396 } 397 } 398 } 399 400 private class CustomActionListener implements ActionListener { 401 402 protected AbstractAction action; 403 404 public CustomActionListener() { 405 action = new CustomAction(); 406 } 407 408 public void actionPerformed(ActionEvent e) { 409 action.actionPerformed(e); 410 } 411 } 412 } | Popular Tags |