001/* JavaSE implementation of the TextFieldContainerInterface. 002 003 Copyright (c) 2011-2015 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 */ 027package ptolemy.actor.lib.gui; 028 029import javax.swing.JTextField; 030 031import ptolemy.actor.injection.PortableContainer; 032import ptolemy.actor.lib.Sink; 033import ptolemy.data.Token; 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036 037/////////////////////////////////////////////////////////////////// 038//// TextFieldContainerJavaSE 039/** 040JavaSE implementation of the TextFieldContainerInterface. 041 042@author Ishwinder Singh 043@version $Id$ 044@since Ptolemy II 10.0 045@Pt.ProposedRating Red (ishwinde) 046@Pt.AcceptedRating Red (ishwinde) 047 */ 048 049public class TextFieldContainerJavaSE implements TextFieldContainerInterface { 050 051 /////////////////////////////////////////////////////////////////// 052 //// public methods //// 053 054 /** Initiate. Do nothing here. 055 * @param sink Object of the Sink actor. 056 * @exception IllegalActionException If the entity cannot be contained 057 * by the proposed container. 058 * @exception NameDuplicationException If the container already has an 059 * actor with this name. 060 */ 061 @Override 062 public void init(Sink sink) 063 throws IllegalActionException, NameDuplicationException { 064 } 065 066 /** Place the visual representation of the actor into the specified container. 067 * @param container The container in which to place the object 068 */ 069 @Override 070 public void place(PortableContainer container) { 071 _textfield = new JTextField(); 072 _textfield.setText("\t\t"); 073 if (container != null) { 074 // If container is null, should we do what DisplayJavaSE.place() does? 075 container.add(_textfield); 076 } 077 _textfield.setEditable(false); 078 } 079 080 /** Set the text to the value of the token. 081 * @param value The Parameter containing the value 082 */ 083 @Override 084 public void setValue(Token value) { 085 if (_textfield != null) { 086 if (value == null) { 087 // Delete the old text. 088 _textfield.setText(null); 089 } else { 090 _textfield.setText(value.toString()); 091 } 092 } 093 } 094 095 /////////////////////////////////////////////////////////////////// 096 //// private variables //// 097 098 // Text field for displaying the value 099 private JTextField _textfield; 100 101}