001/*
002 * Copyright (c) 2004-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.awt.Frame;
033import java.awt.event.ActionEvent;
034
035import javax.swing.Action;
036import javax.swing.ImageIcon;
037import javax.swing.KeyStroke;
038
039import org.kepler.sms.gui.SemanticSearchDialog;
040import org.kepler.util.StaticResources;
041
042import diva.gui.GUIUtilities;
043import ptolemy.actor.gui.TableauFrame;
044import ptolemy.vergil.actor.ActorGraphFrame;
045import ptolemy.vergil.toolbox.FigureAction;
046
047/**
048 * An action that will create a SemanticSearchDialog.
049 * 
050 * @author Shawn Bowers, Christopher Brooks
051 * @version $Id: SemanticSearchDialogAction.java 33630 2015-08-24 22:44:14Z crawl $
052 */
053public class SemanticSearchDialogAction extends FigureAction {
054    /**
055     * An action that will create a SemanticSearchDialog.
056     */
057    public SemanticSearchDialogAction() {
058        super("Semantic Search");
059    }
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.workflow.semanticSearch", "Semantic Search");
068    private static String TOOLTIP =  StaticResources.getDisplayString(
069            "actions.workflow.semanticSearch", "Semantic Search");
070    private static ImageIcon LARGE_ICON = null;
071    private static KeyStroke ACCELERATOR_KEY = null;
072
073    // = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().
074    // getMenuShortcutKeyMask());
075    // //////////////////////////////////////////////////////////////////////////////
076
077    private TableauFrame parent;
078
079    /**
080     * Constructor
081     * 
082     * @param parent
083     *            the "frame" (derived from ptolemy.gui.Top) where the menu is
084     *            being added.
085     */
086    public SemanticSearchDialogAction(TableauFrame parent) {
087        super("");
088        if (parent == null) {
089            IllegalArgumentException iae = new IllegalArgumentException(
090                    "ImportArchiveAction constructor received NULL argument for TableauFrame");
091            iae.fillInStackTrace();
092            throw iae;
093        }
094        this.parent = parent;
095
096        this.putValue(Action.NAME, DISPLAY_NAME);
097        this.putValue(GUIUtilities.LARGE_ICON, LARGE_ICON);
098        this.putValue("tooltip", TOOLTIP);
099        this.putValue(GUIUtilities.ACCELERATOR_KEY, ACCELERATOR_KEY);
100    }
101
102    public void actionPerformed(ActionEvent e) {
103        super.actionPerformed(e);
104        // Only makes sense if this is an ActorGraphFrame.
105        Frame frame = getFrame();
106        if (frame instanceof ActorGraphFrame) {
107            SemanticSearchDialog dialog = new SemanticSearchDialog(frame,
108                    ((ActorGraphFrame) frame).getModel());
109            if (dialog != null) {
110                dialog.setVisible(true);
111            }
112        }
113    }
114}