KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > install > InstallerFrame


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 // InstallerFrame.java
17

18 // Description:
19
// Installer frame for free installer application
20
//
21
// Author:
22
// Peter Pilgrim
23
// Mon Jan 11 23:50:46 GMT 1999
24
//
25
// RCS HEADER
26
//
27
// $Author$
28
// $Date$
29
// $Source$
30
// $Revision$ $State$ $Locker$
31
//
32
// History
33
// ================================================================================
34
// $Log$
35

36 package ixenon.free.install;
37
38 import java.awt.*;
39 import java.awt.event.*;
40 import java.beans.*;
41 import java.util.*; // for Vector/Hashtable
42
import java.io.*; // for File I/O Classes
43
import java.net.*; // Network/Internet classes
44

45 import javax.swing.*; // for JFrame, JOptionPane
46
import javax.swing.event.*;
47 import javax.swing.border.*; // for BevelBorder
48

49 import ixenon.free.util.*; // for ApplicationResources
50
import ixenon.free.swing.*; // for DigitalClock
51

52
53 /** The main application frame for the free installer project. The
54  * frame consists of the frame divided into left and right hand side
55  * areas. The left hand side holds a splash image, which can be an
56  * application specific gif or jpeg. The right hand side contains
57  * selection component. From top to bottom, a combo box allows
58  * a locale and language to be selected. A combo box allows the
59  * installation mode to be selected.
60  *
61  */

