1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.symbolEditor;
14 import org.simantics.g2d.canvas.ICanvasContext;
15 import org.simantics.g2d.participant.GridPainter;
16 import org.simantics.scl.runtime.function.Function1;
17 import org.simantics.utils.datastructures.hints.HintListenerAdapter;
18 import org.simantics.utils.datastructures.hints.IHintContext;
19 import org.simantics.utils.datastructures.hints.IHintObservable;
20 import org.simantics.utils.datastructures.hints.IHintContext.Key;
23 * A function and a listener for diagram grid visibility. The function
24 * returns the current grid visibility as a Boolean.
26 * @author Tuukka Lehtonen
28 public class GridVisibleFunction extends HintListenerAdapter implements Function1<Object, Boolean> {
32 public GridVisibleFunction(ICanvasContext ctx) {
33 IHintContext hctx = ctx.getDefaultHintContext();
35 hintChanged(hctx, GridPainter.KEY_GRID_ENABLED, null, hctx.getHint(GridPainter.KEY_GRID_ENABLED));
37 hctx.addKeyHintListener(GridPainter.KEY_GRID_ENABLED, this);
41 public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
42 enabled = Boolean.valueOf(Boolean.TRUE.equals(newValue));
46 public Boolean apply(Object p0) {