001/* Standalone Application demonstrating the Query class. 002 003 Copyright (c) 1998-2014 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.gui.demo; 028 029import java.awt.event.WindowAdapter; 030import java.awt.event.WindowEvent; 031 032import javax.swing.JFrame; 033import javax.swing.JPanel; 034import javax.swing.SwingUtilities; 035 036import ptolemy.gui.Query; 037import ptolemy.gui.QueryListener; 038import ptolemy.util.StringUtilities; 039 040/////////////////////////////////////////////////////////////////// 041//// FileChooserQuery 042 043/** 044 Demonstration of the addFileChooser() method in Query. 045 This can't be in an applet because applets cannot read from the local files. 046 047 @author Christopher Hylands 048 @version $Id$ 049 @since Ptolemy II 2.0 050 @Pt.ProposedRating Red (cxh) 051 @Pt.AcceptedRating Red (cxh) 052 @see ptolemy.gui.Query 053 */ 054@SuppressWarnings("serial") 055public class FileChooserQuery extends JFrame implements QueryListener { 056 /** Constructor. 057 */ 058 public FileChooserQuery() { 059 super("FileChooserQuery"); 060 061 JPanel contentPane = new JPanel(); 062 _query = new Query(); 063 contentPane.add(_query); 064 065 _query.addCheckBox("check", "Check box", true); 066 _query.setTextWidth(20); 067 _query.addLine("line", "Entry box", "default entry"); 068 _query.addDisplay("display", "Display", "displayed string"); 069 070 String[] choices = { "a", "b", "c" }; 071 _query.addChoice("choice", "Choice", choices, "b"); 072 073 String[] moreChoices = { "d", "e", "f" }; 074 _query.addChoice("editchoice", "Editable Choice", moreChoices, "d", 075 true); 076 _query.addSlider("slider", "Slider", 0, -100, 100); 077 078 String[] options = { "mayonnaise", "mustard", "both", "none" }; 079 _query.addRadioButtons("radio", "Radio buttons", options, "none"); 080 081 _query.addFileChooser("fileChooser", "FileChooser", "default", null, 082 null); 083 _query.addColorChooser("colorChooser", "ColorChoser", 084 "{0.0, 0.0, 0.0, 1.0}"); 085 086 _query.addQueryListener(this); 087 _query.setBackground(getBackground()); 088 setContentPane(contentPane); 089 } 090 091 /////////////////////////////////////////////////////////////////// 092 //// public methods //// 093 094 /** Called to notify that one of the entries has changed. 095 * The name of the entry is passed as an argument. 096 * @param name The name of the entry. 097 */ 098 @Override 099 public void changed(String name) { 100 System.out.println( 101 "Changed " + name + " to: " + _query.getStringValue(name)); 102 } 103 104 /** Create a FileChooserQuery and configure it. 105 * To run a simple test, use: 106 * <pre> 107 * java -classpath $PTII ptolemy.gui.demo.FileChooserQuery 108 * </pre> 109 * @param args Not used. 110 */ 111 public static void main(String[] args) { 112 try { 113 // Run this in the Swing Event Thread. 114 Runnable doActions = new Runnable() { 115 @Override 116 public void run() { 117 try { 118 JFrame frame = new FileChooserQuery(); 119 120 frame.addWindowListener(new WindowAdapter() { 121 @Override 122 public void windowClosing(WindowEvent e) { 123 StringUtilities.exit(0); 124 } 125 }); 126 127 frame.pack(); 128 frame.setVisible(true); 129 } catch (Exception ex) { 130 System.err.println(ex.toString()); 131 ex.printStackTrace(); 132 } 133 } 134 }; 135 SwingUtilities.invokeAndWait(doActions); 136 } catch (Exception ex) { 137 System.err.println(ex.toString()); 138 ex.printStackTrace(); 139 } 140 141 } 142 143 /////////////////////////////////////////////////////////////////// 144 //// private variables //// 145 Query _query; 146}