AVR Z-LINKŪ


Dialogs.java

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00002 package gui;
00003 
00004 import java.util.Vector;
00005 
00006 import javax.comm.SerialPort;
00007 import javax.swing.JOptionPane;
00008 
00009 import serialInterface.SerialPortUtilities;
00010 
00011 
00028 public class Dialogs {
00029         
00040         public static SerialPort chooseSerialPort( MainFrame parentWindow ){
00041                 
00042                 //Fetch available ports and convert into an array of strings.
00043                 Vector<String> portsAvailable = SerialPortUtilities.getSerialPortNames( );
00044                 
00045                 //No ports available.
00046                 if( portsAvailable.isEmpty( ) ){
00047                         
00048                         Dialogs.showErrorMessage( parentWindow, "No serial ports available.\r\n" +
00049                                                                                                         "Free one or more and try again." );
00050                         return null;
00051                 }
00052                 //Ports available.
00053                 else{
00054                 
00055                         Object[] serialPorts = portsAvailable.toArray( );
00056                         
00057                         //Prompt the user for his/her choice.
00058                         String result = showPortInputDialog( parentWindow, serialPorts );
00059                         
00060                         //Port is chosen, try to connect.
00061                         if( result != null ){
00062                                 return SerialPortUtilities.connectToSerialPort( result );
00063                         }
00064                         //Cancel or close window chosen.
00065                         else{
00066                                 return null;
00067                         }
00068                 }
00069         }
00070         
00080         private static String showPortInputDialog( MainFrame parentWindow, Object[] serialPorts ){
00081                 
00082                 return (String)JOptionPane.showInputDialog( parentWindow, "Choose the COM port where\n"
00083                                  + "the radio plaform is connected",
00084                                          "COM Settings",
00085                                          JOptionPane.PLAIN_MESSAGE, null,
00086                                          serialPorts, serialPorts[0] );
00087         }
00088         
00097         public static void showErrorMessage( MainFrame parentWindow, String errorMessage ){
00098                 
00099                 JOptionPane.showMessageDialog( parentWindow, errorMessage, "ERROR",
00100                                                            JOptionPane.ERROR_MESSAGE);
00101         }
00102         
00111         public static void showPlainMessage( MainFrame parentWindow, String message ){
00112                 
00113                 JOptionPane.showMessageDialog( parentWindow, message, "System Message:",
00114                                                            JOptionPane.ERROR_MESSAGE);
00115         }
00116         
00126         public static int showRetryMessage( MainFrame parentWindow ){
00127                 
00128                 Object[] options = {"Retry", "Cancel"};
00129                 
00130         return JOptionPane.showOptionDialog( parentWindow,
00131                         "Communication timed out!" +
00132                         "do you wish to retry?",
00133                         "Retry",
00134                         JOptionPane.YES_NO_OPTION,
00135                         JOptionPane.QUESTION_MESSAGE,
00136                         null,
00137                         options,
00138                         options[0]);
00139         }
00140         
00149         public static String[] showConfigurationDialog( MainFrame parentWindow ){
00150                 
00151                 ConfigurationDialog config = new ConfigurationDialog( parentWindow );
00152                 config.pack( );
00153                 config.setLocationRelativeTo( parentWindow );
00154                 config.setVisible(true);
00155                 
00156                 return config.getUserChoices( );
00157         }
00158 }
@DOC_TITLE@
Generated on Sat Dec 2 16:14:07 2006 for AVR414 User's Guide - ATAVRRZ502 - Accessory Kit by doxygen 1.4.7