1 2 package $packageName$; 3 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 7 import org.eclipse.core.runtime.IConfigurationElement; 8 import org.eclipse.core.runtime.IExtension; 9 import org.eclipse.core.runtime.Platform; 10 import org.eclipse.jface.resource.ImageDescriptor; 11 import org.eclipse.swt.SWT; 12 import org.eclipse.swt.graphics.Image; 13 import org.eclipse.swt.graphics.Point; 14 import org.eclipse.swt.layout.GridLayout; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Label; 17 import org.eclipse.swt.widgets.Shell; 18 import org.eclipse.ui.plugin.AbstractUIPlugin; 19 import org.eclipse.ui.splash.AbstractSplashHandler; 20 21 25 public class ExtensibleSplashHandler extends AbstractSplashHandler { 26 27 private ArrayList fImageList; 28 29 private ArrayList fTooltipList; 30 31 private final static String F_SPLASH_EXTENSION_ID = "$pluginId$.splashExtension"; 33 private final static String F_ELEMENT_ICON = "icon"; 35 private final static String F_ELEMENT_TOOLTIP = "tooltip"; 37 private final static String F_DEFAULT_TOOLTIP = "Image"; 39 private final static int F_IMAGE_WIDTH = 50; 40 41 private final static int F_IMAGE_HEIGHT = 50; 42 43 private final static int F_SPLASH_SCREEN_BEVEL = 5; 44 45 private Composite fIconPanel; 46 47 50 public ExtensibleSplashHandler() { 51 fImageList = new ArrayList (); 52 fTooltipList = new ArrayList (); 53 fIconPanel = null; 54 } 55 56 59 public void init(Shell splash) { 60 super.init(splash); 62 configureUISplash(); 64 loadSplashExtensions(); 66 if (hasSplashExtensions() == false) { 68 return; 69 } 70 createUI(); 72 configureUICompositeIconPanelBounds(); 74 doEventLoop(); 77 } 78 79 82 private boolean hasSplashExtensions() { 83 if (fImageList.isEmpty()) { 84 return false; 85 } else { 86 return true; 87 } 88 } 89 90 93 private void createUI() { 94 createUICompositeIconPanel(); 96 createUIImages(); 98 } 99 100 103 private void createUIImages() { 104 Iterator imageIterator = fImageList.iterator(); 105 Iterator tooltipIterator = fTooltipList.iterator(); 106 int i = 1; 107 int columnCount = ((GridLayout)fIconPanel.getLayout()).numColumns; 108 while (imageIterator.hasNext() && 112 (i <= columnCount)) { 113 Image image = (Image)imageIterator.next(); 114 String tooltip = (String )tooltipIterator.next(); 115 createUILabel(image, tooltip); 117 i++; 118 } 119 } 120 121 125 private void createUILabel(Image image, String tooltip) { 126 Label label = new Label(fIconPanel, SWT.NONE); 128 label.setImage(image); 129 label.setToolTipText(tooltip); 130 } 131 132 135 private void createUICompositeIconPanel() { 136 Shell splash = getSplash(); 137 fIconPanel = new Composite(splash, SWT.NONE); 139 int maxColumnCount = getUsableSplashScreenWidth() / F_IMAGE_WIDTH; 142 int actualColumnCount = Math.min(fImageList.size(), maxColumnCount); 146 GridLayout layout = new GridLayout(actualColumnCount, true); 148 layout.horizontalSpacing = 0; 149 layout.verticalSpacing = 0; 150 layout.marginHeight = 0; 151 layout.marginWidth = 0; 152 fIconPanel.setLayout(layout); 153 } 154 155 158 private void configureUICompositeIconPanelBounds() { 159 Point panelSize = fIconPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); 162 163 int x_coord = getSplash().getSize().x - F_SPLASH_SCREEN_BEVEL - panelSize.x; 164 int y_coord = getSplash().getSize().y - F_SPLASH_SCREEN_BEVEL - panelSize.y; 165 int x_width = panelSize.x; 166 int y_width = panelSize.y; 167 168 fIconPanel.setBounds(x_coord, y_coord, x_width, y_width); 169 } 170 171 174 private int getUsableSplashScreenWidth() { 175 return getSplash().getSize().x - (F_SPLASH_SCREEN_BEVEL * 2); 177 } 178 179 182 private void loadSplashExtensions() { 183 IExtension[] extensions = 185 Platform.getExtensionRegistry().getExtensionPoint( 186 F_SPLASH_EXTENSION_ID).getExtensions(); 187 for (int i = 0; i < extensions.length; i++) { 189 processSplashExtension(extensions[i]); 190 } 191 } 192 193 196 private void processSplashExtension(IExtension extension) { 197 IConfigurationElement[] elements = extension.getConfigurationElements(); 199 for (int j = 0; j < elements.length; j++) { 201 processSplashElements(elements[j]); 202 } 203 } 204 205 208 private void processSplashElements( 209 IConfigurationElement configurationElement) { 210 processSplashElementIcon(configurationElement); 212 processSplashElementTooltip(configurationElement); 214 } 215 216 219 private void processSplashElementTooltip( 220 IConfigurationElement configurationElement) { 221 String tooltip = configurationElement.getAttribute(F_ELEMENT_TOOLTIP); 223 if ((tooltip == null) || 225 (tooltip.length() == 0)) { 226 fTooltipList.add(F_DEFAULT_TOOLTIP); 227 } else { 228 fTooltipList.add(tooltip); 229 } 230 } 231 232 235 private void processSplashElementIcon( 236 IConfigurationElement configurationElement) { 237 String iconImageFilePath = configurationElement.getAttribute(F_ELEMENT_ICON); 239 if ((iconImageFilePath == null) || 241 (iconImageFilePath.length() == 0)) { 242 return; 243 } 244 ImageDescriptor descriptor = 246 AbstractUIPlugin.imageDescriptorFromPlugin( 247 configurationElement.getNamespaceIdentifier(), 248 iconImageFilePath); 249 if (descriptor == null) { 251 return; 252 } 253 Image image = descriptor.createImage(); 255 if (image == null) { 257 return; 258 } 259 if ((image.getBounds().width != F_IMAGE_WIDTH) || 261 (image.getBounds().height != F_IMAGE_HEIGHT)) { 262 image.dispose(); 264 return; 265 } 266 fImageList.add(image); 268 } 269 270 273 private void configureUISplash() { 274 GridLayout layout = new GridLayout(1, true); 276 getSplash().setLayout(layout); 277 getSplash().setBackgroundMode(SWT.INHERIT_DEFAULT); 279 } 280 281 284 private void doEventLoop() { 285 Shell splash = getSplash(); 286 if (splash.getDisplay().readAndDispatch() == false) { 287 splash.getDisplay().sleep(); 288 } 289 } 290 291 294 public void dispose() { 295 super.dispose(); 296 if ((fImageList == null) || 298 fImageList.isEmpty()) { 299 return; 300 } 301 Iterator iterator = fImageList.iterator(); 303 while (iterator.hasNext()) { 304 Image image = (Image) iterator.next(); 305 image.dispose(); 306 } 307 } 308 } 309 | Popular Tags |