Java by API/org.eclipse.swt.browser/Browser — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
- 1 Browser: addCloseWindowListener(CloseWindowListener arg0)
- 2 Browser: addLocationListener(CloseWindowListener arg0)
- 3 Browser.addProgressListener(CloseWindowListener arg0)
- 4 Browser.addStatusTextListener(CloseWindowListener arg0)
- 5 Browser: back()
- 6 Browser: forward()
- 7 Browser: setUrl(String url)
- 8 Browser: stop()
Browser: addCloseWindowListener(CloseWindowListener arg0)
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}
Browser: addLocationListener(CloseWindowListener arg0)
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}
Browser.addProgressListener(CloseWindowListener arg0)
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}
Browser.addStatusTextListener(CloseWindowListener arg0)
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}
Browser: back()
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}
Browser: forward()
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}
Browser: setUrl(String url)
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.ruposite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MainClass {
public static void main(String[] a) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(250, 200);
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.NONE);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(100, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(6, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
shell.setDefaultButton(button);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Browser: stop()
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class MainClass {
private static final String AT_REST = "Ready";
public MainClass(){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Advanced Browser");
createContents(shell, "http://www.jexp.ru");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void createContents(Shell shell, String location) {
shell.setLayout(new FormLayout());
Composite controls = new Composite(shell, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
controls.setLayoutData(data);
Label status = new Label(shell, SWT.NONE);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
status.setLayoutData(data);
final Browser browser = new Browser(shell, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(controls);
data.bottom = new FormAttachment(status);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
browser.setLayoutData(data);
controls.setLayout(new GridLayout(7, false));
Button button = new Button(controls, SWT.PUSH);
button.setText("Back");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.back();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Forward");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.forward();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Refresh");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.refresh();
}
});
button = new Button(controls, SWT.PUSH);
button.setText("Stop");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.stop();
}
});
final Text url = new Text(controls, SWT.BORDER);
url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
url.setFocus();
button = new Button(controls, SWT.PUSH);
button.setText("Go");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
browser.setUrl(url.getText());
}
});
Label throbber = new Label(controls, SWT.NONE);
throbber.setText(AT_REST);
shell.setDefaultButton(button);
browser.addCloseWindowListener(new AdvancedCloseWindowListener());
browser.addLocationListener(new AdvancedLocationListener(url));
browser.addProgressListener(new AdvancedProgressListener(throbber));
browser.addStatusTextListener(new AdvancedStatusTextListener(status));
if (location != null) {
browser.setUrl(location);
}
}
class AdvancedCloseWindowListener implements CloseWindowListener {
public void close(WindowEvent event) {
((Browser) event.widget).getShell().close();
}
}
class AdvancedLocationListener implements LocationListener {
private Text location;
public AdvancedLocationListener(Text text) {
location = text;
}
public void changing(LocationEvent event) {
location.setText("Loading " + event.location + "...");
}
public void changed(LocationEvent event) {
location.setText(event.location);
}
}
class AdvancedProgressListener implements ProgressListener {
private Label progress;
public AdvancedProgressListener(Label label) {
progress = label;
}
public void changed(ProgressEvent event) {
if (event.total != 0) {
int percent = (int) (event.current / event.total);
progress.setText(percent + "%");
} else {
progress.setText("");
}
}
public void completed(ProgressEvent event) {
progress.setText(AT_REST);
}
}
class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
status = label;
}
public void changed(StatusTextEvent event) {
status.setText(event.text);
}
}
public static void main(String[] args) {
new MainClass();
}
}