JAL-4134 column grouping model and methods moved to their own object held by by Conta...
[jalview.git] / src / jalview / datamodel / ContactMatrixI.java
index ba2ee48..256d43d 100644 (file)
@@ -27,21 +27,41 @@ public interface ContactMatrixI
   int getWidth();
   int getHeight();
   
+  public GroupSetI getGroupSet();
+  
+  /// proxy methods to simplify use of the interface
+  /// Mappable contact matrices can override these to perform mapping
+  
+  default public boolean hasGroupSet()
+  {
+    return getGroupSet()!=null;
+  }
+
   default boolean hasGroups() {
-    return false;
+    return hasGroupSet() && getGroupSet().hasGroups();
   }
+
+
   default BitSet getGroupsFor(int column) {
+    if (!hasGroupSet())
+    {
     BitSet colbitset  = new BitSet();
     colbitset.set(column);
     return colbitset;
+    }
+    return getGroupSet().getGroupsFor(column);
   }
 
   default List<BitSet> getGroups() {
+    if (!hasGroupSet())
+    {
     return Arrays.asList();
+    } 
+    return getGroupSet().getGroups();
   }
 
   default boolean hasTree() {
-    return false;
+    return hasGroupSet() ? getGroupSet().hasTree() : false;
   }
 
   /**
@@ -49,25 +69,49 @@ public interface ContactMatrixI
    * @return null unless hasTree is true
    */
   default String getNewick() {
-    return null;
+    return hasGroupSet() ? getGroupSet().getNewick(): null;
   }
 
   default String getTreeMethod() {
-    return null;
+    return hasGroupSet() ? getGroupSet().getTreeMethod() :null;
   }
 
   default boolean hasCutHeight() {
-    return false;
+    return hasGroupSet() ? getGroupSet().hasCutHeight() : false;
   }
 
   default double getCutHeight() {
-    return 0;
+    return hasGroupSet() ? getGroupSet().getCutHeight():0;
   }
 
-  void updateGroups(List<BitSet> colGroups);
+  default void updateGroups(List<BitSet> colGroups)
+  {
+    if (hasGroupSet())
+    {
+      getGroupSet().updateGroups(colGroups);
+    }
+  }
 
-  void setColorForGroup(BitSet bs, Color color);
+  default void setColorForGroup(BitSet bs, Color color)
+  {
+    if (hasGroupSet())
+    {
+      getGroupSet().setColorForGroup(bs, color);
+    }
+  }
+
+  default Color getColourForGroup(BitSet bs)
+  {
+    if (hasGroupSet())
+    {
+      return getGroupSet().getColourForGroup(bs);
+    }
+    else
+    {
+      return Color.white;
+    }
+  }
 
-  default Color getColourForGroup(BitSet bs) { return Color.white;}
+  void setGroupSet(GroupSet makeGroups);
 
 }