62 public class InstallerFrame extends JFrame
63 implements ActionListener, InstallConstants, HyperlinkListener
64 {
65     /** The help button pressed property */
66     public final static String JavaDoc HELP_BUTTON_PRESSED_PROPERTY="help_button_pressed_property";
67     /** The install button pressed property */
68     public final static String JavaDoc INSTALL_BUTTON_PRESSED_PROPERTY="install_button_pressed_property";
69     /** The quit button pressed property */
70     public final static String JavaDoc QUIT_BUTTON_PRESSED_PROPERTY="quit_button_pressed_property";
71     /** The browse button pressed property */
72     public final static String JavaDoc BROWSE_BUTTON_PRESSED_PROPERTY="browse_button_pressed_property";
73     
74     /** The company name */
75     protected String JavaDoc companyName;
76     /** The product name */
77     protected String JavaDoc productName;
78     
79     /** The prefix installation root directory */
80     protected File prefix;
81
82     /** Selected installation locale i18n */
83     protected Locale locale=null;
84     
85     /** Selected installation mode type */
86     protected int installMode=-1;
87
88     /** The array of locales */
89     protected Locale[] locales = getAvailableLocales();
90
91     /** The default application content which could be used for a license
92      * or information about the software package about to be installed
93      */

94     public final static String JavaDoc DEFAULT_APPLICATION_CONTENT=
95     "Sorry, no application/license content could be found.\n\n"+
96     "Please look at the application property file in particular \n"+
97     "the resource called `FreeInstaller.installerFrame.applicationURL'\n\n"+
98     "For more information about Free Installer [c] 1999 License\n"+
99     "and distribution read informational files.\n";
100
101     /** The content type of the default application content */
102     public final static String JavaDoc DEFAULT_APPLICATION_CONTENT_TYPE="text/plain";
103     
104     private SwingPropertyChangeSupport propertyListeners;
105     
106     protected final static String JavaDoc HELP_BUTTON_COMMAND="help";
107     protected final static String JavaDoc INSTALL_BUTTON_COMMAND="install";
108     protected final static String JavaDoc QUIT_BUTTON_COMMAND="quit";
109     protected final static String JavaDoc BROWSE_BUTTON_COMMAND="browse";
110     
111
112     protected JPanel splashPanel;
113     protected JPanel centerArea; // wizard pager.
114
protected ImageIcon splashImage;
115     protected JLabel splashLabel;
116     
117     protected JComboBox languageCombo;
118     protected JComboBox instModeCombo;
119
120     protected JTextField tf_prefix;
121     protected JButton bt_browse;
122     protected JButton bt_install;
123     protected JButton bt_quit;
124     protected JButton bt_help;
125     
126     protected JEditorPane editorPane;
127
128     protected JMenu mb_license; // Menu about button
129

130     /**
131      * Creates the main application frame for the free installer.
132      *
133      * To respond to events in the frame use
134      * @see #addPropertyChangeListener
135      * @see #removePropertyChangeListener
136      * @see #HELP_BUTTON_PRESSED_PROPERTY
137      * @see #INSTALL_BUTTON_PRESSED_PROPERTY
138      * @see #QUIT_BUTTON_PRESSED_PROPERTY
139      * @see #BROWSE_BUTTON_PRESSED_PROPERTY
140      *
141      * @param title frame bar title.
142      * @param splashImageName the splash image name.
143      * @param companyName the company name
144      * @param productName the product name
145      */

146     public InstallerFrame( String JavaDoc title, String JavaDoc splashImageName, String JavaDoc companyName, String JavaDoc productName )
147     {
148     super(title);
149
150     //
151
// Get application resources
152
//
153
ApplicationResources appres = ApplicationResources.getInstance();
154     
155     if (splashImageName == null)
156         splashImageName = appres.getResourceString( "installerFrame.splashImage", "appres/images/M16Crop.jpg" );
157
158     String JavaDoc frameIconName = appres.getResourceString( "installerFrame.icon", "appres/images/FreeInstaller-icon.gif" );
159
160     String JavaDoc appURLName = appres.getResourceString( "installerFrame.applicationURL", "appres/docs/FREE-INST-DEFAULT.html" );
161     String JavaDoc appURLPath = appres.resolvePathname( "docs", appURLName, null );
162
163     String JavaDoc browseButtonText = appres.getResourceString( "installerFrame.browse.text", "Browse" );
164     int browseButtonMnemonic = appres.getResourceMnemonic( "installerFrame.browse.mnemonic", 'B' );
165     String JavaDoc browseButtonToolTip = appres.getResourceString( "installerFrame.browse.toolTipText", "change target directory" );
166     String JavaDoc installButtonText = appres.getResourceString( "installerFrame.install.text", "Install" );
167     int installButtonMnemonic = appres.getResourceMnemonic( "installerFrame.install.mnemonic", 'I' );
168     String JavaDoc installButtonToolTip = appres.getResourceString( "installerFrame.install.toolTipText", "begin installation" );
169     String JavaDoc quitButtonText = appres.getResourceString( "installerFrame.quit.text", "Quit" );
170     int quitButtonMnemonic = appres.getResourceMnemonic( "installerFrame.quit.mnemonic", 'Q' );
171     String JavaDoc quitButtonToolTip = appres.getResourceString( "installerFrame.quit.toolTipText", "quit installation" );
172     String JavaDoc helpButtonText = appres.getResourceString( "installerFrame.help.text", "Help" );
173     int helpButtonMnemonic = appres.getResourceMnemonic( "installerFrame.help.mnemonic", 'H' );
174     String JavaDoc helpButtonToolTip = appres.getResourceString( "installerFrame.help.toolTipText", "get help" );
175
176     //
177
// Set up fonts
178
//
179
Font entryFont = appres.getFont( "installerFrame.entryFont",
180                      new Font( "DialogInput", Font.BOLD, 12 ));
181     Font labelFont = appres.getFont( "installerFrame.labelFont",
182                      new Font( "Dialog", Font.BOLD, 12 ));
183     Font textFont = appres.getFont( "installerFrame.textFont",
184                      new Font( "Courier", Font.BOLD, 10 ));
185     //
186
// Set the prefix directory per operating system
187
//
188
this.companyName = companyName;
189     this.productName = productName;
190     
191     //
192
// os.name = Windows NT
193
// os.arch = x86
194
// os.version = 4.0
195
//
196
// os.name = Windows 95
197
// os.name = Windows 98
198
// os.name = Windows 2000 (Presumably?)
199
//
200
// os.name = OS/2
201
// os.arch = x86
202
// os.version = 20.40
203

204     String JavaDoc osname = System.getProperty( "os.name");
205     String JavaDoc osvers = System.getProperty( "os.vers");
206     String JavaDoc pathSep = System.getProperty( "path.separator" ); // UNIX `:'
207
String JavaDoc fileSep = System.getProperty( "file.separator" ); // UNIX `/'
208
if ( osname.startsWith("Windows 95") ||
209          osname.startsWith("Windows 98") ||
210          osname.startsWith("Windows 2000") ||
211          osname.startsWith("Windows NT") )
212         // i.e. "C:\Program Files\FreeInstaller\FreeInstaller 1.0"
213
prefix = new File( "C:"+fileSep+"Program Files"+
214                    fileSep+companyName+fileSep+productName );
215     else if ( osname.startsWith("OS/2") )
216         // i.e. "C:\Packages\FreeInstaller\FreeInstaller 1.0"
217
prefix = new File( "C:"+fileSep+"Packages"+
218                    fileSep+companyName+fileSep+productName );
219     else
220         // i.e. "/usr/local/XenonSoft/FreeInstaller"
221
prefix = new File( fileSep+"usr"+fileSep+"local"+fileSep+companyName+
222                    fileSep+productName );
223
224     // System.out.println( "DEBUG: prefix = "+prefix );
225

226     getContentPane().setLayout( new BorderLayout(9,9));
227
228     //
229
// Create a menubar and tell the dialog about it
230
//
231
JMenuBar menubar = new JMenuBar();
232     setJMenuBar(menubar);
233
234     // Create three pulldown menus for the menubar
235
JMenu info = createMenu( "info", "Info", 'N' );
236     // Add the menus to the bar, and treat Help menu specially.
237
menubar.add(info);
238
239     JMenuItem mb_license =
240         createMenuItem( "info.viewLicense",
241                 "view-license", "FreeInstaller License ...", 'L', null );
242     mb_license.addActionListener(this);
243     mb_license.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK));
244     info.add(mb_license);
245
246     JMenuItem mb_author =
247         createMenuItem( "info.viewAuthor",
248                 "view-author", "FreeInstaller Author ...", 'A', null );
249     mb_author.addActionListener(this);
250     mb_author.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
251     info.add(mb_author);
252
253     // =================================================================
254
// Create the west Panel with an Image.
255
// =================================================================
256

