Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b84b8ee830bffe8e43f1e05f670acf220165e2c9 (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
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tm.te.ui.terminals.tabs;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.graphics.Font;
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
import org.eclipse.tm.internal.terminal.view.TerminalView;

/**
 * Terminals tab default property change listener implementation.
 */
@SuppressWarnings("restriction")
public class TabPropertyChangeListener implements IPropertyChangeListener {
	/**
	 * Default terminal font property key.
	 *
	 * @see TerminalView#FONT_DEFINITION
	 */
	public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$

	// Reference to the parent tab item
	private final CTabItem tabItem;

	/**
	 * Constructor.
	 *
	 * @param tabItem The parent tab item. Must not be <code>null</code>.
	 */
	public TabPropertyChangeListener(CTabItem tabItem) {
		super();
		Assert.isNotNull(tabItem);
		this.tabItem = tabItem;
	}

	/**
	 * Returns the associated parent tab item.
	 *
	 * @return The parent tab item.
	 */
	protected final CTabItem getTabItem() {
		return tabItem;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
	 */
	@Override
	public void propertyChange(PropertyChangeEvent event) {
		// In case we are called once after the tab item got disposed
		// --> Do nothing
		if (getTabItem() == null || getTabItem().isDisposed()) return;

		// Listen to changes of the Font settings
		if (event.getProperty().equals(FONT_DEFINITION)) {
			onFontDefinitionProperyChanged();
		}
	}

	/**
	 * Called if a property change event for the terminal font
	 * definition is received.
	 */
	protected void onFontDefinitionProperyChanged() {
		// Get the current font from JFace
		Font font = JFaceResources.getFont(FONT_DEFINITION);
		// Get the terminal control from the tab item
		if (getTabItem().getData() instanceof ITerminalViewControl) {
			ITerminalViewControl terminal = (ITerminalViewControl)getTabItem().getData();
			terminal.setFont(font);
		}
	}
}

Back to the top