root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / develtools / MenusDevelTool.java @ 38608
History | View | Annotate | Download (3.6 KB)
1 | 38564 | jjdelcerro | package org.gvsig.app.extension.develtools; |
---|---|---|---|
2 | |||
3 | import java.util.Collections; |
||
4 | import java.util.Comparator; |
||
5 | import java.util.List; |
||
6 | |||
7 | import org.gvsig.andami.Launcher; |
||
8 | import org.gvsig.andami.Launcher.PluginMenuItem; |
||
9 | import org.gvsig.andami.actioninfo.ActionInfo; |
||
10 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
11 | |||
12 | public class MenusDevelTool { |
||
13 | public void showAllMenus() { |
||
14 | String html = this.getAllMenus(); |
||
15 | InfoPanel.save2file("menusinfo", html);
|
||
16 | InfoPanel.showPanel("Menu information", WindowManager.MODE.WINDOW, html);
|
||
17 | } |
||
18 | public void showAllMenusByPlugin() { |
||
19 | String html = this.getAllMenusByPlugin(); |
||
20 | InfoPanel.save2file("menusbyplugininfo", html);
|
||
21 | InfoPanel.showPanel("Menu by plugin information", WindowManager.MODE.WINDOW, html);
|
||
22 | } |
||
23 | |||
24 | public String getAllMenus() { |
||
25 | Launcher launcher = Launcher.getInstance(); |
||
26 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
27 | |||
28 | return this.getAllMenus(menuItems); |
||
29 | } |
||
30 | |||
31 | public String getAllMenusByPlugin() { |
||
32 | Launcher launcher = Launcher.getInstance(); |
||
33 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
34 | |||
35 | Collections.sort(menuItems, new Comparator<PluginMenuItem>() { |
||
36 | public int compare(PluginMenuItem o1, PluginMenuItem o2) { |
||
37 | String s1 = String.format("%s:%012d:%s", o1.getPluginName(), o1.getPosition(), o1.getText()); |
||
38 | String s2 = String.format("%s:%012d:%s", o2.getPluginName(), o2.getPosition(), o2.getText()); |
||
39 | return s1.compareTo(s2);
|
||
40 | } |
||
41 | }); |
||
42 | return this.getAllMenus(menuItems); |
||
43 | } |
||
44 | |||
45 | private String getAllMenus(List<PluginMenuItem> menuItems) { |
||
46 | StringBuffer buffer = new StringBuffer(); |
||
47 | |||
48 | // String warning_open = "<b>";
|
||
49 | // String warning_close = "</b>";
|
||
50 | |||
51 | String error_open = "<b><font color=\"red\">"; |
||
52 | String error_close = "</font></b>"; |
||
53 | |||
54 | buffer.append("<html>\n");
|
||
55 | buffer.append("<body>\n");
|
||
56 | buffer.append("<h2>Menu information </h2>\n");
|
||
57 | buffer.append("<br>\n");
|
||
58 | |||
59 | buffer.append("<table border=\"0\">\n");
|
||
60 | buffer.append(" <tr>\n");
|
||
61 | buffer.append(" <td>Position</td>\n");
|
||
62 | buffer.append(" <td>Text</td>\n");
|
||
63 | buffer.append(" <td>Action</td>\n");
|
||
64 | buffer.append(" <td>Plugin</td>\n");
|
||
65 | buffer.append(" </tr>\n");
|
||
66 | |||
67 | |||
68 | for (PluginMenuItem menu : menuItems) {
|
||
69 | buffer.append(" <tr valign=\"top\">\n");
|
||
70 | buffer |
||
71 | .append(" <td>")
|
||
72 | 38608 | jjdelcerro | .append(formatPosition( menu.getPosition())) |
73 | 38564 | jjdelcerro | .append("</td>\n");
|
74 | buffer |
||
75 | .append(" <td>")
|
||
76 | .append(menu.getText()) |
||
77 | .append("</td>\n");
|
||
78 | if( menu.isParent() ) {
|
||
79 | buffer |
||
80 | .append(" <td>")
|
||
81 | .append("----")
|
||
82 | .append("</td>\n");
|
||
83 | buffer |
||
84 | .append(" <td>")
|
||
85 | .append(menu.getPluginName()) |
||
86 | .append("</td>\n");
|
||
87 | } else {
|
||
88 | ActionInfo action = menu.getAction(); |
||
89 | if( action == null ) { |
||
90 | buffer |
||
91 | .append(" <td>")
|
||
92 | .append(error_open) |
||
93 | .append(menu.getName()) |
||
94 | .append(error_close) |
||
95 | .append("</td>\n");
|
||
96 | buffer |
||
97 | .append(" <td>")
|
||
98 | .append(menu.getPluginName()) |
||
99 | .append("</td>\n");
|
||
100 | } else {
|
||
101 | buffer |
||
102 | .append(" <td>")
|
||
103 | .append(action.getName()) |
||
104 | .append("</td>\n");
|
||
105 | buffer |
||
106 | .append(" <td>")
|
||
107 | .append(action.getPluginName()) |
||
108 | .append("</td>\n");
|
||
109 | } |
||
110 | } |
||
111 | buffer.append(" </tr>\n");
|
||
112 | } |
||
113 | buffer.append("</table>\n");
|
||
114 | buffer.append("</body>\n");
|
||
115 | buffer.append("</html>\n");
|
||
116 | |||
117 | return buffer.toString();
|
||
118 | } |
||
119 | 38608 | jjdelcerro | |
120 | static String formatPosition(long position) { |
||
121 | String pos = String.format("%012d",position); |
||
122 | if( pos.length() != 12) { |
||
123 | return pos;
|
||
124 | } |
||
125 | String posf = pos.substring(0, 5) + "-" + |
||
126 | pos.substring(5,8) + "-" + |
||
127 | pos.substring(8,11) + "-" + |
||
128 | pos.substring(11);
|
||
129 | return posf;
|
||
130 | } |
||
131 | 38564 | jjdelcerro | } |