]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/imagers/ContainerImager.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / imagers / ContainerImager.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.common.imagers;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import org.simantics.browsing.ui.content.Imager;
18
19 /**
20  * @author Antti Villberg
21  * 
22  */
23 public class ContainerImager<Image> implements Imager {
24
25     private final Map<String, Image> constants;
26
27     private Image                    theImage;
28
29     public ContainerImager(Map<String, Image> constants, Image image) {
30         this.constants = constants;
31         this.theImage = image;
32     }
33
34     public ContainerImager(Map<String, Image> constants) {
35         this(constants, null);
36     }
37
38     public ContainerImager(Image image) {
39         this(new HashMap<String, Image>(), image);
40     }
41
42     public ContainerImager() {
43         this(new HashMap<String, Image>(), null);
44     }
45
46
47     public void setImage(String key, Image image) {
48         if (key == null)
49             theImage = image;
50         else
51             constants.put(key, image);
52     }
53
54     public void setImage(Image image) {
55         theImage = image;
56     }
57
58     @SuppressWarnings("unchecked")
59         @Override
60     public Image getImage(String key) {
61         if (theImage != null)
62             return theImage;
63         else
64             return constants.get(key);
65     }
66
67 }