257     splashPanel = new JPanel();
258
259     Image img1 = appres.getImage( "images", frameIconName, null );
260     setIconImage( img1 );
261     
262     Image img2 = appres.getImage( "images", splashImageName, null );
263     splashImage = new ImageIcon( img2 );
264     if (splashImage != null)
265         splashLabel = new JLabel( splashImage );
266     else
267         splashLabel = new JLabel( "No Image Icon Loaded" );
268     CompoundBorder border = new CompoundBorder(
269         new BevelBorder( BevelBorder.RAISED ),
270         new BevelBorder( BevelBorder.LOWERED ));
271     splashLabel.setBorder( border );
272
273     splashPanel.add( "Center", splashLabel );
274     splashLabel.setPreferredSize( new Dimension(300, 400));
275     
276     getContentPane().add( "West", splashLabel );
277
278
279     // =================================================================
280
// Create the center panel
281
// =================================================================
282

283     // north panel of the center panel
284
JPanel np = new JPanel();
285     np.setLayout( new BorderLayout(4,4) );
286     
287     languageCombo = new JComboBox();
288     languageCombo.setFont( labelFont );
289     languageCombo.setEditable( false );
290     languageCombo.setActionCommand( "select-locale" );
291     languageCombo.addItem("Please choose a locale/language");
292     languageCombo.addActionListener(this);
293     int q;
294
295     Locale defLocale = Locale.getDefault();
296     for (q=0; q<locales.length; ++q) {
297         // System.out.println("["+q+"] "+locales[q] );
298
// System.out.println(" language:"+locales[q].getDisplayLanguage() );
299
// System.out.println(" country:"+locales[q].getDisplayCountry() );
300
// System.out.println("["+q+"] country:"+locales[q].getDisplayName() );
301

302         languageCombo.addItem(
303         locales[q].getDisplayName() +
304         (defLocale == locales[q] ? " *Default*" : "" ) );
305     }
306     np.add( "North", languageCombo );
307
308     instModeCombo = new JComboBox();
309     instModeCombo.setFont( labelFont );
310     instModeCombo.setEditable( false );
311     instModeCombo.setActionCommand("select-install-mode");
312     instModeCombo.addActionListener(this);
313     instModeCombo.addItem("Please choose an installation mode");
314     instModeCombo.addItem( BASIC_INSTALLATION_STRING);
315     instModeCombo.addItem( CUSTOM_INSTALLATION_STRING);
316     instModeCombo.addItem( COMPACT_INSTALLATION_STRING);
317     np.add( "Center", instModeCombo );
318
319     // Create the prefix entry area panel
320
JPanel anyPanel = new JPanel();
321     anyPanel.setLayout( new BorderLayout(2,2) );
322
323     JLabel prefixLabel = new JLabel( "Enter The Installation Directory:");
324     prefixLabel.setFont( labelFont );
325     anyPanel.add( "North", prefixLabel );
326     
327     tf_prefix = new JTextField( prefix.getPath() );
328     tf_prefix.setFont( entryFont );
329     anyPanel.add( "Center", tf_prefix );
330     
331     bt_browse = new JButton( browseButtonText );
332     bt_browse.setMnemonic( browseButtonMnemonic );
333     bt_browse.setFont( labelFont );
334     bt_browse.setActionCommand("browse");
335     bt_browse.addActionListener(this);
336     anyPanel.add( "East", bt_browse );
337     np.add( "South", anyPanel );
338     
339     centerArea = new JPanel();
340     centerArea.setLayout( new BorderLayout(2,2) );
341     centerArea.add("North",np );
342
343     // Create the centre - centre panel
344

