spellcheckerimages.java

来自「Eclipse 3高级编程一书源码」· Java 代码 · 共 95 行

JAVA
95
字号
/*******************************************************************************
 * Copyright (c) 2003 Berthold Daum.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     Berthold Daum
 *******************************************************************************/
package com.bdaum.SpellChecker;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;

/**
 * Compilation of the images used in com.bdaum.SpellChecker plug-in.
 */
public class SpellCheckerImages {

	// Get URL for icon folder
	private static URL fgIconBaseURL = SpellCheckerPlugin.getDefault()
			.getBundle().getEntry("icons/");

	/**
	 * Filenames for the images in this registry
	 */

	public static final String IMG_IGNORE = "ignore.gif";

	public static final String IMG_IGNOREALL = "ignoreAll.gif";

	public static final String IMG_CANCEL = "cancel.gif";

	public static final String IMG_REPLACE = "replace.gif";

	public static final String IMG_REPLACEALL = "replaceAll.gif";

	public static final String IMG_ADDTODICTIONARY = "addToDictionary.gif";

	public static final String IMG_CHECK = "check.gif";

	/**
	 * Supply action with icons
	 * 
	 * @param action -
	 *            Action to be decorated
	 * @param type -
	 *            icon type
	 * @param relPath -
	 *            relative path of icon
	 */
	public static void setImageDescriptors(IAction action, String type,
			String relPath) {
		try {
			ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL(
					"full/d" + type, relPath));
			if (id != null)
				action.setDisabledImageDescriptor(id);
		} catch (MalformedURLException e) {
			SpellCheckerPlugin
					.logError(
							8,
							Messages
									.getString("SpellCheckerImages.Bad_URL_when_loading_disabled_image"),
							e);
		}
		try {
			ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL(
					"full/c" + type, relPath));
			if (id != null)
				action.setHoverImageDescriptor(id);
		} catch (MalformedURLException e) {
			SpellCheckerPlugin
					.logError(
							9,
							Messages
									.getString("SpellCheckerImages.Bad_URL_when_loading_hover_image"),
							e);
			action.setImageDescriptor(ImageDescriptor
					.getMissingImageDescriptor());
		}
	}

	// Construct URL for icon file
	private static URL makeIconFileURL(String prefix, String name)
			throws MalformedURLException {
		if (fgIconBaseURL == null)
			throw new MalformedURLException();
		return new URL(fgIconBaseURL, prefix + "/" + name);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?