001/* An Interface Automaton graph view for Ptolemy models 002 003 Copyright (c) 1998-2014 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.modal.ia; 029 030import java.awt.Color; 031 032import ptolemy.actor.gui.Effigy; 033import ptolemy.actor.gui.PtolemyEffigy; 034import ptolemy.actor.gui.Tableau; 035import ptolemy.actor.gui.TableauFactory; 036import ptolemy.domains.modal.kernel.ia.InterfaceAutomaton; 037import ptolemy.kernel.CompositeEntity; 038import ptolemy.kernel.util.IllegalActionException; 039import ptolemy.kernel.util.InternalErrorException; 040import ptolemy.kernel.util.NameDuplicationException; 041import ptolemy.kernel.util.NamedObj; 042import ptolemy.moml.LibraryAttribute; 043import ptolemy.vergil.modal.FSMGraphTableau; 044 045/////////////////////////////////////////////////////////////////// 046//// InterfaceAutomatonGraphTableau 047 048/** 049 An editor tableau for interface automata. 050 051 @author Steve Neuendorffer, Yuhong Xiong 052 @version $Id$ 053 @since Ptolemy II 8.0 054 @Pt.ProposedRating Red (yuhong) 055 @Pt.AcceptedRating Red (johnr) 056 */ 057public class InterfaceAutomatonGraphTableau extends FSMGraphTableau { 058 /** Create a new editor tableau with the specified container 059 * and name, with no default library. 060 * @param container The container. 061 * @param name The name. 062 * @exception IllegalActionException If the model associated with 063 * the container effigy is not an FSMActor. 064 * @exception NameDuplicationException If the container already 065 * contains an object with the specified name. 066 */ 067 public InterfaceAutomatonGraphTableau(PtolemyEffigy container, String name) 068 throws IllegalActionException, NameDuplicationException { 069 this(container, name, null); 070 } 071 072 /** Create a new editor tableau with the specified container, 073 * name, and default library. 074 * @param container The container. 075 * @param name The name. 076 * @param defaultLibrary The default library, or null to not specify one. 077 * @exception IllegalActionException If the model associated with 078 * the container effigy is not an FSMActor. 079 * @exception NameDuplicationException If the container already 080 * contains an object with the specified name. 081 */ 082 public InterfaceAutomatonGraphTableau(PtolemyEffigy container, String name, 083 LibraryAttribute defaultLibrary) 084 throws IllegalActionException, NameDuplicationException { 085 super(container, name, defaultLibrary); 086 } 087 088 /////////////////////////////////////////////////////////////////// 089 //// public methods //// 090 091 /** Override the super class to create an instance of 092 * InterfaceAutomatonGraphFrame. 093 * @param model The Ptolemy II model to display in the graph frame. 094 * @param defaultLibrary The default library, or null to not specify 095 * one. 096 */ 097 @Override 098 public void createGraphFrame(CompositeEntity model, 099 LibraryAttribute defaultLibrary) { 100 InterfaceAutomatonGraphFrame frame = new InterfaceAutomatonGraphFrame( 101 model, this, defaultLibrary); 102 103 try { 104 setFrame(frame); 105 } catch (IllegalActionException ex) { 106 throw new InternalErrorException(ex); 107 } 108 109 frame.setBackground(BACKGROUND_COLOR); 110 frame.pack(); 111 frame.centerOnScreen(); 112 frame.setVisible(true); 113 } 114 115 /////////////////////////////////////////////////////////////////// 116 //// public inner classes //// 117 118 /** A factory that creates graph editing tableaux for Ptolemy models. 119 */ 120 public static class Factory extends TableauFactory { 121 /** Create an factory with the given name and container. 122 * @param container The container. 123 * @param name The name of the entity. 124 * @exception IllegalActionException If the container is incompatible 125 * with this attribute. 126 * @exception NameDuplicationException If the name coincides with 127 * an attribute already in the container. 128 */ 129 public Factory(NamedObj container, String name) 130 throws IllegalActionException, NameDuplicationException { 131 super(container, name); 132 } 133 134 /** Create a tableau in the default workspace with no name for the 135 * given Effigy. The tableau will created with a new unique name 136 * in the given model proxy. If this factory cannot create a tableau 137 * for the given proxy (perhaps because the proxy is not of the 138 * appropriate subclass) then return null. 139 * @param proxy The model proxy. 140 * @return A new InterfaceAutomatonGraphTableau, if the proxy is a 141 * PtolemyEffigy that references an InterfaceAutomaton or null 142 * otherwise. 143 * @exception Exception If an exception occurs when creating the 144 * tableau. 145 */ 146 @Override 147 public Tableau createTableau(Effigy proxy) throws Exception { 148 if (!(proxy instanceof PtolemyEffigy)) { 149 return null; 150 } 151 152 PtolemyEffigy effigy = (PtolemyEffigy) proxy; 153 154 if (effigy.getModel() instanceof InterfaceAutomaton) { 155 // Check to see whether this factory contains a 156 // default library. 157 LibraryAttribute library = (LibraryAttribute) getAttribute( 158 "_library", LibraryAttribute.class); 159 160 InterfaceAutomatonGraphTableau tableau = new InterfaceAutomatonGraphTableau( 161 (PtolemyEffigy) proxy, proxy.uniqueName("tableau"), 162 library); 163 return tableau; 164 } else { 165 return null; 166 } 167 } 168 } 169 170 /////////////////////////////////////////////////////////////////// 171 //// private variables //// 172 private static Color BACKGROUND_COLOR = new Color(0xe5e5e5); 173}