/* SubsetChooserActor actor reads the phylodataset from the input file, * lists each entities in a dialog box, facilitates the user to choose * a subset of the entities for the next step analysis, and outputs the * selected entities into another phylodataset as output files. * * Copyright (c) 2004 The Regents of the University of California. * All rights reserved. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the * above copyright notice and the following two paragraphs appear in * all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN * IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY * OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * PT_COPYRIGHT_VERSION_2 * COPYRIGHTENDKEY */ package org.cipres.kepler; import ptolemy.actor.TypedAtomicActor; import ptolemy.kernel.CompositeEntity; import ptolemy.kernel.util.*; import ptolemy.actor.TypedIOPort; import ptolemy.data.BooleanToken; import ptolemy.data.StringToken; import ptolemy.data.type.BaseType; import ptolemy.data.expr.FileParameter; import ptolemy.data.expr.Parameter; import ptolemy.data.expr.StringParameter; import org.cipres.CipresIDL.api1.DataMatrix; import org.cipres.CipresIDL.api1.Tree; import org.cipres.datatypes.PhyloDataset; import org.cipres.kepler.DisplayObject; import org.cipres.kepler.SubsetChooser; import org.cipres.kepler.registry.CipresKeplerRegistry; import org.cipres.kepler.registry.Globals; import java.io.File; import javax.swing.JOptionPane; ////////////////////////////////////////////////////////////////////////// ////SubsetChooserActor /** * This actor reads the input file, generates the entities list, facilitates * the user to choose a subset of entities, and stores the selected entities * into an output file. * * @author Alex Borchers, Zhijie Guan * @version $Id: $ */ public class SubsetChooserActor extends TypedAtomicActor { // TODO: assign a proper hash value to this static final long serialVersionUID = 1L; /** Construct SubsetChooserActor source with the given container and name. * @param container The container. * @param name The name of this actor. * @exception IllegalActionException If the entity cannot be contained * by the proposed container. * @exception NameDuplicationException If the container already has an * actor with this name. */ public SubsetChooserActor(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException { super(container, name); inputFileName = new TypedIOPort(this, "Subset Chooser Input File", true, false); inputFileName.setTypeEquals(BaseType.STRING); outputFileName = new TypedIOPort(this, "Selected entities file", false, true); // Set the type constraint. outputFileName.setTypeEquals(BaseType.STRING); outputFileDefaultName = new FileParameter(this, "Output File Path and Name"); // set inputFileName and outputFileName names display new Parameter(inputFileName, "_showName", BooleanToken.TRUE); new Parameter(outputFileName, "_showName", BooleanToken.TRUE); // set the type parameter of the subset chooser type = new StringParameter(this, "type"); for (int i=0; i< typeOptions.length; i++) { type.addChoice(typeOptions[i]); } type.setExpression(typeOptions[0]); _attachText("_iconDescription", "\n" + "\n" + "\n"); } /////////////////////////////////////////////////////////////////// //// ports and parameters //// /** The input file name is received from this port. */ public TypedIOPort inputFileName = null; /** The output file name is sent out through this port. */ public TypedIOPort outputFileName = null; /** The file name parameter, which defines the default output file name. */ public FileParameter outputFileDefaultName = null; /** The type of the subset chooser, which defines the type of the entities * that the user can choose from. * Currently the type is either the tree or the taxa. */ public StringParameter type=null; /////////////////////////////////////////////////////////////////// //// functional variables //// /////////////////////////////////////////////////////////////////// //// public methods //// /** Choose a subset from the displayed objects. * @exception IllegalActionException If it is thrown by the * send() method sending out the token. */ public void fire() throws IllegalActionException { super.fire(); if (inputFileName.hasToken(0)) { try { String typeChosed = type.getExpression(); // check if the user set a valid value for the type int typeIndex = 0; while ( (typeIndex