KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > xmlc > AntXMLCOptionsPanel


1 package org.enhydra.kelp.ant.xmlc;
2 //Kelp
3
import org.enhydra.kelp.common.node.OtterProject;
4 import org.enhydra.kelp.common.Constants;
5
6 import org.enhydra.kelp.ant.node.AntProject;
7 import org.enhydra.kelp.ant.xmlc.AntXMLCParamViewer;
8
9 //ToolBox
10
import org.enhydra.tool.common.DialogPanel;
11 import org.enhydra.tool.common.ExtensionFilter;
12 import org.enhydra.tool.common.PathHandle;
13
14 import org.enhydra.tool.swing.layout.*;
15
16 //JDK
17
import java.awt.*;
18 import java.awt.event.*;
19 import javax.swing.*;
20 import javax.swing.border.*;
21 import java.util.ResourceBundle JavaDoc;
22 import java.io.File JavaDoc;
23 //import com.borland.jbcl.layout.*;
24
/**
25  * <p>Title: </p>
26  * <p>Description: </p>
27  * <p>Copyright: Copyright (c) 2003</p>
28  * <p>Company: </p>
29  * @author Damir Milovic
30  * @version 1.0
31  */

32
33 public class AntXMLCOptionsPanel extends JPanel {
34
35     static ResourceBundle JavaDoc res = ResourceBundle.getBundle("org.enhydra.kelp.common.Res");
36
37     XYLayout xYLayout1 = new XYLayout();
38     JPanel jPanel1 = new JPanel();
39     JPanel jPanel2 = new JPanel();
40     XYLayout xYLayout2 = new XYLayout();
41     XYLayout xYLayout3 = new XYLayout();
42     TitledBorder titledBorder1;
43     TitledBorder titledBorder2;
44     JLabel jLabel1 = new JLabel();
45     JTextField jTextPackage = new JTextField();
46     JButton jButtonDefault = new JButton();
47     JLabel jLabel2 = new JLabel();
48     JTextField jTextOptionFile = new JTextField();
49     JButton jButtonEdit = new JButton();
50     JButton jButtonBrowse = new JButton();
51
52 // LocalButtonListener buttonListener = null;
53
AntProject project = null;
54     JPanel jPanel3 = new JPanel();
55     JCheckBox jCheckBoxInvoke = new JCheckBox();
56     XYLayout xYLayout4 = new XYLayout();
57     JCheckBox jCheckBoxVerbose = new JCheckBox();
58
59     public AntXMLCOptionsPanel() {
60         try {
61             jbInit();
62             pmInit();
63         }
64         catch(Exception JavaDoc ex) {
65             ex.printStackTrace();
66         }
67     }
68     void jbInit() throws Exception JavaDoc {
69         titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Mappings");
70         titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"XMLC Options");
71         this.setLayout(xYLayout1);
72         jPanel1.setLayout(xYLayout2);
73         jPanel2.setLayout(xYLayout3);
74         jPanel1.setBorder(titledBorder1);
75         jPanel2.setBorder(titledBorder2);
76         jLabel1.setText(res.getString("Package"));
77         jButtonDefault.setText(res.getString("Default"));
78         jButtonDefault.addActionListener(new java.awt.event.ActionListener JavaDoc() {
79             public void actionPerformed(ActionEvent e) {
80                 jButtonDefault_actionPerformed(e);
81             }
82         });
83         jLabel2.setText(res.getString("Option_file"));
84         jButtonEdit.setText(res.getString("Edit"));
85         jButtonEdit.addActionListener(new java.awt.event.ActionListener JavaDoc() {
86             public void actionPerformed(ActionEvent e) {
87                 jButtonEdit_actionPerformed(e);
88             }
89         });
90         jButtonBrowse.setText(res.getString("Browse"));
91         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
92             public void actionPerformed(ActionEvent e) {
93                 jButtonBrowse_actionPerformed(e);
94             }
95         });
96         xYLayout1.setWidth(520);
97         xYLayout1.setHeight(302);
98         jTextOptionFile.setBackground(SystemColor.inactiveCaptionText);
99         jTextOptionFile.setEditable(false);
100         jPanel3.setLayout(xYLayout4);
101         jCheckBoxInvoke.setText(res.getString("XMLC_Invoke_make"));
102         jCheckBoxInvoke.addActionListener(new java.awt.event.ActionListener JavaDoc() {
103             public void actionPerformed(ActionEvent e) {
104                 jCheckBoxInvoke_actionPerformed(e);
105             }
106         });
107         jCheckBoxVerbose.setText(res.getString("Verbose_output"));
108         jCheckBoxVerbose.addActionListener(new java.awt.event.ActionListener JavaDoc() {
109             public void actionPerformed(ActionEvent e) {
110                 jCheckBoxVerbose_actionPerformed(e);
111             }
112         });
113         jTextPackage.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
114             public void focusLost(FocusEvent e) {
115                 jTextPackage_focusLost(e);
116             }
117         });
118
119         jPanel1.add(jTextPackage, new XYConstraints(63, 13, 357, 23));
120         jPanel1.add(jLabel1, new XYConstraints(4, 13, 59, 20));
121         jPanel1.add(jButtonDefault, new XYConstraints(424, 11, -1, -1));
122         this.add(jPanel3, new XYConstraints(6, 16, 509, 106));
123         jPanel2.add(jLabel2, new XYConstraints(3, 15, -1, -1));
124         jPanel2.add(jTextOptionFile, new XYConstraints(63, 13, 278, 25));
125         jPanel2.add(jButtonBrowse, new XYConstraints(410, 13, 88, -1));
126         jPanel2.add(jButtonEdit, new XYConstraints(343, 13, -1, -1));
127         this.add(jPanel1, new XYConstraints(6, 127, 509, 76));
128         jPanel3.add(jCheckBoxVerbose, new XYConstraints(6, 52, 151, 21));
129         jPanel3.add(jCheckBoxInvoke, new XYConstraints(6, 14, -1, -1));
130         this.add(jPanel2, new XYConstraints(6, 208, 509, 86));
131     }
132     private void pmInit() {
133         //textCommandLine.setText(new String());
134
//buttonListener = new LocalButtonListener();
135
//jButtonBrowse.addActionListener(buttonListener);
136
//jButtonDefault.addActionListener(buttonListener);
137
//jButtonEdit.addActionListener(buttonListener);
138
}
139
140     public void setProject(OtterProject otterProject){
141         if(otterProject instanceof AntProject) {
142             project = (AntProject) otterProject;
143             initOptions();
144         }
145         else
146             System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
147
}
148
149     private void initOptions() {
150         String JavaDoc invoke = project.getProperty(AntProject.XMLC_INVOKE);
151         if(invoke != null)
152             jCheckBoxInvoke.setSelected(invoke.equalsIgnoreCase("true"));
153         String JavaDoc verbose = project.getProperty(AntProject.XMLC_VERBOSE);
154         if(verbose != null)
155             jCheckBoxVerbose.setSelected(verbose.equalsIgnoreCase("true"));
156         jTextPackage.setText(project.getProperty(AntProject.XMLC_PACKAGE_NAME));
157         jTextOptionFile.setText(project.getProperty(AntProject.XMLC_OPTIONS_FILE));
158     }
159
160     public OtterProject getProject(){
161         return (OtterProject) project;
162     }
163
164     private void editParameters() {
165         String JavaDoc[] params = new String JavaDoc[0];
166         AntXMLCParamViewer viewer = null;
167
168         viewer = new AntXMLCParamViewer();
169         params = project.getXMLCOptionsFileParams();
170         viewer.setParameters(params);
171         viewer.setOwner((Dialog) getTopLevelAncestor());
172         if (viewer.showDialog() == DialogPanel.OK_OPTION) {
173             params = viewer.getParameters();
174             project.setXMLCOptionsFileParams(params);
175         }
176     }
177      private void browseForFile() {
178         JFileChooser chooser;
179         ExtensionFilter filter;
180         File JavaDoc file;
181         String JavaDoc fileDir = new String JavaDoc();
182         String JavaDoc fileName = new String JavaDoc();
183         String JavaDoc filePath = new String JavaDoc();
184
185         filter = new ExtensionFilter();
186         filter.addExtension(Constants.TYPE_XMLC);
187         filter.setDescriptionTitle(res.getString("filter_DescriptionTitle"));
188         chooser = new JFileChooser();
189         if (jTextOptionFile.getText().trim().length() > 0) {
190             chooser.setCurrentDirectory(
191                 new File JavaDoc(project.getProperty(AntProject.RESOURCES_DIR)));
192         } else {
193             /*
194             PathHandle ph = null;
195
196             if (node instanceof OtterFileNode) {
197                OtterFileNode fileNode = (OtterFileNode) node;
198                 ph = PathHandle.createPathHandle(fileNode.getFilePath());
199                 if (ph.isEmpty()) {
200                   ph = null;
201                 } else {
202                   ph = ph.getParent();
203                 }
204             }
205
206             if (ph == null) {
207                 ph = PathHandle.createPathHandle(node.getProject().getRootPath());
208             }
209             */

210             PathHandle ph = PathHandle.createPathHandle(getProject().getWorkingPath());
211             chooser.setCurrentDirectory(ph.getFile());
212         }
213         chooser.setFileFilter(filter);
214         chooser.setDialogTitle(res.getString("chooser_DialogTitle"));
215         chooser.setApproveButtonText(res.getString("OK"));
216         int v = chooser.showOpenDialog(this);
217
218         this.requestFocus();
219         jButtonBrowse.requestFocus();
220         if (v == JFileChooser.APPROVE_OPTION) {
221             if (chooser.getSelectedFile() == null
222                     || (!chooser.getSelectedFile().isFile())) {
223                 jTextOptionFile.setText(new String JavaDoc());
224             } else {
225                 fileDir = chooser.getCurrentDirectory().toString();
226                 fileDir = stripSlash(fileDir);
227                 fileName = chooser.getSelectedFile().getName();
228                 filePath = fileDir + File.separator + fileName;
229                 jTextOptionFile.setText(filePath);
230                 project.setProperty(AntProject.XMLC_OPTIONS_FILE, filePath);
231             }
232         }
233         chooser.removeAll();
234         chooser = null;
235     }
236
237     private String JavaDoc stripSlash(String JavaDoc dir) {
238         String JavaDoc stripped = new String JavaDoc(dir);
239
240         if (dir != null) {
241             if (dir.length() > 0) {
242                 if (dir.endsWith(File.separator)) {
243                     stripped = dir.substring(0, dir.length() - 1);
244                 }
245             }
246         }
247         return stripped;
248     }
249 /*
250     private class LocalButtonListener implements ActionListener {
251         public void actionPerformed(ActionEvent e) {
252             Object source = e.getSource();
253
254             if (source == jButtonBrowse) {
255                browseForFile();
256             } else if (source == jButtonDefault) {
257                // setDefaultPackage();
258             } else if (source == jButtonEdit) {
259                 editParameters();
260             }
261         }
262
263     }
264 */

