EFCNDialog.java :  » IDE » Schmortopf » Schmortopf » Utility » gui » Java Open Source

Java Open Source » IDE » Schmortopf 
Schmortopf » Schmortopf » Utility » gui » EFCNDialog.java
package Schmortopf.Utility.gui;


import javax.swing.*;
import java.awt.*;



/** some static utilities
    1) can be shown modal or not ;
    2) thread secure (invokeandwait) can be called from any thread ;
    3) write his content in the console (=> outputFile), to help debugging.
*/

public class EFCNDialog
{


 /** show a modal warning dialog
 */
 public static void showWarning(String message, Component parent)
 {
    optionPane(message, "Warning", parent, JOptionPane.WARNING_MESSAGE, null);
 }




 /** show a modal information dialog attached to the parent
 */
 public static void showInformation(String message, Component parent)
 {
    optionPane(message, "Information", parent, JOptionPane.INFORMATION_MESSAGE, null);
 }




/** show a modal error dialog attached to the parent
 */
 public static void showError(String message, Component parent)
 {
    optionPane(message, "Error", parent, JOptionPane.ERROR_MESSAGE, null);
 }




/** show a modal question dialog attached to the parent
 */
 public static void showQuestion(String message, Component parent)
 {
    optionPane(message, "Question", parent, JOptionPane.QUESTION_MESSAGE, null);
 }





 public static String showInputDialog(String message, Component parent) {
         return JOptionPane.showInputDialog(parent, message);
 }

 public static int showOptionDialog(String message, Component parent, Object[] options, int defaultOption) {
     JSenseButton[] js = new JSenseButton[options.length];
     for(int i=0; i<options.length; i++)
     {
        js[i] = new JSenseButton(options[i].toString(),true,null);
        js[i].addActionListener(new java.awt.event.ActionListener()
        {
           public void actionPerformed(java.awt.event.ActionEvent e) {
               return;
           }
        });
     }

     return JOptionPane.showOptionDialog(parent, message, "Option dialog",
       JOptionPane.DEFAULT_OPTION,
       JOptionPane.QUESTION_MESSAGE,
       null, options, options[defaultOption]);
 }



 //
 // private data and utilities
 //

 /** All methods use this output method, which runs in all cases.
     It must be modal and called with invoke and wait.
 */
 private static void optionPane(final String message,
                                final String title,
                                final Component parent,
                                final int type,
                                final ImageIcon im)
 {
     if( SwingUtilities.isEventDispatchThread())
     {
        if(message.length()>300)
        {
           TextArea ta = new TextArea(message);
           JScrollPane jsp = new JScrollPane(ta);
           jsp.setPreferredSize(new Dimension(500, 220));
           JOptionPane.showMessageDialog(parent, jsp, title, type, im);
        }
        else
        {
           JOptionPane.showMessageDialog(parent, message, title, type, im);
        }
     }
     else
     {
       try
       {
         SwingUtilities.invokeAndWait(new Runnable() {
          public void run() {
            if(message.length()>300)
            {
               TextArea ta = new TextArea(message);
               JScrollPane jsp = new JScrollPane(ta);
               jsp.setPreferredSize(new Dimension(500, 220));
               JOptionPane.showMessageDialog(parent, jsp, title, type, im);
            }
            else
            {
               JOptionPane.showMessageDialog(parent, message, title, type, im);
            }
          }
         });
       } catch (Exception e)
       {
       }
     }
 }


} // EFCNDialog
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.