JAL-1640 more properties moved to style bean and rationalisation of layout update...
[jalview.git] / src / jalview / viewmodel / styles / ViewStyle.java
index ff19573..1e97af4 100644 (file)
@@ -24,12 +24,25 @@ public class ViewStyle implements ViewStyleI
 
   int charWidth;
 
+  int idWidth = -1;
+
   /**
    * gui state - changes to colour scheme propagated to all groups
    */
   private boolean colourAppliesToAllGroups;
 
   /**
+   * centre columnar annotation labels in displayed alignment annotation
+   */
+  boolean centreColumnLabels = false;
+
+  private boolean showdbrefs;
+
+  private boolean shownpfeats;
+
+  // --------END Structure Conservation
+
+  /**
    * colour according to the reference sequence defined on the alignment
    */
   private boolean colourByReferenceSeq = false;
@@ -122,38 +135,53 @@ public class ViewStyle implements ViewStyleI
    */
   boolean upperCasebold = false;
 
+  /**
+   * name of base font for view
+   */
+  private String fontName;
+  /**
+   * size for base font
+   */
+  private int fontSize;
+  
   public ViewStyle(ViewStyleI viewStyle)
   {
-    configureFrom(viewStyle);
+    ViewStyle.configureFrom(this, viewStyle);
   }
 
   public ViewStyle()
   {
   }
 
-  private void configureFrom(ViewStyleI viewStyle)
+  private static HashMap<String, Method> getters, isErs, setters;
+  static
   {
-      HashMap<String, Method> getters = new HashMap<String, Method>(), isErs = new HashMap<String, Method>();
-      HashMap<String, Method> setters = new HashMap<String, Method>();
-      // Match Getters and Setters
-      for (Method m : ViewStyleI.class.getMethods())
+    getters = new HashMap<String, Method>();
+    isErs = new HashMap<String, Method>();
+    setters = new HashMap<String, Method>();
+    // Match Getters and Setters
+    for (Method m : ViewStyleI.class.getMethods())
+    {
+      if (m.getDeclaringClass() == ViewStyleI.class)
       {
-        if (m.getDeclaringClass() == ViewStyleI.class)
+        if (m.getName().startsWith("get"))
         {
-          if (m.getName().startsWith("get"))
-          {
-            getters.put(m.getName().substring(3), m);
-          }
-          if (m.getName().startsWith("is"))
-          {
-            isErs.put(m.getName().substring(2), m);
-          }
-          if (m.getName().startsWith("set"))
-          {
-            setters.put(m.getName().substring(3), m);
-          }
+          getters.put(m.getName().substring(3), m);
+        }
+        if (m.getName().startsWith("is"))
+        {
+          isErs.put(m.getName().substring(2), m);
+        }
+        if (m.getName().startsWith("set"))
+        {
+          setters.put(m.getName().substring(3), m);
         }
       }
+    }
+  }
+
+  private static void configureFrom(ViewStyle us, ViewStyleI viewStyle)
+  {
       // try and do the set thing
       for (String prop : setters.keySet())
       {
@@ -167,7 +195,7 @@ public class ViewStyle implements ViewStyleI
       {
         try
         {
-          setter.invoke(this, getter.invoke(viewStyle));
+          setter.invoke(us, getter.invoke(viewStyle));
         } catch (Exception q)
         {
           System.err.println("Unexpected exception setting view property "
@@ -179,6 +207,41 @@ public class ViewStyle implements ViewStyleI
       }
   }
 
+  private static boolean equivalent(ViewStyle us, ViewStyleI them)
+  {
+    // look for properties we can set
+    for (String prop : setters.keySet())
+    {
+      Method getter = getters.get(prop);
+      if (getter == null)
+      {
+        getter = isErs.get(prop);
+      }
+      if (getter != null)
+      {
+        try
+        {
+          if (!getter.invoke(them).equals(getter.invoke(us)))
+          {
+            return false;
+          }
+        } catch (Exception q)
+        {
+          System.err.println("Unexpected exception testing equivalence of property "
+                  + prop + " by reflection");
+          q.printStackTrace();
+        }
+      }
+    }
+
+    return true;
+  }
+
+  public boolean equals(ViewStyleI other)
+  {
+    return other == null ? false : equivalent(this, other);
+  }
+
   /**
    * @return the upperCasebold
    */
@@ -208,6 +271,8 @@ public class ViewStyle implements ViewStyleI
    */
   int wrappedWidth;
 
+  private int fontStyle;
+
   /**
    * GUI state
    * 
@@ -518,6 +583,7 @@ public class ViewStyle implements ViewStyleI
     abovePIDThreshold = b;
   }
 
+  
   /**
    * DOCUMENT ME!
    * 
@@ -822,4 +888,120 @@ public class ViewStyle implements ViewStyleI
   {
     this.wrappedWidth = w;
   }
+
+  @Override
+  public boolean sameStyle(ViewStyleI them)
+  {
+    return equivalent(this, them);
+  }
+
+  @Override
+  public String getFontName()
+  {
+    return fontName;
+  }
+
+  @Override
+  public int getFontSize()
+  {
+    return fontSize;
+  }
+
+  @Override
+  public int getFontStyle()
+  {
+    return fontStyle;
+  }
+
+  @Override
+  public void setFontName(String name)
+  {
+    fontName = name;
+  }
+
+  @Override
+  public void setFontSize(int size)
+  {
+    fontSize = size;
+
+  }
+
+  @Override
+  public void setFontStyle(int style)
+  {
+    fontStyle = style;
+  }
+
+  @Override
+  public int getIdWidth()
+  {
+    return idWidth;
+  }
+
+  /**
+   * @param idWidth
+   *          the idWidth to set
+   */
+  @Override
+  public void setIdWidth(int idWidth)
+  {
+    this.idWidth = idWidth;
+  }
+
+  /**
+   * @return the centreColumnLabels
+   */
+  @Override
+  public boolean isCentreColumnLabels()
+  {
+    return centreColumnLabels;
+  }
+
+  /**
+   * @param centreColumnLabels
+   *          the centreColumnLabels to set
+   */
+  @Override
+  public void setCentreColumnLabels(boolean centreColumnLabels)
+  {
+    this.centreColumnLabels = centreColumnLabels;
+  }
+
+  /**
+   * @return the showdbrefs
+   */
+  @Override
+  public boolean isShowDBRefs()
+  {
+    return showdbrefs;
+  }
+
+  /**
+   * @param showdbrefs
+   *          the showdbrefs to set
+   */
+  @Override
+  public void setShowDBRefs(boolean showdbrefs)
+  {
+    this.showdbrefs = showdbrefs;
+  }
+
+  /**
+   * @return the shownpfeats
+   */
+  @Override
+  public boolean isShowNPFeats()
+  {
+    return shownpfeats;
+  }
+
+  /**
+   * @param shownpfeats
+   *          the shownpfeats to set
+   */
+  @Override
+  public void setShowNPFeats(boolean shownpfeats)
+  {
+    this.shownpfeats = shownpfeats;
+  }
 }