source: trunk/src/org/expeditee/items/widgets/WebBrowser.java@ 963

Last change on this file since 963 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.5 KB
Line 
1/**
2 * WebBrowser.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items.widgets;
20
21import java.util.List;
22
23import javax.swing.SwingUtilities;
24
25import org.expeditee.gui.MessageBay;
26import org.expeditee.items.Text;
27
28import chrriis.common.UIUtils;
29import chrriis.dj.nativeswing.NativeSwing;
30import chrriis.dj.nativeswing.swtimpl.NativeInterface;
31import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
32import com.sun.jna.Native;
33
34/**
35 * This class is used to create an embedded web browser
36 * widget to be used within Expeditee.
37 * @author kgas1 - 31/01/2012
38 **/
39public class WebBrowser extends DataFrameWidget {
40
41 private JWebBrowser _webBrowser;
42
43 String[] _args = null;
44
45 public WebBrowser(Text source, String[] args) {
46
47 //pass the JWebBrowser a constructor to destroy on finalization so the
48 //web browser can be reconstructed every time we leave the frame that it is
49 //located on and want to go back to that frame. Also allows
50 //us to move the browser around the frame and resize it. - kgas1 31/01/2012.
51
52 super(source, new JWebBrowser(JWebBrowser.destroyOnFinalization(),JWebBrowser.constrainVisibility()),
53 100, 500, -1, 100, 300, -1);
54
55
56 NativeSwing.initialize();
57 UIUtils.setPreferredLookAndFeel();
58 NativeInterface.open();
59 _webBrowser = (JWebBrowser) _swingComponent;
60
61 if(args != null){
62 _args = args.clone();
63
64 for(int i = 0; i < args.length; i++){
65 String[] split = args[i].split("=");
66
67 if(split[0].equals("locationBar")){
68 _webBrowser.setLocationBarVisible(Boolean.parseBoolean(split[1]));
69 }
70 else if(split[0].equals("buttonBar")){
71 _webBrowser.setButtonBarVisible(Boolean.parseBoolean(split[1]));
72 }
73 else if(split[0].equals("menuBar")){
74 _webBrowser.setMenuBarVisible(Boolean.parseBoolean(split[1]));
75 }
76 else if(split[0].equals("statusBar")){
77 _webBrowser.setStatusBarVisible(Boolean.parseBoolean(split[1]));
78 }
79 }
80 }
81
82 final String url;
83
84 List<String> data = getData();
85
86 if(data != null && data.size() > 0) {
87 url = data.get(0);
88 }
89 else {
90 System.out.println("no data can be found");
91 url = "http://www.waikato.ac.nz";
92 }
93
94 navigate(url);
95 }
96
97
98 @Override
99 protected String[] getArgs() {
100 return _args;
101
102 }
103
104 public void navigate(final String url) {
105 try
106 {
107 SwingUtilities.invokeLater(new Runnable() {
108 public void run(){
109 getSource().setData(url);
110 _webBrowser.navigate(url);
111 }
112 });
113
114 }
115 catch(Exception e) {
116 MessageBay.errorMessage(e.getMessage());
117 }
118
119 }
120
121 @Override
122 public void setSourceData(List<String> data) {
123 super.setSourceData(data);
124 if(data != null && data.size() > 0) {
125 navigate(data.get(0));
126 }
127 return;
128 }
129
130
131 @Override
132 protected List<String> getData() {
133 return _textRepresentation.getData();
134 }
135
136}
Note: See TracBrowser for help on using the repository browser.