KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > model > IntroLaunchBarShortcut


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.ui.internal.intro.impl.model;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
19 import org.eclipse.ui.intro.config.IntroElement;
20
21 /**
22  * An Intro Config component that captures launch bar shortcut information.
23  *
24  * @since 3.1
25  */

26 public class IntroLaunchBarShortcut extends AbstractIntroElement {
27
28     protected static final String JavaDoc TAG_SHORTCUT = "shortcut"; //$NON-NLS-1$
29

30     private static final String JavaDoc ATT_TOOLTIP = "tooltip"; //$NON-NLS-1$
31
private static final String JavaDoc ATT_ICON = "icon"; //$NON-NLS-1$
32
private static final String JavaDoc ATT_URL = "url"; //$NON-NLS-1$
33

34     private IntroElement ielement;
35     
36     IntroLaunchBarShortcut(IConfigurationElement element, IntroElement ielement) {
37         super(element);
38         this.ielement = ielement;
39     }
40     
41     IntroLaunchBarShortcut(IConfigurationElement element) {
42         super(element);
43     }
44
45
46     public int getType() {
47         return AbstractIntroElement.LAUNCH_BAR_SHORTCUT;
48     }
49     
50     private String JavaDoc getAttribute(String JavaDoc name) {
51         if (ielement!=null)
52             return ielement.getAttribute(name);
53         return getCfgElement().getAttribute(name);
54     }
55
56     /**
57      * Returns the URL of this shortcut.
58      *
59      * @return
60      */

61     public String JavaDoc getURL() {
62         return getAttribute(ATT_URL);
63     }
64
65     /**
66      * Returns the tooltip of this shortcut.
67      *
68      * @return
69      */

70     public String JavaDoc getToolTip() {
71         return getAttribute(ATT_TOOLTIP);
72     }
73
74     /**
75      * Returns the relative icon path of this shortcut.
76      *
77      * @return
78      */

79     private String JavaDoc getIcon() {
80         return getAttribute(ATT_ICON);
81     }
82
83     /**
84      * Returns the icon image of this shortcut, or <code>null</code> if not
85      * found.
86      *
87      * @return
88      */

89     public ImageDescriptor getImageDescriptor() {
90         String JavaDoc icon = getIcon();
91         if (icon!=null) {
92             try {
93                 URL JavaDoc imageUrl = new URL JavaDoc(icon);
94                 ImageDescriptor desc = ImageDescriptor.createFromURL(imageUrl);
95                 return desc;
96             }
97             catch (MalformedURLException JavaDoc e) {
98                 // not a full url
99
}
100         }
101         return ImageUtil.createImageDescriptor(getBundle(), getIcon());
102     }
103 }
104
Popular Tags