Revision 471 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/EditorHelper.java
EditorHelper.java | ||
---|---|---|
1 | 1 |
package org.gvsig.scripting.swing.impl.composer; |
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
|
4 | 5 |
import java.awt.event.ActionListener; |
5 | 6 |
import java.awt.event.KeyEvent; |
6 | 7 |
import java.awt.event.KeyListener; |
... | ... | |
13 | 14 |
import javax.swing.text.JTextComponent; |
14 | 15 |
import org.gvsig.scripting.ScriptingManager; |
15 | 16 |
import org.gvsig.scripting.ScriptingScript; |
17 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
|
16 | 18 |
import org.gvsig.scripting.swing.api.JEditor; |
17 | 19 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
18 | 20 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent; |
... | ... | |
94 | 96 |
this.editorHelper = editorHelper; |
95 | 97 |
} |
96 | 98 |
|
99 |
private Component findParentComponent(Component comp, Class[] parentClasses) { |
|
100 |
while( comp != null ) { |
|
101 |
for (Class parentClass : parentClasses) { |
|
102 |
if( parentClass.isInstance(comp) ) { |
|
103 |
return comp; |
|
104 |
} |
|
105 |
} |
|
106 |
comp = comp.getParent(); |
|
107 |
} |
|
108 |
return null; |
|
109 |
} |
|
110 |
|
|
97 | 111 |
private JEditor getJEditor(KeyEvent event) { |
98 | 112 |
JEditor editor = null; |
99 | 113 |
|
100 | 114 |
try { |
101 | 115 |
JTextArea textArea = (JTextArea) event.getSource(); |
102 |
JViewport jView = (JViewport) textArea.getParent(); |
|
103 |
JScrollPane jScroll = (JScrollPane) jView.getParent(); |
|
104 |
JPanel panel = (JPanel) jScroll.getParent(); |
|
105 |
JTabbedPane tabsCode = (JTabbedPane) panel.getParent(); |
|
106 |
|
|
107 |
if (tabsCode.getParent() instanceof DefaultJCodeEditor) { |
|
108 |
editor = (DefaultJCodeEditor) tabsCode.getParent(); |
|
109 |
} else if (tabsCode.getParent() instanceof DefaultJDialogEditor) { |
|
110 |
editor = (DefaultJDialogEditor) tabsCode.getParent(); |
|
111 |
} |
|
116 |
Component component = this.findParentComponent( |
|
117 |
textArea, |
|
118 |
new Class[] { JEditor.class } |
|
119 |
); |
|
120 |
editor = (JEditor) component; |
|
112 | 121 |
} catch (Throwable t) { |
113 |
// Do nothing
|
|
122 |
logger.debug("Can't find editor component.",t);
|
|
114 | 123 |
} |
115 | 124 |
return editor; |
116 | 125 |
} |
Also available in: Unified diff