001/* 002 * Copyright (c) 2007-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-24 22:48:48 +0000 (Mon, 24 Aug 2015) $' 007 * '$Revision: 33634 $' 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.awt.event.ActionEvent; 033 034import javax.swing.Action; 035import javax.swing.ImageIcon; 036import javax.swing.JOptionPane; 037import javax.swing.KeyStroke; 038 039import org.apache.commons.logging.Log; 040import org.apache.commons.logging.LogFactory; 041import org.kepler.actor.preview.Previewable; 042import org.kepler.util.StaticResources; 043 044import diva.gui.GUIUtilities; 045import ptolemy.actor.gui.TableauFrame; 046import ptolemy.kernel.util.NamedObj; 047import ptolemy.vergil.toolbox.FigureAction; 048 049/** 050 * This action is used to "Preview" the actor. Actors that wish to have a 051 * meaningful preview should implement the org.kepler.actor.preview.Previewable 052 * interface and provide some mechanism for displaying the information using the 053 * Previewable preview() method. This class simply calls the preview() method if 054 * the actor is of the Previewable type. 055 * 056 *@author Ben Leinfelder 057 *@since 12/28/2007 058 */ 059public class PreviewActorAction extends FigureAction { 060 061 // //////////////////////////////////////////////////////////////////////////// 062 // LOCALIZABLE RESOURCES - NOTE that these default values are later 063 // overridden by values from the uiDisplayText resourcebundle file 064 // //////////////////////////////////////////////////////////////////////////// 065 066 private static String DISPLAY_NAME = StaticResources.getDisplayString( 067 "actions.actor.displayName", "Preview"); 068 private static String TOOLTIP = StaticResources.getDisplayString( 069 "actions.actor.tooltip", "Preview actor (where applicable)"); 070 private static ImageIcon LARGE_ICON = null; 071 private static KeyStroke ACCELERATOR_KEY = null; 072 073 // ////////////////////////////////////////////////////////////////////////////// 074 075 /** 076 * Constructor 077 * 078 * @param parent 079 * the "frame" (derived from ptolemy.gui.Top) where the menu is 080 * being added. 081 */ 082 public PreviewActorAction(TableauFrame parent) { 083 super(""); 084 if (parent == null) { 085 IllegalArgumentException iae = new IllegalArgumentException( 086 "PreviewActorAction constructor received NULL argument for TableauFrame"); 087 iae.fillInStackTrace(); 088 throw iae; 089 } 090 this.parent = parent; 091 092 this.putValue(Action.NAME, DISPLAY_NAME); 093 this.putValue(GUIUtilities.LARGE_ICON, LARGE_ICON); 094 this.putValue("tooltip", TOOLTIP); 095 this.putValue(GUIUtilities.ACCELERATOR_KEY, ACCELERATOR_KEY); 096 } 097 098 /** 099 * Invoked when an action occurs. 100 * 101 *@param e 102 * ActionEvent 103 */ 104 public void actionPerformed(ActionEvent e) { 105 106 // must call this first... 107 super.actionPerformed(e); 108 // ...before calling this: 109 NamedObj target = super.getTarget(); 110 111 // if we have a target that implements the Previewable interface, then 112 // show it 113 if (target instanceof Previewable) { 114 Previewable previewableActor = (Previewable) target; 115 previewableActor.preview(); 116 } else { 117 JOptionPane.showMessageDialog(null, 118 "Preview is not available for actors of type: " 119 + target.getClass().getName(), "Preview Alert", 120 JOptionPane.WARNING_MESSAGE); 121 } 122 } 123 124 private TableauFrame parent; 125 126 private static final Log log = LogFactory.getLog( 127 ActorDialogAction.class.getName()); 128 129 private static final boolean isDebugging = log.isDebugEnabled(); 130 131}