001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.intro.impl.model;
011:
012: import java.net.MalformedURLException;
013: import java.net.URL;
014:
015: import org.eclipse.core.runtime.IConfigurationElement;
016: import org.eclipse.jface.resource.ImageDescriptor;
017: import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
018: import org.eclipse.ui.intro.config.IntroElement;
019:
020: /**
021: * An Intro Config component that captures launch bar shortcut information.
022: *
023: * @since 3.1
024: */
025: public class IntroLaunchBarShortcut extends AbstractIntroElement {
026:
027: protected static final String TAG_SHORTCUT = "shortcut"; //$NON-NLS-1$
028:
029: private static final String ATT_TOOLTIP = "tooltip"; //$NON-NLS-1$
030: private static final String ATT_ICON = "icon"; //$NON-NLS-1$
031: private static final String ATT_URL = "url"; //$NON-NLS-1$
032:
033: private IntroElement ielement;
034:
035: IntroLaunchBarShortcut(IConfigurationElement element,
036: IntroElement ielement) {
037: super (element);
038: this .ielement = ielement;
039: }
040:
041: IntroLaunchBarShortcut(IConfigurationElement element) {
042: super (element);
043: }
044:
045: public int getType() {
046: return AbstractIntroElement.LAUNCH_BAR_SHORTCUT;
047: }
048:
049: private String getAttribute(String name) {
050: if (ielement != null)
051: return ielement.getAttribute(name);
052: return getCfgElement().getAttribute(name);
053: }
054:
055: /**
056: * Returns the URL of this shortcut.
057: *
058: * @return
059: */
060: public String getURL() {
061: return getAttribute(ATT_URL);
062: }
063:
064: /**
065: * Returns the tooltip of this shortcut.
066: *
067: * @return
068: */
069: public String getToolTip() {
070: return getAttribute(ATT_TOOLTIP);
071: }
072:
073: /**
074: * Returns the relative icon path of this shortcut.
075: *
076: * @return
077: */
078: private String getIcon() {
079: return getAttribute(ATT_ICON);
080: }
081:
082: /**
083: * Returns the icon image of this shortcut, or <code>null</code> if not
084: * found.
085: *
086: * @return
087: */
088: public ImageDescriptor getImageDescriptor() {
089: String icon = getIcon();
090: if (icon != null) {
091: try {
092: URL imageUrl = new URL(icon);
093: ImageDescriptor desc = ImageDescriptor
094: .createFromURL(imageUrl);
095: return desc;
096: } catch (MalformedURLException e) {
097: // not a full url
098: }
099: }
100: return ImageUtil.createImageDescriptor(getBundle(), getIcon());
101: }
102: }
|