X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Ftooltip%2FTooltipParticipant.java;fp=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Ftooltip%2FTooltipParticipant.java;h=25798303916936daa83a85dee10403bd56f33e73;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=79345f1501f4a94dd320c8cc56a84835fcb906db;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TooltipParticipant.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TooltipParticipant.java index 79345f150..257983039 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TooltipParticipant.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TooltipParticipant.java @@ -1,95 +1,95 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.tooltip; - -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.diagram.IDiagram.CompositionListener; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.Clickable.PressStatus; -import org.simantics.g2d.element.handler.impl.AbstractClickable; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintListener; -import org.simantics.utils.datastructures.hints.IHintObservable; - -/** - * Tooltip support - * - * @author Marko Luukkainen - * - */ -public class TooltipParticipant extends BaseTooltipParticipant implements CompositionListener { - - private final ElementHoverListener listener = new ElementHoverListener(); - - public TooltipParticipant() { - } - - @Override - protected void onDiagramSet(IDiagram newValue, IDiagram oldValue) { - if (oldValue == newValue) - return; - if (oldValue != null) { - for (IElement e : oldValue.getElements()) { - removeElement(e); - } - oldValue.removeCompositionListener(this); - } - if (newValue != null) { - for (IElement e : newValue.getElements()) { - addElement(e); - } - newValue.addCompositionListener(this); - } - } - - @Override - public void onElementAdded(IDiagram d, IElement e) { - addElement(e); - } - - @Override - public void onElementRemoved(IDiagram d, IElement e) { - removeElement(e); - } - - private void addElement(IElement e) { - e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, listener); - } - - private void removeElement(IElement e) { - e.removeKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, listener); - } - - - - class ElementHoverListener implements IHintListener { - - @Override - public void hintChanged(IHintObservable sender, Key key, - Object oldValue, Object newValue) { - IElement element = (IElement)sender; - PressStatus status = (PressStatus)newValue; - if (status == PressStatus.HOVER) { - showTooltipFor(element); - } else { - hideTooltip(); - } - //System.out.println("ttp element changed " + element + " " + status); - } - - @Override - public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { - - } - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.tooltip; + +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.IDiagram.CompositionListener; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.Clickable.PressStatus; +import org.simantics.g2d.element.handler.impl.AbstractClickable; +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintListener; +import org.simantics.utils.datastructures.hints.IHintObservable; + +/** + * Tooltip support + * + * @author Marko Luukkainen + * + */ +public class TooltipParticipant extends BaseTooltipParticipant implements CompositionListener { + + private final ElementHoverListener listener = new ElementHoverListener(); + + public TooltipParticipant() { + } + + @Override + protected void onDiagramSet(IDiagram newValue, IDiagram oldValue) { + if (oldValue == newValue) + return; + if (oldValue != null) { + for (IElement e : oldValue.getElements()) { + removeElement(e); + } + oldValue.removeCompositionListener(this); + } + if (newValue != null) { + for (IElement e : newValue.getElements()) { + addElement(e); + } + newValue.addCompositionListener(this); + } + } + + @Override + public void onElementAdded(IDiagram d, IElement e) { + addElement(e); + } + + @Override + public void onElementRemoved(IDiagram d, IElement e) { + removeElement(e); + } + + private void addElement(IElement e) { + e.addKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, listener); + } + + private void removeElement(IElement e) { + e.removeKeyHintListener(AbstractClickable.PRESS_STATUS_KEY, listener); + } + + + + class ElementHoverListener implements IHintListener { + + @Override + public void hintChanged(IHintObservable sender, Key key, + Object oldValue, Object newValue) { + IElement element = (IElement)sender; + PressStatus status = (PressStatus)newValue; + if (status == PressStatus.HOVER) { + showTooltipFor(element); + } else { + hideTooltip(); + } + //System.out.println("ttp element changed " + element + " " + status); + } + + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + + } + } + +}