comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:ca07a15b6cc8
1 package de.codedo.java.editor;
2
3 import java.io.InputStream;
4
5 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
6 import org.eclipse.swt.graphics.Device;
7 import org.eclipse.swt.graphics.Image;
8
9 public class CodedoJavaEditor extends CompilationUnitEditor
10 {
11 private Image _originalTitleImage;
12 private Image _customTitleImage;
13
14 public void toggleTitleImage()
15 {
16 if (_originalTitleImage == null)
17 {
18 installCustomTitleImage();
19 }
20 else
21 {
22 restoreOriginalTitleImage();
23 }
24 }
25
26 private void installCustomTitleImage()
27 {
28 _originalTitleImage = getTitleImage();
29
30 Image titleImage = getCustomTitleImage();
31 setTitleImage(titleImage);
32 }
33
34 private Image getCustomTitleImage()
35 {
36 if (_customTitleImage == null)
37 {
38 Device device = getDefaultImage().getDevice();
39
40 InputStream input = getClass().getClassLoader().getResourceAsStream("icons/icon.png");
41 _customTitleImage = new Image(device, input);
42 }
43 return _customTitleImage;
44 }
45
46 private void restoreOriginalTitleImage()
47 {
48 setTitleImage(_originalTitleImage);
49 _originalTitleImage = null;
50 }
51 }