KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > deployer > AntDeployGeneralPanel


1 package org.enhydra.kelp.ant.deployer;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import org.enhydra.tool.swing.layout.*;
6 //import com.borland.jbcl.layout.*;
7
import javax.swing.border.*;
8 import org.enhydra.kelp.ant.node.AntProject;
9 import org.enhydra.kelp.common.node.OtterProject;
10 import java.util.ResourceBundle JavaDoc;
11 import java.awt.event.*;
12 import javax.swing.JFileChooser JavaDoc;
13 import java.io.File JavaDoc;
14
15 /**
16  * <p>Title: </p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author unascribed
21  * @version 1.0
22  */

23
24 public class AntDeployGeneralPanel extends JPanel {
25
26     static ResourceBundle JavaDoc res = ResourceBundle.getBundle(
27             "org.enhydra.kelp.common.Res");
28
29     private XYLayout xYLayout1 = new XYLayout();
30     JLabel jLabelDescr = new JLabel();
31     JLabel jLabelType = new JLabel();
32     JTextField jTextType = new JTextField();
33     JLabel jLabelRoot = new JLabel();
34     JTextField jTextDestination = new JTextField();
35     JButton jButtonBrowse = new JButton();
36     JCheckBox jCheckInvokeMake = new JCheckBox();
37     AntProject project = null;
38     private JCheckBox jCheckBoxMakeWAR = new JCheckBox();
39     private JCheckBox jCheckBoxEnhydraLib = new JCheckBox();
40
41     public AntDeployGeneralPanel() {
42         try {
43             jbInit();
44         }
45         catch(Exception JavaDoc ex) {
46             ex.printStackTrace();
47         }
48     }
49
50     public void setProject(OtterProject otterProject){
51         if(otterProject instanceof AntProject) {
52             project = (AntProject) otterProject;
53             initOptions();
54         }
55         else
56             System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
57
}
58
59     private void initOptions() {
60         if (project.isWebType()) {
61             jTextType.setText(res.getString("Web_Application"));
62             jCheckBoxMakeWAR.setVisible(false); //by default WAR is created for Web app
63
}
64         else {
65             jTextType.setText(res.getString("Enhydra_Super_Servlet"));
66             jCheckBoxMakeWAR.setVisible(true);
67             
68             if(project.getProperty(AntProject.DEPLOY_WAR_ENABLED).equalsIgnoreCase("true")){
69                 jCheckBoxMakeWAR.setSelected(true);
70                 jCheckBoxEnhydraLib.setVisible(true);
71             }else{
72                 jCheckBoxMakeWAR.setSelected(false);
73                 jCheckBoxEnhydraLib.setVisible(false);
74             }
75         }
76         if(project.getProperty(AntProject.DEPLOY_WAR_ENHYDRA_LIBS).equalsIgnoreCase("true")){
77                 jCheckBoxEnhydraLib.setSelected(true);
78         }else{
79                 jCheckBoxEnhydraLib.setSelected(false);
80         }
81         jTextDestination.setText(project.getProperty(AntProject.OUTPUT_DIR));
82         if(project.getProperty(AntProject.DEPLOY_INVOKE).equalsIgnoreCase("true"))
83             jCheckInvokeMake.setSelected(true);
84         else
85             jCheckInvokeMake.setSelected(false);
86
87
88     }
89
90     public OtterProject getProject(){
91         return (OtterProject) project;
92     }
93
94     void jbInit() throws Exception JavaDoc {
95         jLabelDescr.setFont(new java.awt.Font JavaDoc("Dialog", 1, 12));
96         jLabelDescr.setText(res.getString("General_deployment_options"));
97         this.setLayout(xYLayout1);
98         jLabelType.setText(res.getString("Deploy_type"));
99         jTextType.setBackground(SystemColor.control);
100         jTextType.setEditable(false);
101         jLabelRoot.setText(res.getString("Deploy_destination_directory"));
102         jButtonBrowse.setText(res.getString("Browse"));
103         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
104             public void actionPerformed(ActionEvent e) {
105                 jButtonBrowse_actionPerformed(e);
106             }
107         });
108         jCheckInvokeMake.setText(res.getString("Deploy_during_make"));
109         jCheckInvokeMake.addActionListener(new java.awt.event.ActionListener JavaDoc() {
110             public void actionPerformed(ActionEvent e) {
111                 jCheckInvokeMake_actionPerformed(e);
112             }
113         });
114
115         jTextDestination.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
116             public void focusLost(FocusEvent e) {
117                 jTextDestination_focusLost(e);
118             }
119         });
120
121         jCheckBoxMakeWAR.setText("Make WAR (Web Archive)");
122         jCheckBoxMakeWAR.addActionListener(new java.awt.event.ActionListener JavaDoc() {
123             public void actionPerformed(ActionEvent e) {
124                 jCheckBoxMakeWAR_actionPerformed(e);
125             }
126         });
127
128         xYLayout1.setWidth(460);
129         xYLayout1.setHeight(372);
130         jCheckBoxEnhydraLib.setText("Include Enhydra library into WAR");
131         jCheckBoxEnhydraLib.addActionListener(new java.awt.event.ActionListener JavaDoc() {
132             public void actionPerformed(ActionEvent e) {
133                 jCheckBoxEnhydraLib_actionPerformed(e);
134             }
135         });
136         this.add(jLabelDescr, new XYConstraints(13, 13, 178, 18));
137         this.add(jCheckInvokeMake, new XYConstraints(13, 55, 258, 20));
138         this.add(jLabelType, new XYConstraints(13, 88, 74, 18));
139         this.add(jTextType, new XYConstraints(13, 112, 368, 22));
140         this.add(jLabelRoot, new XYConstraints(13, 159, 170, 26));
141         this.add(jTextDestination, new XYConstraints(13, 189, 267, 22));
142         this.add(jButtonBrowse, new XYConstraints(291, 187, 90, 25));
143         this.add(jCheckBoxMakeWAR, new XYConstraints(13, 245, 328, 24));
144         this.add(jCheckBoxEnhydraLib, new XYConstraints(13, 277, 368, 32));
145     }
146
147     public void jTextDestination_focusLost(FocusEvent fe) {
148         project.setProperty(AntProject.OUTPUT_DIR, jTextDestination.getText());
149     }
150
151     void jButtonBrowse_actionPerformed(ActionEvent e) {
152         browseForDir();
153     }
154
155     private void browseForDir() {
156         JFileChooser JavaDoc chooser;
157         String JavaDoc fileDir = new String JavaDoc();
158         File JavaDoc file = null;
159         chooser = new JFileChooser JavaDoc();
160         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
161         file = new File JavaDoc(project.getProperty(AntProject.OUTPUT_DIR));
162         if (!file.isAbsolute()) {
163             file = new File JavaDoc(project.getWorkingPath(), file.getPath());
164         }
165         chooser.setCurrentDirectory(file);
166         chooser.setDialogTitle(res.getString("chooser_DeployRoot_DialogTitle"));
167         chooser.setApproveButtonText(res.getString("OK"));
168         int v = chooser.showOpenDialog(this);
169
170         this.requestFocus();
171         jButtonBrowse.requestFocus();
172         if (v == JFileChooser.APPROVE_OPTION) {
173             if (!(chooser.getCurrentDirectory() == null)) {
174                 fileDir = chooser.getSelectedFile().toString();
175                 jTextDestination.setText(fileDir);
176                 project.setProperty(AntProject.OUTPUT_DIR, fileDir);
177             }
178         }
179         chooser.removeAll();
180         chooser = null;
181     }
182
183     void jCheckInvokeMake_actionPerformed(ActionEvent e) {
184         if (jCheckInvokeMake.isSelected()) {
185             project.setProperty(AntProject.DEPLOY_INVOKE, "true");
186         }
187         else {
188             project.setProperty(AntProject.DEPLOY_INVOKE, "false");
189         }
190     }
191
192     void jCheckBoxMakeWAR_actionPerformed(ActionEvent e) {
193         if(jCheckBoxMakeWAR.isSelected()){
194             project.setProperty(AntProject.DEPLOY_WAR_ENABLED,"true");
195             jCheckBoxEnhydraLib.setVisible(true);
196         }else{
197             project.setProperty(AntProject.DEPLOY_WAR_ENABLED,"false");
198             jCheckBoxEnhydraLib.setVisible(false);
199         }
200     }
201
202     void jCheckBoxEnhydraLib_actionPerformed(ActionEvent e) {
203         if(jCheckBoxEnhydraLib.isSelected()){
204             project.setProperty(AntProject.DEPLOY_WAR_ENHYDRA_LIBS,"true");
205         }else{
206             project.setProperty(AntProject.DEPLOY_WAR_ENHYDRA_LIBS,"false");
207         }
208     }
209 }
Popular Tags