001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:48:48 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33634 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.cipres.kepler; 031 032import forester.atv.ATVjframe; 033// Ptolemy packages 034import ptolemy.actor.TypedAtomicActor; 035import ptolemy.actor.TypedIOPort; 036import ptolemy.data.StringToken; 037import ptolemy.data.type.BaseType; 038import ptolemy.kernel.CompositeEntity; 039import ptolemy.kernel.util.IllegalActionException; 040import ptolemy.kernel.util.NameDuplicationException; 041 042////////////////////////////////////////////////////////////////////////// 043//// TreeVizForester 044/** 045 * Given a tree expression (in newick format), the TreeVizForester actor 046 * displays the phylogenetic tree in the Forester tree view window. 047 * 048 * @author Zhijie Guan 049 * @version $Id: TreeVizForester.java 33634 2015-08-24 22:48:48Z crawl $ 050 */ 051 052public class TreeVizForester extends TypedAtomicActor { 053 054 /** 055 * Construct a TreeVizForester actor with the given container and name. 056 * 057 * @param container 058 * The container. 059 * @param name 060 * The name of this actor. 061 * @exception IllegalActionException 062 * If the entity cannot be contained by the proposed 063 * container. 064 * @exception NameDuplicationException 065 * If the container already has an actor with this name. 066 */ 067 068 public TreeVizForester(CompositeEntity container, String name) 069 throws NameDuplicationException, IllegalActionException { 070 super(container, name); 071 072 // construct the input port inputTreeString 073 inputTreeString = new TypedIOPort(this, "inputTreeString", true, false); 074 inputTreeString.setDisplayName("Tree Expression (Newick)"); 075 // inputTreeString.setDisplayName("Tree Expression (Newick)"); 076 inputTreeString.setTypeEquals(BaseType.GENERAL); 077 078 _attachText("_iconDescription", "<svg>\n" + "<rect x=\"0\" y=\"0\" " 079 + "width=\"60\" height=\"20\" " + "style=\"fill:white\"/>\n" 080 + "</svg>\n"); 081 082 } 083 084 // ///////////////////////////////////////////////////////////////// 085 // // ports and parameters //// 086 087 /** 088 * Tree expression to pass to the Forester tree display package. This port 089 * is an input port of type GENERAL. 090 */ 091 public TypedIOPort inputTreeString = null; 092 093 // ///////////////////////////////////////////////////////////////// 094 // // functional variables //// 095 096 // ///////////////////////////////////////////////////////////////// 097 // // public methods //// 098 099 /** 100 * Display the phylogenetic tree ported in from the input port with the 101 * Forester package. 102 * 103 * @exception IllegalActionException 104 * if it is thrown by the super.fire() method. 105 */ 106 public void fire() throws IllegalActionException { 107 super.fire(); 108 109 if (inputTreeString.hasToken(0)) { 110 // get the tree expression 111 String treeDescription = ((StringToken) inputTreeString.get(0)) 112 .stringValue(); 113 try { 114 // create the tree in Forester 115 forester.tree.Tree displayedTree = new forester.tree.Tree( 116 treeDescription); 117 // create the Forester tree view window 118 ATVjframe atvframe = new ATVjframe(displayedTree); 119 // atvframe.setTitle(treeDescription); 120 // display the tree 121 atvframe.showWhole(); 122 } catch (Exception e) { 123 e.printStackTrace(); 124 } 125 } 126 127 } 128}