001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: import java.io.File;
031: import java.io.FileOutputStream;
032:
033: /**
034: * A <code>WebBrowser</code> inserts a web browser object in your application.
035: * <p>
036: * <b>Example:</b> <br>
037: * <img src="doc-files/WebBrowser-1.png"> <br>
038: *
039: * <pre>
040: * Dialog dlg = new Dialog("WebBrowser Test");
041: * dlg.setBounds(20, 20, 640, 480);
042: *
043: * WebBrowser wb = new WebBrowser();
044: * wb.setBounds(25, 25, 590, 430);
045: * wb.setLocation("http://www.thinwire.com");
046: * dlg.getChildren().add(wb);
047: * dlg.setVisible(true);
048: * </pre>
049: *
050: * </p>
051: * <p>
052: * <b>Keyboard Navigation:</b><br>
053: * <table border="1">
054: * <tr>
055: * <td>KEY</td>
056: * <td>RESPONSE</td>
057: * <td>NOTE</td>
058: * </tr>
059: * </table>
060: * </p>
061: *
062: * @author Joshua J. Gertzen
063: */
064: // TODO Nice to haves on the client side Iframe - Back/Forward/Stop/Refresh.
065: // i.e. Browser like functionality.
066: public class WebBrowser extends AbstractComponent {
067: public static final String PROPERTY_LOCATION = "location";
068:
069: private String location = "";
070: private File content;
071:
072: public WebBrowser() {
073: }
074:
075: public WebBrowser(String location) {
076: this .setLocation(location);
077: }
078:
079: public void setLocation(String location) {
080: String oldLocation = this .location;
081: location = location == null ? "" : location;
082: this .location = location;
083: firePropertyChange(this , PROPERTY_LOCATION, oldLocation,
084: location);
085:
086: if (this .content != null) {
087: this .content.delete();
088: this .content = null;
089: }
090: }
091:
092: public String getLocation() {
093: return this .location;
094: }
095:
096: /**
097: * A convenience method that writes out the HTML passed into a temp file and
098: * then sets the location of the component to the temp file.
099: *
100: * @param content
101: * HTML to display in the <code>WebBrowser</code>
102: */
103: public void setContent(String content) {
104: try {
105: if (this .content != null) {
106: this .content.delete();
107: this .content = null;
108: }
109:
110: File tmpFile = File.createTempFile("ThinWire_WebBrowser_",
111: ".html");
112: tmpFile.deleteOnExit();
113: FileOutputStream fos = new FileOutputStream(tmpFile);
114: fos.write(content.getBytes());
115: fos.flush();
116: fos.close();
117: setLocation(tmpFile.getCanonicalPath());
118: this .content = tmpFile;
119: } catch (Exception e) {
120: throw new RuntimeException(e);
121: }
122: }
123: }
|