1 /**********************************************************************
2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal;
14 import java.text.MessageFormat;
15 import java.util.HashMap;
18 import org.eclipse.core.runtime.Platform;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.ui.plugin.AbstractUIPlugin;
23 import org.osgi.framework.BundleContext;
25 * The TCP/IP monitor UI plugin.
27 public class MonitorUIPlugin extends AbstractUIPlugin {
28 private static MonitorUIPlugin singleton;
30 protected Map imageDescriptors = new HashMap();
32 private static URL ICON_BASE_URL;
34 private static final String URL_CLCL = "clcl16/";
35 private static final String URL_ELCL = "elcl16/";
36 private static final String URL_DLCL = "dlcl16/";
37 private static final String URL_OBJ = "obj16/";
39 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.monitor.ui";
41 public static final String IMG_ELCL_SORT_RESPONSE_TIME = "IMG_ELCL_SORT_RESPONSE_TIME";
42 public static final String IMG_ELCL_CLEAR = "IMG_ELCL_CLEAR";
43 public static final String IMG_ELCL_HTTP_HEADER = "IMG_ELCL_HTTP_HEADER";
44 public static final String IMG_CLCL_SORT_RESPONSE_TIME = "IMG_CLCL_SORT_RESPONSE_TIME";
45 public static final String IMG_CLCL_CLEAR = "IMG_CLCL_CLEAR";
46 public static final String IMG_CLCL_HTTP_HEADER = "IMG_CLCL_HTTP_HEADER";
47 public static final String IMG_DLCL_SORT_RESPONSE_TIME = "IMG_DLCL_SORT_RESPONSE_TIME";
48 public static final String IMG_DLCL_CLEAR = "IMG_DLCL_CLEAR";
49 public static final String IMG_DLCL_HTTP_HEADER = "IMG_DLCL_HTTP_HEADER";
51 public static final String IMG_REQUEST_RESPONSE = "requestResponse";
52 public static final String IMG_HOST = "host";
53 public static final String IMG_MONITOR_ON = "monitorOn";
54 public static final String IMG_MONITOR_OFF = "monitorOff";
56 private static final String SHOW_VIEW_ON_ACTIVITY = "show-view";
57 private static final String SHOW_HEADER = "show-header";
60 * MonitorUIPlugin constructor comment.
62 public MonitorUIPlugin() {
68 * Creates and pre-loads the image registry.
70 * @return ImageRegistry
72 protected ImageRegistry createImageRegistry() {
73 ImageRegistry registry = super.createImageRegistry();
75 registerImage(registry, IMG_REQUEST_RESPONSE, URL_OBJ + "tcp.gif");
76 registerImage(registry, IMG_HOST, URL_OBJ + "host.gif");
77 registerImage(registry, IMG_MONITOR_ON, URL_OBJ + "monitorOn.gif");
78 registerImage(registry, IMG_MONITOR_OFF, URL_OBJ + "monitorOff.gif");
80 registerImage(registry, IMG_CLCL_CLEAR, URL_CLCL + "clear.gif");
81 registerImage(registry, IMG_CLCL_SORT_RESPONSE_TIME, URL_CLCL + "sortResponseTime.gif");
82 registerImage(registry, IMG_CLCL_HTTP_HEADER, URL_CLCL + "httpHeader.gif");
84 registerImage(registry, IMG_ELCL_CLEAR, URL_ELCL + "clear.gif");
85 registerImage(registry, IMG_ELCL_SORT_RESPONSE_TIME, URL_ELCL + "sortResponseTime.gif");
86 registerImage(registry, IMG_ELCL_HTTP_HEADER, URL_ELCL + "httpHeader.gif");
88 registerImage(registry, IMG_DLCL_CLEAR, URL_DLCL + "clear.gif");
89 registerImage(registry, IMG_DLCL_SORT_RESPONSE_TIME, URL_DLCL + "sortResponseTime.gif");
90 registerImage(registry, IMG_DLCL_HTTP_HEADER, URL_DLCL + "httpHeader.gif");
96 * Return the image with the given key from the image registry.
98 * @param key java.lang.String
99 * @return org.eclipse.jface.parts.IImage
101 public static Image getImage(String key) {
102 return getInstance().getImageRegistry().get(key);
106 * Return the image with the given key from the image registry.
108 * @param key java.lang.String
109 * @return org.eclipse.jface.parts.IImage
111 public static ImageDescriptor getImageDescriptor(String key) {
113 getInstance().getImageRegistry();
114 return (ImageDescriptor) getInstance().imageDescriptors.get(key);
115 } catch (Exception e) {
121 * Returns the singleton instance of this plugin.
123 * @return org.eclipse.tcpip.monitor.MonitorServerPlugin
125 public static MonitorUIPlugin getInstance() {
130 * Returns the translated String found with the given key.
132 * @return java.lang.String
133 * @param key java.lang.String
135 public static String getResource(String key) {
137 return Platform.getResourceString(getInstance().getBundle(), key);
138 } catch (Exception e) {
144 * Returns the translated String found with the given key,
145 * and formatted with the given object.
147 * @param key java.lang.String
148 * @param obj java.lang.Object[]
149 * @return java.lang.String
151 public static String getResource(String key, Object[] obj) {
153 return MessageFormat.format(getResource(key), obj);
154 } catch (Exception e) {
160 * Returns the translated String found with the given key,
161 * and formatted with the given object.
163 * @param key java.lang.String
164 * @param s java.lang.String
165 * @return java.lang.String
167 public static String getResource(String key, String s) {
169 return MessageFormat.format(getResource(key), new String[] {s});
170 } catch (Exception e) {
176 * Register an image with the registry.
178 * @param key java.lang.String
179 * @param partialURL java.lang.String
181 private void registerImage(ImageRegistry registry, String key, String partialURL) {
182 if (ICON_BASE_URL == null) {
183 String pathSuffix = "icons/";
184 ICON_BASE_URL = singleton.getBundle().getEntry(pathSuffix);
188 ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
189 registry.put(key, id);
190 imageDescriptors.put(key, id);
191 } catch (Exception e) {
192 Trace.trace(Trace.SEVERE, "Error registering image", e);
197 * Start this plug-in.
199 public void start(BundleContext context) throws Exception {
200 super.start(context);
202 getPreferenceStore().setDefault(MonitorUIPlugin.SHOW_VIEW_ON_ACTIVITY, true);
205 public static boolean getDefaultShowOnActivityPreference() {
206 return getInstance().getPreferenceStore().getDefaultBoolean(SHOW_VIEW_ON_ACTIVITY);
209 public static boolean getShowOnActivityPreference() {
210 return getInstance().getPreferenceStore().getBoolean(SHOW_VIEW_ON_ACTIVITY);
213 public static void setShowOnActivityPreference(boolean b) {
214 getInstance().getPreferenceStore().setValue(SHOW_VIEW_ON_ACTIVITY, b);
215 getInstance().savePluginPreferences();
218 public static boolean getShowHeaderPreference() {
219 return getInstance().getPreferenceStore().getBoolean(SHOW_HEADER);
222 public static void setShowHeaderPreference(boolean b) {
223 getInstance().getPreferenceStore().setValue(SHOW_HEADER, b);
224 getInstance().savePluginPreferences();