Debian Codegraph @

arduino-core/src/processing/app/linux/Platform.java

raw symbols SCIP
1 /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3 /*
4 Part of the Processing project - http://processing.org
5
6 Copyright (c) 2008 Ben Fry and Casey Reas
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 package processing.app.linux;
24
25 import processing.app.PreferencesData;
26 import processing.app.legacy.PConstants;
27
28 import java.awt.Font;
29 import java.io.File;
30
31 import javax.swing.UIManager;
32
33
34 /**
35 * Used by Base for platform-specific tweaking, for instance finding the
36 * sketchbook location using the Windows registry, or OS X event handling.
37 */
38 public class Platform extends processing.app.Platform {
39
40 @Override
41 public void setLookAndFeel() throws Exception {
42 // Override desktop check
43 System.setProperty("sun.desktop", "gnome");
44 super.setLookAndFeel();
45 GTKLookAndFeelFixer.installGtkPopupBugWorkaround();
46 }
47
48
49 @Override
50 public File getDefaultSketchbookFolder() throws Exception {
51 File home = new File(System.getProperty("user.home"));
52 return new File(home, "Arduino");
53 }
54
55
56 @Override
57 public void openURL(String url) throws Exception {
58 if (openFolderAvailable()) {
59 String launcher = PreferencesData.get("launcher");
60 if (launcher != null) {
61 Runtime.getRuntime().exec(new String[] { launcher, url });
62 }
63 }
64 }
65
66
67 @Override
68 public boolean openFolderAvailable() {
69 if (PreferencesData.get("launcher") != null) {
70 return true;
71 }
72
73 // Attempt to use xdg-open
74 try {
75 Process p = Runtime.getRuntime().exec(new String[] { "xdg-open" });
76 p.waitFor();
77 PreferencesData.set("launcher", "xdg-open");
78 return true;
79 } catch (Exception e) { }
80
81 // Attempt to use gnome-open
82 try {
83 Process p = Runtime.getRuntime().exec(new String[] { "gnome-open" });
84 p.waitFor();
85 // Not installed will throw an IOException (JDK 1.4.2, Ubuntu 7.04)
86 PreferencesData.set("launcher", "gnome-open");
87 return true;
88 } catch (Exception e) { }
89
90 // Attempt with kde-open
91 try {
92 Process p = Runtime.getRuntime().exec(new String[] { "kde-open" });
93 p.waitFor();
94 PreferencesData.set("launcher", "kde-open");
95 return true;
96 } catch (Exception e) { }
97
98 return false;
99 }
100
101
102 @Override
103 public void openFolder(File file) throws Exception {
104 if (openFolderAvailable()) {
105 String launcher = PreferencesData.get("launcher");
106 try {
107 String[] params = new String[] { launcher, file.getAbsolutePath() };
108 //processing.core.PApplet.println(params);
109 /*Process p =*/ Runtime.getRuntime().exec(params);
110 /*int result =*/ //p.waitFor();
111 } catch (Exception e) {
112 e.printStackTrace();
113 }
114 } else {
115 System.out.println("No launcher set, cannot open " +
116 file.getAbsolutePath());
117 }
118 }
119
120 @Override
121 public String getName() {
122 return PConstants.platformNames[PConstants.LINUX];
123 }
124
125 private int detectedDpi = -1;
126
127 @Override
128 public int getSystemDPI() {
129 if (detectedDpi != -1)
130 return detectedDpi;
131
132 // we observed that JMenu fonts in java follows the
133 // System DPI settings, so we compare it to the standard
134 // font size (12) to obtain a rough estimate of DPI.
135 Font menuFont = UIManager.getFont("Menu.font");
136 detectedDpi = menuFont.getSize() * 96 / 12;
137 return detectedDpi;
138 }
139 }