345     // A scrollable text area for the application information text
346
// which could be license text
347
editorPane = new JEditorPane();
348     editorPane.setFont( textFont );
349     editorPane.addHyperlinkListener( this );
350     editorPane.setToolTipText( "application info text" );
351     try {
352         File file = new File(appURLPath);
353         if ( file.exists() )
354         appURLPath = "file:"+file.getAbsolutePath();
355         // System.out.println(" appURLPath = "+appURLPath );
356
editorPane.setPage( appURLPath );
357     }
358     catch (IOException e) {
359         System.err.println( "I/O Exception failure:"+e ); // DEBUG:
360
editorPane.setContentType( DEFAULT_APPLICATION_CONTENT_TYPE );
361         editorPane.setText( DEFAULT_APPLICATION_CONTENT );
362     }
363     editorPane.setEditable( false );
364     
365     JScrollPane ta_scrollable_text = new JScrollPane( editorPane ) {
366         public Dimension getPreferredSize() {
367         Dimension size = getSize();
368         if (size.width < 400 )
369             size.width = 400;
370         if (size.height < 360 )
371             size.height = 360;
372         return (size);
373         }
374     };
375     centerArea.add("Center", ta_scrollable_text );
376     
377     // Southern Button Panel in the centre
378
JPanel sp = new JPanel();
379     sp.setLayout( new FlowLayout( FlowLayout.LEFT, 10, 10 ));
380     bt_install = new JButton( installButtonText );
381     bt_install.setMnemonic( installButtonMnemonic );
382     bt_install.setFont(labelFont);
383     bt_install.setActionCommand("install");
384     bt_install.addActionListener(this);
385     sp.add( bt_install);
386     
387     bt_quit = new JButton( quitButtonText);
388     bt_quit.setMnemonic( quitButtonMnemonic );
389     bt_quit.setFont(labelFont);
390     bt_quit.setActionCommand("quit");
391     bt_quit.addActionListener(this);
392     sp.add( bt_quit);
393     
394     bt_help = new JButton( helpButtonText );
395     bt_help.setMnemonic( helpButtonMnemonic );
396     bt_help.setFont(labelFont);
397     bt_help.setActionCommand("help");
398     bt_help.addActionListener(this);
399     sp.add( bt_help);
400
401     // Create digital clock
402
DigitalClock clock = new DigitalClock();
403     clock.start();
404     clock.setBorder(new BevelBorder( BevelBorder.LOWERED ));
405     sp.add(clock);
406     
407     centerArea.add("South", sp );
408
409     getContentPane().add("Center", centerArea );
410     
411     setSize( 600, 450 );
412
413     // Add a keyboard action `<CTRL> <SHIFT D' to set a debuggable option
414
// on the installer frame
415
bt_install.registerKeyboardAction(
416         new DebuggablePrefix(),
417         KeyStroke.getKeyStroke(
418         KeyEvent.VK_D, InputEvent.SHIFT_MASK|InputEvent.CTRL_MASK, true ),
419         JComponent.WHEN_IN_FOCUSED_WINDOW );
420     }
421     
422     protected JMenu createMenu( String JavaDoc resource_name,
423                 String JavaDoc default_name,
424                 int default_mnemonic )
425     {
426     JMenu menu;
427     
428     ApplicationResources appres = ApplicationResources.getInstance();
429     String JavaDoc menuLabel =
430         appres.getResourceString(
431         "menubar." + resource_name + ".label", default_name );
432     int menuMnemonic =
433         appres.getResourceMnemonic(
434         "menubar." + resource_name + ".mnemonic", default_mnemonic );
435     
436     menu = new JMenu( menuLabel );
437     if (menuMnemonic>0) menu.setMnemonic( menuMnemonic );
438     return (menu);
439     }
440     
441     protected JMenuItem createMenuItem( String JavaDoc resource_name,
442                     String JavaDoc action_command,
443                     String JavaDoc default_name,
444                     int default_mnemonic,
445                     String JavaDoc accelerator )
446     {
447     JMenuItem menuitem;
448
449     ApplicationResources appres = ApplicationResources.getInstance();
450     String JavaDoc itemLabel =
451         appres.getResourceString(
452         resource_name + ".label", default_name );
453     int itemMnemonic =
454         appres.getResourceMnemonic(
455         resource_name + ".mnemonic", default_mnemonic );
456     String JavaDoc itemAccel =
457         appres.getResourceString(
458         resource_name + ".accelerator", accelerator );
459     
460     menuitem = new JMenuItem( itemLabel );
461     if (itemMnemonic>0)
462         menuitem.setMnemonic( itemMnemonic );
463     if (action_command != null)
464         menuitem.setActionCommand(action_command);
465     return (menuitem);
466     }
467
468     /** Gets the splash image icon */
469     public ImageIcon getSplashImageIcon()
470     {
471     return (splashImage);
472     }
473
474     /** Sets the splash image icon */
475     public void setSplashImageIcon( ImageIcon newIcon )
476     {
477     if (newIcon != null) {
478         splashImage = newIcon;
479         splashLabel.setIcon(splashImage);
480     }
481     }
482
483     /** Gets the <B>prefix</B> installation root directory */
484     public File getPrefix()
485     {
486     // FIXME: Do we need the `prefix' member.
487
String JavaDoc tmp = tf_prefix.getText().trim();
488     prefix = new File(tmp);
489     return (prefix);
490     }
491
492     /** Sets the <B>prefix</B> installation root directory */
493     public void setPrefix( File newPrefix )
494     {
495     if (newPrefix == null)
496         newPrefix = new File( System.getProperty("user.home" ));
497     if (newPrefix.isFile() )
498         // Use the parent directory if this is an ordinary file.
499
newPrefix = new File( newPrefix.getParent() );
500     prefix = newPrefix;
501     tf_prefix.setText( prefix.getPath() );
502     }
503
504     /** gets the selected locale */
505     public Locale getLocale()
506     {
507     // FIX ME: Update from GUI
508
return (locale);
509     }
510     
511     /** sets the selected locale */
512     public void setLocale( Locale newLocale )
513     {
514     locale = newLocale;
515
516     // Update the user interface
517
for (int j=0; j<locales.length; ++j)
518         if ( locales[j] == locale )
519         languageCombo.setSelectedIndex(j+1);
520     }
521     
522     /** gets the selected install mode */
523     public int getInstallMode()
524     {
525     // FIXME: Do we need the `install mode' member?
526
return (installMode);
527     }
528     
529     /** sets the selected install mode */
530     public void setInstallMode( int newMode )
531     {
532     installMode = newMode;
533     // Update the component
534
if ( newMode >= 0 )
535         instModeCombo.setSelectedIndex(newMode);
536     }
537     
538     /**
539      * get the available locale objects
540      */

