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.participant;
14 import java.awt.GraphicsConfiguration;
16 import org.simantics.g2d.canvas.ICanvasContext;
17 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
18 import org.simantics.g2d.image.Image;
19 import org.simantics.utils.datastructures.cache.IProvider;
20 import org.simantics.utils.datastructures.hints.HintContext;
21 import org.simantics.utils.datastructures.hints.IHintContext.Key;
24 * Utility participant used for acquiring and storing symbols.
27 * //TODO: Toni, explain why this is deprecated ??
28 * @author Toni Kalajainen
30 public class SymbolUtil extends AbstractCanvasParticipant {
32 static class SymbolKey extends Key {
33 public final IProvider<Image> provider;
34 public final GraphicsConfiguration gc;
35 private final int hash;
36 public SymbolKey(GraphicsConfiguration gc,
37 IProvider<Image> provider) {
38 assert(gc!=null && provider!=null);
40 this.provider = provider;
41 this.hash = gc.hashCode() ^provider.hashCode();
44 public boolean equals(Object obj) {
45 if (!(obj instanceof SymbolKey)) return false;
46 SymbolKey other = (SymbolKey) obj;
47 if (!other.provider.equals(provider)) return false;
48 if (!other.gc.equals(gc)) return false;
52 public int hashCode() {
56 public boolean isValueAccepted(Object value) {
57 return value instanceof Image;
61 HintContext hintCtx = new HintContext();
64 public void removedFromContext(ICanvasContext ctx) {
66 super.removedFromContext(ctx);
70 * Acquire and store symbol.
76 public Image get(IProvider<Image> provider, GraphicsConfiguration gc) {
77 SymbolKey key = new SymbolKey(gc, provider);
78 Image ps = hintCtx.getHint(key);
79 if (ps!=null) return ps;
81 hintCtx.setHint(key, ps);