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;
15 import java.text.MessageFormat;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.resource.ImageRegistry;
20 import org.eclipse.core.runtime.*;
21 import org.eclipse.ui.plugin.AbstractUIPlugin;
22 import org.osgi.framework.BundleContext;
24 * The TCP/IP monitor UI plugin.
26 public class MonitorUIPlugin extends AbstractUIPlugin {
27 private static MonitorUIPlugin singleton;
29 protected Map imageDescriptors = new HashMap();
31 private static URL ICON_BASE_URL;
33 private static final String URL_CLCL = "clcl16/";
34 private static final String URL_ELCL = "elcl16/";
35 private static final String URL_DLCL = "dlcl16/";
36 private static final String URL_OBJ = "obj16/";
38 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.monitor.ui";
40 public static final String IMG_ELCL_SORT_RESPONSE_TIME = "IMG_ELCL_SORT_RESPONSE_TIME";
41 public static final String IMG_ELCL_CLEAR = "IMG_ELCL_CLEAR";
42 public static final String IMG_ELCL_HTTP_HEADER = "IMG_ELCL_HTTP_HEADER";
43 public static final String IMG_CLCL_SORT_RESPONSE_TIME = "IMG_CLCL_SORT_RESPONSE_TIME";
44 public static final String IMG_CLCL_CLEAR = "IMG_CLCL_CLEAR";
45 public static final String IMG_CLCL_HTTP_HEADER = "IMG_CLCL_HTTP_HEADER";
46 public static final String IMG_DLCL_SORT_RESPONSE_TIME = "IMG_DLCL_SORT_RESPONSE_TIME";
47 public static final String IMG_DLCL_CLEAR = "IMG_DLCL_CLEAR";
48 public static final String IMG_DLCL_HTTP_HEADER = "IMG_DLCL_HTTP_HEADER";
50 public static final String IMG_REQUEST_RESPONSE = "requestResponse";
51 public static final String IMG_HOST = "host";
52 public static final String IMG_MONITOR_ON = "monitorOn";
53 public static final String IMG_MONITOR_OFF = "monitorOff";
55 private static final String SHOW_VIEW_ON_ACTIVITY = "show-view";
56 private static final String SHOW_HEADER = "show-header";
59 * MonitorUIPlugin constructor comment.
61 public MonitorUIPlugin() {
67 * Creates and pre-loads the image registry.
69 * @return ImageRegistry
71 protected ImageRegistry createImageRegistry() {
72 ImageRegistry registry = super.createImageRegistry();
74 registerImage(registry, IMG_REQUEST_RESPONSE, URL_OBJ + "tcp.gif");
75 registerImage(registry, IMG_HOST, URL_OBJ + "host.gif");
76 registerImage(registry, IMG_MONITOR_ON, URL_OBJ + "monitorOn.gif");
77 registerImage(registry, IMG_MONITOR_OFF, URL_OBJ + "monitorOff.gif");
79 registerImage(registry, IMG_CLCL_CLEAR, URL_CLCL + "clear.gif");
80 registerImage(registry, IMG_CLCL_SORT_RESPONSE_TIME, URL_CLCL + "sortResponseTime.gif");
81 registerImage(registry, IMG_CLCL_HTTP_HEADER, URL_CLCL + "httpHeader.gif");
83 registerImage(registry, IMG_ELCL_CLEAR, URL_ELCL + "clear.gif");
84 registerImage(registry, IMG_ELCL_SORT_RESPONSE_TIME, URL_ELCL + "sortResponseTime.gif");
85 registerImage(registry, IMG_ELCL_HTTP_HEADER, URL_ELCL + "httpHeader.gif");
87 registerImage(registry, IMG_DLCL_CLEAR, URL_DLCL + "clear.gif");
88 registerImage(registry, IMG_DLCL_SORT_RESPONSE_TIME, URL_DLCL + "sortResponseTime.gif");
89 registerImage(registry, IMG_DLCL_HTTP_HEADER, URL_DLCL + "httpHeader.gif");
95 * Return the image with the given key from the image registry.
97 * @param key java.lang.String
98 * @return org.eclipse.jface.parts.IImage
100 public static Image getImage(String key) {
101 return getInstance().getImageRegistry().get(key);
105 * Return the image with the given key from the image registry.
107 * @param key java.lang.String
108 * @return org.eclipse.jface.parts.IImage
110 public static ImageDescriptor getImageDescriptor(String key) {
112 getInstance().getImageRegistry();
113 return (ImageDescriptor) getInstance().imageDescriptors.get(key);
114 } catch (Exception e) {
120 * Returns the singleton instance of this plugin.
122 * @return org.eclipse.tcpip.monitor.MonitorServerPlugin
124 public static MonitorUIPlugin getInstance() {
129 * Returns the translated String found with the given key.
131 * @return java.lang.String
132 * @param key java.lang.String
134 public static String getResource(String key) {
136 return Platform.getResourceString(getInstance().getBundle(), key);
137 } catch (Exception e) {
143 * Returns the translated String found with the given key,
144 * and formatted with the given object.
146 * @param key java.lang.String
147 * @param obj java.lang.Object[]
148 * @return java.lang.String
150 public static String getResource(String key, Object[] obj) {
152 return MessageFormat.format(getResource(key), obj);
153 } catch (Exception e) {
159 * Returns the translated String found with the given key,
160 * and formatted with the given object.
162 * @param key java.lang.String
163 * @param s java.lang.String
164 * @return java.lang.String
166 public static String getResource(String key, String s) {
168 return MessageFormat.format(getResource(key), new String[] {s});
169 } catch (Exception e) {
175 * Register an image with the registry.
177 * @param key java.lang.String
178 * @param partialURL java.lang.String
180 private void registerImage(ImageRegistry registry, String key, String partialURL) {
181 if (ICON_BASE_URL == null) {
182 String pathSuffix = "icons/";
183 ICON_BASE_URL = singleton.getBundle().getEntry(pathSuffix);
187 ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
188 registry.put(key, id);
189 imageDescriptors.put(key, id);
190 } catch (Exception e) {
191 Trace.trace(Trace.SEVERE, "Error registering image", e);
196 * Start this plug-in.
198 public void start(BundleContext context) throws Exception {
199 super.start(context);
201 getPreferenceStore().setDefault(MonitorUIPlugin.SHOW_VIEW_ON_ACTIVITY, true);
204 public static boolean getDefaultShowOnActivityPreference() {
205 return getInstance().getPreferenceStore().getDefaultBoolean(SHOW_VIEW_ON_ACTIVITY);
208 public static boolean getShowOnActivityPreference() {
209 return getInstance().getPreferenceStore().getBoolean(SHOW_VIEW_ON_ACTIVITY);
212 public static void setShowOnActivityPreference(boolean b) {
213 getInstance().getPreferenceStore().setValue(SHOW_VIEW_ON_ACTIVITY, b);
214 getInstance().savePluginPreferences();
217 public static boolean getShowHeaderPreference() {
218 return getInstance().getPreferenceStore().getBoolean(SHOW_HEADER);
221 public static void setShowHeaderPreference(boolean b) {
222 getInstance().getPreferenceStore().setValue(SHOW_HEADER, b);
223 getInstance().savePluginPreferences();