001/* 002 * Copyright (c) 1999-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:44:14 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33630 $' 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.kepler.gui; 031 032import java.util.Map; 033 034import diva.canvas.Figure; 035import diva.graph.GraphController; 036import diva.gui.toolbox.MenuFactory; 037import ptolemy.kernel.util.IllegalActionException; 038import ptolemy.kernel.util.NameDuplicationException; 039import ptolemy.kernel.util.NamedObj; 040import ptolemy.vergil.basic.ContextMenuFactoryCreator; 041 042////////////////////////////////////////////////////////////////////////// 043//// KeplerSchematicContextMenuFactory 044 045/** 046 * A factory that creates popup context menus for Kepler actors, directors, etc. 047 * 048 * @author Matthew Brooke 049 * @version $Id: KeplerSchematicContextMenuFactory.java 12085 2006-02-25 050 * 06:23:24Z brooke $ 051 * @since Ptolemy II 1.0 052 * @Pt.ProposedRating Red 053 * @Pt.AcceptedRating Red 054 */ 055public class KeplerSchematicContextMenuFactory extends KeplerContextMenuFactory { 056 057 /** 058 * Create a new context menu factory associated with the specified 059 * controller. 060 * 061 * @param controller 062 * The controller. 063 */ 064 public KeplerSchematicContextMenuFactory(GraphController controller) { 065 super(controller); 066 } 067 068 // ///////////////////////////////////////////////////////////////// 069 // // protected methods //// 070 071 /** 072 * OVERRIDES PARENT CLASS TO SET isWorkflow TO TRUE 073 * 074 * get Map of name/value pairs containing menu paths of original PTII 075 * context- menu items, and their correspondign Action objects 076 * 077 * @param object 078 * NamedObj 079 * @param isWorkflow 080 * boolean - @todo - FIXME - this is a gnarly hack because a 081 * workflow is actually a TypedCompositeActor, so if we just rely 082 * in the "instanceof" checks like we do for other context menus, 083 * this code will assume the workflow is actually an actor, and 084 * will display the actor context menu instead of the workflow 085 * one 086 * @return Map 087 */ 088 protected Map getOriginalMenuItemsMap(NamedObj object, boolean isWorkflow) { 089 return super.getOriginalMenuItemsMap(object, true); 090 } 091 092 /** 093 * @see ptolemy.vergil.basic.BasicGraphController$SchematicContextMenuFactory 094 * @param source 095 * Figure 096 * @return NamedObj 097 */ 098 protected NamedObj _getObjectFromFigure(Figure source) { 099 if (source != null) { 100 Object object = source.getUserObject(); 101 return (NamedObj) getController().getGraphModel() 102 .getSemanticObject(object); 103 } else { 104 return (NamedObj) getController().getGraphModel().getRoot(); 105 } 106 } 107 108 // ///////////////////////////////////////////////////////////////// 109 // // inner classes //// 110 111 /** 112 * A factory that creates the KeplerSchematicContextMenuFactory - used by 113 * the config 114 * 115 * @author Matthew Brooke 116 */ 117 public static class Factory extends ContextMenuFactoryCreator { 118 119 /** 120 * Create an factory with the given name and container. 121 * 122 *@param container 123 * The container. 124 *@param name 125 * The name of the entity. 126 *@exception IllegalActionException 127 * If the container is incompatible with this attribute. 128 *@exception NameDuplicationException 129 * If the name coincides with an attribute already in the 130 * container. 131 */ 132 public Factory(NamedObj container, String name) 133 throws IllegalActionException, NameDuplicationException { 134 super(container, name); 135 } 136 137 public MenuFactory createContextMenuFactory(GraphController controller) { 138 return new KeplerSchematicContextMenuFactory(controller); 139 } 140 } 141}