1 11 package org.eclipse.help.internal.browser; 12 import org.eclipse.help.browser.*; 13 16 public class CurrentBrowser implements IBrowser { 17 private IBrowser browserAdapter; 18 private String browserAdapterId; 19 22 private IBrowser newBrowserAdapter = null; 23 private String 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 browserAdapterId, 32 boolean externalBrowser) { 33 this.browserAdapter = browserImpl; 34 this.browserAdapterId = browserAdapterId; 35 this.external = externalBrowser; 36 } 37 40 public void close() { 41 browserAdapter.close(); 42 } 43 46 public boolean isCloseSupported() { 47 return browserAdapter.isCloseSupported(); 48 } 49 52 public void displayURL(String url) throws Exception { 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 72 public boolean isSetLocationSupported() { 73 checkDefaultAdapter(); 74 if (newBrowserAdapterId == null) { 75 return browserAdapter.isSetLocationSupported(); 76 } 77 return browserAdapter.isSetLocationSupported() 78 || newBrowserAdapter.isSetLocationSupported(); 79 } 80 83 public boolean isSetSizeSupported() { 84 checkDefaultAdapter(); 85 if (newBrowserAdapterId == null) { 86 return browserAdapter.isSetSizeSupported(); 87 } 88 return browserAdapter.isSetSizeSupported() 89 || newBrowserAdapter.isSetSizeSupported(); 90 } 91 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 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 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 |