1 package org
.argeo
.cms
.desktop
.mini
;
3 import java
.net
.MalformedURLException
;
6 import org
.eclipse
.swt
.SWT
;
7 import org
.eclipse
.swt
.browser
.Browser
;
8 import org
.eclipse
.swt
.browser
.LocationEvent
;
9 import org
.eclipse
.swt
.browser
.LocationListener
;
10 import org
.eclipse
.swt
.browser
.TitleListener
;
11 import org
.eclipse
.swt
.events
.SelectionAdapter
;
12 import org
.eclipse
.swt
.events
.SelectionEvent
;
13 import org
.eclipse
.swt
.graphics
.Point
;
14 import org
.eclipse
.swt
.layout
.FillLayout
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.swt
.widgets
.Text
;
22 public class MiniBrowser
{
24 private Text addressT
;
25 private Browser browser
;
27 public MiniBrowser(Composite parent
, int style
) {
28 parent
.setLayout(new GridLayout());
30 Composite toolBar
= new Composite(parent
, SWT
.NONE
);
31 toolBar
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
32 toolBar
.setLayout(new FillLayout());
33 addressT
= new Text(toolBar
, SWT
.SINGLE
| SWT
.BORDER
);
34 // addressT.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
35 addressT
.addSelectionListener(new SelectionAdapter() {
38 public void widgetDefaultSelected(SelectionEvent e
) {
39 setUrl(addressT
.getText().trim());
43 browser
= new Browser(parent
, SWT
.WEBKIT
);
44 browser
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
45 browser
.addLocationListener(new LocationListener() {
48 public void changing(LocationEvent event
) {
52 public void changed(LocationEvent event
) {
54 MiniBrowser
.this.url
= new URL(browser
.getUrl());
55 addressT
.setText(url
.toString());
56 } catch (MalformedURLException e
) {
57 addressT
.setText(e
.getMessage());
58 throw new IllegalArgumentException("Cannot interpet new URL", e
);
65 public void setUrl(URL url
) {
68 addressT
.setText(url
.toString());
70 browser
.setUrl(url
.toString());
73 public void setUrl(String url
) {
76 } catch (MalformedURLException e
) {
79 setUrl(new URL("http://"+url
));
81 } catch (MalformedURLException e1
) {
84 throw new IllegalArgumentException("Cannot interpret URL " + url
, e
);
88 public void addTitleListener(TitleListener titleListener
) {
89 browser
.addTitleListener(titleListener
);
92 public static void main(String
[] args
) {
93 Display display
= Display
.getCurrent() == null ?
new Display() : Display
.getCurrent();
94 Shell shell
= new Shell(display
, SWT
.SHELL_TRIM
);
96 MiniBrowser miniBrowser
= new MiniBrowser(shell
, SWT
.NONE
);
97 miniBrowser
.addTitleListener(e
-> shell
.setText(e
.title
));
98 String url
= args
.length
> 0 ? args
[0] : "http://www.argeo.org";
99 miniBrowser
.setUrl(url
);
102 shell
.setSize(new Point(800, 480));
103 while (!shell
.isDisposed()) {
104 if (!display
.readAndDispatch())