001/* 002 * Copyright (c) 2009-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2014-08-07 00:13:32 +0000 (Thu, 07 Aug 2014) $' 007 * '$Revision: 32861 $' 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.Component; 033import java.awt.Window; 034import java.awt.event.ActionEvent; 035 036import org.kepler.util.StaticResources; 037 038import ptolemy.actor.gui.TableauFrame; 039import ptolemy.util.MessageHandler; 040import ptolemy.vergil.toolbox.FigureAction; 041 042 043/** 044 * Adding a new PreferencesAction to a component will open up the preferences 045 * frame to the desired preferences tab. 046 * 047 * @author Aaron Schultz 048 * 049 */ 050public class PreferencesAction extends FigureAction { 051 private String _initialOpenTab; 052 private TableauFrame _parent; 053 054 public PreferencesAction(String initialOpenTab) { 055 super("Preferences"); 056 _initialOpenTab = initialOpenTab; 057 } 058 059 public PreferencesAction(TableauFrame parent) { 060 super("Preferences"); 061 _parent = parent; 062 } 063 064 @Override 065 public void actionPerformed(ActionEvent e) { 066 067 PreferencesFrame frame = null; 068 069 PreferencesFrameTracker pft = PreferencesFrameTracker.getInstance(); 070 if (pft.isOpen()) { 071 072 // There is a Preferences Frame already open, so lets use that one 073 frame = pft.getPreferencesFrame(); 074 075 } else { 076 Window window = null; 077 // There is not an open Preferences Frame so lets create one 078 079 if (_parent != null){ 080 window = _parent; 081 } 082 else{ 083 window = GUIUtil.getParentWindow((Component) e.getSource()); 084 } 085 086 if(window == null || !(window instanceof TableauFrame)) { 087 window = GUIUtil.getParentTableauFrame((Component) e.getSource()); 088 } 089 090 if (window != null && window instanceof TableauFrame) { 091 _parent = (TableauFrame)window; 092 TableauFrame _parentFrame = _parent; 093 frame = new PreferencesFrame( 094 StaticResources.getDisplayString( 095 "preferences.title", 096 "Preferences"), 097 _parentFrame); 098 frame.setLocationRelativeTo(null); 099 frame.setVisible(true); 100 pft.setOpen(frame); 101 } else { 102 MessageHandler.error("Couldn't open the Preferences frame - the action is not fired in a TableauFrame object"); 103 } 104 105 } 106 107 if (frame != null) { 108 frame.setSelectedTab(_initialOpenTab); 109 frame.toFront(); 110 } 111 112 } 113}