svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / develtools / MenusDevelTool.java @ 40558
History | View | Annotate | Download (5.1 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.app.extension.develtools; |
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.Collections; |
||
28 | import java.util.Comparator; |
||
29 | import java.util.List; |
||
30 | |||
31 | import org.gvsig.andami.Launcher; |
||
32 | import org.gvsig.andami.Launcher.PluginMenuItem; |
||
33 | import org.gvsig.andami.actioninfo.ActionInfo; |
||
34 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
35 | |||
36 | public class MenusDevelTool { |
||
37 | public void showAllMenus() { |
||
38 | String html = "<html>\n<body>\n"+ this.getAllMenus()+"</body>\n</html>\n"; |
||
39 | InfoPanel.save2file("menus-report", html);
|
||
40 | InfoPanel.showPanel("Menu information", WindowManager.MODE.WINDOW, html);
|
||
41 | } |
||
42 | public void showAllMenusByPlugin() { |
||
43 | String html = "<html>\n<body>\n"+ this.getAllMenusByPlugin()+"</body>\n</html>\n"; |
||
44 | InfoPanel.save2file("menus-report-sorted-by-plugin", html);
|
||
45 | InfoPanel.showPanel("Menu by plugin information", WindowManager.MODE.WINDOW, html);
|
||
46 | } |
||
47 | |||
48 | public String getAllMenus() { |
||
49 | Launcher launcher = Launcher.getInstance(); |
||
50 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
51 | |||
52 | return this.getAllMenus(menuItems); |
||
53 | } |
||
54 | |||
55 | public String getMenusOfPlugin(String pluginName) { |
||
56 | Launcher launcher = Launcher.getInstance(); |
||
57 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
58 | List<PluginMenuItem> pluginMenus = new ArrayList<Launcher.PluginMenuItem>(); |
||
59 | |||
60 | for (PluginMenuItem pluginMenuItem : menuItems) {
|
||
61 | if( pluginName.equalsIgnoreCase(pluginMenuItem.getPluginName())) {
|
||
62 | pluginMenus.add(pluginMenuItem); |
||
63 | } |
||
64 | } |
||
65 | if( pluginMenus.isEmpty() ) {
|
||
66 | return ""; |
||
67 | } |
||
68 | return this.getAllMenus(pluginMenus); |
||
69 | } |
||
70 | |||
71 | |||
72 | public String getAllMenusByPlugin() { |
||
73 | Launcher launcher = Launcher.getInstance(); |
||
74 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
75 | |||
76 | Collections.sort(menuItems, new Comparator<PluginMenuItem>() { |
||
77 | public int compare(PluginMenuItem o1, PluginMenuItem o2) { |
||
78 | String s1 = String.format("%s:%012d:%s", o1.getPluginName(), o1.getPosition(), o1.getText()); |
||
79 | String s2 = String.format("%s:%012d:%s", o2.getPluginName(), o2.getPosition(), o2.getText()); |
||
80 | return s1.compareTo(s2);
|
||
81 | } |
||
82 | }); |
||
83 | return this.getAllMenus(menuItems); |
||
84 | } |
||
85 | |||
86 | private String getAllMenus(List<PluginMenuItem> menuItems) { |
||
87 | StringBuffer buffer = new StringBuffer(); |
||
88 | |||
89 | // String warning_open = "<b>";
|
||
90 | // String warning_close = "</b>";
|
||
91 | |||
92 | String error_open = "<b><font color=\"red\">"; |
||
93 | String error_close = "</font></b>"; |
||
94 | |||
95 | buffer.append("<div>\n");
|
||
96 | buffer.append("<h2>Menu information </h2>\n");
|
||
97 | buffer.append("<br>\n");
|
||
98 | |||
99 | buffer.append("<table border=\"0\">\n");
|
||
100 | buffer.append(" <tr>\n");
|
||
101 | buffer.append(" <td>Position</td>\n");
|
||
102 | buffer.append(" <td>Text</td>\n");
|
||
103 | buffer.append(" <td>Action</td>\n");
|
||
104 | buffer.append(" <td>Plugin</td>\n");
|
||
105 | buffer.append(" </tr>\n");
|
||
106 | |||
107 | |||
108 | for (PluginMenuItem menu : menuItems) {
|
||
109 | buffer.append(" <tr valign=\"top\">\n");
|
||
110 | buffer |
||
111 | .append(" <td>")
|
||
112 | .append(formatPosition( menu.getPosition())) |
||
113 | .append("</td>\n");
|
||
114 | buffer |
||
115 | .append(" <td>")
|
||
116 | .append(menu.getText()) |
||
117 | .append("</td>\n");
|
||
118 | if( menu.isParent() ) {
|
||
119 | buffer |
||
120 | .append(" <td>")
|
||
121 | .append("----")
|
||
122 | .append("</td>\n");
|
||
123 | buffer |
||
124 | .append(" <td>")
|
||
125 | .append(menu.getPluginName()) |
||
126 | .append("</td>\n");
|
||
127 | } else {
|
||
128 | ActionInfo action = menu.getAction(); |
||
129 | if( action == null ) { |
||
130 | buffer |
||
131 | .append(" <td>")
|
||
132 | .append(error_open) |
||
133 | .append(menu.getName()) |
||
134 | .append(error_close) |
||
135 | .append("</td>\n");
|
||
136 | buffer |
||
137 | .append(" <td>")
|
||
138 | .append(menu.getPluginName()) |
||
139 | .append("</td>\n");
|
||
140 | } else {
|
||
141 | buffer |
||
142 | .append(" <td>")
|
||
143 | .append(action.getName()) |
||
144 | .append("</td>\n");
|
||
145 | buffer |
||
146 | .append(" <td>")
|
||
147 | .append(action.getPluginName()) |
||
148 | .append("</td>\n");
|
||
149 | } |
||
150 | } |
||
151 | buffer.append(" </tr>\n");
|
||
152 | } |
||
153 | buffer.append("</table>\n");
|
||
154 | buffer.append("</div>\n");
|
||
155 | |||
156 | return buffer.toString();
|
||
157 | } |
||
158 | |||
159 | static String formatPosition(long position) { |
||
160 | String pos = String.format("%012d",position); |
||
161 | if( pos.length() != 12) { |
||
162 | return pos;
|
||
163 | } |
||
164 | String posf = pos.substring(0, 5) + "-" + |
||
165 | pos.substring(5,8) + "-" + |
||
166 | pos.substring(8,11) + "-" + |
||
167 | pos.substring(11);
|
||
168 | return posf;
|
||
169 | } |
||
170 | } |