view src/de/codedo/java/editor/CodedoJavaEditor.java @ 0:ca07a15b6cc8

created a plugin that allows to set a custom icon on a java editor
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 23 Oct 2014 22:20:08 +0200
parents
children f7d908568cfc
line wrap: on
line source

package de.codedo.java.editor;

import java.io.InputStream;

import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;

public class CodedoJavaEditor extends CompilationUnitEditor 
{
	private Image _originalTitleImage;
	private Image _customTitleImage;
	
	public void toggleTitleImage()
	{
		if (_originalTitleImage == null)
		{
			installCustomTitleImage();
		}
		else
		{
			restoreOriginalTitleImage();
		}
	}

	private void installCustomTitleImage() 
	{
		_originalTitleImage = getTitleImage();
		
		Image titleImage = getCustomTitleImage();
		setTitleImage(titleImage);
	}

	private Image getCustomTitleImage()
	{
		if (_customTitleImage == null)
		{
			Device device = getDefaultImage().getDevice();

			InputStream input = getClass().getClassLoader().getResourceAsStream("icons/icon.png");
			_customTitleImage = new Image(device, input);
		}
		return _customTitleImage;
	}
	
	private void restoreOriginalTitleImage() 
	{
		setTitleImage(_originalTitleImage);
		_originalTitleImage = null;
	}
}