| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 38 |
public class Platform extends processing.app.Platform { |
| 39 |
|
| 40 |
@Override |
| 41 |
public void setLookAndFeel() throws Exception { |
| 42 |
|
| 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 |
|
| 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 |
|
| 82 |
try { |
| 83 |
Process p = Runtime.getRuntime().exec(new String[] { "gnome-open" }); |
| 84 |
p.waitFor(); |
| 85 |
|
| 86 |
PreferencesData.set("launcher", "gnome-open"); |
| 87 |
return true; |
| 88 |
} catch (Exception e) { } |
| 89 |
|
| 90 |
|
| 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 |
|
| 109 |
Runtime.getRuntime().exec(params); |
| 110 |
|
| 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 |
|
| 133 |
|
| 134 |
|
| 135 |
Font menuFont = UIManager.getFont("Menu.font"); |
| 136 |
detectedDpi = menuFont.getSize() * 96 / 12; |
| 137 |
return detectedDpi; |
| 138 |
} |
| 139 |
} |