1 16 package sample.mtom.client; 17 18 import org.apache.axis2.om.OMElement; 19 20 import javax.swing.*; 21 import javax.swing.filechooser.FileFilter ; 22 import java.awt.*; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.io.File ; 26 27 public class UserInterface extends JPanel implements ActionListener { 28 29 JButton browse; 30 31 JButton send; 32 33 JTextArea jTextArea; 34 35 JFileChooser jFileChooser; 36 37 File 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 deriredFileName = null; 50 51 private String 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 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 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 e) { 152 e.printStackTrace(); } 155 156 } 157 158 class ImageFilter extends FileFilter { 159 160 public boolean accept(File f) { 162 if (f.isDirectory()) { 163 return true; 164 } 165 166 String 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 getDescription() { 179 return null; } 182 183 private String getExtension(File f) { 184 String ext = null; 185 String 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 public String getDescription() { 198 return "Just Images"; 199 } 200 201 } | Popular Tags |