/[svn]/jsampler/trunk/src/org/jsampler/HF.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/HF.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2287 by iliev, Mon Aug 11 22:51:24 2008 UTC revision 2288 by iliev, Wed Nov 23 21:19:44 2011 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 22  Line 22 
22    
23  package org.jsampler;  package org.jsampler;
24    
 import java.awt.Component;  
 import java.awt.Dialog;  
 import java.awt.Font;  
 import java.awt.Frame;  
   
25  import java.io.File;  import java.io.File;
26  import java.io.FileInputStream;  import java.io.FileInputStream;
27  import java.io.FileOutputStream;  import java.io.FileOutputStream;
28    
29  import java.util.logging.Level;  import java.util.logging.Level;
30    
 import javax.swing.JOptionPane;  
 import javax.swing.UIManager;  
 import javax.swing.plaf.FontUIResource;  
   
31  import org.linuxsampler.lscp.LSException;  import org.linuxsampler.lscp.LSException;
32  import org.linuxsampler.lscp.LscpException;  import org.linuxsampler.lscp.LscpException;
33    
# Line 48  import static org.jsampler.JSI18n.i18n; Line 39  import static org.jsampler.JSI18n.i18n;
39   * @author Grigor Iliev   * @author Grigor Iliev
40   */   */
41  public class HF {  public class HF {
 // GUI HELPER FUNCIONS  
42                    
43          /**          /**
44           * Returns more meaningful, non-<code>null</code> message.           * Returns more meaningful, non-<code>null</code> message.
# Line 68  public class HF { Line 58  public class HF {
58          }          }
59                    
60          /**          /**
          * Shows a dialog with the specified error message.  
          * @param msg The error message to be shown.  
          */  
         public static void  
         showErrorMessage(String msg) { showErrorMessage(msg, CC.getMainFrame()); }  
           
         /**  
          * Shows a dialog with the specified error message.  
          * @param parentComponent determines the Frame in which the dialog is displayed  
          * @param msg The error message to be shown.  
          */  
         public static void  
         showErrorMessage(String msg, Component parentComponent) {  
                 JOptionPane.showMessageDialog (  
                         parentComponent, msg,  
                         i18n.getError("error"),  
                         JOptionPane.ERROR_MESSAGE  
                 );  
         }  
           
         /**  
          * Shows a dialog with error message obtained by {@link #getErrorMessage} method.  
          * @param e The <code>Exception</code> from which the error message is obtained.  
          */  
         public static void  
         showErrorMessage(Exception e) { showErrorMessage(e, CC.getMainFrame()); }  
           
         /**  
          * Shows a dialog with error message obtained by {@link #getErrorMessage} method.  
          * @param e The <code>Exception</code> from which the error message is obtained.  
          * @param prefix The prefix to be added to the error message.  
          */  
         public static void  
         showErrorMessage(Exception e, String prefix) {  
                 showErrorMessage(e, CC.getMainFrame(), prefix);  
         }  
           
         /**  
          * Shows a dialog with error message obtained by {@link #getErrorMessage} method.  
          * @param e The <code>Exception</code> from which the error message is obtained.  
          * @param frame The parent <code>Frame</code> for the dialog.  
          */  
         public static void  
         showErrorMessage(Exception e, Frame frame) {  
                 showErrorMessage(e, frame, "");  
         }  
           
         /**  
          * Shows a dialog with error message obtained by {@link #getErrorMessage} method.  
          * @param e The <code>Exception</code> from which the error message is obtained.  
          * @param frame The parent <code>Frame</code> for the dialog.  
          * @param prefix The prefix to be added to the error message.  
          */  
         public static void  
         showErrorMessage(Exception e, Frame frame, String prefix) {  
                 String msg = prefix + getErrorMessage(e);  
                   
                 CC.getLogger().log(Level.INFO, msg, e);  
                           
                 JOptionPane.showMessageDialog (  
                         frame, msg,  
                         i18n.getError("error"),  
                         JOptionPane.ERROR_MESSAGE  
                 );  
         }  
           
         /**  
          * Shows a dialog with error message obtained by {@link #getErrorMessage} method.  
          * @param e The <code>Exception</code> from which the error message is obtained.  
          * @param dlg The parent <code>Dialog</code> from which the dialog is displayed.  
          */  
         public static void  
         showErrorMessage(Exception e, Dialog dlg) {  
                 String msg = getErrorMessage(e);  
                   
                 CC.getLogger().log(Level.INFO, msg, e);  
                   
                 JOptionPane.showMessageDialog (  
                         dlg, msg,  
                         i18n.getError("error"),  
                         JOptionPane.ERROR_MESSAGE  
                 );  
         }  
           
         /**  
          * Brings up a question dialog with Yes, No options, empty title and the specified message.  
          * @param parent The parent <code>Component</code> for the dialog.  
          * @param message The message to display.  
          * @return <code>true</code> if the user chooses "yes", <code>false</code> otherwise.  
          */  
         public static boolean  
         showYesNoDialog(Component parent, String message) {  
                 return showYesNoDialog(parent, message, "");  
         }  
           
         /**  
          * Brings up a question dialog with Yes, No options, empty title and the specified message.  
          * @param parent The parent <code>Component</code> for the dialog.  
          * @param message The message to display.  
          * @param title The dialog's title.  
          * @return <code>true</code> if the user chooses "yes", <code>false</code> otherwise.  
          */  
         public static boolean  
         showYesNoDialog(Component parent, String message, String title) {  
                 Object[] options = { i18n.getButtonLabel("yes"), i18n.getButtonLabel("no") };  
                 int n = JOptionPane.showOptionDialog (  
                         parent,  
                         message, title,  
                         JOptionPane.YES_NO_OPTION,  
                         JOptionPane.QUESTION_MESSAGE,  
                         null,  
                         options, options[0]  
                 );  
                   
                 return n == 0;  
         }  
           
         /**  
          * Sets the default font to be used in the GUI.  
          * @param fontName The name of the font to be used as default.  
          */  
         public static void  
         setUIDefaultFont(String fontName) {  
                 if(fontName == null) return;  
                   
                 java.util.Enumeration keys = UIManager.getDefaults().keys();  
                 while(keys.hasMoreElements()) {  
                         Object key = keys.nextElement();  
                         Object value = UIManager.get(key);  
                         if(value instanceof FontUIResource) {  
                                 Font f = (FontUIResource)value;  
                                 FontUIResource fr =  
                                         new FontUIResource(fontName, f.getStyle(), f.getSize());  
                                 UIManager.put(key, fr);  
                         }  
                 }  
         }  
 ///////  
           
         /**  
61           * Deletes the specified file, if exists and           * Deletes the specified file, if exists and
62           * is located in the JSampler's home directory.           * is located in the JSampler's home directory.
63           * @param file The file to delete.           * @param file The file to delete.
# Line 305  public class HF { Line 155  public class HF {
155                  f /= 100;                  f /= 100;
156                  return f;                  return f;
157          }          }
158            
159            /** Tests whether the application can read/write the specified file. */
160            public static boolean
161            canReadWrite(String file) {
162                    File f = new File(file);
163                    if(f.isDirectory()) return false;
164                    if(f.canRead() && f.canWrite()) return true;
165                    return false;
166            }
167            
168            /** Tests whether the application can read/write files in the specified directory. */
169            public static boolean
170            canReadWriteFiles(String dir) {
171                    File f = new File(dir);
172                    if(!f.isDirectory()) return false;
173                    if(f.canRead() && f.canWrite() && f.canExecute()) return true;
174                    return false;
175            }
176  }  }

Legend:
Removed from v.2287  
changed lines
  Added in v.2288

  ViewVC Help
Powered by ViewVC