KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > SearchPluginImages


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.search.internal.ui;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.core.runtime.FileLocator;
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.Path;
18
19 import org.eclipse.swt.graphics.Image;
20
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.resource.ImageRegistry;
24
25 import org.osgi.framework.Bundle;
26
27 /**
28  * Bundle of all images used by the Search UI plugin.
29  */

30 public class SearchPluginImages {
31
32     // The plugin registry
33
private final static ImageRegistry PLUGIN_REGISTRY= SearchPlugin.getDefault().getImageRegistry();
34
35     private static final IPath ICONS_PATH= new Path("$nl$/icons/full"); //$NON-NLS-1$
36

37     public static final String JavaDoc T_OBJ= "obj16/"; //$NON-NLS-1$
38
public static final String JavaDoc T_WIZBAN= "wizban/"; //$NON-NLS-1$
39
public static final String JavaDoc T_LCL= "lcl16/"; //$NON-NLS-1$
40
public static final String JavaDoc T_TOOL= "tool16/"; //$NON-NLS-1$
41
public static final String JavaDoc T_EVIEW= "eview16/"; //$NON-NLS-1$
42

43     private static final String JavaDoc NAME_PREFIX= "org.eclipse.search.ui."; //$NON-NLS-1$
44
private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length();
45
46     // Define image names
47
public static final String JavaDoc IMG_TOOL_SEARCH= NAME_PREFIX + "search.gif"; //$NON-NLS-1$
48

49     public static final String JavaDoc IMG_LCL_SEARCH_AGAIN= NAME_PREFIX + "search_again.gif"; //$NON-NLS-1$
50
public static final String JavaDoc IMG_LCL_PIN_VIEW= NAME_PREFIX + "pin_view.gif"; //$NON-NLS-1$
51

52     public static final String JavaDoc IMG_LCL_SEARCH_REM= NAME_PREFIX + "search_rem.gif"; //$NON-NLS-1$
53
public static final String JavaDoc IMG_LCL_SEARCH_REM_ALL= NAME_PREFIX + "search_remall.gif"; //$NON-NLS-1$
54
public static final String JavaDoc IMG_LCL_SEARCH_NEXT= NAME_PREFIX + "search_next.gif"; //$NON-NLS-1$
55
public static final String JavaDoc IMG_LCL_SEARCH_PREV= NAME_PREFIX + "search_prev.gif"; //$NON-NLS-1$
56
public static final String JavaDoc IMG_LCL_SEARCH_GOTO= NAME_PREFIX + "search_goto.gif"; //$NON-NLS-1$
57
public static final String JavaDoc IMG_LCL_SEARCH_SORT= NAME_PREFIX + "search_sortmatch.gif"; //$NON-NLS-1$
58
public static final String JavaDoc IMG_LCL_SEARCH_HISTORY= NAME_PREFIX + "search_history.gif"; //$NON-NLS-1$
59
public static final String JavaDoc IMG_LCL_SEARCH_FLAT_LAYOUT= NAME_PREFIX + "flatLayout.gif"; //$NON-NLS-1$
60
public static final String JavaDoc IMG_LCL_SEARCH_HIERARCHICAL_LAYOUT= NAME_PREFIX + "hierarchicalLayout.gif"; //$NON-NLS-1$
61
public static final String JavaDoc IMG_LCL_SEARCH_HORIZONTAL_ORIENTATION= NAME_PREFIX + "horizontalOrientation.gif"; //$NON-NLS-1$
62
public static final String JavaDoc IMG_LCL_SEARCH_VERTICAL_ORIENTATION= NAME_PREFIX + "verticalOrientation.gif"; //$NON-NLS-1$
63
public static final String JavaDoc IMG_LCL_SEARCH_AUTOMATIC_ORIENTATION= NAME_PREFIX + "automaticOrientation.gif"; //$NON-NLS-1$
64
public static final String JavaDoc IMG_LCL_SEARCH_SINGLE_ORIENTATION= NAME_PREFIX + "singleOrientation.gif"; //$NON-NLS-1$
65
public static final String JavaDoc IMG_LCL_SEARCH_CANCEL= NAME_PREFIX + "stop.gif"; //$NON-NLS-1$
66
public static final String JavaDoc IMG_LCL_SEARCH_COLLAPSE_ALL= NAME_PREFIX + "collapseall.gif"; //$NON-NLS-1$
67
public static final String JavaDoc IMG_LCL_SEARCH_EXPAND_ALL= NAME_PREFIX + "expandall.gif"; //$NON-NLS-1$
68
public static final String JavaDoc IMG_LCL_SEARCH_FILTER= NAME_PREFIX + "filter_ps.gif"; //$NON-NLS-1$
69
public static final String JavaDoc IMG_VIEW_SEARCHRES= NAME_PREFIX + "searchres.gif"; //$NON-NLS-1$
70

71     public static final String JavaDoc IMG_OBJ_TSEARCH_DPDN= NAME_PREFIX + "tsearch_dpdn_obj.gif"; //$NON-NLS-1$
72
public static final String JavaDoc IMG_OBJ_SEARCHMARKER= NAME_PREFIX + "searchm_obj.gif"; //$NON-NLS-1$
73
public static final String JavaDoc IMG_OBJ_TEXT_SEARCH_LINE= NAME_PREFIX + "line_match.gif"; //$NON-NLS-1$
74

75     // Define images
76
public static final ImageDescriptor DESC_OBJ_TSEARCH_DPDN= createManaged(T_OBJ, IMG_OBJ_TSEARCH_DPDN);
77     public static final ImageDescriptor DESC_OBJ_SEARCHMARKER= createManaged(T_OBJ, IMG_OBJ_SEARCHMARKER);
78     public static final ImageDescriptor DESC_OBJ_TEXT_SEARCH_LINE= createManaged(T_OBJ, IMG_OBJ_TEXT_SEARCH_LINE);
79     public static final ImageDescriptor DESC_VIEW_SEARCHRES= createManaged(T_EVIEW, IMG_VIEW_SEARCHRES);
80     
81     public static Image get(String JavaDoc key) {
82         return PLUGIN_REGISTRY.get(key);
83     }
84     
85     private static ImageDescriptor createManaged(String JavaDoc prefix, String JavaDoc name) {
86         ImageDescriptor result= create(prefix, name.substring(NAME_PREFIX_LENGTH), true);
87         PLUGIN_REGISTRY.put(name, result);
88         return result;
89     }
90
91     /*
92      * Creates an image descriptor for the given prefix and name in the Search plugin bundle. The path can
93      * contain variables like $NL$.
94      * If no image could be found, <code>useMissingImageDescriptor</code> decides if either
95      * the 'missing image descriptor' is returned or <code>null</code>.
96      * or <code>null</code>.
97      */

98     private static ImageDescriptor create(String JavaDoc prefix, String JavaDoc name, boolean useMissingImageDescriptor) {
99         IPath path= ICONS_PATH.append(prefix).append(name);
100         return createImageDescriptor(SearchPlugin.getDefault().getBundle(), path, useMissingImageDescriptor);
101     }
102     
103     /*
104      * Sets all available image descriptors for the given action.
105      */

106     public static void setImageDescriptors(IAction action, String JavaDoc type, String JavaDoc relPath) {
107         relPath= relPath.substring(NAME_PREFIX_LENGTH);
108         
109         action.setDisabledImageDescriptor(create("d" + type, relPath, false)); //$NON-NLS-1$
110

111         ImageDescriptor desc= create("e" + type, relPath, true); //$NON-NLS-1$
112
action.setHoverImageDescriptor(desc);
113         action.setImageDescriptor(desc);
114     }
115     
116     /*
117      * Creates an image descriptor for the given path in a bundle. The path can contain variables
118      * like $NL$.
119      * If no image could be found, <code>useMissingImageDescriptor</code> decides if either
120      * the 'missing image descriptor' is returned or <code>null</code>.
121      * Added for 3.1.1.
122      */

123     public static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path, boolean useMissingImageDescriptor) {
124         URL JavaDoc url= FileLocator.find(bundle, path, null);
125         if (url != null) {
126             return ImageDescriptor.createFromURL(url);
127         }
128         if (useMissingImageDescriptor) {
129             return ImageDescriptor.getMissingImageDescriptor();
130         }
131         return null;
132     }
133     
134 }
135
Popular Tags