1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.element.handler.impl;
\r
14 import org.simantics.g2d.canvas.ICanvasContext;
\r
15 import org.simantics.g2d.element.IElement;
\r
16 import org.simantics.g2d.element.handler.Togglable;
\r
17 import org.simantics.scenegraph.g2d.events.MouseEvent;
\r
18 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
19 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
23 * Base implementation for button handlers
\r
26 * @author Toni Kalajainen
\r
28 public abstract class AbstractTogglable extends AbstractClickable implements Togglable {
\r
30 private static final long serialVersionUID = 8409636755289629134L;
\r
31 public static Key TOGGLE_KEY = new KeyOf(Boolean.class);
\r
33 public AbstractTogglable(Double strayDistance) {
\r
34 super(strayDistance);
\r
37 public AbstractTogglable() {
\r
43 public boolean handleMouseEvent(IElement e, ICanvasContext ctx,
\r
46 boolean b = super.handleMouseEvent(e, ctx, me);
\r
52 protected void onClicked(GrabInfo gi, ICanvasContext ctx) {
\r
54 Boolean b = e.getHint(TOGGLE_KEY);
\r
57 e.setHint(TOGGLE_KEY, !b);
\r
61 public boolean isChecked(IElement e) {
\r
62 Boolean b = e.getHint(TOGGLE_KEY);
\r
63 return (b == null ? false : b);
\r