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
14 * @author Toni Kalajainen
\r
16 package org.simantics.utils.datastructures.hints;
\r
18 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
19 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
\r
21 public class HintStackTest {
\r
23 public static final Key KEY = new KeyOf(Double.class);
\r
28 public static void main(String[] args) {
\r
29 IHintStack stack = new HintStack();
\r
30 stack.addHintListener(new IHintListener() {
\r
32 public void hintChanged(IHintObservable sender, Key key,
\r
33 Object oldValue, Object newValue) {
\r
34 System.out.println("Hint changed: "+key+"="+newValue+" (was "+oldValue+")");
\r
38 public void hintRemoved(IHintObservable sender, Key key,
\r
40 System.out.println("Hint removed: "+key+" (was "+oldValue+")");
\r
42 IHintContext c1 = new HintContext();
\r
43 IHintContext c2 = new HintContext();
\r
45 c1.setHint(KEY, 1.0);
\r
46 c2.setHint(KEY, 2.0);
\r
49 stack.addHintContext(c1, 0);
\r
51 stack.addHintContext(c2, 1);
\r
53 // underlying removed, do not do anything
\r
54 stack.removeHintContext(c1);
\r
56 // add over prev value, override
\r
57 stack.addHintContext(c1, 2);
\r
59 // should not do anything, is overridden
\r
60 c2.setHint(KEY, 3.0);
\r
62 // changed. overrides c2
\r
63 c1.setHint(KEY, 4.0);
\r
65 // removed. c2's value 3 becomes effective
\r