001/* An attribute that produces a custom node controller. 002 003 Copyright (c) 1998-2016 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 027 */ 028package ptolemy.vergil.basic; 029 030import diva.graph.GraphController; 031import ptolemy.kernel.util.IllegalActionException; 032import ptolemy.kernel.util.NameDuplicationException; 033import ptolemy.kernel.util.NamedObj; 034import ptolemy.kernel.util.SingletonAttribute; 035 036/////////////////////////////////////////////////////////////////// 037//// NodeControllerFactory 038 039/** 040 This is an attribute that produces a custom node controller. 041 This base class produces a node controller that offers only a 042 configure command in the context menu, and invokes a dialog to 043 edit parameters in response to that command. It does this by 044 returning an instance of IconController 045 in its create() method. Derived classes can override this 046 base class to put whatever they want in the context menu, 047 invoking whatever dialogs are appropriate. 048 To use this class, just insert it as an attribute inside 049 any Ptolemy II object, and then right clicking on the icon for 050 that object will result in the use of the controller specified 051 here. The instance by convention will be named "_controllerFactory", 052 but the only reason to enforce this is that only the first such 053 controller factory found as an attribute will be used. 054 It is a singleton, so placing it any container will replace any 055 previous controller factory with the same name. 056 057 @author Edward A. Lee 058 @version $Id$ 059 @since Ptolemy II 2.0 060 @Pt.ProposedRating Red (eal) 061 @Pt.AcceptedRating Red (johnr) 062 */ 063public class NodeControllerFactory extends SingletonAttribute { 064 /** Construct a new attribute with the given container and name. 065 * @param container The container. 066 * @param name The name. 067 * @exception IllegalActionException If the attribute cannot be contained 068 * by the proposed container. 069 * @exception NameDuplicationException If the container already has an 070 * attribute with this name. 071 */ 072 public NodeControllerFactory(NamedObj container, String name) 073 throws NameDuplicationException, IllegalActionException { 074 super(container, name); 075 } 076 077 /////////////////////////////////////////////////////////////////// 078 //// public methods //// 079 080 /** Return a new node controller. This base class returns an 081 * instance of IconController. Derived 082 * classes can return some other class to customize the 083 * context menu. 084 * @param controller The associated graph controller. 085 * @return A new node controller. 086 */ 087 public NamedObjController create(GraphController controller) { 088 return new IconController(controller); 089 } 090}