Revision 15847
trunk/frameworks/_fwAndami/src/com/iver/andami/help/Help.java | ||
---|---|---|
6 | 6 |
import java.io.File; |
7 | 7 |
import java.net.MalformedURLException; |
8 | 8 |
import java.net.URL; |
9 |
import java.net.URLClassLoader; |
|
9 | 10 |
import java.text.MessageFormat; |
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Iterator; |
|
13 |
import java.util.Locale; |
|
10 | 14 |
|
11 | 15 |
import javax.help.HelpSet; |
12 | 16 |
import javax.swing.JComponent; |
... | ... | |
16 | 20 |
|
17 | 21 |
public class Help { |
18 | 22 |
|
19 |
private static Help help = null;
|
|
23 |
private static Help help = null;
|
|
20 | 24 |
|
21 | 25 |
private HelpSet mainHS = null; |
22 |
private String helpPath=null; |
|
26 |
private ArrayList resources = new ArrayList(); |
|
27 |
private ArrayList helps = new ArrayList(); |
|
23 | 28 |
|
24 | 29 |
private HelpPanel window=null; |
25 | 30 |
|
26 |
private static Logger log() { |
|
31 |
public static Help getHelp() { |
|
32 |
if( help == null ) { |
|
33 |
help = new Help(); |
|
34 |
} |
|
35 |
return help; |
|
36 |
} |
|
37 |
|
|
38 |
private Logger log() { |
|
27 | 39 |
return Logger.getLogger("org.gvsig"); |
28 | 40 |
} |
29 | 41 |
|
30 | 42 |
public void show() { |
43 |
log().info("show()"); |
|
31 | 44 |
show(null); |
32 | 45 |
} |
33 | 46 |
|
34 |
public static Help getHelp() { |
|
35 |
if( help == null ) { |
|
36 |
help = new Help(); |
|
37 |
} |
|
38 |
return help; |
|
39 |
} |
|
40 |
|
|
41 | 47 |
public void show(String id) { |
42 | 48 |
try { |
49 |
log().info("show(id) id="+id); |
|
43 | 50 |
initHelp(); |
44 | 51 |
try { |
45 | 52 |
window.showWindow(id); |
46 | 53 |
}catch(NullPointerException e) { |
47 |
window = new HelpPanel(mainHS, id); |
|
54 |
window = new AndamiHelpPanel(mainHS, id);
|
|
48 | 55 |
window.showWindow(); |
49 | 56 |
} |
50 | 57 |
} catch (Exception ex) { |
... | ... | |
52 | 59 |
} |
53 | 60 |
} |
54 | 61 |
|
55 |
|
|
56 |
|
|
57 | 62 |
public void enableHelp(JComponent comp, String id) |
58 | 63 |
{ |
59 | 64 |
try{ |
... | ... | |
65 | 70 |
} |
66 | 71 |
} |
67 | 72 |
|
68 |
public void setHelpPath(String path){ |
|
69 |
helpPath=path; |
|
73 |
public boolean addResource(String path) { |
|
74 |
URL url = null; |
|
75 |
try { |
|
76 |
url = (new File(path)).toURL(); |
|
77 |
} catch (MalformedURLException e) { |
|
78 |
return false; |
|
79 |
} |
|
80 |
resources.add(url); |
|
81 |
return true; |
|
70 | 82 |
} |
71 | 83 |
|
84 |
|
|
85 |
public boolean addHelp(String helpName) { |
|
86 |
helps.add(helpName); |
|
87 |
return true; |
|
88 |
} |
|
89 |
|
|
72 | 90 |
private void initHelp() |
73 | 91 |
{ |
74 | 92 |
if ( mainHS != null ) { |
75 | 93 |
return; |
76 | 94 |
} |
77 |
mainHS = createHelpSet( |
|
78 |
//FALTA LA GESTION DEL LOCALE |
|
79 |
helpPath+ File.separator + "es" + File.separator, |
|
80 |
"help.hs" |
|
81 |
); |
|
95 |
|
|
96 |
// |
|
97 |
// Obtenemos un array de URLs de array list de URLs |
|
98 |
// |
|
99 |
URL urls[] = new URL[resources.size()]; |
|
100 |
int i=0; |
|
101 |
for( Iterator it=resources.iterator(); it.hasNext() ;) { |
|
102 |
urls[i++] = (URL) it.next(); |
|
103 |
} |
|
104 |
|
|
105 |
// |
|
106 |
// Creamos la lista de helpsets que han de componer |
|
107 |
// la ayuda |
|
108 |
// |
|
109 |
ArrayList helpSets = new ArrayList(); |
|
110 |
|
|
111 |
for( Iterator it=helps.iterator(); it.hasNext() ;) { |
|
112 |
String name = (String) it.next(); |
|
113 |
String lang = Locale.getDefault().getLanguage(); |
|
114 |
HelpSet hs = createHelpSet(urls, name + "/" + lang + "/help.hs"); |
|
115 |
if( hs == null ) { |
|
116 |
lang = "en"; |
|
117 |
hs = createHelpSet(urls, name + "/" + lang + "/help.hs"); |
|
118 |
} |
|
119 |
if( hs != null ) { |
|
120 |
helpSets.add(hs); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
// |
|
125 |
// Fijamos el primer helpset de la lista como master y |
|
126 |
// le a?adimos (merge) a este los demas helpsets |
|
127 |
// |
|
128 |
Iterator it=helpSets.iterator(); |
|
129 |
if( ! it.hasNext() ) { |
|
130 |
return; |
|
131 |
} |
|
132 |
mainHS = (HelpSet) it.next(); |
|
133 |
while( it.hasNext() ) { |
|
134 |
try { |
|
135 |
mainHS.add( (HelpSet) it.next() ); |
|
136 |
} catch (Exception ex) { |
|
137 |
log().error(ex); |
|
138 |
} |
|
139 |
} |
|
82 | 140 |
} |
83 | 141 |
|
84 |
private HelpSet createHelpSet(String hspath, String hsName) { |
|
85 |
String hsPathName = "file:" + hspath +File.separator+ hsName; |
|
142 |
private HelpSet createHelpSet(URL resources[], String hsName) { |
|
86 | 143 |
HelpSet hs = null; |
87 |
URL url = null; |
|
88 |
try { |
|
89 |
url = new URL(hsPathName); |
|
90 |
} catch (MalformedURLException e) { |
|
144 |
|
|
145 |
ClassLoader loader = ClassLoader.getSystemClassLoader(); |
|
146 |
loader = new URLClassLoader(resources, loader); |
|
147 |
URL url = HelpSet.findHelpSet(loader, hsName); |
|
148 |
if (url == null) { |
|
91 | 149 |
log().error( |
92 | 150 |
MessageFormat.format( |
93 |
"La ruta ''{0}'' no es una ruta correcta.", |
|
94 |
new Object[] { hsPathName } |
|
95 |
), |
|
96 |
e |
|
97 |
); |
|
151 |
"No se ha encontrado el helpset ''{0}''.", |
|
152 |
new Object[] { hsName } |
|
153 |
) |
|
154 |
); |
|
98 | 155 |
return null; |
99 | 156 |
} |
157 |
log().info("createHelpSet: url="+url); |
|
100 | 158 |
|
101 | 159 |
try { |
102 | 160 |
hs = new HelpSet(null, url); |
... | ... | |
113 | 171 |
return hs; |
114 | 172 |
} |
115 | 173 |
|
116 |
class DisplayHelpFromFocus implements ActionListener { |
|
117 | 174 |
|
118 |
private String id = null;
|
|
175 |
public class DisplayHelpFromFocus implements ActionListener {
|
|
119 | 176 |
|
120 |
public DisplayHelpFromFocus(String id) { |
|
121 |
this.id=id; |
|
122 |
} |
|
177 |
private String id = null; |
|
123 | 178 |
|
124 |
public void actionPerformed(ActionEvent e) { |
|
125 |
Help.getHelp().show(this.id); |
|
179 |
public DisplayHelpFromFocus(String id) { |
|
180 |
log().info("DisplayHelpFromFocus(id) id="+id); |
|
181 |
this.id=id; |
|
182 |
} |
|
183 |
|
|
184 |
public void actionPerformed(ActionEvent e) { |
|
185 |
Help.getHelp().show(this.id); |
|
186 |
} |
|
126 | 187 |
} |
127 |
} |
|
128 |
|
|
129 | 188 |
} |
130 | 189 |
|
trunk/frameworks/_fwAndami/src/com/iver/andami/help/HelpPanel.java | ||
---|---|---|
1 | 1 |
package com.iver.andami.help; |
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Frame; |
|
5 |
import java.awt.event.ComponentEvent; |
|
6 |
import java.awt.event.ComponentListener; |
|
4 | 7 |
|
5 | 8 |
import javax.help.BadIDException; |
6 | 9 |
import javax.help.HelpSet; |
... | ... | |
9 | 12 |
|
10 | 13 |
import org.apache.log4j.Logger; |
11 | 14 |
|
12 |
import com.iver.andami.PluginServices; |
|
13 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
14 |
import com.iver.andami.ui.mdiManager.MDIManager; |
|
15 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
|
15 |
public class HelpPanel extends JPanel { |
|
16 | 16 |
|
17 |
public class HelpPanel extends JPanel implements IWindow { |
|
18 |
|
|
19 | 17 |
private static final long serialVersionUID = 4164482247505362337L; |
20 | 18 |
|
21 | 19 |
public static int WIDTH = 645; |
22 | 20 |
public static int HEIGHT = 495; |
23 | 21 |
private String title = null; |
24 |
private WindowInfo info = null ; |
|
25 | 22 |
private JHelp jh; |
26 | 23 |
|
27 |
private static Logger log() {
|
|
24 |
private Logger log() { |
|
28 | 25 |
return Logger.getLogger("org.gvsig"); |
29 | 26 |
} |
30 | 27 |
|
31 | 28 |
public HelpPanel(HelpSet hs){ |
32 |
System.out.println("HelpPanel(hs)");
|
|
29 |
log().info("HelpPanel(hs)");
|
|
33 | 30 |
init(hs,null); |
34 | 31 |
} |
35 | 32 |
|
36 | 33 |
public HelpPanel(HelpSet hs, String id){ |
37 |
System.out.println("HelpPanel(hs,id) id="+id);
|
|
34 |
log().info("HelpPanel(hs,id) id="+id);
|
|
38 | 35 |
init(hs,id); |
39 | 36 |
} |
40 | 37 |
|
41 | 38 |
private void init(HelpSet hs, String id){ |
42 | 39 |
jh = new JHelp(hs); |
43 |
System.out.println("Help: ID "+ id);
|
|
40 |
log().info("init() ID "+ id);
|
|
44 | 41 |
if (id != null) { |
45 | 42 |
try { |
46 |
System.out.println("Help: setCurrentID "+ id);
|
|
43 |
log().info("init() setCurrentID "+ id);
|
|
47 | 44 |
jh.setCurrentID(id); |
48 | 45 |
} catch (BadIDException ex) { |
49 | 46 |
log().error(ex); |
... | ... | |
59 | 56 |
} |
60 | 57 |
|
61 | 58 |
public void showWindow() { |
62 |
MDIManager mdim = PluginServices.getMDIManager(); |
|
63 |
mdim.addWindow((IWindow) this); |
|
59 |
|
|
60 |
log().info("showWindow()"); |
|
61 |
Frame frame = new Frame(); |
|
62 |
frame.add(this); |
|
63 |
frame.setSize(WIDTH, HEIGHT + 30); |
|
64 |
frame.setTitle(getTitle()); |
|
65 |
frame.setResizable(true); |
|
66 |
this.setVisible(true); |
|
67 |
frame.show(); |
|
64 | 68 |
} |
65 | 69 |
|
66 | 70 |
public void showWindow(String id) { |
67 | 71 |
if (id != null) { |
68 | 72 |
try { |
69 |
System.out.println("Help: setCurrentID "+ id);
|
|
73 |
log().info("showWindow(id) -> setCurrentID "+ id);
|
|
70 | 74 |
jh.setCurrentID(id); |
71 | 75 |
} catch (BadIDException ex) { |
72 | 76 |
log().error(ex); |
... | ... | |
77 | 81 |
hsTitle = "gvSIG Help"; |
78 | 82 |
} |
79 | 83 |
title = hsTitle; |
80 |
MDIManager mdim = PluginServices.getMDIManager(); |
|
81 |
mdim.addWindow((IWindow) this); |
|
84 |
showWindow(); |
|
82 | 85 |
} |
83 | 86 |
|
84 |
public WindowInfo getWindowInfo() { |
|
85 |
if( info == null ) { |
|
86 |
info = new WindowInfo( WindowInfo.RESIZABLE | |
|
87 |
WindowInfo.MAXIMIZABLE | WindowInfo.MODELESSDIALOG); |
|
88 |
info.setHeight(HEIGHT); |
|
89 |
info.setWidth(WIDTH); |
|
90 |
info.setTitle(this.title); |
|
91 |
} |
|
92 |
return info; |
|
87 |
public String getTitle() { |
|
88 |
return this.title; |
|
93 | 89 |
} |
90 |
|
|
94 | 91 |
} |
trunk/frameworks/_fwAndami/src/com/iver/andami/help/AndamiHelpPanel.java | ||
---|---|---|
1 |
package com.iver.andami.help; |
|
2 |
|
|
3 |
import javax.help.HelpSet; |
|
4 |
|
|
5 |
import com.iver.andami.PluginServices; |
|
6 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
7 |
import com.iver.andami.ui.mdiManager.MDIManager; |
|
8 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
|
9 |
|
|
10 |
|
|
11 |
public class AndamiHelpPanel extends HelpPanel implements IWindow { |
|
12 |
|
|
13 |
private static final long serialVersionUID = 2683827167020046672L; |
|
14 |
|
|
15 |
private WindowInfo info = null ; |
|
16 |
|
|
17 |
public AndamiHelpPanel(HelpSet hs){ |
|
18 |
super(hs); |
|
19 |
} |
|
20 |
|
|
21 |
public AndamiHelpPanel(HelpSet hs, String id){ |
|
22 |
super(hs,id); |
|
23 |
} |
|
24 |
|
|
25 |
public void showWindow() { |
|
26 |
MDIManager mdim = PluginServices.getMDIManager(); |
|
27 |
mdim.addWindow((IWindow) this); |
|
28 |
} |
|
29 |
|
|
30 |
public WindowInfo getWindowInfo() { |
|
31 |
if( info == null ) { |
|
32 |
info = new WindowInfo( WindowInfo.RESIZABLE | |
|
33 |
WindowInfo.MAXIMIZABLE | WindowInfo.MODELESSDIALOG); |
|
34 |
info.setHeight(HEIGHT); |
|
35 |
info.setWidth(WIDTH); |
|
36 |
info.setTitle(getTitle()); |
|
37 |
} |
|
38 |
return info; |
|
39 |
} |
|
40 |
|
|
41 |
} |
|
0 | 42 |
Also available in: Unified diff