PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/files/FileActionHandler.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 86 lines | 47 code | 6 blank | 33 comment | 3 complexity | 50801d127a1b5e20006d1afe40e8d673 MD5 | raw file
 1/*
 2 *  This file is part of YaBS.
 3 *
 4 *  YaBS is free software: you can redistribute it and/or modify
 5 *  it under the terms of the GNU General Public License as published by
 6 *  the Free Software Foundation, either version 3 of the License, or
 7 *  (at your option) any later version.
 8 *
 9 *  YaBS is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *  GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package mpv5.utils.files;
18
19import java.awt.Desktop;
20import java.io.File;
21import java.io.IOException;
22import mpv5.logging.Log;
23import mpv5.utils.print.PrintJob;
24
25/**
26 * This class is designed to have easy and quick, OS independent 
27 * access to common desktop actions
28 *  
29 */
30public class FileActionHandler {
31
32    /**
33     * Print file f
34     * @param f
35     */
36    public static void print(File f) {
37        if (Desktop.isDesktopSupported()) {
38            try {
39                Desktop.getDesktop().print(f);
40            } catch (IOException ex) {
41                Log.Debug(FileActionHandler.class, "Print Error (Native printing not supported. Do you have the GNOME libraries installed?): ");
42                Log.Debug(FileActionHandler.class, ex);
43                alternatePrint(f);
44            }
45        }
46    }
47
48    private static void alternatePrint(File f) {
49        try {
50            new PrintJob().print(f);
51        } catch (Exception ex) {
52            Log.Debug(FileActionHandler.class, "Alternative Print Method Error: ");
53            Log.Debug(FileActionHandler.class, ex);
54        }
55    }
56
57    /**
58     * Open File f for editing
59     * @param f
60     */
61    public static void edit(File f) {
62        if (Desktop.isDesktopSupported()) {
63            try {
64                Desktop.getDesktop().edit(f);
65            } catch (IOException ex) {
66                Log.Debug(FileActionHandler.class, "Open for Edit Error: ");
67                Log.Debug(FileActionHandler.class, ex);
68            }
69        }
70    }
71
72    /**
73     * Open File f in default application
74     * @param f
75     */
76    public static void open(File f) {
77        if (Desktop.isDesktopSupported()) {
78            try {
79                Desktop.getDesktop().open(f);
80            } catch (IOException ex) {
81                Log.Debug(FileActionHandler.class, "Open File Error: ");
82                Log.Debug(FileActionHandler.class, ex);
83            }
84        }
85    }
86}