541     public Locale[] getAvailableLocales()
542     {
543     Locale [] locales = new Locale[] {
544         Locale.UK, // This get overriden with the default
545
Locale.CANADA,
546         Locale.CANADA_FRENCH,
547         Locale.CHINA,
548         Locale.CHINESE,
549         Locale.ENGLISH,
550         Locale.FRANCE,
551         Locale.FRENCH,
552         Locale.GERMAN,
553         Locale.GERMANY,
554         Locale.ITALIAN,
555         Locale.ITALY,
556         Locale.JAPAN,
557         Locale.JAPANESE,
558         Locale.KOREA,
559         Locale.KOREAN,
560         Locale.PRC,
561         Locale.SIMPLIFIED_CHINESE,
562         Locale.TAIWAN,
563         Locale.TRADITIONAL_CHINESE,
564         Locale.UK,
565         Locale.US };
566     locales[0] = Locale.getDefault();
567     return (locales);
568     }
569
570     /** Sets the visibility of this component so that it is <EM>always</EM>
571      * centered.
572      * @param visible true if this the component is visible.
573      */

574     public void setVisible( boolean visible )
575     {
576     if (visible) {
577         Dimension size = new Dimension(getSize());
578         Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
579         
580         if (screen.width > 1100 ) {
581         // For hires screens.
582
size.width = 1024;
583         size.height = 695;
584         }
585         int x = (screen.width-size.width)/2;
586         int y = (screen.height-size.height)/2;
587         setBounds(x, y, size.width, size.height);
588     }
589     
590     super.setVisible(visible);
591     }
592     
593
594     /**
595      * A nice convenience method to pop up a dialog reporting the
596      * the Java Exception.
597      * @param frame the frame component
598      * @param ex the exception
599      */

600     public static int popupExceptionDialog( Frame frame, Exception JavaDoc ex )
601     {
602     // Pop up exception
603
return popupErrorDialog( frame,
604                  "exceptionDialog", "Java Exception Dialog",
605                  ex.getMessage() );
606     }
607     
608
609     /** A nice convenience method to pop up a dialog reporting
610      * an informational message
611      *
612      * Application resources
613      * dialog title: resource+".title"
614      * ok button label: resource+".okButton.label"
615      * cancel button label: resource+".cancelButton.label"
616      *
617      *
618      * @param frame the frame component
619      * @param resource the application resource name of this dialog title
620      * without the "title" end-part. The resource is used to retrieve
621      * ok button and cancel labels.
622      * @param def the default dialog title
623      * @param errmsg the error or exception message
624      */

625     public static int popupInfoDialog( Frame frame, String JavaDoc resource,
626                        String JavaDoc def, String JavaDoc errmsg )
627     {
628     return popupOptionPaneDialog( frame, JOptionPane.INFORMATION_MESSAGE,
629                       JOptionPane.OK_CANCEL_OPTION,
630                       resource, def, errmsg );
631     }
632     
633     /** A nice convenience method to pop up a dialog reporting
634      * a warning message
635      *
636      * Application resources
637      * dialog title: resource+".title"
638      * ok button label: resource+".okButton.label"
639      * cancel button label: resource+".cancelButton.label"
640      *
641      *
642      * @param frame the frame component
643      * @param resource the application resource name of this dialog title
644      * without the "title" end-part. The resource is used to retrieve
645      * ok button and cancel labels.
646      * @param def the default dialog title
647      * @param errmsg the error or exception message
648      */

649     public static int popupWarningDialog( Frame frame, String JavaDoc resource,
650                       String JavaDoc def, String JavaDoc errmsg )
651     {
652     return popupOptionPaneDialog( frame, JOptionPane.INFORMATION_MESSAGE,
653                           JOptionPane.DEFAULT_OPTION,
654                       resource, def, errmsg );
655     }
656     
657     /** A nice convenience method to pop up a dialog reporting
658      * an error message
659      *
660      * Application resources
661      * dialog title: resource+".title"
662      * ok button label: resource+".okButton.label"
663      * cancel button label: resource+".cancelButton.label"
664      *
665      *
666      * @param frame the frame component
667      * @param resource the application resource name of this dialog title
668      * without the "title" end-part. The resource is used to retrieve
669      * ok button and cancel labels.
670      * @param def the default dialog title
671      * @param errmsg the error or exception message
672      */

