});
*/
final Label status = new Label(parent, SWT.NONE);
final ProgressBar progressBar = new ProgressBar(parent, SWT.NONE);
FormData data = new FormData();
data.top = new FormAttachment(0, 5);
toolbar.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(canvas, 5, SWT.DEFAULT);
data.bottom = new FormAttachment(status, -5, SWT.DEFAULT);
try
{
browser = new Browser(parent, SWT.NONE);
browser.setLayoutData(data);
}
catch(SWTError e)
{
// Browser widget could not be instantiated
Label label = new Label(parent, SWT.CENTER | SWT.WRAP);
label.setText(getResourceString("Browser Not Created (" + e.toString() + ")" ));
label.setLayoutData(data);
}
data = new FormData();
data.width = 24;
data.height = 24;
data.top = new FormAttachment(0, 5);
data.right = new FormAttachment(100, -5);
canvas.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(toolbar, 0, SWT.TOP);
data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
location.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 5);
data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT);
data.bottom = new FormAttachment(100, -5);
status.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100, -5);
data.bottom = new FormAttachment(100, -5);
progressBar.setLayoutData(data);
location.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {}
public void focusLost(FocusEvent e) {
locationSelectedOnce = false;
}
}
);
location.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
if (!locationSelectedOnce) {
System.out.println("No text selected; selecting");
location.selectAll();
locationSelectedOnce = true;
}
}
public void mouseDown(MouseEvent e) {}
public void mouseDoubleClick(MouseEvent e) {}
});
if(browser != null)
{
itemBack.setEnabled(browser.isBackEnabled());
itemForward.setEnabled(browser.isForwardEnabled());
Listener listener = new Listener(){
public void handleEvent(Event event)
{
//System.out.println("Event fired");
ToolItem item = (ToolItem) event.widget;
if (item == itemBack) {
//System.out.println("Back pressed");
browser.back();
}
else if (item == itemForward) {
//System.out.println("Forward pressed");
browser.forward();
}
else if (item == itemStop){
//System.out.println("Stop pressed");
browser.stop();
}
else if (item == itemRefresh) {
//System.out.println("Refresh pressed");
browser.refresh();
}
else if (item == itemGo) {
//System.out.println("Go pressed");
browser.setUrl(location.getText());
}
else if (item == itemHome) {
//System.out.println("Home pressed");
browser.setUrl(getProjectURL());
}
}
};
browser.addLocationListener(new LocationListener(){
public void changed(LocationEvent event)
{
busy = true;
if (event.top)
location.setText(event.location);
}
public void changing(LocationEvent event)
{
}
});
browser.addProgressListener(new ProgressListener(){
public void changed(ProgressEvent event)
{
if(event.total == 0)
return;
int ratio = event.current * 100 / event.total;
progressBar.setSelection(ratio);
busy = event.current != event.total;
if(!busy)
{
index = 0;
canvas.redraw();
}
}
public void completed(ProgressEvent event)
{
itemBack.setEnabled(browser.isBackEnabled());
itemForward.setEnabled(browser.isForwardEnabled());
progressBar.setSelection(0);
busy = false;
index = 0;
canvas.redraw();
}
});