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