265     void jCheckBoxInvoke_actionPerformed(ActionEvent e) {
266         String JavaDoc invoke = "false";
267         if(jCheckBoxInvoke.isSelected())
268             invoke = "true";
269         project.setProperty(AntProject.XMLC_INVOKE, invoke);
270     }
271
272     void jCheckBoxVerbose_actionPerformed(ActionEvent e) {
273         String JavaDoc verbose = "false";
274         if(jCheckBoxVerbose.isSelected())
275             verbose = "true";
276         project.setProperty(AntProject.XMLC_VERBOSE, verbose);
277     }
278
279     void jButtonDefault_actionPerformed(ActionEvent e) {
280         //get default package name
281
jTextPackage.setText(project.getProperty(AntProject.XMLC_DEFAULT_PACKAGE));
282         project.setProperty(AntProject.XMLC_PACKAGE_NAME, jTextPackage.getText());
283     }
284
285     void jButtonEdit_actionPerformed(ActionEvent e) {
286         editParameters();
287     }
288
289     void jButtonBrowse_actionPerformed(ActionEvent e) {
290         browseForFile();
291     }
292
293     void jTextPackage_focusLost(FocusEvent e) {
294         project.setProperty(AntProject.XMLC_PACKAGE_NAME, jTextPackage.getText());
295     }
296 }
Popular Tags