001/* 002 * Copyright (c) 2002-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 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.geon; 031 032import ptolemy.actor.TypedIOPort; 033import ptolemy.actor.lib.io.LineWriter; 034import ptolemy.data.StringToken; 035import ptolemy.data.expr.FileParameter; 036import ptolemy.data.type.BaseType; 037import ptolemy.kernel.CompositeEntity; 038import ptolemy.kernel.util.IllegalActionException; 039import ptolemy.kernel.util.NameDuplicationException; 040 041////////////////////////////////////////////////////////////////////////// 042//// FileWriter 043/** 044 * This actor extends LineWriter by outputing the filename. The actor writes the 045 * value of string tokens to a file, and outputs the file path. 046 * 047 * The file is specified by the fileName attribute using any form acceptable to 048 * FileParameter. 049 * 050 * If the append attribute has value true, then the file will be appended to. If 051 * it has value false, then if the file exists, the user will be queried for 052 * permission to overwrite, and if granted, the file will be overwritten. 053 * 054 * If the confirmOverwrite parameter has value false, then this actor will 055 * overwrite the specified file if it exists without asking. If true (the 056 * default), then if the file exists, then this actor will ask for confirmation 057 * before overwriting. 058 * 059 * @see FileParameter 060 * @version $Id: FileWrite.java 24234 2010-05-06 05:21:26Z welker $ 061 * @since Ptolemy II 2.2 062 */ 063public class FileWrite extends LineWriter { 064 065 /** 066 * Construct an actor with the given container and name. 067 * 068 * @param container 069 * The container. 070 * @param name 071 * The name of this actor. 072 * @exception IllegalActionException 073 * If the actor cannot be contained by the proposed 074 * container. 075 * @exception NameDuplicationException 076 * If the container already has an actor with this name. 077 */ 078 public FileWrite(CompositeEntity container, String name) 079 throws IllegalActionException, NameDuplicationException { 080 super(container, name); 081 082 url = new TypedIOPort(this, "url", false, true); 083 url.setTypeEquals(BaseType.STRING); 084 url.setMultiport(false); 085 086 _attachText("_iconDescription", "<svg>\n" 087 + "<rect x=\"-25\" y=\"-20\" " + "width=\"50\" height=\"40\" " 088 + "style=\"fill:white\"/>\n" 089 + "<polygon points=\"-15,-10 -12,-10 -8,-14 -1,-14 3,-10" 090 + " 15,-10 15,10, -15,10\" " + "style=\"fill:red\"/>\n" 091 + "</svg>\n"); 092 } 093 094 // ///////////////////////////////////////////////////////////////// 095 // // ports and parameters //// 096 097 /** 098 * Written file URL 099 */ 100 public TypedIOPort url; 101 102 /** 103 * Calls LineWriter's postfire and broadcasts the fileName. 104 */ 105 public boolean postfire() throws IllegalActionException { 106 boolean ret = super.postfire(); 107 url.broadcast(new StringToken(fileName.asFile().getAbsolutePath())); 108 return ret; 109 } 110 111}