]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/IHintContext.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.datastructures / src / org / simantics / utils / datastructures / hints / IHintContext.java
index 8391c55d53a482f45153ced6aa782d61ec3545b3..d4c28e6a2835c58d5993c87c726bd6f34838d92c 100644 (file)
-/*******************************************************************************\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
-/*\r
- *\r
- * @author Toni Kalajainen\r
- */\r
-package org.simantics.utils.datastructures.hints;\r
-\r
-import java.util.Map;\r
-\r
-/**\r
- * Hint context interface\r
- *\r
- * @see Key\r
- * @see HintContext\r
- * @see HintStack\r
- * @see IHintObservable\r
- */\r
-public interface IHintContext extends IHintObservable {\r
-\r
-       /**\r
-        * Set a value for a hint. \r
-        * @param key key\r
-        * @param value the value, <code>null</code> is not accepted\r
-        */\r
-       void setHint(Key key, Object value);\r
-       \r
-       /**\r
-        * Set a set of hints\r
-        * @param hints\r
-        */\r
-       void setHints(Map<Key, Object> hints);\r
-       \r
-       /**\r
-        * Remove a hint. In stack hint implementation lower priority hint will\r
-        * become effective. \r
-\r
-        * @param <E> type of the object bound to the specified key\r
-        * @param key key to use for the hint\r
-        * @return the typed object currently bound to the specified key\r
-        */\r
-       <E> E removeHint(Key key);\r
-\r
-       /**\r
-        * Clears the context of all current hints without notifying any listeners.\r
-        */\r
-       void clearWithoutNotification();\r
-\r
-       /**\r
-        * Hint key\r
-        */\r
-       public static abstract class Key {\r
-               /**\r
-                * Test if value is accepted\r
-                * @param value the value\r
-                * @return true if value is accepted, false if not\r
-                */\r
-               public abstract boolean isValueAccepted(Object value);          \r
-       }\r
-       \r
-       /**\r
-        * Mouse id specific key. With this key there is unique value for each mouse id.\r
-        */\r
-       public static abstract class MouseSpecificKey extends Key {\r
-               private final int mouseId;\r
-               public MouseSpecificKey(int mouseId)\r
-               {\r
-                       this.mouseId = mouseId;\r
-               }\r
-               public int getMouseId()\r
-               {\r
-                       return mouseId;\r
-               }\r
-               @Override\r
-               public int hashCode() {\r
-                       return super.hashCode() ^ mouseId;\r
-               }               \r
-               @Override\r
-               public boolean equals(Object obj) {\r
-                       if (!(obj instanceof MouseSpecificKey)) return false;\r
-                       if (((MouseSpecificKey)obj).mouseId != mouseId) return false;\r
-                       if (!obj.getClass().equals(getClass())) return false;\r
-                       return true;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Key whose value is of a specific given class. \r
-        */\r
-       public static class KeyOf extends Key {\r
-               final Class<?> clazz;\r
-               final String keyName;\r
-        public KeyOf(Class<?> clazz)\r
-        {\r
-            this.clazz = clazz;\r
-            this.keyName = null;\r
-        }\r
-        public KeyOf(Class<?> clazz, String keyName)\r
-        {\r
-            this.clazz = clazz;\r
-            this.keyName = keyName;\r
-        }\r
-               @Override\r
-               public boolean isValueAccepted(Object value) {\r
-                       return clazz.isInstance(value);\r
-               }\r
-               @Override\r
-               public String toString() {\r
-                   if (keyName == null)\r
-                       return "Key Of "+clazz.getName();\r
-                   return keyName + "(" + clazz.getSimpleName() + ")";\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * String based key\r
-        */\r
-       public static abstract class StringKey extends Key {\r
-               protected final String str;             \r
-               protected int hash;\r
-               public StringKey(String str)\r
-               {\r
-                       this.str = str;\r
-                       hash = getClass().hashCode() ^str.hashCode();                   \r
-               }\r
-               public String getString()\r
-               {\r
-                       return str;\r
-               }\r
-               @Override\r
-               public int hashCode() {\r
-                       return hash;\r
-               }               \r
-               @Override\r
-               public boolean equals(Object obj) {\r
-                       if (!(obj instanceof StringKey)) return false;\r
-                       if (!((StringKey)obj).str.equals(str)) return false;\r
-                       if (obj.getClass()!=getClass()) return false;\r
-                       return true;\r
-               }\r
-       }       \r
-       \r
-       /**\r
-        * String based key whose value is of a specific class.\r
-        */\r
-       public static class StringKeyOf extends StringKey {\r
-               final Class<?> clazz;           \r
-               public StringKeyOf(String str, Class<?> clazz)\r
-               {\r
-                       super(str);\r
-                       this.clazz = clazz;\r
-               }\r
-               @Override\r
-               public boolean isValueAccepted(Object value) {\r
-                       return clazz.isInstance(value);\r
-               }\r
-               @Override\r
-               public String toString() {\r
-                       return "Key Of ("+clazz.getName()+", "+str+")";\r
-               }               \r
-       }\r
-       \r
-\r
-       public static class MouseSpecificKeyOf extends MouseSpecificKey {\r
-               public final Class<?> clazz;\r
-               public final int mouseId;\r
-               final int hash;\r
-               public MouseSpecificKeyOf(int mouseId, Class<?> clazz)\r
-               {\r
-                       super(mouseId);\r
-                       this.clazz = clazz;\r
-                       this.mouseId = mouseId;\r
-                       hash = getClass().hashCode() ^ mouseId ^ 24392439;\r
-               }\r
-               @Override\r
-               public boolean isValueAccepted(Object value) {\r
-                       return clazz.isInstance(value);\r
-               }\r
-               @Override\r
-               public int hashCode() {\r
-                       return hash;\r
-               }\r
-               @Override\r
-               public boolean equals(Object obj) {\r
-                       if (obj.getClass()!=this.getClass()) return false;\r
-                       MouseSpecificKeyOf other = (MouseSpecificKeyOf) obj;\r
-                       return other.mouseId == mouseId;\r
-               }\r
-       }\r
-       \r
-       \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+/*
+ *
+ * @author Toni Kalajainen
+ */
+package org.simantics.utils.datastructures.hints;
+
+import java.util.Map;
+
+/**
+ * Hint context interface
+ *
+ * @see Key
+ * @see HintContext
+ * @see HintStack
+ * @see IHintObservable
+ */
+public interface IHintContext extends IHintObservable {
+
+       /**
+        * Set a value for a hint. 
+        * @param key key
+        * @param value the value, <code>null</code> is not accepted
+        */
+       void setHint(Key key, Object value);
+       
+       /**
+        * Set a set of hints
+        * @param hints
+        */
+       void setHints(Map<Key, Object> hints);
+       
+       /**
+        * Remove a hint. In stack hint implementation lower priority hint will
+        * become effective. 
+
+        * @param <E> type of the object bound to the specified key
+        * @param key key to use for the hint
+        * @return the typed object currently bound to the specified key
+        */
+       <E> E removeHint(Key key);
+
+       /**
+        * Clears the context of all current hints without notifying any listeners.
+        */
+       void clearWithoutNotification();
+
+       /**
+        * Hint key
+        */
+       public static abstract class Key {
+               /**
+                * Test if value is accepted
+                * @param value the value
+                * @return true if value is accepted, false if not
+                */
+               public abstract boolean isValueAccepted(Object value);          
+       }
+       
+       /**
+        * Mouse id specific key. With this key there is unique value for each mouse id.
+        */
+       public static abstract class MouseSpecificKey extends Key {
+               private final int mouseId;
+               public MouseSpecificKey(int mouseId)
+               {
+                       this.mouseId = mouseId;
+               }
+               public int getMouseId()
+               {
+                       return mouseId;
+               }
+               @Override
+               public int hashCode() {
+                       return super.hashCode() ^ mouseId;
+               }               
+               @Override
+               public boolean equals(Object obj) {
+                       if (!(obj instanceof MouseSpecificKey)) return false;
+                       if (((MouseSpecificKey)obj).mouseId != mouseId) return false;
+                       if (!obj.getClass().equals(getClass())) return false;
+                       return true;
+               }
+       }
+
+       /**
+        * Key whose value is of a specific given class. 
+        */
+       public static class KeyOf extends Key {
+               final Class<?> clazz;
+               final String keyName;
+        public KeyOf(Class<?> clazz)
+        {
+            this.clazz = clazz;
+            this.keyName = null;
+        }
+        public KeyOf(Class<?> clazz, String keyName)
+        {
+            this.clazz = clazz;
+            this.keyName = keyName;
+        }
+               @Override
+               public boolean isValueAccepted(Object value) {
+                       return clazz.isInstance(value);
+               }
+               @Override
+               public String toString() {
+                   if (keyName == null)
+                       return "Key Of "+clazz.getName();
+                   return keyName + "(" + clazz.getSimpleName() + ")";
+               }
+       }
+       
+       /**
+        * String based key
+        */
+       public static abstract class StringKey extends Key {
+               protected final String str;             
+               protected int hash;
+               public StringKey(String str)
+               {
+                       this.str = str;
+                       hash = getClass().hashCode() ^str.hashCode();                   
+               }
+               public String getString()
+               {
+                       return str;
+               }
+               @Override
+               public int hashCode() {
+                       return hash;
+               }               
+               @Override
+               public boolean equals(Object obj) {
+                       if (!(obj instanceof StringKey)) return false;
+                       if (!((StringKey)obj).str.equals(str)) return false;
+                       if (obj.getClass()!=getClass()) return false;
+                       return true;
+               }
+       }       
+       
+       /**
+        * String based key whose value is of a specific class.
+        */
+       public static class StringKeyOf extends StringKey {
+               final Class<?> clazz;           
+               public StringKeyOf(String str, Class<?> clazz)
+               {
+                       super(str);
+                       this.clazz = clazz;
+               }
+               @Override
+               public boolean isValueAccepted(Object value) {
+                       return clazz.isInstance(value);
+               }
+               @Override
+               public String toString() {
+                       return "Key Of ("+clazz.getName()+", "+str+")";
+               }               
+       }
+       
+
+       public static class MouseSpecificKeyOf extends MouseSpecificKey {
+               public final Class<?> clazz;
+               public final int mouseId;
+               final int hash;
+               public MouseSpecificKeyOf(int mouseId, Class<?> clazz)
+               {
+                       super(mouseId);
+                       this.clazz = clazz;
+                       this.mouseId = mouseId;
+                       hash = getClass().hashCode() ^ mouseId ^ 24392439;
+               }
+               @Override
+               public boolean isValueAccepted(Object value) {
+                       return clazz.isInstance(value);
+               }
+               @Override
+               public int hashCode() {
+                       return hash;
+               }
+               @Override
+               public boolean equals(Object obj) {
+                       if (obj.getClass()!=this.getClass()) return false;
+                       MouseSpecificKeyOf other = (MouseSpecificKeyOf) obj;
+                       return other.mouseId == mouseId;
+               }
+       }
+       
+       
+}