001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.tool.info.internal.display;
018:
019: import net.refractions.udig.tool.info.InfoDisplay;
020: import net.refractions.udig.tool.info.InfoPlugin;
021: import net.refractions.udig.tool.info.LayerPointInfo;
022:
023: import org.eclipse.jface.action.Action;
024: import org.eclipse.jface.action.ToolBarManager;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.browser.Browser;
027: import org.eclipse.swt.browser.LocationAdapter;
028: import org.eclipse.swt.browser.LocationEvent;
029: import org.eclipse.swt.browser.StatusTextEvent;
030: import org.eclipse.swt.browser.StatusTextListener;
031: import org.eclipse.swt.browser.TitleEvent;
032: import org.eclipse.swt.browser.TitleListener;
033: import org.eclipse.swt.custom.ViewForm;
034: import org.eclipse.swt.widgets.Composite;
035: import org.eclipse.swt.widgets.Control;
036: import org.eclipse.swt.widgets.ToolBar;
037:
038: /**
039: * Nested browser used to display LayerPointInfo.
040: *
041: * @author Jody Garnett
042: * @since 0.3
043: */
044: public class BrowserInfoDisplay extends InfoDisplay {
045:
046: /** <code>browser</code> field */
047: protected Browser browser;
048:
049: private Action backAction = new Action("Back") { //$NON-NLS-1$
050: public void run() {
051: browser.back();
052: }
053: };
054: private Action forwardAction = new Action("Forward") { //$NON-NLS-1$
055: public void run() {
056: browser.forward();
057: }
058: };
059:
060: private Action stopAction = new Action("Stop") { //$NON-NLS-1$
061: public void run() {
062: browser.stop();
063: // cancel any partial progress.
064: // getViewSite().getActionBars().getStatusLineManager().getProgressMonitor().done();
065: }
066: };
067:
068: private Action refreshAction = new Action("Refresh") { //$NON-NLS-1$
069: public void run() {
070: browser.refresh();
071: }
072: };
073: /** <code>DEBUG</code> field */
074: static final protected boolean DEBUG = false;
075: //private CLabel label;
076: private ViewForm viewForm;
077:
078: /*
079: * Nested viewForm containing browser, locationbar and toolbar
080: * @return embded browser
081: */
082: public Control getControl() {
083: return viewForm;
084: }
085:
086: /*
087: * Set up w/ an embeded brower.
088: */
089: public void createDisplay(Composite parent) {
090: viewForm = new ViewForm(parent, SWT.NONE);
091:
092: //label= new CLabel( viewForm, SWT.NONE);
093: //viewForm.setTopLeft( label );
094:
095: ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.WRAP);
096: viewForm.setTopCenter(toolBar);
097:
098: browser = createBrowser(viewForm, toolBar);
099: browser.setUrl("about:blank"); //$NON-NLS-1$
100:
101: viewForm.setContent(browser);
102: }
103:
104: /**
105: * Focus the browser onto LayerPointInfo.getRequestURL.
106: *
107: * @see net.refractions.udig.tool.info.InfoDisplay#setInfo(net.refractions.udig.project.render.LayerPointInfo)
108: * @param info
109: */
110: public void setInfo(LayerPointInfo info) {
111: if (info == null || info.getRequestURL() == null) {
112: browser.setVisible(false);
113: } else {
114: browser.setVisible(true);
115: // FIXME: Make the request in a separate thread?
116: browser.setUrl(info.getRequestURL().toString());
117: }
118: }
119:
120: private Browser createBrowser(Composite parent,
121: final ToolBar toolbar) {
122: try {
123: browser = new Browser(parent, SWT.NONE);
124: } catch (Exception e) {
125: InfoPlugin.log("Could not create browser", e); //$NON-NLS-1$
126: }
127: /* FIXME Help Jesse! I need to find my status bar :(
128: browser.addProgressListener( new ProgressAdapter() {
129: IProgressMonitor monitor = toolbar.getStatusLineManager().getProgressMonitor();
130: boolean working = false;
131: int workedSoFar;
132: public void changed(ProgressEvent event) {
133: if (DEBUG) {
134: System.out.println("changed: " + event.current + "/" + event.total);
135: }
136: if (event.total == 0) return;
137: if (!working) {
138: if (event.current == event.total) return;
139: monitor.beginTask("", event.total); //$NON-NLS-1$
140: workedSoFar = 0;
141: working = true;
142: }
143: monitor.worked(event.current - workedSoFar);
144: workedSoFar = event.current;
145: }
146: public void completed(ProgressEvent event) {
147: if (DEBUG) {
148: System.out.println("completed: " + event.current + "/" + event.total);
149: }
150: monitor.done();
151: working = false;
152: }
153: });*/
154: browser.addStatusTextListener(new StatusTextListener() {
155: // IStatusLineManager status = toolbar.getStatusLineManager();
156: public void changed(StatusTextEvent event) {
157: /*
158: if (DEBUG) {
159: System.out.println("status: " + event.text);
160: }
161: status.setMessage(event.text);
162: */
163: }
164: });
165: browser.addLocationListener(new LocationAdapter() {
166: public void changed(LocationEvent event) {
167: if (event.top) {
168: //label.setToolTipText( browser.getUrl() );
169: }
170: }
171: });
172: browser.addTitleListener(new TitleListener() {
173: public void changed(TitleEvent event) {
174: //label.setText( event.title );
175: }
176: });
177:
178: // Hook the navigation actons as handlers for the retargetable actions
179: // defined in BrowserActionBuilder.
180: ToolBarManager tbmanager = new ToolBarManager(toolbar);
181: tbmanager.add(backAction);
182: tbmanager.add(forwardAction);
183: tbmanager.add(stopAction);
184: tbmanager.add(refreshAction);
185:
186: return browser;
187: }
188: }
|