diff options
author | Steffen Pingel | 2011-07-15 23:02:51 +0000 |
---|---|---|
committer | Steffen Pingel | 2011-07-15 23:02:51 +0000 |
commit | 15a7d3def70bc6ce5a3e02cfa035a7ff5518a834 (patch) | |
tree | cb81d1ea8ee8db74d98abfd2ed9a54ab57fd4b87 | |
parent | e851e09d6f2159a78d36e71f8362b6b728bc8d5a (diff) | |
download | org.eclipse.mylyn.commons-15a7d3def70bc6ce5a3e02cfa035a7ff5518a834.tar.gz org.eclipse.mylyn.commons-15a7d3def70bc6ce5a3e02cfa035a7ff5518a834.tar.xz org.eclipse.mylyn.commons-15a7d3def70bc6ce5a3e02cfa035a7ff5518a834.zip |
RESOLVED - bug 350333: show content-type icons for files in changes
section
https://bugs.eclipse.org/bugs/show_bug.cgi?id=350333
-rw-r--r-- | org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImageManger.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImageManger.java b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImageManger.java new file mode 100644 index 00000000..008d747a --- /dev/null +++ b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImageManger.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2011 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + * Perforce - fixes for bug 343892 + * GitHub - fixes for bug 350333 + *******************************************************************************/ + +package org.eclipse.mylyn.internal.provisional.commons.ui; + +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.WorkbenchImages; + +/** + * @author Steffen Pingel + * @author Kevin Sawicki + */ +public class CommonImageManger { + + private static final String[] IMAGE_EXTENSIONS = { "jpg", "gif", "png", "tiff", "tif", "bmp" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + + private final LocalResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources()); + + public CommonImageManger() { + } + + public void dispose() { + resourceManager.dispose(); + } + + public Image getFileImage(String filename) { + if (filename != null) { + int dotIndex = filename.lastIndexOf('.'); + if (dotIndex != -1) { + String fileType = filename.substring(dotIndex + 1); + for (String element2 : IMAGE_EXTENSIONS) { + if (element2.equalsIgnoreCase(fileType)) { + return CommonImages.getImage(CommonImages.IMAGE_FILE); + } + } + } + String file = new Path(filename).lastSegment(); + if (file != null) { + return getImage(PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(filename)); + } + } + return WorkbenchImages.getImage(ISharedImages.IMG_OBJ_FILE); + } + + public Image getImage(ImageDescriptor imageDescriptor) { + return (Image) resourceManager.get(imageDescriptor); + } + + public LocalResourceManager getResourceManager() { + return resourceManager; + } + +} |