Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7d7bd08ad3c314bd94c701eea4f77eccf9cf4665 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.examples.paint;


import org.eclipse.jface.action.*;
import org.eclipse.jface.resource.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.part.*;

/**
 * The view for the paint application.
 * All rendering happens inside the area created by createPartControl().
 * 
 * @see ViewPart
 */
public class PaintView extends ViewPart {
	PaintExample instance = null;

	/**
	 * Constructs a Paint view.
	 */
	public PaintView() {
	}

	/**
	 * Creates the example.
	 * 
	 * @see ViewPart#createPartControl
	 */
	@Override
	public void createPartControl(Composite parent) {
		instance = new PaintExample(parent);
		instance.createGUI(parent);

		/*** Add toolbar contributions ***/
		final IActionBars actionBars = getViewSite().getActionBars();
		IToolBarManager toolbarManager = actionBars.getToolBarManager();
		Tool tools[] = PaintExample.tools;
		String group = tools[0].group;
		toolbarManager.add(new GroupMarker(group));
		for (int i = 0; i < tools.length; i++) {
			Tool tool = tools[i];
			if (!tool.group.equals(group)) {
				toolbarManager.add(new Separator());
				toolbarManager.add(new GroupMarker(tool.group));
			}
			group = tool.group;
			PaintAction action = new PaintAction(tool);
			toolbarManager.appendToGroup(group, action);
			if (i == PaintExample.Default_tool || i == PaintExample.Default_fill || i == PaintExample.Default_linestyle) {
				action.setChecked(true);
			}
		}
		actionBars.updateActionBars();

		instance.setDefaults();
	}

	/**
	 * Called when the View is to be disposed
	 */	
	@Override
	public void dispose() {
		instance.dispose();
		instance = null;
		super.dispose();
	}
	
	/**
	 * Returns the Display.
	 * 
	 * @return the display we're using
	 */
	public Display getDisplay() {
		return instance.getDisplay();
	}
	
	/**
	 * Called when we must grab focus.
	 * 
	 * @see org.eclipse.ui.part.ViewPart#setFocus
	 */
	@Override
	public void setFocus() {
		instance.setFocus();
	}

	/**
	 * Action set glue.
	 */
	class PaintAction extends Action {
		private int style;
		private Runnable action;
		public PaintAction(Tool tool) {
			super();
			String id = tool.group + '.' + tool.name;
			setId(id);
			style = tool.type == SWT.RADIO ? IAction.AS_RADIO_BUTTON : IAction.AS_PUSH_BUTTON;
			action = tool.action;
			setText(PaintExample.getResourceString(id + ".label"));
			setToolTipText(PaintExample.getResourceString(id + ".tooltip"));
			setDescription(PaintExample.getResourceString(id + ".description"));
			setImageDescriptor(ImageDescriptor.createFromFile(
					PaintExample.class,
					PaintExample.getResourceString(id + ".image")));
		}
		@Override
		public int getStyle() { return style; }
		@Override
		public void run() { action.run(); }
	}
}

Back to the top