Import java. util. arrayList; <br/> import java. util. list; </p> <p> import org. apache. commons. lang. stringUtils; <br/> import org. eclipse. swt. SWT; <br/> import org. eclipse. swt. browser. browser; <br/> import org. eclipse. swt. browser. closeWindowListener; <br/> import org. eclipse. swt. browser. locationAdapter; <br/> import org. eclipse. swt. browser. locationEvent; <br/> import org. eclipse. swt. browser. openWindowListener; <Br/> import org. eclipse. swt. browser. progressEvent; <br/> import org. eclipse. swt. browser. progressListener; <br/> import org. eclipse. swt. browser. statusTextEvent; <br/> import org. eclipse. swt. browser. statusTextListener; <br/> import org. eclipse. swt. browser. titleEvent; <br/> import org. eclipse. swt. browser. titleListener; <br/> import org. eclipse. swt. browser. using wevent; <br/> import org. eclipse. swt. custom. CIA Bel; <br/> import org. eclipse. swt. custom. CTabFolder; <br/> import org. eclipse. swt. custom. CTabItem; <br/> import org. eclipse. swt. events. keyAdapter; <br/> import org. eclipse. swt. events. keyEvent; <br/> import org. eclipse. swt. events. mouseAdapter; <br/> import org. eclipse. swt. events. mouseEvent; <br/> import org. eclipse. swt. events. selectionAdapter; <br/> import org. eclipse. swt. events. selectionEvent; <br/> import Org. eclipse. swt. graphics. point; <br/> import org. eclipse. swt. layout. formAttachment; <br/> import org. eclipse. swt. layout. formData; <br/> import org. eclipse. swt. layout. formLayout; <br/> import org. eclipse. swt. layout. gridData; <br/> import org. eclipse. swt. layout. gridLayout; <br/> import org. eclipse. swt. widgets. button; <br/> import org. eclipse. swt. widgets. combo; <br/> import org. eclipse. swt. widgets. composite; <Br/> import org. eclipse. swt. widgets. display; <br/> import org. eclipse. swt. widgets. label; <br/> import org. eclipse. swt. widgets. progressBar; <br/> import org. eclipse. ui. forms. widgets. formToolkit; </p> <p> import com. sinosoft. media360.server. domain. news_Document; <br/> import com. sinosoft. media360.util. newActionMenu; <br/> import com. swtdesigner. SWTResourceManager; </p> <p> public class BrowserComposite exten Ds Composite {<br/> private static final String default_blk_url = "about: blank"; <br/> private static final String BROWSER_DATA_STATUS = "status "; <br/> private List <String> invalidTitleList = new ArrayList <String> (); </p> <p> private final static FormToolkit toolkit = new FormToolkit (Display. getCurrent (); <br/> private static Combo combUrl; <br/> private CTabFolder browserFolder; <br/> private CTabIte M newTab; <br/> private CLabel statusLabel; <br/> private ProgressBar progressBar; </p> <p >{< br/> invalidTitleList. add (default_blk_url); <br/> invalidTitleList. add ("503 Service Unavailable"); <br/> invalidTitleList. add ("navigation canceled"); <br/> invalidTitleList. add ("Internet Explorer cannot display this webpage"); <br/> invalidTitleList. add ("this page cannot be displayed "); <br/>}</p> <p>/** <br/> * Create the composite <br/> * @ param parent <br/> * @ Param style <br/> */<br/> public BrowserComposite (Composite parent, int style) {<br/> super (parent, style ); <br/> setLayout (new FormLayout (); <br/> toolkit. adapt (this); <br/> toolkit. paintBordersFor (this); </p> <p> final Composite composite = toolkit. createComposite (this, SWT. NO_TRIM | SWT. RESIZE); <br/> final GridLayout gridLayout = new GridLayout (); <br/> gridLayout. horizontalSpacing = 2; <br/> gridL Ayout. numColumns = 7; <br/> composite. setLayout (gridLayout); <br/> final FormData fd_composite = new FormData (); <br/> fd_composite.right = new FormAttachment (100,-5 ); <br/> fd_composite.bottom = new FormAttachment (0, 40); <br/> fd_composite.top = new FormAttachment (0, 0); <br/> fd_composite.left = new FormAttachment (0, 5); <br/> composite. setLayoutData (fd_composite); <br/> toolkit. paintBordersFor (compos Ite); </p> <p> final Button newBt = new Button (composite, SWT. NONE); <br/> newBt. setToolTipText ("new browser"); <br/> newBt. setImage (SWTResourceManager. getImage (BrowserComposite. class, "/tool_new.gif"); <br/> newBt. setLayoutData (new GridData (SWT. CENTER, SWT. CENTER, false, false); <br/> // open a new browser window <br/> newBt. addSelectionListener (new SelectionAdapter () {<br/> public void widgetSelected (final SelectionEvent e) {<Br/> openNewBrowserTab (); <br/>}< br/>}); <br/> toolkit. adapt (newBt, true, true); </p> <p> final Label label_1 = new Label (composite, SWT. SEPARATOR); <br/> label_1.setLayoutData (new GridData (SWT. DEFAULT, 35); <br/> toolkit. adapt (label_1, true, true); </p> <p> ButtonSelectionListener listener = new ButtonSelectionListener (); </p> <p> final Button backBt = new Button (composite, SWT. NONE); <br/> backBt. setLa YoutData (new GridData (SWT. CENTER, SWT. CENTER, false, false); <br/> backBt. setImage (SWTResourceManager. getImage (BrowserComposite. class, "/back.gif"); <br/> backBt. addSelectionListener (listener); <br/> backBt. setToolTipText ("back"); <br/> toolkit. adapt (backBt, true, true); </p> <p> final Button forwardBt = new Button (composite, SWT. NONE); <br/> forwardBt. setImage (SWTResourceManager. getImage (BrowserComposite. Class, "/forward.gif"); <br/> forwardBt. addSelectionListener (listener); <br/> forwardBt. setToolTipText ("Forward"); <br/> forwardBt. setLayoutData (new GridData (SWT. CENTER, SWT. CENTER, false, false); <br/> toolkit. adapt (forwardBt, true, true); </p> <p> combUrl = new Combo (composite, SWT. BORDER); <br/> combUrl. setLayoutData (new GridData (GridData. FILL, GridData. CENTER, true, false); <br/> combUrl. setVisibleItemC Ount (25); <br/> combUrl. addSelectionListener (new SelectionAdapter () {<br/> @ Override <br/> public void widgetSelected (SelectionEvent e) {<br/> openEnteredUrl (false ); <br/>}< br/>}); <br/> combUrl. addKeyListener (new KeyAdapter () {<br/> // press Enter or press Enter to view the content <br/> public void keyPressed (final KeyEvent e) {<br/> if (e. keyCode = SWT. CR | e. keyCode = SWT. KEYPAD_CR) {<br/> openEnteredUrl (true); <br/>}< br/ >}< Br/>}); <br/> toolkit. adapt (combUrl, true, true); </p> <p> final Button refreshBt = new Button (composite, SWT. NONE); <br/> refreshBt. setImage (SWTResourceManager. getImage (BrowserComposite. class, "/tool_refresh.gif"); <br/> refreshBt. addSelectionListener (listener); <br/> refreshBt. setToolTipText ("refresh"); <br/> refreshBt. setLayoutData (new GridData (SWT. CENTER, SWT. CENTER, false, false); <br/> toolkit. adapt (RefreshBt, true, true); </p> <p> final Button stopBt = new Button (composite, SWT. NONE); <br/> stopBt. setImage (SWTResourceManager. getImage (BrowserComposite. class, "/stop.gif"); <br/> stopBt. addSelectionListener (listener); <br/> stopBt. setToolTipText ("stop"); <br/> stopBt. setLayoutData (new GridData (SWT. CENTER, SWT. CENTER, false, false); <br/> toolkit. adapt (stopBt, true, true); </p> <p> browserFolder = new CTa BFolder (this, SWT. BORDER); <br/> browserFolder. setMinimumCharacters (8); <br/> browserFolder. setSelectionBackground (SWTResourceManager. getColor (227,238,251); <br/> browserFolder. setTabHeight (25); <br/> browserFolder. addSelectionListener (new SelectionAdapter () {<br/> public void widgetSelected (final SelectionEvent e) {<br/> if (e. item = newTab) {<br/> openNewBrowserTab (); // new tab <br/>} else {<br/> Browser Browser = (Browser) (CTabItem) e. item). getControl (); <br/> if (browser! = Null) {<br/> String url = browser. getUrl (); <br/> if ("". equals (url) {<br/> url = default_blk_url; <br/>}< br/> combUrl. setText (url); <br/> if (url. equals (DEFAULT_BLANK_URL) {<br/> combUrl. setFocus (); <br/>}</p> <p> String status = (String) browser. getData (BROWSER_DATA_STATUS); <br/> if (status! = Null) {<br/> statusLabel. setText (status); <br/>}</p> <p> progressBar. setVisible (false); <br/>}< br/>}); </p> <p> browserFolder. addMouseListener (new MouseAdapter () {<br/> // double-click to close the selected browser window <br/> public void mouseDoubleClick (final MouseEvent e) {<br/> CTabItem tab = browserFolder. getItem (new Point (e. x, e. y); <br/> if (tab! = Null & tab! = NewTab) {<br/> tab. dispose (); <br/> if (browserFolder. getItemCount () = 1) {<br/> openNewBrowserTab (); <br/>}< br/>} else {<br/> openNewBrowserTab (); <br/>}< br/>}); <br/> final FormData fd_tabFolder = new FormData (); <br/> fd_tabFolder.left = new FormAttachment (composite, 0, SWT. LEFT); <br/> fd_tabFolder.right = new FormAttachment (composite, 0, SWT. RIGHT); <br/> fd_tabFolder.top = new FormAtta Chment (composite, 5, SWT. BOTTOM); <br/> browserFolder. setLayoutData (fd_tabFolder); <br/> toolkit. adapt (browserFolder, true, true); </p> <p> newTab = new CTabItem (browserFolder, SWT. NONE); <br/> // newTab. setText (""); <br/> newTab. setImage (SWTResourceManager. getImage (BrowserComposite. class, "/newTab.jpg"); <br/> newTab. setToolTipText ("new tab"); </p> <p> statusLabel = new CLabel (this, SWT. NONE); <br/> fd_tabFold Er. bottom = new FormAttachment (statusLabel,-5, SWT. TOP); <br/> final FormData fd_statusLabel = new FormData (); <br/> fd_statusLabel.left = new FormAttachment (browserFolder, 0, SWT. LEFT); <br/> fd_statusLabel.right = new FormAttachment (100,-210); <br/> fd_statusLabel.bottom = new FormAttachment (100,-5); <br/> statusLabel. setLayoutData (fd_statusLabel); <br/> toolkit. adapt (statusLabel, true, true); <br/> StatusLabel. setText ("status bar"); </p> <p> progressBar = new ProgressBar (this, SWT. NONE); <br/> final FormData fd_progressBar = new FormData (); <br/> fd_progressBar.bottom = new FormAttachment (statusLabel, 0, SWT. BOTTOM); <br/> fd_progressBar.left = new FormAttachment (100,-200); <br/> fd_progressBar.right = new FormAttachment (browserFolder, 0, SWT. RIGHT); <br/> progressBar. setLayoutData (fd_progressBar); <br/> Toolkit. adapt (progressBar, true, true); </p> <p> openNewBrowserTab (); <br/>}</p> <p> private void addUrlToCombo (String url) {<br/> if (! Default_blk_url.equals (url) {<br/> int index = combUrl. indexOf (url); <br/> if (index> 0) {<br/> combUrl. remove (index); <br/>}< br/> if (index! = 0) {<br/> combUrl. add (url, 0); <br/>}< br/> combUrl. select (0); <br/> if (combUrl. getItemCount ()> 50) {<br/> combUrl. remove (50, combUrl. getItemCount ()-1 ); <br/>}</p> <p>/** <br/> * Open the webpage <br/> * @ param newTabItem whether to open <br/> */<br/> private void openEnteredUrl (boolean newTabItem) on the new tab) {<br/> String url = combUrl. getText (); <br/> if (! ("". Equals (url) | default_blk_url.equals (url) {<br/> Browser browser = null; <br/> CTabItem tabItem = browserFolder. getSelection (); <br/> String itemTitle = tabItem. getToolTipText (); <br/> if (newTabItem &&! InvalidTitleList. contains (itemTitle) {<br/> browser = openNewBrowserTab (); <br/>}else {<br/> browser = (Browser) tabItem. getControl (); <br/>}< br/> browser. setUrl (url); <br/> CTabItem item = (CTabFolder) browser. getParent ()). getSelection (); <br/> item. setText (StringUtils. abbreviate (url, 20); <br/> item. setToolTipText (url); <br/> addUrlToCombo (url ); <br/>}</p> <p>/** <br/> * open a new tab <br/> * @ retur N new tab's Broser object <br/> */<br/> private Browser openNewBrowserTab () {<br/> final CTabItem browserTab = new CTabItem (browserFolder, SWT. NONE, browserFolder. getItemCount ()-1); <br/> browserTab. setShowClose (true); <br/> browserTab. setImage (SWTResourceManager. getImage (BrowserComposite. class, "/ie.gif"); <br/> browserFolder. setSelection (browserTab); </p> <p> final Browser browser = new Browser (browserFolder, SWT. NONE); <br/> initialize (browser); <br/> browserTab. setText (default_blk_url); <br/> browserTab. setToolTipText (DEFAULT_BLANK_URL); <br/> combUrl. setText (default_blk_url); <br/> combUrl. setFocus (); <br/> toolkit. adapt (browser, true, true); <br/> browserTab. setControl (browser); <br/> return browser; <br/>}</p> <p>/** register initialize wevent listeners */<br/> private void initialize (final Browser browser) {<Br/> browser. addOpenWindowListener (new OpenWindowListener () {// open a new browser window event <br/> public void open (javaswevent event) {<br/> event. browser = openNewBrowserTab (); <br/>}< br/>}); </p> <p> browser. addCloseWindowListener (new CloseWindowListener () {// close the Browser event <br/> public void close (expose wevent event) {<br/> browser Browser = (Browser) event. widget; <br/> (CTabFolder) browser. getParent ()). getSelection (). Dispose (); <br/>}< br/>}); <br/> browser. addProgressListener (new ProgressListener () {// load webpage events <br/> public void changed (ProgressEvent event) {<br/> if (browserFolder. getSelection (). getControl () = browser) {<br/> if (! ProgressBar. isVisible () {<br/> progressBar. setVisible (true); <br/>}< br/> if (event. current <event. total) {<br/> progressBar. setMaximum (event. total); <br/> progressBar. setSelection (event. current); <br/>}else {<br/> progressBar. setVisible (false); <br/>}</p> <p> public void completed (ProgressEvent event) {<br/> if (browserFolder. getSelection (). getControl () = browser) <br/> progressBar. se TVisible (false); <br/>}< br/>}); <br/> browser. addStatusTextListener (new StatusTextListener () {// status bar change event <br/> public void changed (StatusTextEvent event) {<br/> browser. setData (BROWSER_DATA_STATUS, event. text); <br/> if (browserFolder. getSelection (). getControl () = browser) {<br/> statusLabel. setText (event. text); <br/>}< br/>}); <br/> browser. addTitleListener (new TitleListener () {// Title change event <br/> Public void changed (TitleEvent event) {<br/> CTabItem item = (CTabFolder) browser. getParent ()). getSelection (); <br/> item. setText (StringUtils. abbreviate (event. title, 20); <br/> item. setToolTipText (event. title); <br/>}< br/>}); </p> <p> browser. addLocationListener (new LocationAdapter () {// register an address change event for the browser <br/> @ Override <br/> public void changed (LocationEvent e) {<br/> if (e. top) {<br/> addUrlToCombo (e. locat Ion); <br/>}< br/>}); </p> <p> News_Document doc = new News_Document (); <br/> new NewActionMenu (browser, doc, true ); // right-click <br/>}</p> <p> class ButtonSelectionListener extends SelectionAdapter {<br/> @ Override <br/> public void widgetSelected (SelectionEvent e) {<br/> String operationName = (Button) e. widget ). getToolTipText (); <br/> Browser browser = (Browser) browserFolder. getSelection (). getControl (); <Br/> if (browser! = Null) {<br/> if ("backward ". equals (operationName) {<br/> if (browser. isBackEnabled () {<br/> browser. back (); <br/>}< br/>} else if ("forward ". equals (operationName) {<br/> if (browser. isForwardEnabled () {<br/> browser. forward (); <br/>}< br/>} else if ("refresh ". equals (operationName) {<br/> browser. refresh (); <br/>} else if ("stop ". equals (operationName) {<br/> browser. stop (); <br/>}< br/>