1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GraphicsEnvironment;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.io.BufferedReader;
|
---|
9 | import java.io.File;
|
---|
10 | import java.io.IOException;
|
---|
11 | import java.io.InputStreamReader;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * see PlatformHook.java
|
---|
15 | *
|
---|
16 | * BTW: THIS IS A STUB. See comments below for details.
|
---|
17 | *
|
---|
18 | * Don't write (Main.platform instanceof PlatformHookUnixoid) because other platform
|
---|
19 | * hooks are subclasses of this class.
|
---|
20 | */
|
---|
21 | public class PlatformHookUnixoid implements PlatformHook {
|
---|
22 | @Override
|
---|
23 | public void preStartupHook(){
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public void startupHook() {
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void openUrl(String url) throws IOException {
|
---|
32 | String[] programs = {"gnome-open", "kfmclient openURL", "firefox"};
|
---|
33 | for (String program : programs) {
|
---|
34 | try {
|
---|
35 | Runtime.getRuntime().exec(program+" "+url);
|
---|
36 | return;
|
---|
37 | } catch (IOException e) {
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void initSystemShortcuts() {
|
---|
44 | // TODO: Insert system shortcuts here. See Windows and especially OSX to see how to.
|
---|
45 | for(int i = KeyEvent.VK_F1; i <= KeyEvent.VK_F12; ++i)
|
---|
46 | Shortcut.registerSystemShortcut("screen:toogle"+i, tr("reserved"), i, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK).setAutomatic();
|
---|
47 | Shortcut.registerSystemShortcut("system:reset", tr("reserved"), KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK).setAutomatic();
|
---|
48 | Shortcut.registerSystemShortcut("system:resetX", tr("reserved"), KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK).setAutomatic();
|
---|
49 | }
|
---|
50 | /**
|
---|
51 | * This should work for all platforms. Yeah, should.
|
---|
52 | * See PlatformHook.java for a list of reasons why
|
---|
53 | * this is implemented here...
|
---|
54 | */
|
---|
55 | @Override
|
---|
56 | public String makeTooltip(String name, Shortcut sc) {
|
---|
57 | String result = "";
|
---|
58 | result += "<html>";
|
---|
59 | result += name;
|
---|
60 | if (sc != null && sc.getKeyText().length() != 0) {
|
---|
61 | result += " ";
|
---|
62 | result += "<font size='-2'>";
|
---|
63 | result += "("+sc.getKeyText()+")";
|
---|
64 | result += "</font>";
|
---|
65 | }
|
---|
66 | result += " </html>";
|
---|
67 | return result;
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public String getDefaultStyle() {
|
---|
72 | return "javax.swing.plaf.metal.MetalLookAndFeel";
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public boolean canFullscreen()
|
---|
77 | {
|
---|
78 | return GraphicsEnvironment.getLocalGraphicsEnvironment()
|
---|
79 | .getDefaultScreenDevice().isFullScreenSupported();
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public boolean rename(File from, File to)
|
---|
84 | {
|
---|
85 | return from.renameTo(to);
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public String getOSDescription() {
|
---|
90 | String osName = System.getProperty("os.name");
|
---|
91 | if ("Linux".equalsIgnoreCase(osName)) {
|
---|
92 | try {
|
---|
93 | Process p = Runtime.getRuntime().exec("lsb_release -ds");
|
---|
94 | BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
---|
95 | String line = Utils.strip(input.readLine());
|
---|
96 | input.close();
|
---|
97 | if (line != null && !line.isEmpty()) {
|
---|
98 | line = line.replaceAll("\"+","");
|
---|
99 | if(!line.isEmpty())
|
---|
100 | return "Linux " + line;
|
---|
101 | }
|
---|
102 | } catch (IOException e) {
|
---|
103 | e.printStackTrace();
|
---|
104 | }
|
---|
105 | }
|
---|
106 | return osName;
|
---|
107 | }
|
---|
108 | }
|
---|