1
2
3
4 package net.sf.ovanttasks.ovnative.demos;
5
6 import javax.swing.JOptionPane;
7 import net.sf.ovanttasks.ovnative.win32.Registry;
8
9
10
11
12
13
14
15 public class ExplorerContextMenuEntry {
16
17 public static class DirectoryMenuEntry {
18
19 public static void main(String[] args) {
20 msgBox("ROXES Example Context Menu Entry\n\nSelected Directory is \"" + args[0] + "\"");
21 }
22 }
23
24 public ExplorerContextMenuEntry(String[] args) {
25 if (args.length != 1) {
26 System.out.println(getClass().getName() + "(-install|-uninstall)");
27 System.out.println("show how to add/remove an explorer context menu entry");
28 return;
29 }
30
31 if (args[0].equals("-install")) {
32 install();
33 } else if (args[0].equals("-uninstall")) {
34 uninstall();
35 } else {
36 System.out.println(getClass().getName() + "(-install|-uninstall)");
37 }
38 }
39
40 void install() {
41 Registry reg = new Registry(Registry.HKEY_LOCAL_MACHINE,
42 "SOFTWARE\\Classes\\Directory\\shell\\roxes_context_example_menu");
43
44 if (!reg.canOpenWith(Registry.KEY_READ)) {
45 reg.create();
46 }
47 reg.setValue("", "ROXES Example Context Menu Entry");
48
49 reg = new Registry(reg, "command");
50 if (!reg.canOpenWith(Registry.KEY_READ)) {
51 reg.create();
52 }
53 reg.setValue("", "javaw -cp \"" + System.getProperty("java.class.path") + "\" " + DirectoryMenuEntry.class.getName() +" \"%1\"");
54
55 }
56
57 void uninstall() {
58 Registry reg = new Registry(Registry.HKEY_LOCAL_MACHINE,
59 "SOFTWARE\\Classes\\Directory\\shell\\roxes_context_example_menu");
60
61 if (reg.canOpenWith(Registry.KEY_READ)) {
62 reg.delete();
63 msgBox("Deinstallation successful");
64 }
65 }
66
67 static void msgBox(String msg) {
68 JOptionPane.showMessageDialog(null, msg);
69 }
70
71 public static void main(String[] args) {
72 new ExplorerContextMenuEntry(new String[]{"-install"});
73 System.exit(0);
74 }
75 }