blob: 98832d50862a3257b87b91d01fff6c8aea6f0eea [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 Zoltan Ujhelyi and Daniel Varro.
* 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:
* Zoltan Ujhelyi - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.visualisation;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.themes.ITheme;
import org.eclipse.ui.themes.IThemeManager;
/**
* An abstract label provider class that listens to changes in the platform
* color registry.
* @author Zoltan Ujhelyi
*/
public abstract class ViatraColoredLabelProvider extends LabelProvider {
protected Color ENTITY_BG, ENTITY_HL, ENTITY_FG, ENTITY_BO, ENTITY_BOHL;
protected Color RELATION_BG, RELATION_HL, RELATION_FG, RELATION_BO,
RELATION_BOHL;
protected Color PATTERN_BG, PATTERN_HL, PATTERN_FG, PATTERN_BO,
PATTERN_BOHL;
protected Color ARC, ARC_HL;
protected Color PARAM, PARAM_HL;
private ITheme theme;
private IPropertyChangeListener listener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
reloadColors();
}
};
/**
* Initializes the colored label provider and loads the color theme
* information from the color registry.
*/
public ViatraColoredLabelProvider() {
super();
IThemeManager themeManager = PlatformUI.getWorkbench()
.getThemeManager();
ITheme currentTheme = themeManager.getCurrentTheme();
loadTheme(currentTheme);
}
/**
* Loads the color information from a theme
* @param theme
* the theme to load
*/
public void loadTheme(ITheme theme) {
if (this.theme != null)
this.theme.removePropertyChangeListener(listener);
this.theme = theme;
this.theme.addPropertyChangeListener(listener);
reloadColors();
}
/**
* <p>
* Reloads the color theme from the Color Registry of the currently selected
* theme.
* </p>
* <p>
* <strong>Warning!</strong> Reloading the colors does not trigger the
* redraw of the graph, so changes might not be visible instantly.
* </p>
*/
public void reloadColors() {
ColorRegistry colorRegistry = theme.getColorRegistry();
ENTITY_BG = colorRegistry
.get("org.eclipse.viatra2.visualisation.entity.background");
ENTITY_HL = colorRegistry
.get("org.eclipse.viatra2.visualisation.entity.highlight");
ENTITY_FG = colorRegistry
.get("org.eclipse.viatra2.visualisation.entity.foreground");
ENTITY_BO = colorRegistry
.get("org.eclipse.viatra2.visualisation.entity.border");
ENTITY_BOHL = colorRegistry
.get("org.eclipse.viatra2.visualisation.entity.borderhighlight");
RELATION_BG = colorRegistry
.get("org.eclipse.viatra2.visualisation.relation.background");
RELATION_HL = colorRegistry
.get("org.eclipse.viatra2.visualisation.relation.highlight");
RELATION_FG = colorRegistry
.get("org.eclipse.viatra2.visualisation.relation.foreground");
RELATION_BO = colorRegistry
.get("org.eclipse.viatra2.visualisation.relation.border");
RELATION_BOHL = colorRegistry
.get("org.eclipse.viatra2.visualisation.relation.borderhighlight");
PATTERN_BG = colorRegistry
.get("org.eclipse.viatra2.visualisation.pattern.background");
PATTERN_HL = colorRegistry
.get("org.eclipse.viatra2.visualisation.pattern.highlight");
PATTERN_FG = colorRegistry
.get("org.eclipse.viatra2.visualisation.pattern.foreground");
PATTERN_BO = colorRegistry
.get("org.eclipse.viatra2.visualisation.pattern.border");
PATTERN_BOHL = colorRegistry
.get("org.eclipse.viatra2.visualisation.pattern.borderhighlight");
ARC = colorRegistry.get("org.eclipse.viatra2.visualisation.arc");
ARC_HL = colorRegistry
.get("org.eclipse.viatra2.visualisation.archighlight");
PARAM = colorRegistry
.get("org.eclipse.viatra2.visualisation.parameter");
PARAM_HL = colorRegistry
.get("org.eclipse.viatra2.visualisation.parameterhighlight");
}
@Override
public void dispose() {
if (theme != null) theme.removePropertyChangeListener(listener);
super.dispose();
}
}