673     public static int popupErrorDialog( Frame frame, String JavaDoc resource,
674                     String JavaDoc def, String JavaDoc errmsg )
675     {
676     return popupOptionPaneDialog( frame, JOptionPane.ERROR_MESSAGE,
677                       JOptionPane.DEFAULT_OPTION,
678                       resource, def, errmsg );
679     }
680     
681     
682     
683     /** A nice convenience method to pop up an option pane dialog
684      * reporting a general message
685      *
686      * Application resources
687      * dialog title: resource+".title"
688      * ok button label: resource+".okButton.label"
689      * cancel button label: resource+".cancelButton.label"
690      *
691      *
692      * @param frame the frame component
693      * @param dialogType specifies the dialog type
694      * e.g JOptionPane.ERROR_MESSAGE
695      * @param dialogOption specifies the dialog option
696      * e.g JOptionPane.OK_CANCEL_OPTION
697      * @param resource the application resource name of this dialog title
698      * without the "title" end-part. The resource is used to retrieve
699      * ok button and cancel labels.
700      * @param def the default dialog title
701      * @param errmsg the error or exception message
702      */

703     public static int popupOptionPaneDialog(
704     Frame frame, int dialogType, int dialogOption,
705     String JavaDoc resource, String JavaDoc def, String JavaDoc errmsg )
706     {
707     //
708
// Use the Swing JFC to pop up an error dialog box.
709
// (It is really so simple!)
710
//
711
JTextArea ta_error_msg; // Error message text area
712
JScrollPane ta_error_msg_scroller; // and it respective scrolling pane
713

714     ta_error_msg = new JTextArea( "" );
715     ta_error_msg.setEditable(false);
716     ta_error_msg.setFont( new Font("Dialog", Font.PLAIN, 10 ));
717     ta_error_msg_scroller = new JScrollPane() {
718         public Dimension getPreferredSize() {
719         Dimension currSize = new Dimension( getSize() );
720         if (currSize.width < 500 )
721             currSize.width = 500;
722         if (currSize.height < 200 )
723             currSize.height = 200;
724         
725         return currSize;
726         }
727         public float getAlignmentX() {
728         return LEFT_ALIGNMENT;
729         }
730     };
731     ta_error_msg_scroller.getViewport().add(ta_error_msg); // Add it !!!
732
ta_error_msg.setText( errmsg );
733     
734     Object JavaDoc msg[] = new Object JavaDoc[1];
735     msg[0] = ta_error_msg_scroller;
736     
737     //
738
// Get Application Resources for i18n of the Error Dialog
739
// Use a general option pane and pass it two string
740
// objects, which used to created the JButtons, which are
741
// added to the options area.
742
// "Programming with JFC" Table 9.11 pages 236-240
743
//
744
ApplicationResources appres = ApplicationResources.getInstance();
745     String JavaDoc dialogTitle =
746         appres.getResourceString( resource+".title", def );
747     Object JavaDoc[] options;
748     if ( dialogType == JOptionPane.DEFAULT_OPTION ) {
749         options = new Object JavaDoc[1];
750         options[0] =
751         appres.getResourceString( resource+".okButton.label", "Ok" );
752     }
753     else {
754         options = new Object JavaDoc[2];
755         options[0] =
756         appres.getResourceString( resource+".okButton.label", "Ok" );
757         options[1] =
758         appres.getResourceString( resource+".cancelButton.label", "Cancel" );
759     }
760     
761     return JOptionPane.showOptionDialog( frame, msg, dialogTitle,
762                          dialogOption, dialogType,
763                          null, options, options[0] );
764     }
765
766     // ----------------------------------------------------------------------
767
// EVENT HANDLING
768
// ----------------------------------------------------------------------
769

770     public void hyperlinkUpdate( HyperlinkEvent evt )
771     {
772     if ( evt.getEventType() == HyperlinkEvent.EventType.ENTERED )
773         editorPane.setToolTipText( evt.getURL().toString() );
774     }
775     
776     /** Add <I>PropertyChangeListener</I> obejcts interested in receiving
777      * property change events.
778      * @param listener the property change listener
779      */

780     public void addPropertyChangeListener( PropertyChangeListener listener )
781     {
782     if (propertyListeners == null)
783         propertyListeners = new SwingPropertyChangeSupport( this );
784     propertyListeners.addPropertyChangeListener( listener );
785     }
786     
787     /** Remove <I>PropertyChangeListener</I> obejcts interested in receiving
788      * property change events.
789      * @param listener the property change listener
790      */

791     public void removePropertyChangeListener( PropertyChangeListener listener )
792     {
793     if (propertyListeners != null)
794         propertyListeners.removePropertyChangeListener( listener );
795     }
796     
797     /** Remove <I>PropertyChangeListener</I> obejcts interested in receiving
798      * property change events.
799      * @param propertyName the property name
800      * @param oldValue the old property value
801      * @param newValue the new property value
802      */

