View Javadoc

1   /*
2    * Copyright (c) 2005 Regents of the University of California (Regents). Created
3    * by TELS, Graduate School of Education, University of California at Berkeley.
4    *
5    * This software is distributed under the GNU Lesser General Public License, v2.
6    *
7    * Permission is hereby granted, without written agreement and without license
8    * or royalty fees, to use, copy, modify, and distribute this software and its
9    * documentation for any purpose, provided that the above copyright notice and
10   * the following two paragraphs appear in all copies of this software.
11   *
12   * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14   * PURPOSE. THE SOFTWAREAND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
15   * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
16   * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17   *
18   * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
19   * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
20   * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
21   * REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22   */
23  package net.sf.sail.common.apps;
24  
25  import java.util.logging.Logger;
26  
27  import java.awt.BorderLayout;
28  import java.awt.Container;
29  import java.io.File;
30  import java.io.IOException;
31  import java.net.MalformedURLException;
32  import java.net.URL;
33  
34  import javax.swing.ImageIcon;
35  import javax.swing.JFrame;
36  import javax.swing.JLabel;
37  import javax.swing.JTextArea;
38  
39  import net.sf.sail.core.util.BinaryUtils;
40  
41  /**
42   * @author turadg
43   */
44  public class TestJWS extends JFrame {
45  	/**
46  	 * Logger for this class
47  	 */
48  	private static final Logger logger = Logger.getLogger(TestJWS.class
49  			.getName());
50  
51  	private static final long serialVersionUID = 5826896226244741246L;
52  
53  	URL checkboxSource;
54  
55  	URL badxSource;
56  
57  	URL dlSource;
58  	{
59  		try {
60  			checkboxSource = new URL(
61  					"http://www2.sls.lib.il.us/CTS/checkmark.gif");
62  			badxSource = new URL(
63  					"http://audilab.bmed.mcgill.ca/~funnell/quiz/gif/red_x.GIF");
64  			dlSource = new URL(
65  					"http://turadg.wisetest.org/tmp/jnlp/curnit16146.zip");
66  		} catch (MalformedURLException e) {
67  			e.printStackTrace();
68  		}
69  	}
70  
71  	StringBuffer messageBuffer = new StringBuffer("Messages:\n");
72  
73  	boolean success = true;
74  
75  	/**
76  	 * TODO ADD COMMENT
77  	 */
78  	public void buildContent() {
79  		Container contentPane = getContentPane();
80  		contentPane.setLayout(new BorderLayout());
81  		ImageIcon imageIcon;
82  		if (success)
83  			imageIcon = new ImageIcon(checkboxSource);
84  		else
85  			imageIcon = new ImageIcon(badxSource);
86  		contentPane.add(new JLabel(imageIcon), BorderLayout.NORTH);
87  		JTextArea messageArea = new JTextArea(messageBuffer.toString());
88  		messageArea.setLineWrap(true);
89  		contentPane.add(messageArea, BorderLayout.CENTER);
90  		setSize(400, 600);
91  	}
92  
93  	public static void main(String[] args) {
94  		TestJWS tester = new TestJWS();
95  		tester.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
96  		tester.check();
97  		tester.buildContent();
98  		tester.setVisible(true);
99  	}
100 
101 	/**
102 	 * TODO ADD COMMENT
103 	 */
104 	private void check() {
105 		try {
106 			File downloaded = BinaryUtils.tempFileForUrl(dlSource);
107 			if (!downloaded.exists())
108 				throw new IOException("failed to download");
109 			messageBuffer.append("download success");
110 		} catch (IOException e) {
111 			logger.severe("exception: " + e); //$NON-NLS-1$
112 			success = false;
113 			messageBuffer.append("while downloading:\n  " + e);
114 		}
115 	}
116 
117 }