PageRenderTime 29ms CodeModel.GetById 14ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  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. */
  17. package mpv5.utils.files;
  18. import java.awt.Desktop;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import mpv5.logging.Log;
  22. import mpv5.utils.print.PrintJob;
  23. /**
  24. * This class is designed to have easy and quick, OS independent
  25. * access to common desktop actions
  26. *
  27. */
  28. public class FileActionHandler {
  29. /**
  30. * Print file f
  31. * @param f
  32. */
  33. public static void print(File f) {
  34. if (Desktop.isDesktopSupported()) {
  35. try {
  36. Desktop.getDesktop().print(f);
  37. } catch (IOException ex) {
  38. Log.Debug(FileActionHandler.class, "Print Error (Native printing not supported. Do you have the GNOME libraries installed?): ");
  39. Log.Debug(FileActionHandler.class, ex);
  40. alternatePrint(f);
  41. }
  42. }
  43. }
  44. private static void alternatePrint(File f) {
  45. try {
  46. new PrintJob().print(f);
  47. } catch (Exception ex) {
  48. Log.Debug(FileActionHandler.class, "Alternative Print Method Error: ");
  49. Log.Debug(FileActionHandler.class, ex);
  50. }
  51. }
  52. /**
  53. * Open File f for editing
  54. * @param f
  55. */
  56. public static void edit(File f) {
  57. if (Desktop.isDesktopSupported()) {
  58. try {
  59. Desktop.getDesktop().edit(f);
  60. } catch (IOException ex) {
  61. Log.Debug(FileActionHandler.class, "Open for Edit Error: ");
  62. Log.Debug(FileActionHandler.class, ex);
  63. }
  64. }
  65. }
  66. /**
  67. * Open File f in default application
  68. * @param f
  69. */
  70. public static void open(File f) {
  71. if (Desktop.isDesktopSupported()) {
  72. try {
  73. Desktop.getDesktop().open(f);
  74. } catch (IOException ex) {
  75. Log.Debug(FileActionHandler.class, "Open File Error: ");
  76. Log.Debug(FileActionHandler.class, ex);
  77. }
  78. }
  79. }
  80. }