KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 import javax.swing.JPanel JavaDoc;
13
14 import javax.swing.AbstractAction JavaDoc;
15 import javax.swing.JCheckBox 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 EnhydraBasePanel extends JPanel JavaDoc {
29
30     private JCheckBox JavaDoc createNew = null;
31
32     private JLabel JavaDoc jLabel = null;
33
34     private JLabel JavaDoc serviceLabel = null;
35
36     private JTextField JavaDoc serviceText = null;
37
38     private JLabel JavaDoc pathLabel = null;
39
40     private JTextField JavaDoc pathText = null;
41
42     private JButton JavaDoc browseButton = null;
43
44     private JLabel JavaDoc jLabel2 = null;
45
46     private JLabel JavaDoc jLabel1 = null;
47
48     /**
49      * This is the default constructor
50      */

51     public EnhydraBasePanel() {
52         super();
53         initialize();
54     }
55
56     /**
57      * This method initializes this
58      *
59      * @return void
60      */

61     private void initialize() {
62         jLabel1 = new JLabel JavaDoc();
63         serviceLabel = new JLabel JavaDoc();
64         jLabel2 = new JLabel JavaDoc();
65         pathLabel = new JLabel JavaDoc();
66         jLabel = new JLabel JavaDoc();
67         this.setPreferredSize(new java.awt.Dimension JavaDoc(300, 150));
68         this.setSize(300, 150);
69         jLabel.setText("");
70         jLabel.setPreferredSize(new java.awt.Dimension JavaDoc(300, 16));
71         serviceLabel.setText("Service Name:");
72         serviceLabel.setName("serviceLabel");
73         serviceLabel.setEnabled(false);
74         pathLabel.setText("Path to Enhydra Base Directory:");
75         pathLabel.setEnabled(false);
76         pathLabel.setName("pathLabel");
77         pathLabel.setPreferredSize(new java.awt.Dimension JavaDoc(281, 16));
78         jLabel2.setText("");
79         jLabel2.setPreferredSize(new java.awt.Dimension JavaDoc(80, 10));
80         jLabel1.setText("");
81         jLabel1.setPreferredSize(new java.awt.Dimension JavaDoc(300, 5));
82         this.add(getCreateNew(), null);
83         this.add(jLabel, null);
84         this.add(serviceLabel, null);
85         this.add(getServiceText(), null);
86         this.add(jLabel2, null);
87         this.add(jLabel1, null);
88         this.add(pathLabel, null);
89         this.add(getPathText(), null);
90         this.add(getBrowseButton(), null);
91     }
92
93     /**
94      * This method initializes jCheckBox
95      *
96      * @return javax.swing.JCheckBox
97      */

98     private JCheckBox JavaDoc getCreateNew() {
99         if (createNew == null) {
100             createNew = new JCheckBox JavaDoc();
101             createNew.setSelected(false);
102             createNew.setName("createNew");
103             createNew.setText("Create New Enhydra Base Directory");
104             createNew.setPreferredSize(new java.awt.Dimension JavaDoc(300, 24));
105             createNew.addActionListener(new CustomActionListener());
106         }
107         return createNew;
108     }
109
110     /**
111      * This method initializes jTextField
112      *
113      * @return javax.swing.JTextField
114      */

115     private JTextField JavaDoc getServiceText() {
116         if (serviceText == null) {
117             serviceText = new JTextField JavaDoc();
118             serviceText.setName("serviceText");
119             serviceText.setPreferredSize(new java.awt.Dimension JavaDoc(110, 20));
120             serviceText.setEnabled(false);
121         }
122         return serviceText;
123     }
124
125     /**
126      * This method initializes jTextField
127      *
128      * @return javax.swing.JTextField
129      */

130     private JTextField JavaDoc getPathText() {
131         if (pathText == null) {
132             pathText = new JTextField JavaDoc();
133             pathText.setPreferredSize(new java.awt.Dimension JavaDoc(196, 20));
134             pathText.setEnabled(false);
135             pathText.setName("pathText");
136         }
137         return pathText;
138     }
139
140     /**
141      * This method initializes jButton
142      *
143      * @return javax.swing.JButton
144      */

145     private JButton JavaDoc getBrowseButton() {
146         if (browseButton == null) {
147             browseButton = new JButton JavaDoc();
148             browseButton.setText("Browse");
149             browseButton.setEnabled(false);
150             browseButton.setName("browseButton");
151             browseButton.setPreferredSize(new java.awt.Dimension JavaDoc(80, 26));
152             browseButton.addActionListener(new CustomActionListener());
153         }
154         return browseButton;
155     }
156     
157     public void setServiceName (String JavaDoc name){
158         getServiceText().setText(name);
159     }
160     
161     public String JavaDoc getServiceName (){
162         return getServiceText().getText();
163     }
164     
165     public void setBasePath (String JavaDoc path){
166         getPathText().setText(path);
167     }
168     
169     public String JavaDoc getBasePath (){
170         return getPathText().getText();
171     }
172     
173     public void setBaseChecked (boolean selected){
174         getCreateNew().setSelected(selected);
175         
176         serviceLabel.setEnabled(getCreateNew().isSelected());
177         serviceText.setEnabled(getCreateNew().isSelected());
178         pathLabel.setEnabled(getCreateNew().isSelected());
179         pathText.setEnabled(getCreateNew().isSelected());
180         browseButton.setEnabled(getCreateNew().isSelected());
181     }
182     
183     public boolean getBaseChecked (){
184         return getCreateNew().isSelected();
185     }
186
187     private class CustomAction extends AbstractAction JavaDoc {
188         public void actionPerformed(ActionEvent JavaDoc ae) {
189             String JavaDoc command = ae.getActionCommand();
190             if ("Create New Enhydra Base Directory".equals(command)) {
191                 serviceLabel.setEnabled(getCreateNew().isSelected());
192                 serviceText.setEnabled(getCreateNew().isSelected());
193                 pathLabel.setEnabled(getCreateNew().isSelected());
194                 pathText.setEnabled(getCreateNew().isSelected());
195                 browseButton.setEnabled(getCreateNew().isSelected());
196             } else if ("Browse".equals(command)) {
197                 JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
198                 chooser.setDialogTitle("Choose Enhydra Base Path!!!");
199                 chooser.setFileSelectionMode(chooser.DIRECTORIES_ONLY);
200                 int returnVal = chooser.showOpenDialog(null);
201                 if (returnVal == JFileChooser.APPROVE_OPTION) {
202                     pathText.setText(chooser.getSelectedFile()
203                             .getAbsolutePath());
204                 }
205             }
206         }
207     }
208
209     private class CustomActionListener implements ActionListener JavaDoc {
210
211         protected AbstractAction JavaDoc action;
212
213         public CustomActionListener() {
214             action = new CustomAction();
215         }
216
217         public void actionPerformed(ActionEvent JavaDoc e) {
218             action.actionPerformed(e);
219         }
220     }
221
222     public boolean checkEntries() {
223         boolean valid = true;
224         if (createNew.isSelected()) {
225             if ("".equals(serviceText.getText())
226                     || serviceText.getText() == null) {
227                 displayErrorMessage("Service Name");
228                 valid = false;
229             } else {
230                 serviceText.setText(serviceText.getText().replace(' ', '_'));
231             }
232
233             if ("".equals(pathText.getText()) || pathText.getText() == null) {
234                 displayErrorMessage("Path to Enhydra Base Directory");
235                 valid = false;
236             }
237         }
238         return valid;
239     }
240
241     private void displayErrorMessage(String JavaDoc field) {
242         JOptionPane.showMessageDialog(null, "Check '" + field
243                 + "' Field Setting!",
244                 "Enhydra Configuration Tool - Houston, we have a problem!",
245                 JOptionPane.ERROR_MESSAGE);
246     }
247
248 }
Popular Tags