blob: b9070e0c16bb06e53cbb444e9bfa2f4368ccaed5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package at.hannibal2.skyhanni.tweaker;
import javax.swing.JButton;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.Method;
import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class TweakerUtils {
public static boolean isOnWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}
public static void openUrl(String url) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (Exception e) {
e.printStackTrace();
}
}
// Taken from Skytils
public static void exit() {
try {
Class<?> clazz = Class.forName("java.lang.Shutdown");
Method method = clazz.getDeclaredMethod("exit", int.class);
method.setAccessible(true);
method.invoke(null, 0);
} catch (Exception e) {
e.printStackTrace();
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
Runtime.getRuntime().exit(1);
return null;
});
}
}
public static JButton createButton(String text, Runnable action) {
JButton button = new JButton(text);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
action.run();
}
});
return button;
}
}
|