gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / JHelpSelection.java @ 457
History | View | Annotate | Download (5.57 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.util.Iterator; |
9 |
import java.util.Map; |
10 |
|
11 |
import javax.help.HelpBroker; |
12 |
import javax.help.HelpSet; |
13 |
import javax.help.JHelp; |
14 |
import javax.swing.DefaultListModel; |
15 |
import javax.swing.JComponent; |
16 |
import javax.swing.JList; |
17 |
import javax.swing.JOptionPane; |
18 |
import javax.swing.JPanel; |
19 |
import javax.swing.JScrollPane; |
20 |
import javax.swing.JTextField; |
21 |
import javax.swing.ListSelectionModel; |
22 |
|
23 |
import org.gvsig.scripting.ScriptingHelpManager; |
24 |
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpClass; |
25 |
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpMethod; |
26 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
27 |
import org.gvsig.scripting.swing.impl.DialogPanel; |
28 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
29 |
|
30 |
public class JHelpSelection extends JPanel implements DialogPanel, |
31 |
ActionListener {
|
32 |
|
33 |
/**
|
34 |
*
|
35 |
*
|
36 |
*/
|
37 |
private static final long serialVersionUID = -4299714728279029924L; |
38 |
|
39 |
protected JList list = null; |
40 |
protected ScriptingUIManager uimanager;
|
41 |
protected ScriptingHelpManager helpmanager;
|
42 |
protected ActionListener defaultActionlistener = null; |
43 |
protected boolean isAcceptActive = true; |
44 |
protected Component parent; |
45 |
|
46 |
public JHelpSelection(final ScriptingUIManager uimanager, |
47 |
final String text, Component parent) { |
48 |
this.uimanager = uimanager;
|
49 |
this.parent = parent;
|
50 |
this.helpmanager = uimanager.getManager().getHelpManager();
|
51 |
|
52 |
Map<String, ScriptingHelpMethod> methods = uimanager.getManager() |
53 |
.getHelpManager().findMethods(text); |
54 |
// final HashMap<String, String> helpReferences = new HashMap<String,
|
55 |
// String>();
|
56 |
|
57 |
// ListSelectionListener menuListener = new ListSelectionListener() {
|
58 |
// public void valueChanged(ListSelectionEvent arg0) {
|
59 |
// if (arg0.getValueIsAdjusting()) {
|
60 |
// String[] s = ((JList) arg0.getSource()).getSelectedValue()
|
61 |
// .toString().split(" - ");
|
62 |
// String selection = "";
|
63 |
// if (s.length == 1) {
|
64 |
// selection = s[0];
|
65 |
// } else {
|
66 |
// for (int i = 0; i < s.length - 1; i++) {
|
67 |
// selection = selection + s[i];
|
68 |
// }
|
69 |
// }
|
70 |
// launchException(this, 1, helpReferences.get(selection));
|
71 |
// }
|
72 |
// }
|
73 |
//
|
74 |
// };
|
75 |
|
76 |
DefaultListModel listModel = new DefaultListModel(); |
77 |
|
78 |
Iterator<ScriptingHelpMethod> itMethods = methods.values().iterator();
|
79 |
while (itMethods.hasNext()) {
|
80 |
ScriptingHelpMethod helpMethod = itMethods.next(); |
81 |
Iterator<ScriptingHelpClass> itClasses = helpMethod.iterator();
|
82 |
while (itClasses.hasNext()) {
|
83 |
ScriptingHelpClass helpClass = itClasses.next(); |
84 |
listModel.addElement(helpClass); |
85 |
} |
86 |
} |
87 |
|
88 |
//
|
89 |
//
|
90 |
// for (int x = 0; x < methods.size(); x++) {
|
91 |
// Set<String> keys = methods.keySet();
|
92 |
// Object[] l = keys.toArray();
|
93 |
//
|
94 |
// ScriptingHelpMethod helpMethod = methods.get(l[x]);
|
95 |
// Iterator<ScriptingHelpClass> it = helpMethod.iterator();
|
96 |
// while (it.hasNext()) {
|
97 |
// ScriptingHelpClass cn = it.next();
|
98 |
// if (!(helpReferences.containsKey(helpMethod.getName()) &&
|
99 |
// helpReferences
|
100 |
// .containsValue(cn.getName()))) {
|
101 |
// helpReferences.put(cn.getName(), cn.getUrl());
|
102 |
// }
|
103 |
// }
|
104 |
// }
|
105 |
|
106 |
//
|
107 |
// for (int x = 0; x < helpReferences.size(); x++) {
|
108 |
// Set<String> keys = helpReferences.keySet();
|
109 |
// Object[] l = keys.toArray();
|
110 |
//
|
111 |
// listModel.addElement(l[x].toString());
|
112 |
// }
|
113 |
|
114 |
setLayout(new BorderLayout()); |
115 |
|
116 |
if (listModel.getSize() != 0) { |
117 |
list = new JList(listModel); |
118 |
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
119 |
list.setLayoutOrientation(JList.VERTICAL);
|
120 |
list.setVisibleRowCount(0);
|
121 |
// list.addListSelectionListener(menuListener);
|
122 |
JScrollPane scroll = new JScrollPane(list); |
123 |
|
124 |
add(scroll, BorderLayout.CENTER);
|
125 |
setPreferredSize(new Dimension(300, 150)); |
126 |
} else {
|
127 |
JTextField textfield = new JTextField( |
128 |
this.uimanager.getTranslation("help_key")+" '" + text + "'."); |
129 |
textfield.setEditable(false);
|
130 |
add(textfield, BorderLayout.CENTER);
|
131 |
setPreferredSize(new Dimension(300, 50)); |
132 |
this.isAcceptActive = false; |
133 |
} |
134 |
|
135 |
} |
136 |
|
137 |
@Override
|
138 |
public void actionAccept() { |
139 |
ScriptingHelpClass helpClass = (ScriptingHelpClass) list.getSelectedValue(); |
140 |
if ( helpClass == null ) { |
141 |
JOptionPane.showMessageDialog(null, this.uimanager.getTranslation("Error_help"), |
142 |
this.uimanager.getTranslation("Error"), JOptionPane.ERROR_MESSAGE); |
143 |
return;
|
144 |
} |
145 |
setVisible(false);
|
146 |
|
147 |
// HelpBroker hb;
|
148 |
HelpSet hs = uimanager.getManager().getHelpManager().getHelpSet(); |
149 |
|
150 |
JHelp help = new JHelp(hs);
|
151 |
help.setCurrentID(helpClass.getUrl()); |
152 |
|
153 |
JPanel panel = new JPanel(); |
154 |
panel.setLayout(new BorderLayout()); |
155 |
panel.add(help,BorderLayout.CENTER);
|
156 |
panel.setPreferredSize(new Dimension(800,600)); |
157 |
uimanager.showWindow(panel, "JavaDoc");
|
158 |
|
159 |
// hb = hs.createHelpBroker();
|
160 |
// hb.enableHelpOnButton(parent, helpClass.getUrl(), hs);
|
161 |
|
162 |
|
163 |
} |
164 |
|
165 |
@Override
|
166 |
public void actionApply() { |
167 |
} |
168 |
|
169 |
@Override
|
170 |
public void actionCancel() { |
171 |
setVisible(false);
|
172 |
} |
173 |
|
174 |
@Override
|
175 |
public boolean isVisibleAccept() { |
176 |
return this.isAcceptActive; |
177 |
} |
178 |
|
179 |
@Override
|
180 |
public boolean isVisibleApply() { |
181 |
return false; |
182 |
} |
183 |
|
184 |
@Override
|
185 |
public boolean isVisibleCancel() { |
186 |
return true; |
187 |
} |
188 |
|
189 |
// private void launchException(Object source, int id, String action) {
|
190 |
// this.defaultActionlistener.actionPerformed(new ActionEvent(source, id,
|
191 |
// action));
|
192 |
// }
|
193 |
|
194 |
public void actionPerformed(ActionEvent arg0) { |
195 |
|
196 |
} |
197 |
|
198 |
public void addDefaultActionListener(ActionListener actionlistener) { |
199 |
this.defaultActionlistener = actionlistener;
|
200 |
} |
201 |
|
202 |
public JComponent getJComponent() { |
203 |
return this; |
204 |
} |
205 |
} |