KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > mtom > client > UserInterface


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package sample.mtom.client;
17
18 import org.apache.axis2.om.OMElement;
19
20 import javax.swing.*;
21 import javax.swing.filechooser.FileFilter JavaDoc;
22 import java.awt.*;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.io.File JavaDoc;
26
27 public class UserInterface extends JPanel implements ActionListener JavaDoc {
28
29     JButton browse;
30
31     JButton send;
32
33     JTextArea jTextArea;
34
35     JFileChooser jFileChooser;
36
37     File JavaDoc file = null;
38
39     JTextField EPR;
40
41     JTextField fileName;
42
43     JTextField fileFeild;
44
45     JLabel label;
46
47     JLabel savefile;
48
49     private String JavaDoc deriredFileName = null;
50
51     private String JavaDoc EPRName = null;
52
53     private MTOMClient parent;
54
55     public UserInterface(MTOMClient parent) {
56         this.parent = parent;
57         EPR = new JTextField();
58         fileFeild = new JTextField();
59         fileName = new JTextField();
60         label = new JLabel("END Point:");
61         savefile = new JLabel("Desired File Name:");
62         jTextArea = new JTextArea(5, 5);
63         jTextArea.setPreferredSize(new Dimension(200, 100));
64
65         jFileChooser = new JFileChooser();
66         jFileChooser.addChoosableFileFilter(new ImageFilter());
67         jFileChooser.setAcceptAllFileFilterUsed(false);
68         jFileChooser.setName("Image Chosser");
69         this.browse = new JButton("Browse");
70         this.send = new JButton("Send The Image");
71         fileFeild.setBounds(20, 20, 270, 20);
72         browse.setBounds(300, 20, 120, 20);
73         savefile.setBounds(20, 60, 200, 20);
74         fileName.setBounds(150, 60, 270, 20);
75
76         label.setBounds(20, 90, 200, 20);
77         EPR.setBounds(150, 90, 270, 20);
78
79         EPR.setText("http://127.0.0.1:8080/axis2/services/MTOMService");
80
81         send.setBounds(140, 120, 150, 20);
82
83         jTextArea.setBounds(20, 150, 400, 180);
84
85         browse.addActionListener(this);
86         send.addActionListener(this);
87
88         Container pane = parent.getContentPane();
89         this.setLayout(null);
90
91         pane.add(browse);
92
93         pane.add(send);
94         pane.add(jTextArea);
95         pane.add(EPR);
96         pane.add(fileFeild);
97         pane.add(label);
98         pane.add(savefile);
99         pane.add(fileName);
100
101     }
102
103     public void actionPerformed(ActionEvent JavaDoc e) {
104
105         if (e.getSource() == browse) {
106
107             int returnVal = jFileChooser.showDialog(this, "OK");
108
109             if (returnVal == JFileChooser.APPROVE_OPTION) {
110                 file = jFileChooser.getSelectedFile();
111                 if (file.getAbsolutePath() != null) {
112                     fileFeild.setText(file.getAbsolutePath());
113                 }
114             } else {
115
116             }
117
118             jFileChooser.setSelectedFile(null);
119
120         }
121         if (e.getSource() == send) {
122             if (fileName.getText() != null) {
123                 deriredFileName = fileName.getText();
124             }
125             if (file == null) {
126                 JOptionPane.showMessageDialog(parent,
127                         "Attachments should not be null.", " error",
128                         JOptionPane.ERROR_MESSAGE);
129
130             } else if (("").equals(EPR.getText())) {
131                 JOptionPane.showMessageDialog(parent, "END Point null",
132                         " error", JOptionPane.ERROR_MESSAGE);
133
134             } else {
135                 EPRName = EPR.getText();
136                 this.send(deriredFileName);
137             }
138
139         }
140     }
141
142     public void send(String JavaDoc fileName) {
143
144         MTOMClientModel mtomTest = new MTOMClientModel();
145
146         try {
147             mtomTest.setInputFile(file);
148             mtomTest.setTargetEPR(EPRName);
149             OMElement result = (OMElement) mtomTest.testEchoXMLSync(fileName);
150             jTextArea.setText(result.toString());
151         } catch (Exception JavaDoc e) {
152             e.printStackTrace(); //To change body of catch statement use File |
153
// Settings | File Templates.
154
}
155
156     }
157
158     class ImageFilter extends FileFilter JavaDoc {
159
160         //Accept all directories and all gif, jpg, tiff, or png files.
161
public boolean accept(File JavaDoc f) {
162             if (f.isDirectory()) {
163                 return true;
164             }
165
166             String JavaDoc extension = getExtension(f);
167             if (extension != null) {
168                 if (extension.equals("jpg") || extension.equals("JPEG"))
169                     return true;
170                 else {
171                     return false;
172                 }
173             }
174
175             return false;
176         }
177
178         public String JavaDoc getDescription() {
179             return null; //To change body of implemented methods use File |
180
// Settings | File Templates.
181
}
182
183         private String JavaDoc getExtension(File JavaDoc f) {
184             String JavaDoc ext = null;
185             String JavaDoc s = f.getName();
186             int i = s.lastIndexOf('.');
187
188             if (i > 0 && i < s.length() - 1) {
189                 ext = s.substring(i + 1).toLowerCase();
190             }
191             return ext;
192         }
193
194     }
195
196     //The description of this filter
197
public String JavaDoc getDescription() {
198         return "Just Images";
199     }
200
201 }
Popular Tags