KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > base > tool > JavaConfigurationPanel


1 /*
2  * Created on Jul 20, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.base.tool;
8
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.awt.event.ActionListener JavaDoc;
11 import java.io.File JavaDoc;
12
13 import javax.swing.JPanel JavaDoc;
14
15 import javax.swing.AbstractAction JavaDoc;
16 import javax.swing.JFileChooser JavaDoc;
17 import javax.swing.JLabel JavaDoc;
18 import javax.swing.JOptionPane JavaDoc;
19 import javax.swing.JTextField JavaDoc;
20 import javax.swing.JButton JavaDoc;
21
22 /**
23  * @author slobodan
24  *
25  * TODO To change the template for this generated type comment go to Window -
26  * Preferences - Java - Code Style - Code Templates
27  */

28 public class JavaConfigurationPanel extends JPanel JavaDoc {
29
30     private JLabel JavaDoc jLabel = null;
31
32     private JLabel JavaDoc jLabel1 = null;
33
34     private JTextField JavaDoc javaPathText = null;
35
36     private JButton JavaDoc browseButton = null;
37
38     /**
39      * This is the default constructor
40      */

41     public JavaConfigurationPanel() {
42         super();
43         initialize();
44     }
45
46     /**
47      * This method initializes this
48      *
49      * @return void
50      */

51     private void initialize() {
52         jLabel1 = new JLabel JavaDoc();
53         jLabel = new JLabel JavaDoc();
54         this.setPreferredSize(new java.awt.Dimension JavaDoc(300, 150));
55         this.setSize(300, 150);
56         jLabel.setText("");
57         jLabel.setPreferredSize(new java.awt.Dimension JavaDoc(300, 40));
58         jLabel1.setText("Path To JAVA_HOME Directory:");
59         jLabel1.setPreferredSize(new java.awt.Dimension JavaDoc(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     /**
67      * This method initializes jTextField1
68      *
69      * @return javax.swing.JTextField
70      */

71     private JTextField JavaDoc getJavaPathText() {
72         if (javaPathText == null) {
73             javaPathText = new JTextField JavaDoc();
74             javaPathText.setName("javaPathText");
75             javaPathText.setPreferredSize(new java.awt.Dimension JavaDoc(200, 20));
76         }
77         return javaPathText;
78     }
79
80     /**
81      * This method initializes jButton
82      *
83      * @return javax.swing.JButton
84      */

85     private JButton JavaDoc getBrowseButton() {
86         if (browseButton == null) {
87             browseButton = new JButton JavaDoc();
88             browseButton.setName("browseButton");
89             browseButton.setText("Browse");
90             browseButton.setPreferredSize(new java.awt.Dimension JavaDoc(80, 26));
91             browseButton.addActionListener(new CustomActionListener());
92         }
93         return browseButton;
94     }
95
96     public void setJavaPath(String JavaDoc path) {
97         getJavaPathText().setText(path);
98     }
99
100     public String JavaDoc getJavaPath() {
101         return getJavaPathText().getText();
102     }
103
104     public boolean checkEntries() {
105         boolean valid = true;
106         File JavaDoc javaExecutable = null;
107         if ('/' == File.separatorChar) {
108             javaExecutable = new File JavaDoc(getJavaPathText().getText() + File.separator
109                     + "bin" + File.separator + "java");
110         } else {
111             javaExecutable = new File JavaDoc(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 JavaDoc 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 JavaDoc {
129         public void actionPerformed(ActionEvent JavaDoc ae) {
130             String JavaDoc command = ae.getActionCommand();
131             if ("Browse".equals(command)) {
132                 JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
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 JavaDoc {
145
146         protected AbstractAction JavaDoc action;
147
148         public CustomActionListener() {
149             action = new CustomAction();
150         }
151
152         public void actionPerformed(ActionEvent JavaDoc e) {
153             action.actionPerformed(e);
154         }
155     }
156 }
Popular Tags