1 7 package org.enhydra.base.tool; 8 9 import java.awt.event.ActionEvent ; 10 import java.awt.event.ActionListener ; 11 import java.io.File ; 12 13 import javax.swing.JPanel ; 14 15 import javax.swing.AbstractAction ; 16 import javax.swing.JFileChooser ; 17 import javax.swing.JLabel ; 18 import javax.swing.JOptionPane ; 19 import javax.swing.JTextField ; 20 import javax.swing.JButton ; 21 22 28 public class JavaConfigurationPanel extends JPanel { 29 30 private JLabel jLabel = null; 31 32 private JLabel jLabel1 = null; 33 34 private JTextField javaPathText = null; 35 36 private JButton browseButton = null; 37 38 41 public JavaConfigurationPanel() { 42 super(); 43 initialize(); 44 } 45 46 51 private void initialize() { 52 jLabel1 = new JLabel (); 53 jLabel = new JLabel (); 54 this.setPreferredSize(new java.awt.Dimension (300, 150)); 55 this.setSize(300, 150); 56 jLabel.setText(""); 57 jLabel.setPreferredSize(new java.awt.Dimension (300, 40)); 58 jLabel1.setText("Path To JAVA_HOME Directory:"); 59 jLabel1.setPreferredSize(new java.awt.Dimension (280, 16)); 60 this.add(jLabel, null); 61 this.add(jLabel1, null); 62 this.add(getJavaPathText(), null); 63 this.add(getBrowseButton(), null); 64 } 65 66 71 private JTextField getJavaPathText() { 72 if (javaPathText == null) { 73 javaPathText = new JTextField (); 74 javaPathText.setName("javaPathText"); 75 javaPathText.setPreferredSize(new java.awt.Dimension (200, 20)); 76 } 77 return javaPathText; 78 } 79 80 85 private JButton getBrowseButton() { 86 if (browseButton == null) { 87 browseButton = new JButton (); 88 browseButton.setName("browseButton"); 89 browseButton.setText("Browse"); 90 browseButton.setPreferredSize(new java.awt.Dimension (80, 26)); 91 browseButton.addActionListener(new CustomActionListener()); 92 } 93 return browseButton; 94 } 95 96 public void setJavaPath(String path) { 97 getJavaPathText().setText(path); 98 } 99 100 public String getJavaPath() { 101 return getJavaPathText().getText(); 102 } 103 104 public boolean checkEntries() { 105 boolean valid = true; 106 File javaExecutable = null; 107 if ('/' == File.separatorChar) { 108 javaExecutable = new File (getJavaPathText().getText() + File.separator 109 + "bin" + File.separator + "java"); 110 } else { 111 javaExecutable = new File (getJavaPathText().getText() + File.separator 112 + "bin" + File.separator + "java.exe"); 113 } 114 if (!javaExecutable.exists()) { 115 displayErrorMessage("Path To JAVA_HOME Directory"); 116 valid = false; 117 } 118 return valid; 119 } 120 121 private void displayErrorMessage(String field) { 122 JOptionPane.showMessageDialog(null, "Check '" + field 123 + "' Field Setting!", 124 "Enhydra Configuration Tool - Houston, we have a problem!", 125 JOptionPane.ERROR_MESSAGE); 126 } 127 128 private class CustomAction extends AbstractAction { 129 public void actionPerformed(ActionEvent ae) { 130 String command = ae.getActionCommand(); 131 if ("Browse".equals(command)) { 132 JFileChooser chooser = new JFileChooser (); 133 chooser.setDialogTitle("Choose Enhydra Base Path!!!"); 134 chooser.setFileSelectionMode(chooser.DIRECTORIES_ONLY); 135 int returnVal = chooser.showOpenDialog(null); 136 if (returnVal == JFileChooser.APPROVE_OPTION) { 137 javaPathText.setText(chooser.getSelectedFile() 138 .getAbsolutePath()); 139 } 140 } 141 } 142 } 143 144 private class CustomActionListener implements ActionListener { 145 146 protected AbstractAction action; 147 148 public CustomActionListener() { 149 action = new CustomAction(); 150 } 151 152 public void actionPerformed(ActionEvent e) { 153 action.actionPerformed(e); 154 } 155 } 156 } | Popular Tags |