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 @ 185
History | View | Annotate | Download (4.22 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.util.HashMap; |
8 |
import java.util.Iterator; |
9 |
import java.util.Set; |
10 |
|
11 |
import javax.swing.DefaultListModel; |
12 |
import javax.swing.JList; |
13 |
import javax.swing.JOptionPane; |
14 |
import javax.swing.JScrollPane; |
15 |
import javax.swing.JTextField; |
16 |
import javax.swing.ListSelectionModel; |
17 |
import javax.swing.event.ListSelectionEvent; |
18 |
import javax.swing.event.ListSelectionListener; |
19 |
|
20 |
import org.gvsig.scripting.ScriptingHelpManager; |
21 |
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpClass; |
22 |
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpMethod; |
23 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
24 |
import org.gvsig.scripting.swing.impl.AbstractJDialogPanel; |
25 |
|
26 |
|
27 |
public class JHelpSelection extends AbstractJDialogPanel implements ActionListener{ |
28 |
|
29 |
/**
|
30 |
*
|
31 |
*
|
32 |
*/
|
33 |
private static final long serialVersionUID = -4299714728279029924L; |
34 |
|
35 |
protected JList list = null; |
36 |
protected ScriptingUIManager uimanager;
|
37 |
protected ScriptingHelpManager helpmanager;
|
38 |
protected ActionListener defaultActionlistener = null; |
39 |
protected boolean isAcceptActive = true; |
40 |
|
41 |
|
42 |
public JHelpSelection(final ScriptingUIManager uimanager,final String text){ |
43 |
this.uimanager= uimanager;
|
44 |
this.helpmanager = uimanager.getManager().getHelpManager();
|
45 |
|
46 |
HashMap methods = (HashMap) uimanager.getManager().getHelpManager().findMethods(text); |
47 |
final HashMap<String, String> helpReferences = new HashMap<String, String>(); |
48 |
|
49 |
ListSelectionListener menuListener = new ListSelectionListener() { |
50 |
public void valueChanged(ListSelectionEvent arg0) { |
51 |
if(arg0.getValueIsAdjusting()){
|
52 |
String[] s = ((JList)arg0.getSource()).getSelectedValue().toString().split(" - "); |
53 |
String selection = ""; |
54 |
if(s.length==1){ |
55 |
selection = s[0];
|
56 |
}else{
|
57 |
for(int i=0;i<s.length-1;i++){ |
58 |
selection=selection+s[i]; |
59 |
} |
60 |
} |
61 |
launchException(this, 1, (String) helpReferences.get(selection)); |
62 |
} |
63 |
} |
64 |
|
65 |
}; |
66 |
DefaultListModel listModel = new DefaultListModel(); |
67 |
|
68 |
for(int x=0;x<methods.size();x++){ |
69 |
Set keys = methods.keySet();
|
70 |
Object[] l = keys.toArray(); |
71 |
|
72 |
ScriptingHelpMethod helpMethod = (ScriptingHelpMethod) methods.get(l[x]); |
73 |
Iterator it = helpMethod.iterator();
|
74 |
while(it.hasNext()){
|
75 |
ScriptingHelpClass cn = (ScriptingHelpClass)it.next(); |
76 |
if(!(helpReferences.containsKey(helpMethod.getName()) && helpReferences.containsValue(cn.getName()))){
|
77 |
helpReferences.put(cn.getName(),cn.getUrl()); |
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
setLayout(new BorderLayout()); |
83 |
|
84 |
|
85 |
for(int x=0;x<helpReferences.size();x++){ |
86 |
Set keys = helpReferences.keySet();
|
87 |
Object[] l = keys.toArray(); |
88 |
|
89 |
listModel.addElement(l[x].toString()); |
90 |
} |
91 |
if(listModel.getSize()!=0){ |
92 |
list = new JList(listModel); |
93 |
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
94 |
list.setLayoutOrientation(JList.VERTICAL);
|
95 |
list.setVisibleRowCount(0);
|
96 |
list.addListSelectionListener(menuListener); |
97 |
JScrollPane scroll = new JScrollPane(list); |
98 |
|
99 |
add(scroll,BorderLayout.CENTER);
|
100 |
setPreferredSize(new Dimension(300,150)); |
101 |
}else{
|
102 |
JTextField textfield = new JTextField("There isn't any help to the text '"+text+"'."); |
103 |
textfield.setEditable(false);
|
104 |
add(textfield,BorderLayout.CENTER);
|
105 |
setPreferredSize(new Dimension(300,50)); |
106 |
this.isAcceptActive=false; |
107 |
} |
108 |
|
109 |
} |
110 |
|
111 |
public void actionAccept() { |
112 |
int selected = list.getSelectedIndex();
|
113 |
if(selected==-1){ |
114 |
JOptionPane.showMessageDialog(null, "Please, select any help", "Error", JOptionPane.ERROR_MESSAGE); |
115 |
}else{
|
116 |
setVisible(false);
|
117 |
} |
118 |
} |
119 |
|
120 |
public void actionApply() { |
121 |
} |
122 |
|
123 |
public void actionCancel() { |
124 |
setVisible(false);
|
125 |
} |
126 |
|
127 |
public boolean isVisibleAccept() { |
128 |
return this.isAcceptActive; |
129 |
} |
130 |
|
131 |
public boolean isVisibleApply() { |
132 |
return false; |
133 |
} |
134 |
|
135 |
public boolean isVisibleCancel() { |
136 |
return true; |
137 |
} |
138 |
|
139 |
private void launchException(Object source, int id, String action){ |
140 |
this.defaultActionlistener.actionPerformed(
|
141 |
new ActionEvent(source,id,action) |
142 |
); |
143 |
} |
144 |
|
145 |
public void actionPerformed(ActionEvent arg0) { |
146 |
|
147 |
} |
148 |
|
149 |
public void addDefaultActionListener(ActionListener actionlistener) { |
150 |
this.defaultActionlistener = actionlistener;
|
151 |
} |
152 |
|
153 |
} |