001/* Utilities for Querys 002 003 Copyright (c) 2004-2005 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 */ 027package ptolemy.actor.gui; 028 029import java.awt.Frame; 030import java.net.URL; 031 032import ptolemy.util.CancelException; 033import ptolemy.util.ClassUtilities; 034import ptolemy.util.MessageHandler; 035 036////////////////////////////////////////////////////////////////////////// 037//// QueryUtilities 038 039/** 040 This class contains utility methods for Ptolemy Query classes 041 that access the configuration. 042 043 @author Christopher Brooks 044 @version $Id$ 045 @since Ptolemy II 4.1 046 @Pt.ProposedRating Red (cxh) 047 @Pt.AcceptedRating Red (cxh) 048 */ 049public class QueryUtilities { 050 /** Instances of this class cannot be created. 051 */ 052 private QueryUtilities() { 053 } 054 055 /** Open a HTML resource in the current configuration if possible. 056 * @param urlName A string naming the url of the file to be opened 057 * as a resource. For example "doc/expressions.htm". 058 * @param owner The frame that owns the HTMLViewer to be created. 059 */ 060 public static void openHTMLResource(String urlName, Frame owner) { 061 // Note: This method is necessary so that we avoid some code 062 // duplication on classes that extend Query that want to use 063 // the configuration to open up a help file. ptolemy.gui.Query 064 // knows nothing about configuration and PtolemyQuery is 065 // misnamed, it is really a ParameterQuery. We could make 066 // this class extend Query and have other classes extend it 067 try { 068 // Note: call Thread.currentThread() so this works in Web Start 069 URL doc = ClassUtilities.getResource(urlName); 070 071 // Try to use the configuration, if we can. 072 boolean success = false; 073 074 if (owner instanceof TableauFrame) { 075 Configuration configuration = ((TableauFrame) owner) 076 .getConfiguration(); 077 078 if (configuration != null) { 079 configuration.openModel(null, doc, doc.toExternalForm()); 080 success = true; 081 } 082 } 083 084 if (!success) { 085 // Just open an HTML page. 086 HTMLViewer viewer = new HTMLViewer(); 087 viewer.setPage(doc); 088 viewer.pack(); 089 viewer.show(); 090 } 091 } catch (Exception ex) { 092 try { 093 MessageHandler.warning("Cannot open '" + urlName + "'", ex); 094 } catch (CancelException exception) { 095 // Ignore the cancel. 096 } 097 } 098 } 099}