001/* A viewer for Welcome Windows 002 003 Copyright (c) 2006-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 027 */ 028package ptolemy.actor.gui; 029 030import java.awt.BorderLayout; 031import java.awt.Color; 032import java.awt.event.ActionEvent; 033import java.awt.event.ActionListener; 034 035import javax.swing.JButton; 036import javax.swing.JCheckBox; 037import javax.swing.JPanel; 038 039import ptolemy.data.BooleanToken; 040import ptolemy.data.expr.SingletonParameter; 041import ptolemy.util.MessageHandler; 042 043/////////////////////////////////////////////////////////////////// 044//// WelcomeWindow 045 046/** 047 A toplevel frame that can view HTML documents, but has no menus. 048 049 <p>This window uses the _showWelcomeWindowAtStartup 050 SingletonParameter preference in 051 {@link ptolemy.actor.gui.PtolemyPreferences} to determine whether the 052 window is shown or not. If this parameter is not present or is true, 053 then the window is show, if the parameter is false, then it is not shown. 054 This parameter is set in ~/.ptolemyII/PtolemyPreferences.xml, which under 055 Windows might be in 056 <code>c:/Documents and Settings/<i>yourlogin</i>/.ptolemyII/PtolemyPreferences.xml</code> 057 <p>The easiest way to adjust the configuration so that this window 058 is used is to edit the <code>welcomeWindow.xml</code> file that corresponds 059 with the configuration and set the tableau to be 060 <code>ptolemy.actor.gui.WelcomeWindowTableau</code> 061 For example, <code>$PTII/ptolemy/configs/full/welcomeWindow.xml</code> 062 might look like: 063 <pre> 064 <?xml version="1.0" standalone="no"?> 065 <!DOCTYPE plot PUBLIC "-//UC Berkeley//DTD MoML 1//EN" 066 "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> 067 <entity name="directory"> 068 <entity name="doc" class="ptolemy.actor.gui.HTMLEffigy"> 069 <entity name="tableau" class="ptolemy.actor.gui.WelcomeWindowTableau"> 070 <!-- If you adjust the size, be sure to try it under Java 1.5 --> 071 <property name="size" value="[600, 220]"/> 072 <property name="url" value="ptolemy/configs/full/intro.htm"/> 073 </entity> 074 </entity> 075 </entity> 076 </pre> 077 The above configuration will create a WelcomeWindow with a 600x200 078 size that displays the contents of 079 <code>ptolemy/configs/full/intro.htm</code> 080 081 <p>Note that since this widow has no menus, if you use this window, then 082 you will want to set the 083 <code>_applicationBlankPtolemyEffigyAtStartup</code> parameter in the 084 configuration so that a blank Graph Editor window pops up along with 085 this welcome window. For example: 086 <pre> 087 <property name="_applicationBlankPtolemyEffigyAtStartup" 088 class="ptolemy.data.expr.Parameter" 089 value="true"/> 090 </pre> 091 092 093 @author Christopher Brooks, Nandita Mangal 094 @version $Id$ 095 @since Ptolemy II 5.2 096 @Pt.ProposedRating Red (cxh) 097 @Pt.AcceptedRating Red (cxh) 098 */ 099@SuppressWarnings("serial") 100public class WelcomeWindow extends HTMLViewer { 101 /** Construct a blank HTML Viewer with no menu items. 102 */ 103 public WelcomeWindow() { 104 super(); 105 //setUndecorated(true); 106 setResizable(false); 107 _statusBar = null; 108 109 // Add the close panel 110 _closePanel = new JPanel(); 111 _closePanel.setBackground(new Color(227, 231, 236)); 112 _closePanel.setSize(401, 100); 113 _closePanel.setLayout(new BorderLayout()); 114 115 _startupCheck = new JCheckBox( 116 "<html><table cellpadding=0><tr><td width=9/><td><font size=3>Show this dialog upon startup </font></td></tr></table></html>", 117 true); 118 _startupCheck.setBackground(new Color(227, 231, 236)); 119 120 _closeButton = new JButton("Close"); 121 _closeButton.addActionListener(new ActionListener() { 122 @Override 123 public void actionPerformed(ActionEvent evt) { 124 setVisible(false); 125 close(); 126 } 127 }); 128 129 _closePanel.add(_startupCheck, BorderLayout.WEST); 130 _closePanel.add(_closeButton, BorderLayout.EAST); 131 132 super.hideMenuBar(); 133 } 134 135 /////////////////////////////////////////////////////////////////// 136 //// public methods //// 137 138 /** Make this window displayable. The menubar is hidden and 139 * close panel is added. 140 */ 141 @Override 142 public void pack() { 143 hideMenuBar(); 144 getContentPane().add(_closePanel, BorderLayout.SOUTH); 145 super.pack(); 146 147 } 148 149 /** Always set the title to the string "Welcome". 150 * @param title The title, which is ignored. The title is always 151 * the value returned by {@link #_getName()}. 152 */ 153 @Override 154 public void setTitle(String title) { 155 super.setTitle(_getName()); 156 } 157 158 /** Show the window if the _showWelcomeWindowAtStartup parameter 159 * is not set or is true. 160 */ 161 @Override 162 public void show() { 163 164 Configuration configuration = getConfiguration(); 165 166 _showWelcomeWindowAtStartup = (BooleanToken) PtolemyPreferences 167 .preferenceValue(configuration, "_showWelcomeWindowAtStartup"); 168 169 if (_showWelcomeWindowAtStartup != null 170 && !_showWelcomeWindowAtStartup.booleanValue()) { 171 // Call super.close() because _close() expects that the window has been 172 // rendered via successful completion of show() and that we can query the 173 // checkbox. There was a bug where if user started Kepler, unchecked 174 // "Show this Window at Startup" and then restarted Kepler, Kepler would 175 // not exit. 176 super._close(); 177 return; 178 } 179 super.show(); 180 } 181 182 /////////////////////////////////////////////////////////////////// 183 //// protected methods //// 184 185 /** Read the "Show this dialog on startup" checkbox, update the 186 * preferences if necessary and then call the super class and close 187 * this window. This method is called by {@link ptolemy.gui.Top#close()}. 188 */ 189 @Override 190 protected boolean _close() { 191 Configuration configuration = getConfiguration(); 192 if (_showWelcomeWindowAtStartup == null && !_startupCheck.isSelected() 193 || _showWelcomeWindowAtStartup != null 194 && _showWelcomeWindowAtStartup 195 .booleanValue() != _startupCheck.isSelected()) { 196 // Update the preferences if there is no preference and 197 // the user unchecked the "Show this dialog on startup" 198 // or if the value of the preference and the checkbox differ. 199 try { 200 PtolemyPreferences preferences = PtolemyPreferences 201 .getPtolemyPreferencesWithinConfiguration( 202 configuration); 203 // FIXME: is ok to create a new parameter each time? 204 SingletonParameter showWelcomeWindowAtStartupParameter = new SingletonParameter( 205 preferences, "_showWelcomeWindowAtStartup"); 206 207 // FIXME: is there a better way to set a BooleanToken? 208 showWelcomeWindowAtStartupParameter 209 .setToken(_startupCheck.isSelected() ? BooleanToken.TRUE 210 : BooleanToken.FALSE); 211 preferences.save(); 212 } catch (Exception ex) { 213 MessageHandler.error( 214 "Failed to update preferences and" 215 + "save _showWelcomeWindowAtStarupPreferences", 216 ex); 217 } 218 } 219 return super._close(); 220 } 221 222 /** Get the name of this object, which in this case is the 223 * string "Welcome". 224 * @return The string "Welcome"; 225 */ 226 @Override 227 protected String _getName() { 228 return "Welcome"; 229 } 230 231 /////////////////////////////////////////////////////////////////// 232 //// private variables //// 233 234 /** The panel at the bottom that contains the 235 * "Show this dialog on startup" checkbox and the close button. 236 */ 237 private JPanel _closePanel; 238 239 /** True if the welcome window is shown at startup. */ 240 private BooleanToken _showWelcomeWindowAtStartup; 241 242 private JCheckBox _startupCheck; 243 244 private JButton _closeButton; 245}