1 | /**
|
---|
2 | * Browser.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 |
|
---|
19 | package org.expeditee.items.widgets;
|
---|
20 |
|
---|
21 | import java.net.MalformedURLException;
|
---|
22 | import java.util.List;
|
---|
23 |
|
---|
24 | import org.expeditee.gui.MessageBay;
|
---|
25 | import org.expeditee.items.Text;
|
---|
26 | import org.lobobrowser.gui.BrowserPanel;
|
---|
27 | import org.lobobrowser.main.PlatformInit;
|
---|
28 |
|
---|
29 | public class Browser extends DataFrameWidget {
|
---|
30 |
|
---|
31 | private BrowserPanel _browser;
|
---|
32 |
|
---|
33 | public Browser(Text source, String[] args) {
|
---|
34 | super(source, new BrowserPanel(), 100, 500, -1, 100, 300, -1);
|
---|
35 |
|
---|
36 | try {
|
---|
37 | // This optional step initializes logging so only warnings
|
---|
38 | // are printed out.
|
---|
39 | PlatformInit.getInstance().initLogging(false);
|
---|
40 | // This step is necessary for extensions to work:
|
---|
41 | PlatformInit.getInstance().init(false, false);
|
---|
42 | PlatformInit.getInstance().initLookAndFeel();
|
---|
43 | PlatformInit.getInstance().initSecurity();
|
---|
44 | } catch (Exception e) {
|
---|
45 | // TODO Auto-generated catch block
|
---|
46 | e.printStackTrace();
|
---|
47 | }
|
---|
48 |
|
---|
49 | _browser = (BrowserPanel) _swingComponent;
|
---|
50 | String url = "http://www.google.com";
|
---|
51 | List<String> data = getSource().getData();
|
---|
52 | if (data != null && data.size() > 0) {
|
---|
53 | url = data.get(0);
|
---|
54 | }
|
---|
55 | navigate(url);
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | protected String[] getArgs() {
|
---|
60 | return null;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public void navigate(String url) {
|
---|
64 | try {
|
---|
65 | getSource().setData(url);
|
---|
66 | _browser.navigate(url);
|
---|
67 | } catch (MalformedURLException e) {
|
---|
68 | MessageBay.errorMessage("Could not navigate to " + url);
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public void setSourceData(List<String> data) {
|
---|
74 | super.setSourceData(data);
|
---|
75 | if (data != null && data.size() > 0) {
|
---|
76 | navigate(data.get(0));
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | protected List<String> getData() {
|
---|
82 | return _textRepresentation.getData();
|
---|
83 | }
|
---|
84 |
|
---|
85 | }
|
---|