803     public void firePropertyChange( String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue )
804     {
805     if (propertyListeners != null)
806         propertyListeners.firePropertyChange( propertyName, oldValue, newValue );
807     }
808
809     public void actionPerformed( ActionEvent evt )
810     {
811     String JavaDoc cmd = evt.getActionCommand();
812     if (cmd.equals("browse")) {
813
814         firePropertyChange( BROWSE_BUTTON_PRESSED_PROPERTY, null, evt );
815
816         JFileChooser chooser = new JFileChooser();
817         chooser.setDialogTitle("Select Install Root Directory");
818         chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
819         chooser.setCurrentDirectory( prefix );
820         chooser.setApproveButtonText("Select Dir");
821         chooser.setApproveButtonToolTipText("prefix directory");
822         chooser.setApproveButtonMnemonic('S');
823         
824         int answer = chooser.showDialog(this,"Select Dir");
825         if ( answer == JFileChooser.APPROVE_OPTION ) {
826         // Operator selected a directory.
827
File dir = chooser.getSelectedFile();
828         if (dir != null) {
829             // System.out.println("setting new prefix directory:"+dir.getPath() );
830
prefix = dir;
831             tf_prefix.setText( prefix.getPath() );
832         }
833         }
834     }
835     else if (cmd.equals("select-locale")) {
836         int idx = languageCombo.getSelectedIndex();
837         if (idx <= 0 )
838         locale = null;
839         else {
840         locale = locales[idx-1];
841         // System.out.println( "selected locale:" + locales[idx-1].getDisplayName() );
842
}
843     }
844     else if (cmd.equals("select-install-mode")) {
845         int idx = instModeCombo.getSelectedIndex();
846         if (idx <= 0 )
847         installMode = -1;
848         else {
849         installMode = idx;
850         // System.out.println( "selected install mode:" + InstallUtilities.installModeToString(installMode) );
851
}
852     }
853     else if (cmd.equals("install")) {
854         // Make sure we set the prefix directory from the current
855
// contents of the text field.
856
prefix = new File( tf_prefix.getText().trim() );
857
858         int idx1 = languageCombo.getSelectedIndex();
859         int idx2 = instModeCombo.getSelectedIndex();
860         if (idx1 <= 0 )
861         popupErrorDialog( this, "errorDialog",
862                   "Error Setting Dialog",
863                   "please select an appropiate locale." );
864         else if (idx2 <= 0 )
865         popupErrorDialog( this, "errorDialog",
866                   "Error Setting Dialog",
867                   "please select a genuine installation mode." );
868         else {
869         // System.out.println("install button pressed ...");
870
firePropertyChange( INSTALL_BUTTON_PRESSED_PROPERTY, null, evt );
871         }
872     }
873     else if (cmd.equals("help")) {
874         firePropertyChange( HELP_BUTTON_PRESSED_PROPERTY, null, evt );
875         popupHelpDialog( this, "Help.html" );
876     }
877     else if (cmd.equals("quit")) {
878         firePropertyChange( QUIT_BUTTON_PRESSED_PROPERTY, null, evt );
879     }
880     else if (cmd.equals("view-license")) {
881         popupViewLicenseDialog( this, null );
882     }
883     else if (cmd.equals("view-author")) {
884         popupAuthorDialog( this, "Author.html" );
885     }
886     
887     }
888
889     public static void popupViewLicenseDialog( Frame frame, String JavaDoc url )
890     {
891     //
892
// Popup a dialog to view the FreeInstaller license context
893
//
894
if (url==null) url="appres/docs/FREE-INST-LICENSE.html";
895     
896     // System.out.println("popupViewLicenseDialog() url: "+url );
897

898     ApplicationResources appres = ApplicationResources.getInstance();
899     String JavaDoc title = appres.getResourceString( "viewLicenseDialog.dialogTitle", "View License Dialog" );
900     String JavaDoc licURLName = appres.getResourceString( "viewLicenseDialog.infoURL", url );
901     String JavaDoc licURLPath = appres.resolvePathname( "docs", licURLName, null );
902     
903     String JavaDoc approveButtonText =
904         appres.getResourceString( "HTMLViewerDialog.approveButton.label", "Close" );
905     String JavaDoc backButtonText =
906         appres.getResourceString( "HTMLViewerDialog.backButton.label", "Back" );
907     String JavaDoc nextButtonText =
908         appres.getResourceString( "HTMLViewerDialog.nextButton.label", "Next" );
909     
910     String JavaDoc backButtonToolTipText =
911         appres.getResourceString( "HTMLViewerDialog.backButton.toolTipText", "go to previous" );
912     String JavaDoc nextButtonToolTipText =
913         appres.getResourceString( "HTMLViewerDialog.nextButton.toolTipText", "go to next" );
914     
915     try {
916         File file = new File(licURLPath);
917         if ( file.exists() )
918         licURLPath = "file:"+file.getAbsolutePath();
919         // System.out.println("URL: `"+licURLPath+"'");
920
HTMLViewerDialog dialog =
921         new HTMLViewerDialog( frame, title, licURLPath, approveButtonText );
922         
923         HTMLViewerPane viewer = dialog.getHTMLViewerPane();
924         viewer.setBackButtonText(backButtonText);
925         viewer.setBackButtonToolTipText(backButtonToolTipText);
926         
927         viewer.setNextButtonText(nextButtonText);
928         viewer.setNextButtonToolTipText(nextButtonToolTipText);
929         
930         InstallUtilities.centerComponentOnScreen(dialog);
931         dialog.show();
932     }
933     catch (IOException e) {
934         System.out.println(e);
935     }
936     }
937     
938     public static void popupHelpDialog( Frame frame, String JavaDoc url )
939     {
940     //
941
// Popup a dialog to view the help dialog
942
//
943

944     // System.out.println("popupHelpDialog() url: "+url );
945

946     ApplicationResources appres = ApplicationResources.getInstance();
947     String JavaDoc title = appres.getResourceString( "helpDialog.dialogTitle", "On-Line Help Dialog" );
948     String JavaDoc urlPath = appres.resolvePathname( "appres/docs", url, null );
949     
950     String JavaDoc approveButtonText =
951         appres.getResourceString( "helpDialog.approveButton.label", "Close" );
952     String JavaDoc backButtonText =
953         appres.getResourceString( "helpDialog.backButton.label", "Back" );
954     String JavaDoc nextButtonText =
955         appres.getResourceString( "helpDialog.nextButton.label", "Next" );
956     
957     String JavaDoc backButtonToolTipText =
958         appres.getResourceString( "helpDialog.backButton.toolTipText", "go to previous" );
959     String JavaDoc nextButtonToolTipText =
960         appres.getResourceString( "helpDialog.nextButton.toolTipText", "go to next" );
961     
962     try {
963         File file = new File(urlPath);
964         if ( file.exists() )
965         urlPath = "file:"+file.getAbsolutePath();
966         // System.out.println("URLPath: `"+urlPath+"'");
967
HTMLViewerDialog dialog =
968         new HTMLViewerDialog( frame, title, urlPath, approveButtonText );
969         HTMLViewerPane viewer = dialog.getHTMLViewerPane();
970         viewer.setBackButtonText(backButtonText);
971         viewer.setBackButtonToolTipText(backButtonToolTipText);
972         
973         viewer.setNextButtonText(nextButtonText);
974         viewer.setNextButtonToolTipText(nextButtonToolTipText);
975         
976         InstallUtilities.centerComponentOnScreen(dialog);
977         dialog.show();
978     }
979     catch (IOException e) {
980         System.out.println(e);
981     }
982     }
983
984     public static void popupAuthorDialog( Frame frame, String JavaDoc url )
985     {
986     //
987
// Popup a dialog to view the author dialog
988
//
989
// System.out.println("popupAuthorDialog() url: "+url );
990

991     ApplicationResources appres = ApplicationResources.getInstance();
992     String JavaDoc title = appres.getResourceString( "authorDialog.dialogTitle", "View Author Dialog" );
993     String JavaDoc urlPath = appres.resolvePathname( "appres/docs", url, null );
994     
995     String JavaDoc approveButtonText =
996         appres.getResourceString( "authorDialog.approveButton.label", "Close" );
997     String JavaDoc backButtonText =
998         appres.getResourceString( "authorDialog.backButton.label", "Back" );
999     String JavaDoc nextButtonText =
1000        appres.getResourceString( "authorDialog.nextButton.label", "Next" );
1001    
1002    String JavaDoc backButtonToolTipText =
1003        appres.getResourceString( "authorDialog.backButton.toolTipText", "go to previous" );
1004    String JavaDoc nextButtonToolTipText =
1005        appres.getResourceString( "authorDialog.nextButton.toolTipText", "go to next" );
1006    
1007    try {
1008        File file = new File(urlPath);
1009        if ( file.exists() )
1010        urlPath = "file:"+file.getAbsolutePath();
1011        // System.out.println("URLPath: `"+urlPath+"'");
1012
HTMLViewerDialog dialog =
1013        new HTMLViewerDialog( frame, title, urlPath, approveButtonText );
1014        HTMLViewerPane viewer = dialog.getHTMLViewerPane();
1015        viewer.setBackButtonText(backButtonText);
1016        viewer.setBackButtonToolTipText(backButtonToolTipText);
1017        
1018        viewer.setNextButtonText(nextButtonText);
1019        viewer.setNextButtonToolTipText(nextButtonToolTipText);
1020        
1021        dialog.setSize( new Dimension( 465, 575 ) );
1022        InstallUtilities.centerComponentOnScreen(dialog);
1023        dialog.show();
1024    }
1025    catch (IOException e) {
1026        System.out.println(e);
1027    }
1028    }
1029
1030    // ======================================================================
1031
// I N N E R C L A S S E S
1032
// ======================================================================
1033

1034    public class DebuggablePrefix implements ActionListener
1035    {
1036    public void actionPerformed( ActionEvent evt )
1037    {
1038        String JavaDoc osname = System.getProperty( "os.name");
1039        Toolkit.getDefaultToolkit().beep();
1040        if ( osname.startsWith("Windows 95") ||
1041         osname.startsWith("Windows 98") ||
1042         osname.startsWith("Windows 2000") ||
1043         osname.startsWith("OS/2") ||
1044         osname.startsWith("Windows NT") )
1045        setPrefix( new File("C:\\Temp\\Testing") );
1046        else
1047        setPrefix( new File("/tmp/testing") );
1048        setLocale( Locale.getDefault() );
1049        setInstallMode( BASIC_INSTALLATION );
1050    }
1051    }
1052    
1053}
1054
1055// fini
1056
Popular Tags