--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.common.imagers;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.content.Imager;\r
+\r
+/**\r
+ * @author Antti Villberg\r
+ * \r
+ */\r
+public class ContainerImager<Image> implements Imager {\r
+\r
+ private final Map<String, Image> constants;\r
+\r
+ private Image theImage;\r
+\r
+ public ContainerImager(Map<String, Image> constants, Image image) {\r
+ this.constants = constants;\r
+ this.theImage = image;\r
+ }\r
+\r
+ public ContainerImager(Map<String, Image> constants) {\r
+ this(constants, null);\r
+ }\r
+\r
+ public ContainerImager(Image image) {\r
+ this(new HashMap<String, Image>(), image);\r
+ }\r
+\r
+ public ContainerImager() {\r
+ this(new HashMap<String, Image>(), null);\r
+ }\r
+\r
+\r
+ public void setImage(String key, Image image) {\r
+ if (key == null)\r
+ theImage = image;\r
+ else\r
+ constants.put(key, image);\r
+ }\r
+\r
+ public void setImage(Image image) {\r
+ theImage = image;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public Image getImage(String key) {\r
+ if (theImage != null)\r
+ return theImage;\r
+ else\r
+ return constants.get(key);\r
+ }\r
+\r
+}\r