X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fparticipant%2FSubCanvas.java;h=776c15a90c51a7b299742a0d75678016cf3a3187;hb=HEAD;hp=016d8fbb014cb90793fef66aeb9d6483ae1f802f;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/SubCanvas.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/SubCanvas.java index 016d8fbb0..776c15a90 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/SubCanvas.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/participant/SubCanvas.java @@ -1,118 +1,118 @@ -/******************************************************************************* - * 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.participant; - -import org.simantics.g2d.canvas.Hints; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.canvas.IMouseCaptureContext; -import org.simantics.g2d.canvas.IMouseCursorContext; -import org.simantics.g2d.canvas.IContentContext; -import org.simantics.g2d.canvas.IContentContext.IContentListener; -import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; -import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; - -/** - * Subcanvas encapsulates a canvas (another) in one participant. - * - * - * @author Toni Kalajainen - */ -public class SubCanvas extends AbstractCanvasParticipant { - - @Dependency TransformUtil util; - - private boolean enabled = true; - private ICanvasContext superCtx = null; - - /** Sub-Canvas */ - private ICanvasContext sub; - int eventPriority, paintPriority, hintPriority; - //IHintContext subHintStack; - IMouseCursorContext origSubCursorCtx; - IMouseCaptureContext origSubCaptureCtx; - - // Subcanvas has become dirty, make super canvas also dirty - IContentListener paintableCtxListener = new IContentListener() { - - @Override - public void onDirty(IContentContext sender) { - if (superCtx==null) return; - superCtx.getContentContext().setDirty(); - } - }; - - public SubCanvas(ICanvasContext subCanvas, int eventPriority, int paintPriority, int hintPriority) { - assert(subCanvas!=null); - this.sub = subCanvas; - this.eventPriority = eventPriority; - this.paintPriority = paintPriority; - this.hintPriority = hintPriority; - //subHintStack = sub.getHintStack().createStackRead(sub.getDefaultHintContext()); - -// subCanvas.getMouseCaptureContext().addMouseCaptureListener(new IMouseCaptureListener() { -// @Override -// public void onMouseCaptured(IMouseCaptureContext sender, int mouseId) { -// if (superCtx==null) return; -// superCtx.getMouseCaptureContext(). -// } -// @Override -// public void onMouseReleased(IMouseCaptureContext sender, int mouseId) { -// }}); - } - - @Override - public void addedToContext(ICanvasContext ctx) { - super.addedToContext(ctx); - superCtx = ctx; - if (enabled) enable(); - } - - @Override - public void removedFromContext(ICanvasContext ctx) { - assert(superCtx==ctx); - if (enabled) disable(); - superCtx = null; - super.removedFromContext(ctx); - } - - public void setEnabled(boolean enabled) - { - if (this.enabled == enabled) return; - if (enabled) enable(); else disable(); - } - - void enable() { - superCtx.getEventHandlerStack().add(sub.getEventHandlerStack(), eventPriority); -// superCtx.getPainterStack().add(sub.getPainterStack(), paintPriority); - //superCtx.getHintStack().addHintContext(subHintStack, hintPriority); - sub.getContentContext().addPaintableContextListener(paintableCtxListener); - origSubCursorCtx = sub.getMouseCursorContext(); - sub.setMouseCursorContext(getContext().getMouseCursorContext()); - origSubCaptureCtx = sub.getMouseCaptureContext(); - sub.setMouseCaptureContext(getContext().getMouseCaptureContext()); - assert(sub.getDefaultHintContext().getHint(Hints.KEY_SUPER_CANVAS)==null); - //sub.getDefaultHintContext().setHint(Hints.KEY_SUPER_CANVAS, ctx); - this.enabled = true; - } - - void disable() { - sub.getDefaultHintContext().removeHint(Hints.KEY_SUPER_CANVAS); - sub.setMouseCaptureContext(origSubCaptureCtx); - sub.setMouseCursorContext(origSubCursorCtx); - sub.getContentContext().removePaintableContextListener(paintableCtxListener); - //ctx.getHintStack().removeHintContext(subHintStack); -// superCtx.getPainterStack().remove(sub.getPainterStack()); - superCtx.getEventHandlerStack().remove(sub.getEventHandlerStack()); - this.enabled = false; - } - -} +/******************************************************************************* + * 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.participant; + +import org.simantics.g2d.canvas.Hints; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.canvas.IMouseCaptureContext; +import org.simantics.g2d.canvas.IMouseCursorContext; +import org.simantics.g2d.canvas.IContentContext; +import org.simantics.g2d.canvas.IContentContext.IContentListener; +import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; +import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; + +/** + * Subcanvas encapsulates a canvas (another) in one participant. + * + * + * @author Toni Kalajainen + */ +public class SubCanvas extends AbstractCanvasParticipant { + + @Dependency TransformUtil util; + + private boolean enabled = true; + private ICanvasContext superCtx = null; + + /** Sub-Canvas */ + private ICanvasContext sub; + int eventPriority, paintPriority, hintPriority; + //IHintContext subHintStack; + IMouseCursorContext origSubCursorCtx; + IMouseCaptureContext origSubCaptureCtx; + + // Subcanvas has become dirty, make super canvas also dirty + IContentListener paintableCtxListener = new IContentListener() { + + @Override + public void onDirty(IContentContext sender) { + if (superCtx==null) return; + superCtx.getContentContext().setDirty(); + } + }; + + public SubCanvas(ICanvasContext subCanvas, int eventPriority, int paintPriority, int hintPriority) { + assert(subCanvas!=null); + this.sub = subCanvas; + this.eventPriority = eventPriority; + this.paintPriority = paintPriority; + this.hintPriority = hintPriority; + //subHintStack = sub.getHintStack().createStackRead(sub.getDefaultHintContext()); + +// subCanvas.getMouseCaptureContext().addMouseCaptureListener(new IMouseCaptureListener() { +// @Override +// public void onMouseCaptured(IMouseCaptureContext sender, int mouseId) { +// if (superCtx==null) return; +// superCtx.getMouseCaptureContext(). +// } +// @Override +// public void onMouseReleased(IMouseCaptureContext sender, int mouseId) { +// }}); + } + + @Override + public void addedToContext(ICanvasContext ctx) { + super.addedToContext(ctx); + superCtx = ctx; + if (enabled) enable(); + } + + @Override + public void removedFromContext(ICanvasContext ctx) { + assert(superCtx==ctx); + if (enabled) disable(); + superCtx = null; + super.removedFromContext(ctx); + } + + public void setEnabled(boolean enabled) + { + if (this.enabled == enabled) return; + if (enabled) enable(); else disable(); + } + + void enable() { + superCtx.getEventHandlerStack().add(sub.getEventHandlerStack(), eventPriority); +// superCtx.getPainterStack().add(sub.getPainterStack(), paintPriority); + //superCtx.getHintStack().addHintContext(subHintStack, hintPriority); + sub.getContentContext().addPaintableContextListener(paintableCtxListener); + origSubCursorCtx = sub.getMouseCursorContext(); + sub.setMouseCursorContext(getContext().getMouseCursorContext()); + origSubCaptureCtx = sub.getMouseCaptureContext(); + sub.setMouseCaptureContext(getContext().getMouseCaptureContext()); + assert(sub.getDefaultHintContext().getHint(Hints.KEY_SUPER_CANVAS)==null); + //sub.getDefaultHintContext().setHint(Hints.KEY_SUPER_CANVAS, ctx); + this.enabled = true; + } + + void disable() { + sub.getDefaultHintContext().removeHint(Hints.KEY_SUPER_CANVAS); + sub.setMouseCaptureContext(origSubCaptureCtx); + sub.setMouseCursorContext(origSubCursorCtx); + sub.getContentContext().removePaintableContextListener(paintableCtxListener); + //ctx.getHintStack().removeHintContext(subHintStack); +// superCtx.getPainterStack().remove(sub.getPainterStack()); + superCtx.getEventHandlerStack().remove(sub.getEventHandlerStack()); + this.enabled = false; + } + +}