001package jmri.jmrit.operations.trains; 002 003import java.io.File; 004import java.io.IOException; 005 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * Train file utilities 011 * 012 * @author Daniel Boudreau (C) 2010 013 * 014 * 015 */ 016public class TrainUtilities { 017 018 /** 019 * This method uses Desktop which is supported in Java 1.6. 020 * @param file The File to open. 021 */ 022 public static void openDesktop(File file) { 023 if (!java.awt.Desktop.isDesktopSupported()) { 024 log.warn("desktop not supported"); 025 return; 026 } 027 java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); 028 if (!desktop.isSupported(java.awt.Desktop.Action.OPEN)) { 029 log.warn("desktop open not supported"); 030 return; 031 } 032 try { 033 desktop.open(file); 034 } catch (IOException e) { 035 log.error("unable to open {} in desktop application: {}", file.getName(), e.getLocalizedMessage()); 036 } 037 } 038 039 private final static Logger log = LoggerFactory.getLogger(TrainUtilities.class); 040}