Coverage Report - org.jtheque.utils.DesktopUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DesktopUtils
0%
0/30
0%
0/16
3.8
 
 1  
 package org.jtheque.utils;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.slf4j.LoggerFactory;
 20  
 
 21  
 import java.awt.Desktop;
 22  
 import java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.net.URI;
 25  
 import java.net.URISyntaxException;
 26  
 
 27  
 /**
 28  
  * Utility class for the class Desktop.
 29  
  *
 30  
  * @author Baptiste Wicht
 31  
  */
 32  
 public final class DesktopUtils {
 33  
     /**
 34  
      * Construct a new DesktopUtils. This class isn't instanciable
 35  
      */
 36  
     private DesktopUtils() {
 37  0
         super();
 38  0
     }
 39  
 
 40  
     /**
 41  
      * Open the mailer.
 42  
      */
 43  
     public static void mail() {
 44  0
         if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.MAIL)) {
 45  
             try {
 46  0
                 Desktop.getDesktop().mail();
 47  0
             } catch (IOException e) {
 48  0
                 LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open mailer", e);
 49  0
             }
 50  
         }
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Open the mailer with specifics information.
 55  
      *
 56  
      * @param mail The mail to send
 57  
      */
 58  
     public static void mail(DesktopMail mail) {
 59  0
         if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.MAIL)) {
 60  
             try {
 61  0
                 Desktop.getDesktop().mail(mail.getURI());
 62  0
             } catch (IOException e) {
 63  0
                 LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open mailer", e);
 64  0
             } catch (URISyntaxException e) {
 65  0
                 LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open mailer", e);
 66  0
             }
 67  
         }
 68  0
     }
 69  
 
 70  
     /**
 71  
      * Open the file.
 72  
      *
 73  
      * @param file The file to open.
 74  
      */
 75  
     public static void open(File file) {
 76  0
         if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
 77  
             try {
 78  0
                 Desktop.getDesktop().open(file);
 79  0
             } catch (IOException e) {
 80  0
                 LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open file", e);
 81  0
             }
 82  
         }
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Open the browser at the url.
 87  
      *
 88  
      * @param url The URL to browse.
 89  
      */
 90  
     public static void browse(String url) {
 91  0
         if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
 92  
             try {
 93  0
                 Desktop.getDesktop().browse(new URI(url));
 94  0
             } catch (IOException e) {
 95  0
                 LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open browser", e);
 96  0
             } catch (URISyntaxException e) {
 97  0
                 LoggerFactory.getLogger(DesktopUtils.class).error("Unable to open browser", e);
 98  0
             }
 99  
         }
 100  0
     }
 101  
 }