KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > browser > CurrentBrowser


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.browser;
12 import org.eclipse.help.browser.*;
13 /**
14  * Wrapper for individual browsers contributed through extension point.
15  */

16 public class CurrentBrowser implements IBrowser {
17     private IBrowser browserAdapter;
18     private String JavaDoc browserAdapterId;
19     /**
20      * new adapter selected in preferences but not yet shown
21      */

22     private IBrowser newBrowserAdapter = null;
23     private String JavaDoc newBrowserAdapterId = null;
24     private boolean locationSet = false;
25     private boolean sizeSet = false;
26     private int x;
27     private int y;
28     private int width;
29     private int height;
30     boolean external;
31     public CurrentBrowser(IBrowser browserImpl, String JavaDoc browserAdapterId,
32             boolean externalBrowser) {
33         this.browserAdapter = browserImpl;
34         this.browserAdapterId = browserAdapterId;
35         this.external = externalBrowser;
36     }
37     /**
38      * @see org.eclipse.help.browser.IBrowser#close()
39      */

40     public void close() {
41         browserAdapter.close();
42     }
43     /**
44      * @see org.eclipse.help.browser.IBrowser#isCloseSupported()
45      */

46     public boolean isCloseSupported() {
47         return browserAdapter.isCloseSupported();
48     }
49     /**
50      * @see org.eclipse.help.browser.IBrowser#displayURL(java.lang.String)
51      */

52     public void displayURL(String JavaDoc url) throws Exception JavaDoc {
53         checkDefaultAdapter();
54         if (newBrowserAdapter != null) {
55             browserAdapter.close();
56             browserAdapter = newBrowserAdapter;
57             newBrowserAdapter = null;
58             browserAdapterId = newBrowserAdapterId;
59             newBrowserAdapterId = null;
60             if (locationSet) {
61                 browserAdapter.setLocation(x, y);
62             }
63             if (sizeSet) {
64                 browserAdapter.setSize(width, height);
65             }
66         }
67         browserAdapter.displayURL(url);
68     }
69     /**
70      * @see org.eclipse.help.browser.IBrowser#isSetLocationSupported()
71      */

72     public boolean isSetLocationSupported() {
73         checkDefaultAdapter();
74         if (newBrowserAdapterId == null) {
75             return browserAdapter.isSetLocationSupported();
76         }
77         return browserAdapter.isSetLocationSupported()
78                 || newBrowserAdapter.isSetLocationSupported();
79     }
80     /**
81      * @see org.eclipse.help.browser.IBrowser#isSetSizeSupported()
82      */

83     public boolean isSetSizeSupported() {
84         checkDefaultAdapter();
85         if (newBrowserAdapterId == null) {
86             return browserAdapter.isSetSizeSupported();
87         }
88         return browserAdapter.isSetSizeSupported()
89                 || newBrowserAdapter.isSetSizeSupported();
90     }
91     /**
92      * @see org.eclipse.help.browser.IBrowser#setLocation(int, int)
93      */

94     public void setLocation(int x, int y) {
95         checkDefaultAdapter();
96         browserAdapter.setLocation(x, y);
97         locationSet = true;
98         this.x = x;
99         this.y = y;
100     }
101     /**
102      * @see org.eclipse.help.browser.IBrowser#setSize(int, int)
103      */

104     public void setSize(int width, int height) {
105         checkDefaultAdapter();
106         browserAdapter.setSize(width, height);
107         sizeSet = true;
108         this.width = width;
109         this.height = height;
110     }
111     /*
112      * Checks wheter default adapter has changed. If yes, sets the
113      * newBrowserAdapterId field
114      */

115     private void checkDefaultAdapter() {
116         if (external) {
117             if (browserAdapterId != BrowserManager.getInstance()
118                     .getCurrentBrowserID()) {
119                 newBrowserAdapter = BrowserManager.getInstance().createBrowser(
120                         true);
121                 newBrowserAdapterId = BrowserManager.getInstance()
122                         .getCurrentBrowserID();
123             }
124         } else {
125             if (browserAdapterId != BrowserManager.getInstance()
126                     .getCurrentInternalBrowserID()) {
127                 newBrowserAdapter = BrowserManager.getInstance().createBrowser(
128                         false);
129                 newBrowserAdapterId = BrowserManager.getInstance()
130                         .getCurrentInternalBrowserID();
131             }
132         }
133     }
134 }
135
Popular Tags