All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.bio.phylogeny.TreeDisplaySettings Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.bio.phylogeny;


import com.hfg.setting.BooleanSetting;
import com.hfg.setting.ComplexSetting;
import com.hfg.setting.FloatSetting;
import com.hfg.setting.IntSetting;
import com.hfg.setting.Settings;
import com.hfg.setting.StringSetting;

//------------------------------------------------------------------------------
/**
 * Phylogenetic tree display options for use with NewickTree.
 *
 * @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class TreeDisplaySettings extends Settings
{

   private static final String CLADOGRAM_STYLE               = "CladogramStyle";
   private static final String TREE_WIDTH                    = "TreeWidth";
   private static final String ASSIGN_GROUPS_TO_SINGLETONS   = "AssignGroupsToSingletons";
   private static final String ALIGN_LEAF_NODE_LABELS        = "AlignLeaftNodeLabels";
   private static final String SHOW_SCALE                    = "ShowScale";
   private static final String ENABLE_DYNAMIC_GROUPING       = "EnableDynamicGrouping";
   private static final String BRANCH_LENGTH_TRAVERSAL_LIMIT = "BranchLengthTraversalLimit";
   private static final String BLTL_ONCHANGE_CALLBACK        = "BLTL_OnChangeCallback";
   private static final String BLTL_SELECTION_COMPLETE_CALLBACK = "BLTL_SelectionCompleteCallback";

   private static CladogramStyle sDefaultCladogramStyle      = CladogramStyle.Rectangular;
   private static int     sDefaultTreeWidth                  = 500;
   private static boolean sDefaultAssignGroupsToSingletons   = false;
   private static boolean sDefaultAlignLeaftNodeLabels       = true;
   private static boolean sDefaultShowScale                  = true;
   private static boolean sDefaultEnableDynamicGrouping      = false;

   //**************************************************************************
   // CONSTRUCTORS
   //**************************************************************************

   //---------------------------------------------------------------------------
   public TreeDisplaySettings()
   {

   }

   //---------------------------------------------------------------------------
   @Override
   protected void init()
   {
      super.init();

      add(new ComplexSetting(CLADOGRAM_STYLE, sDefaultCladogramStyle));
      add(new IntSetting(TREE_WIDTH, sDefaultTreeWidth));
      add(new BooleanSetting(ASSIGN_GROUPS_TO_SINGLETONS, sDefaultAssignGroupsToSingletons));
      add(new BooleanSetting(ALIGN_LEAF_NODE_LABELS, sDefaultAlignLeaftNodeLabels));
      add(new BooleanSetting(SHOW_SCALE, sDefaultShowScale));
      add(new BooleanSetting(ENABLE_DYNAMIC_GROUPING, sDefaultEnableDynamicGrouping));
      add(new FloatSetting(BRANCH_LENGTH_TRAVERSAL_LIMIT));
      add(new StringSetting(BLTL_ONCHANGE_CALLBACK));
      add(new StringSetting(BLTL_SELECTION_COMPLETE_CALLBACK));
   }

   //###########################################################################
   // PUBLIC METHODS
   //###########################################################################

   //---------------------------------------------------------------------------
   public TreeDisplaySettings setCladogramStyle(CladogramStyle inValue)
   {
      get(CLADOGRAM_STYLE).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public CladogramStyle getCladogramStyle()
   {
      return (CladogramStyle) get(CLADOGRAM_STYLE).getValue();
   }


   //---------------------------------------------------------------------------
   public TreeDisplaySettings setTreeWidth(int inValue)
   {
      get(TREE_WIDTH).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public Integer getTreeWidth()
   {
      return (Integer) get(TREE_WIDTH).getValue();
   }


   //---------------------------------------------------------------------------
   public TreeDisplaySettings setAssignGroupsToSingletons(boolean inValue)
   {
      get(ASSIGN_GROUPS_TO_SINGLETONS).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public Boolean getAssignGroupsToSingletons()
   {
      return (Boolean) get(ASSIGN_GROUPS_TO_SINGLETONS).getValue();
   }


   //---------------------------------------------------------------------------
   public TreeDisplaySettings setAlignLeaftNodeLabels(boolean inValue)
   {
      get(ALIGN_LEAF_NODE_LABELS).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public Boolean getAlignLeaftNodeLabels()
   {
      return (Boolean) get(ALIGN_LEAF_NODE_LABELS).getValue();
   }


   //---------------------------------------------------------------------------
   public TreeDisplaySettings setShowScale(boolean inValue)
   {
      get(SHOW_SCALE).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public Boolean getShowScale()
   {
      return (Boolean) get(SHOW_SCALE).getValue();
   }


   //---------------------------------------------------------------------------
   /**
    When outputting the tree in SVG, this option allows for dynamically adjusting
    the branch length traversal limit to group closely related leaf nodes.
    * @param inValue whether or not to enable the dynamic grouping option
    * @return this Settings object to allow method chaining
    */
   public TreeDisplaySettings setEnableDynamicGrouping(boolean inValue)
   {
      get(ENABLE_DYNAMIC_GROUPING).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public Boolean getEnableDynamicGrouping()
   {
      return (Boolean) get(ENABLE_DYNAMIC_GROUPING).getValue();
   }


   //---------------------------------------------------------------------------
   public TreeDisplaySettings setBranchLengthTraversalLimit(Float inValue)
   {
      get(BRANCH_LENGTH_TRAVERSAL_LIMIT).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public Float getBranchLengthTraversalLimit()
   {
      return (Float) get(BRANCH_LENGTH_TRAVERSAL_LIMIT).getValue();
   }

   //--------------------------------------------------------------------------
   public void boundsCheckBranchLengthTraversalLimit(NewickTree inTree)
   {
      Float branchLengthTraversalLimit = getBranchLengthTraversalLimit();
      if (branchLengthTraversalLimit != null)
      {
         // Bounds check
         if (branchLengthTraversalLimit < 0)
         {
            branchLengthTraversalLimit = 0f;
         }
         else if (branchLengthTraversalLimit > 2 * inTree.getRootedTreeDistance())
         {
            branchLengthTraversalLimit = 2 * inTree.getRootedTreeDistance();
         }

         setBranchLengthTraversalLimit(branchLengthTraversalLimit);
      }
   }


   //---------------------------------------------------------------------------
   /**
    While dynamically adjusting the branch length traversal limit to group closely
    related leaf nodes, this callback, if defined, is invoked so the changing BLTL
    value can be displayed.
    * @param inValue the javascript method to invoke (with the new BLTL value, and
    *                the drag handle object as arguments)
    * @return this Settings object to allow method chaining
    */
   public TreeDisplaySettings setBLTL_OnChangeCallback(String inValue)
   {
      get(BLTL_ONCHANGE_CALLBACK).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public String getBLTL_OnChangeCallback()
   {
      return (String) get(BLTL_ONCHANGE_CALLBACK).getValue();
   }


   //---------------------------------------------------------------------------
   /**
    When the dynamic adjustment of the branch length traversal limit to group closely
    related leaf nodes is completed (end of drag event), this callback, if defined, is invoked.
    * @param inValue the javascript method to invoke (with the new BLTL value, and
    *                the drag handle object as arguments)
    * @return this Settings object to allow method chaining
    */
   public TreeDisplaySettings setBLTL_SelectionCompleteCallback(String inValue)
   {
      get(BLTL_SELECTION_COMPLETE_CALLBACK).setValue(inValue);
      return this;
   }

   //---------------------------------------------------------------------------
   public String getBLTL_SelectionCompleteCallback()
   {
      return (String) get(BLTL_SELECTION_COMPLETE_CALLBACK).getValue();
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy