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.diagram.synchronization.graph;
14 import java.awt.geom.AffineTransform;
15 import java.awt.geom.Rectangle2D;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.Resource;
19 import org.simantics.diagram.synchronization.IModificationQueue;
20 import org.simantics.diagram.synchronization.ISynchronizationContext;
21 import org.simantics.g2d.element.ElementHints;
22 import org.simantics.utils.datastructures.hints.IHintObservable;
23 import org.simantics.utils.datastructures.hints.IHintContext.Key;
26 * @author Tuukka Lehtonen
28 public class TransformSynchronizer extends ResourceSynchronizer {
30 public static final TransformSynchronizer INSTANCE = new TransformSynchronizer();
32 private static final Key[] SYNCHRONIZED_HINTS = {
33 ElementHints.KEY_TRANSFORM,
34 ElementHints.KEY_BOUNDS
38 public Key[] getSynchronizedHints() {
39 return SYNCHRONIZED_HINTS;
43 public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) {
44 if(newValue == null) return false;
45 if (ElementHints.KEY_TRANSFORM.equals(key)) {
46 BasicResources br = context.get(GraphSynchronizationHints.BASIC_RESOURCES);
48 final double[] flatmatrix = new double[6];
49 ((AffineTransform) newValue).getMatrix(flatmatrix);
51 return queue.offer(new PropertyModification(object, br.DIA.HasTransform, br.G2D.Transform, flatmatrix, Bindings.DOUBLE_ARRAY), null);
52 } else if (ElementHints.KEY_BOUNDS.equals(key)) {
53 BasicResources br = context.get(GraphSynchronizationHints.BASIC_RESOURCES);
55 final double[] flatmatrix = new double[4];
56 flatmatrix[0] = ((Rectangle2D)newValue).getMinX();
57 flatmatrix[1] = ((Rectangle2D)newValue).getMinY();
58 flatmatrix[2] = ((Rectangle2D)newValue).getWidth();
59 flatmatrix[3] = ((Rectangle2D)newValue).getHeight();
60 return queue.offer(new PropertyModification(object, br.G2D.HasBounds, br.G2D.Rectangle2D, flatmatrix, Bindings.DOUBLE_ARRAY), null);