| // SEIRRelativeValueColorProviderAdapter.java |
| package org.eclipse.stem.ui.adapters.color; |
| |
| /******************************************************************************* |
| * Copyright (c) 2007 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 |
| *******************************************************************************/ |
| |
| import java.util.ConcurrentModificationException; |
| |
| import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| import org.eclipse.stem.core.graph.DynamicNodeLabel; |
| import org.eclipse.stem.core.graph.Node; |
| import org.eclipse.stem.core.graph.NodeLabel; |
| import org.eclipse.stem.diseasemodels.standard.DiseaseModel; |
| import org.eclipse.stem.diseasemodels.standard.DiseaseModelLabel; |
| import org.eclipse.stem.populationmodels.standard.PopulationModel; |
| import org.eclipse.stem.populationmodels.standard.PopulationModelLabel; |
| import org.eclipse.stem.ui.adapters.color.AbstractRelativeValueColorProviderAdapterFactory.PropertySelectionListener; |
| import org.eclipse.swt.graphics.Color; |
| import org.eclipse.swt.graphics.GC; |
| |
| /** |
| * This class adapts {@link Node} objects to |
| * {@link SEIRRelativeValueColorProvider} object. |
| */ |
| public class SEIRRelativeValueColorProviderAdapter extends |
| AbstractRelativeValueColorProviderAdapter implements PropertySelectionListener{ |
| |
| private ItemPropertyDescriptor selectedProperty; |
| |
| /** |
| * Constructor |
| * @param selectedProperty |
| */ |
| public SEIRRelativeValueColorProviderAdapter(ItemPropertyDescriptor selectedProperty) { |
| super(); |
| this.selectedProperty = selectedProperty; |
| } // SEIRRelativeValueColorProviderAdapter |
| |
| /** |
| * @see org.eclipse.stem.ui.adapters.color.AbstractRelativeValueColorProviderAdapter#getRelativeValue() |
| */ |
| @Override |
| public float getRelativeValue() { |
| |
| final Node node = (Node) getTarget(); |
| try { |
| for (final NodeLabel label : node.getLabels()) { |
| if (label instanceof DynamicNodeLabel) { |
| DynamicNodeLabel nodeLabel = (DynamicNodeLabel)label; |
| if (nodeLabel.getDecorator() == selectedDecorator) { |
| |
| if(selectedDecorator instanceof DiseaseModel) { |
| if(nodeLabel instanceof DiseaseModelLabel) { |
| if(!((DiseaseModelLabel)nodeLabel).getPopulationModelLabel().getPopulationIdentifier().equals(selectedPopulationIdentifier)) { |
| continue; // wrong population identifier |
| } else { |
| setRVPTarget(nodeLabel); |
| return (float) rvp.getRelativeValue(selectedProperty); |
| } |
| }// if disease model label |
| } // if disease model |
| |
| if(selectedDecorator instanceof PopulationModel) { |
| String popId = selectedPopulationIdentifier; |
| if(nodeLabel instanceof PopulationModelLabel) { |
| if(! ((PopulationModelLabel)nodeLabel).getPopulationIdentifier().equals(popId)) { |
| continue; // wrong population identifier |
| } else { |
| setRVPTarget(nodeLabel); |
| return (float) rvp.getRelativeValue(selectedProperty); |
| } |
| }// if population model label |
| }// if population model |
| |
| }// if selected |
| }// if dynamic label |
| }// for all labels |
| } catch(ConcurrentModificationException cme) { |
| // We expect exception to be rare so we simply retry the getRelativeValue call |
| return getRelativeValue(); |
| } |
| |
| return 0; // We shouldn't reach this point |
| } // getRelativeValue |
| |
| /** |
| * @see org.eclipse.stem.ui.adapters.color.AbstractRelativeValueColorProviderAdapter#updateGC(org.eclipse.swt.graphics.GC, float, boolean) |
| */ |
| @Override |
| public void updateGC(GC gcToUpdate, float gainFactor, boolean useLogScaling) { |
| device = gcToUpdate.getDevice(); |
| double relativeValue = getRelativeValue(); |
| double gainedRelativeValue = gainFactor * relativeValue; |
| if (useLogScaling) { |
| gainedRelativeValue = Math.log10(99.0*gainedRelativeValue + 1.0) / 2.0; |
| } |
| STEMColor foreground = getColorForRelativeValue(gainedRelativeValue); |
| gcToUpdate.setBackground(foreground.toSWTColor(gcToUpdate.getDevice())); |
| } |
| |
| /** |
| * @see org.eclipse.stem.ui.adapters.color.IntensityColorsLabelsMappingColorProviderAdapterFactory.PropertySelectionListener#propertySelected(org.eclipse.emf.edit.provider.ItemPropertyDescriptor) |
| */ |
| public void propertySelected(ItemPropertyDescriptor selectedProperty) { |
| this.selectedProperty = selectedProperty; |
| } |
| |
| } // SEIRRelativeValueColorProviderAdapter |