Revision 368
org.gvsig.scripting.app/trunk/org.gvsig.scripting.app/org.gvsig.scripting.app.extension/distribution/distribution.xml | ||
---|---|---|
24 | 24 |
</outputDirectory> |
25 | 25 |
<includes> |
26 | 26 |
<include>org.gvsig:org.gvsig.scripting.app.extension</include> |
27 |
<include>com.fifesoft:rsyntaxtextarea</include> |
|
27 | 28 |
<!-- Only needed if we want to support Java 1.5 |
28 | 29 |
<include>org.apache.bsf:bsf-api</include> |
29 | 30 |
--> |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.api/src/main/java/org/gvsig/scripting/swing/api/JEditor.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import javax.swing.JEditorPane; |
6 | 6 |
import javax.swing.JPanel; |
7 |
import javax.swing.text.JTextComponent; |
|
7 | 8 |
|
8 | 9 |
import org.gvsig.scripting.ScriptingScript; |
9 | 10 |
|
... | ... | |
43 | 44 |
* |
44 | 45 |
* @return JEditorPane |
45 | 46 |
*/ |
46 |
public abstract JEditorPane getJEditorPanel();
|
|
47 |
public abstract JTextComponent getJTextComponent();
|
|
47 | 48 |
} |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.api/src/main/java/org/gvsig/scripting/swing/api/SyntaxtHighlightTextComponent.java | ||
---|---|---|
1 |
package org.gvsig.scripting.swing.api; |
|
2 |
|
|
3 |
import java.awt.event.ActionListener; |
|
4 |
|
|
5 |
import javax.swing.JScrollPane; |
|
6 |
import javax.swing.text.JTextComponent; |
|
7 |
|
|
8 |
public interface SyntaxtHighlightTextComponent { |
|
9 |
|
|
10 |
public interface UpdateCaretPositionActionEvent { |
|
11 |
public int getLine(); |
|
12 |
public int getColumn(); |
|
13 |
public boolean hasLineAndColumn(); |
|
14 |
} |
|
15 |
|
|
16 |
public JTextComponent getJTextComponent(); |
|
17 |
|
|
18 |
public JScrollPane getJScrollPane(); |
|
19 |
|
|
20 |
public void setText(String text); |
|
21 |
|
|
22 |
public String getText(); |
|
23 |
|
|
24 |
public void setContentType(String contentType); |
|
25 |
|
|
26 |
public String getContentType(); |
|
27 |
|
|
28 |
public void addUpdateCaretPositionActionListener(ActionListener updateCaretPosition); |
|
29 |
|
|
30 |
} |
|
0 | 31 |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.api/src/main/java/org/gvsig/scripting/swing/api/ScriptingUIManager.java | ||
---|---|---|
3 | 3 |
import java.net.URL; |
4 | 4 |
|
5 | 5 |
import javax.swing.ImageIcon; |
6 |
import javax.swing.JEditorPane; |
|
7 | 6 |
import javax.swing.JPanel; |
7 |
import javax.swing.text.JTextComponent; |
|
8 | 8 |
|
9 | 9 |
import org.gvsig.about.AboutManager; |
10 | 10 |
import org.gvsig.scripting.ScriptingDialog; |
... | ... | |
82 | 82 |
* |
83 | 83 |
* @see JEditorPaneSyntaxHighlighting |
84 | 84 |
*/ |
85 |
public JEditorPane createSyntaxHighlightingPanel();
|
|
85 |
public SyntaxtHighlightTextComponent createSyntaxHighlightingPanel();
|
|
86 | 86 |
|
87 | 87 |
/** |
88 | 88 |
* Creates a new {@link JCodeEditor} component. |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/DefaultScriptingUIManager.java | ||
---|---|---|
12 | 12 |
import javax.help.HelpSetException; |
13 | 13 |
import javax.help.JHelp; |
14 | 14 |
import javax.swing.ImageIcon; |
15 |
import javax.swing.JEditorPane; |
|
16 | 15 |
import javax.swing.JPanel; |
17 | 16 |
|
18 |
import org.slf4j.Logger; |
|
19 |
import org.slf4j.LoggerFactory; |
|
20 |
|
|
21 | 17 |
import org.gvsig.about.AboutLocator; |
22 | 18 |
import org.gvsig.about.AboutManager; |
23 | 19 |
import org.gvsig.scripting.ScriptingDialog; |
... | ... | |
33 | 29 |
import org.gvsig.scripting.swing.api.JThinG; |
34 | 30 |
import org.gvsig.scripting.swing.api.JThinlet; |
35 | 31 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
32 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent; |
|
36 | 33 |
import org.gvsig.scripting.swing.impl.composer.DefaultJCodeEditor; |
37 | 34 |
import org.gvsig.scripting.swing.impl.composer.DefaultJDialogEditor; |
38 | 35 |
import org.gvsig.scripting.swing.impl.composer.DefaultJScriptingComposer; |
39 | 36 |
import org.gvsig.scripting.swing.impl.syntaxhighlight.JEditorPaneSyntaxHighlighting; |
37 |
import org.gvsig.scripting.swing.impl.syntaxhighlight.JRSyntaxTextArea; |
|
40 | 38 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
41 | 39 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
40 |
import org.slf4j.Logger; |
|
41 |
import org.slf4j.LoggerFactory; |
|
42 | 42 |
|
43 | 43 |
|
44 | 44 |
public class DefaultScriptingUIManager implements ScriptingUIManager{ |
... | ... | |
46 | 46 |
private final static Logger logger= LoggerFactory.getLogger(DefaultScriptingUIManager.class); |
47 | 47 |
; |
48 | 48 |
private ScriptingManager manager; |
49 |
// private WindowManager windowManager; |
|
50 | 49 |
private Map<String,URL> userHelps= new HashMap<String, URL>(); |
51 |
// private JFrame mainFrame = null; |
|
52 | 50 |
|
53 | 51 |
|
54 |
// private class MyWindowManager implements WindowManager, ComponentListener{ |
|
55 |
// JDialog frame; |
|
56 |
// public void showWindow(JPanel panel, String title, int mode) { |
|
57 |
// frame = new JDialog(mainFrame,true); |
|
58 |
// frame.setAlwaysOnTop(true); |
|
59 |
// |
|
60 |
// final Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); |
|
61 |
// frame.setLocation(s.width / 4, s.height / 4); |
|
62 |
// |
|
63 |
// frame.setLayout(new BorderLayout()); |
|
64 |
// frame.setTitle(title); |
|
65 |
// frame.add(panel, BorderLayout.CENTER); |
|
66 |
// |
|
67 |
// frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
|
68 |
// |
|
69 |
// frame.setSize(400,400); |
|
70 |
// panel.addComponentListener(this); |
|
71 |
// |
|
72 |
// frame.pack(); |
|
73 |
// frame.setVisible(true); |
|
74 |
// |
|
75 |
// } |
|
76 |
// |
|
77 |
// public void componentHidden(ComponentEvent arg0) { |
|
78 |
// this.frame.dispose(); |
|
79 |
// |
|
80 |
// } |
|
81 |
// public void componentMoved(ComponentEvent arg0) { |
|
82 |
// // Do nothing |
|
83 |
// |
|
84 |
// } |
|
85 |
// public void componentResized(ComponentEvent arg0) { |
|
86 |
// // Do nothing |
|
87 |
// |
|
88 |
// } |
|
89 |
// public void componentShown(ComponentEvent arg0) { |
|
90 |
// // Do nothing |
|
91 |
// |
|
92 |
// } |
|
93 |
// |
|
94 |
// } |
|
95 | 52 |
|
96 | 53 |
public DefaultScriptingUIManager(){ |
97 | 54 |
this.manager = ScriptingLocator.getManager(); |
98 | 55 |
this.manager.put("ScriptingUIManager",this); |
99 |
// this.windowManager = new MyWindowManager(); |
|
100 | 56 |
} |
101 | 57 |
|
102 |
// public void setMainFrame(JFrame mainFrame){ |
|
103 |
// this.mainFrame = mainFrame; |
|
104 |
// } |
|
105 |
|
|
106 | 58 |
public JScriptingComposer createComposer() { |
107 | 59 |
return new DefaultJScriptingComposer(this); |
108 | 60 |
} |
... | ... | |
251 | 203 |
return thinlet; |
252 | 204 |
} |
253 | 205 |
|
254 |
public JEditorPane createSyntaxHighlightingPanel() { |
|
255 |
return new JEditorPaneSyntaxHighlighting(); |
|
206 |
public SyntaxtHighlightTextComponent createSyntaxHighlightingPanel() { |
|
207 |
try { |
|
208 |
return new JRSyntaxTextArea(); |
|
209 |
} catch( Throwable t) { |
|
210 |
logger.info("Can't create advanced SyntaxHighlightingPanel.", t); |
|
211 |
return new JEditorPaneSyntaxHighlighting(); |
|
212 |
} |
|
256 | 213 |
} |
257 | 214 |
|
258 |
// public void registerWindowManager(WindowManager manager) { |
|
259 |
// this.windowManager=manager; |
|
260 |
// } |
|
261 |
|
|
262 |
|
|
263 | 215 |
} |
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/DefaultJDialogEditor.java | ||
---|---|---|
7 | 7 |
import javax.swing.JPanel; |
8 | 8 |
import javax.swing.JScrollPane; |
9 | 9 |
import javax.swing.JTabbedPane; |
10 |
import javax.swing.text.JTextComponent; |
|
10 | 11 |
|
11 | 12 |
import org.gvsig.scripting.ScriptingDialog; |
12 | 13 |
import org.gvsig.scripting.ScriptingScript; |
... | ... | |
69 | 70 |
this.editorHelper.addDefaultActionListener(actionlistener); |
70 | 71 |
} |
71 | 72 |
|
72 |
public JEditorPane getJEditorPanel(){
|
|
73 |
public JTextComponent getJTextComponent(){
|
|
73 | 74 |
return this.editorHelper.getJEditorPanel(); |
74 | 75 |
} |
75 | 76 |
|
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 | ||
---|---|---|
21 | 21 |
import javax.swing.JTabbedPane; |
22 | 22 |
import javax.swing.JViewport; |
23 | 23 |
import javax.swing.ListSelectionModel; |
24 |
import javax.swing.event.CaretEvent; |
|
25 |
import javax.swing.event.CaretListener; |
|
26 | 24 |
import javax.swing.event.ListSelectionEvent; |
27 | 25 |
import javax.swing.event.ListSelectionListener; |
28 |
import javax.swing.text.BadLocationException; |
|
29 |
import javax.swing.text.Document; |
|
26 |
import javax.swing.text.JTextComponent; |
|
30 | 27 |
|
31 | 28 |
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpClass; |
32 | 29 |
import org.gvsig.scripting.ScriptingHelpManager.ScriptingHelpMethod; |
... | ... | |
34 | 31 |
import org.gvsig.scripting.ScriptingScript; |
35 | 32 |
import org.gvsig.scripting.swing.api.JEditor; |
36 | 33 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
34 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent; |
|
37 | 35 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
38 |
import org.gvsig.scripting.swing.impl.composer.DefaultJCodeEditor.EditorActionEvent; |
|
39 |
import org.gvsig.scripting.swing.impl.syntaxhighlight.styles.PythonStyledDocument; |
|
40 | 36 |
|
41 | 37 |
|
42 | 38 |
public class EditorHelper { |
43 |
JEditorPane editorPanel;
|
|
39 |
SyntaxtHighlightTextComponent editorPanel;
|
|
44 | 40 |
private final ScriptingUIManager uimanager; |
45 |
protected ActionListener defaultActionlistener = null; |
|
41 |
// protected ActionListener defaultActionlistener = null;
|
|
46 | 42 |
private final ScriptingScript script; |
47 |
private PythonStyledDocument pydoc = null; |
|
43 |
// private PythonStyledDocument pydoc = null;
|
|
48 | 44 |
|
49 | 45 |
EditorHelper(ScriptingUIManager uimanager, ScriptingScript script){ |
50 | 46 |
this.uimanager=uimanager; |
... | ... | |
55 | 51 |
return editorPanel.getText(); |
56 | 52 |
} |
57 | 53 |
|
58 |
public JEditorPane getJEditorPanel(){
|
|
59 |
return this.editorPanel; |
|
54 |
public JTextComponent getJEditorPanel(){
|
|
55 |
return this.editorPanel.getJTextComponent();
|
|
60 | 56 |
} |
61 | 57 |
|
62 | 58 |
public void addDefaultActionListener(ActionListener actionlistener) { |
63 |
this.defaultActionlistener = actionlistener;
|
|
59 |
editorPanel.addUpdateCaretPositionActionListener(actionlistener);
|
|
64 | 60 |
} |
65 | 61 |
|
66 | 62 |
public JPanel getPropertiesPanel(){ |
... | ... | |
72 | 68 |
JPanel panel = new JPanel(); |
73 | 69 |
panel.setLayout( new BorderLayout() ); |
74 | 70 |
|
75 |
editorPanel = uimanager.createSyntaxHighlightingPanel(); |
|
71 |
editorPanel = (SyntaxtHighlightTextComponent) uimanager.createSyntaxHighlightingPanel();
|
|
76 | 72 |
editorPanel.setContentType("text/"+ script.getLangName()); |
77 | 73 |
editorPanel.setText(script.getCode()); |
78 |
Document doc = editorPanel.getDocument(); |
|
79 |
if( doc instanceof PythonStyledDocument ) { |
|
80 |
pydoc = (PythonStyledDocument) doc; |
|
81 |
} |
|
82 | 74 |
|
83 |
editorPanel.addCaretListener(new CaretListener() |
|
84 |
{ |
|
85 |
public void caretUpdate(CaretEvent e) |
|
86 |
{ |
|
87 |
int lineNumber = 1; |
|
88 |
int columnNumber = 0; |
|
89 |
int currentPosition = editorPanel.getCaretPosition(); |
|
90 |
try |
|
91 |
{ |
|
92 |
String strText = editorPanel.getDocument().getText(0, currentPosition); |
|
93 |
char arrText[] = strText.toCharArray(); |
|
94 |
for(int i=0; i<strText.length(); i++) |
|
95 |
{ |
|
96 |
if(arrText[i] == '\n') lineNumber++; |
|
97 |
} |
|
98 |
columnNumber = currentPosition - strText.lastIndexOf('\n'); |
|
99 |
} |
|
100 |
catch(BadLocationException ble) |
|
101 |
{ |
|
102 |
System.err.println(ble); |
|
103 |
} |
|
104 |
if( pydoc != null ) { |
|
105 |
pydoc.setPosition(lineNumber, columnNumber); |
|
106 |
} |
|
107 |
launchException(this,1,"position",lineNumber,columnNumber); |
|
108 |
} |
|
109 |
|
|
110 |
}); |
|
75 |
// editorPanel.addKeyListener(new MyKeyListener(this)); |
|
111 | 76 |
|
112 |
editorPanel.addKeyListener(new MyKeyListener(this)); |
|
113 |
|
|
114 |
panel.add(new JScrollPane(editorPanel),BorderLayout.CENTER); |
|
77 |
panel.add(editorPanel.getJScrollPane(),BorderLayout.CENTER); |
|
115 | 78 |
panel.setVisible(true); |
116 | 79 |
|
117 | 80 |
return panel; |
118 | 81 |
} |
119 | 82 |
|
120 |
public void launchException(CaretListener listener, int excId, String command, int lineNumber, int columnNumber){ |
|
121 |
this.defaultActionlistener.actionPerformed( |
|
122 |
new EditorActionEvent(listener, excId, command, lineNumber, columnNumber)); |
|
123 |
} |
|
83 |
// public void launchException(CaretListener listener, int excId, String command, int lineNumber, int columnNumber){
|
|
84 |
// this.defaultActionlistener.actionPerformed(
|
|
85 |
// new EditorActionEvent(listener, excId, command, lineNumber, columnNumber));
|
|
86 |
// }
|
|
124 | 87 |
|
125 | 88 |
public void getSuggestions(final JEditorPane editor,final String text) { |
126 | 89 |
Map<String, ScriptingHelpMethod> methods = |
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/DefaultJScriptingComposer.java | ||
---|---|---|
13 | 13 |
import java.util.List; |
14 | 14 |
|
15 | 15 |
import javax.swing.JButton; |
16 |
import javax.swing.JEditorPane; |
|
17 | 16 |
import javax.swing.JLabel; |
18 | 17 |
import javax.swing.JMenu; |
19 | 18 |
import javax.swing.JMenuBar; |
... | ... | |
34 | 33 |
import javax.swing.event.ListSelectionEvent; |
35 | 34 |
import javax.swing.event.ListSelectionListener; |
36 | 35 |
import javax.swing.table.DefaultTableModel; |
36 |
import javax.swing.text.JTextComponent; |
|
37 | 37 |
|
38 | 38 |
import org.gvsig.scripting.CompileErrorException; |
39 | 39 |
import org.gvsig.scripting.ExecuteErrorException; |
... | ... | |
49 | 49 |
import org.gvsig.scripting.swing.api.JScriptingBrowser; |
50 | 50 |
import org.gvsig.scripting.swing.api.JScriptingComposer; |
51 | 51 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
52 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent.UpdateCaretPositionActionEvent; |
|
52 | 53 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingBrowser; |
53 | 54 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher; |
54 | 55 |
import org.gvsig.scripting.swing.impl.DefaultJScriptingLauncher.LauncherActionEvent; |
55 | 56 |
import org.gvsig.scripting.swing.impl.JDialogContent; |
56 |
import org.gvsig.scripting.swing.impl.composer.DefaultJCodeEditor.EditorActionEvent; |
|
57 | 57 |
import org.gvsig.tools.observer.Observable; |
58 | 58 |
import org.gvsig.tools.observer.Observer; |
59 | 59 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
... | ... | |
447 | 447 |
if(((JEditor)scriptEditors.getComponent(i)).getScript().getId().equals(name)){ |
448 | 448 |
scriptEditors.setSelectedIndex(i); |
449 | 449 |
|
450 |
JEditorPane editor = ((JCodeEditor)scriptEditors.getComponent(i)).getJEditorPanel();
|
|
450 |
JTextComponent editor = ((JCodeEditor)scriptEditors.getComponent(i)).getJTextComponent();
|
|
451 | 451 |
editor.requestFocusInWindow(); |
452 | 452 |
|
453 | 453 |
String code = editor.getText(); |
... | ... | |
1058 | 1058 |
if (!unitsEditor.isEmpty()){ |
1059 | 1059 |
int pestanaIndex = scriptEditors.getSelectedIndex(); |
1060 | 1060 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1061 |
pestanaEditor.getJEditorPanel().copy();
|
|
1061 |
pestanaEditor.getJTextComponent().copy();
|
|
1062 | 1062 |
} |
1063 | 1063 |
} |
1064 | 1064 |
|
... | ... | |
1066 | 1066 |
if (!unitsEditor.isEmpty()){ |
1067 | 1067 |
int pestanaIndex = scriptEditors.getSelectedIndex(); |
1068 | 1068 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1069 |
pestanaEditor.getJEditorPanel().cut();
|
|
1069 |
pestanaEditor.getJTextComponent().cut();
|
|
1070 | 1070 |
JTabbedPane tabs = (JTabbedPane)pestanaEditor.getParent(); |
1071 | 1071 |
|
1072 | 1072 |
String title = tabs.getTitleAt(pestanaIndex); |
... | ... | |
1081 | 1081 |
if (!unitsEditor.isEmpty()){ |
1082 | 1082 |
int pestanaIndex = scriptEditors.getSelectedIndex(); |
1083 | 1083 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1084 |
pestanaEditor.getJEditorPanel().paste();
|
|
1084 |
pestanaEditor.getJTextComponent().paste();
|
|
1085 | 1085 |
JTabbedPane tabs = (JTabbedPane)pestanaEditor.getParent(); |
1086 | 1086 |
|
1087 | 1087 |
String title = tabs.getTitleAt(pestanaIndex); |
... | ... | |
1096 | 1096 |
if (!unitsEditor.isEmpty()){ |
1097 | 1097 |
int pestanaIndex = scriptEditors.getSelectedIndex(); |
1098 | 1098 |
JEditor pestanaEditor = (JEditor) scriptEditors.getComponentAt(pestanaIndex); |
1099 |
pestanaEditor.getJEditorPanel().selectAll();
|
|
1099 |
pestanaEditor.getJTextComponent().selectAll();
|
|
1100 | 1100 |
} |
1101 | 1101 |
} |
1102 | 1102 |
|
... | ... | |
1162 | 1162 |
*/ |
1163 | 1163 |
public void actionPerformed(ActionEvent e) { |
1164 | 1164 |
|
1165 |
if(e instanceof EditorActionEvent){
|
|
1166 |
EditorActionEvent e2 = (EditorActionEvent) e;
|
|
1165 |
if(e instanceof UpdateCaretPositionActionEvent){
|
|
1166 |
UpdateCaretPositionActionEvent e2 = (UpdateCaretPositionActionEvent) e;
|
|
1167 | 1167 |
|
1168 |
int lineAndColumn[] = e2.getLineAndColumn(); |
|
1169 |
if (lineAndColumn.length>=2){ |
|
1170 |
setEditorCursorPosition(lineAndColumn[0],lineAndColumn[1]); |
|
1168 |
if( e2.hasLineAndColumn() ) { |
|
1169 |
setEditorCursorPosition(e2.getLine(),e2.getColumn()); |
|
1171 | 1170 |
}else{ |
1172 | 1171 |
setEditorCursorPosition(0,0); |
1173 | 1172 |
} |
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/DefaultJCodeEditor.java | ||
---|---|---|
8 | 8 |
import javax.swing.JTabbedPane; |
9 | 9 |
import javax.swing.JTextArea; |
10 | 10 |
import javax.swing.JTextField; |
11 |
import javax.swing.text.JTextComponent; |
|
11 | 12 |
|
12 | 13 |
import org.gvsig.scripting.ScriptingBaseScript; |
13 | 14 |
import org.gvsig.scripting.ScriptingScript; |
... | ... | |
80 | 81 |
this.add(BorderLayout.CENTER, pestana); |
81 | 82 |
} |
82 | 83 |
|
83 |
|
|
84 | 84 |
public void save(){ |
85 | 85 |
this.editorHelper.saveScript( ((JPropertiesScript)pestana.getComponent(1))); |
86 | 86 |
} |
87 | 87 |
|
88 |
public JEditorPane getJEditorPanel(){
|
|
88 |
public JTextComponent getJTextComponent(){
|
|
89 | 89 |
return this.editorHelper.getJEditorPanel(); |
90 | 90 |
} |
91 |
|
|
92 |
/*private String cursorLocation(String text, int point){ |
|
93 |
int row=0; |
|
94 |
int positionLastRow=0; |
|
95 |
for(int i=0;i<point;i++){ |
|
96 |
String x = ""+text.charAt(i)+""; |
|
97 |
if(x.equals("\n")){ |
|
98 |
row++; |
|
99 |
positionLastRow = i; |
|
100 |
} |
|
101 |
} |
|
102 |
String result = row+":"+(point-positionLastRow); |
|
103 |
|
|
104 |
return result; |
|
105 |
}*/ |
|
106 |
|
|
107 |
} |
|
91 |
} |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/syntaxhighlight/JRSyntaxTextArea.java | ||
---|---|---|
1 |
package org.gvsig.scripting.swing.impl.syntaxhighlight; |
|
2 |
|
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
5 |
|
|
6 |
import javax.swing.JScrollPane; |
|
7 |
import javax.swing.event.CaretEvent; |
|
8 |
import javax.swing.event.CaretListener; |
|
9 |
import javax.swing.text.JTextComponent; |
|
10 |
|
|
11 |
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; |
|
12 |
import org.fife.ui.rsyntaxtextarea.SyntaxConstants; |
|
13 |
import org.fife.ui.rtextarea.RTextScrollPane; |
|
14 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent; |
|
15 |
|
|
16 |
public class JRSyntaxTextArea implements SyntaxtHighlightTextComponent { |
|
17 |
|
|
18 |
public class DefaultUpdateCaretPositionActionEvent extends ActionEvent implements UpdateCaretPositionActionEvent { |
|
19 |
|
|
20 |
int line = -1; |
|
21 |
int column = -1; |
|
22 |
|
|
23 |
public DefaultUpdateCaretPositionActionEvent(Object source, int id, |
|
24 |
String command, int line, int column) { |
|
25 |
super(source, id, command); |
|
26 |
this.line = line; |
|
27 |
this.column = column; |
|
28 |
} |
|
29 |
|
|
30 |
public int getLine() { |
|
31 |
return this.line+1; |
|
32 |
} |
|
33 |
|
|
34 |
public int getColumn() { |
|
35 |
return this.column; |
|
36 |
} |
|
37 |
|
|
38 |
public boolean hasLineAndColumn() { |
|
39 |
return this.line >=0 && this.column >= 0; |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
protected ActionListener updateCaretPosition = null; |
|
45 |
protected RSyntaxTextArea textArea = null; |
|
46 |
|
|
47 |
public JRSyntaxTextArea() { |
|
48 |
this.textArea = new RSyntaxTextArea(20, 60); |
|
49 |
this.init(); |
|
50 |
} |
|
51 |
|
|
52 |
protected void init() { |
|
53 |
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON); |
|
54 |
textArea.setCodeFoldingEnabled(true); |
|
55 |
textArea.setClearWhitespaceLinesEnabled(true); |
|
56 |
textArea.setAutoIndentEnabled(true); |
|
57 |
textArea.setCloseCurlyBraces(true); |
|
58 |
textArea.setWhitespaceVisible(true); |
|
59 |
textArea.setAnimateBracketMatching(true); |
|
60 |
textArea.setBracketMatchingEnabled(true); |
|
61 |
textArea.setAutoIndentEnabled(true); |
|
62 |
textArea.setTabsEmulated(true); |
|
63 |
textArea.setAntiAliasingEnabled(true); |
|
64 |
|
|
65 |
textArea.addCaretListener(new CaretListener() { |
|
66 |
public void caretUpdate(CaretEvent e) { |
|
67 |
if( updateCaretPosition== null ) { |
|
68 |
return; |
|
69 |
} |
|
70 |
updateCaretPosition.actionPerformed( |
|
71 |
new DefaultUpdateCaretPositionActionEvent(textArea, 1, "position", textArea.getCaretLineNumber(), textArea.getCaretOffsetFromLineStart() ) |
|
72 |
); |
|
73 |
} |
|
74 |
|
|
75 |
}); |
|
76 |
} |
|
77 |
|
|
78 |
public void setContentType(String contentType) { |
|
79 |
this.textArea.setSyntaxEditingStyle(contentType); |
|
80 |
} |
|
81 |
|
|
82 |
public JScrollPane getJScrollPane() { |
|
83 |
return new RTextScrollPane(this.textArea); |
|
84 |
} |
|
85 |
|
|
86 |
public JTextComponent getJTextComponent() { |
|
87 |
return this.textArea; |
|
88 |
} |
|
89 |
|
|
90 |
public String getContentType() { |
|
91 |
return this.textArea.getSyntaxEditingStyle(); |
|
92 |
} |
|
93 |
|
|
94 |
public void addUpdateCaretPositionActionListener(ActionListener updateCaretPosition) { |
|
95 |
this.updateCaretPosition = updateCaretPosition; |
|
96 |
} |
|
97 |
|
|
98 |
public void setText(String text) { |
|
99 |
this.textArea.setText(text); |
|
100 |
} |
|
101 |
|
|
102 |
public String getText() { |
|
103 |
return this.textArea.getText(); |
|
104 |
} |
|
105 |
} |
|
0 | 106 |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/src/main/java/org/gvsig/scripting/swing/impl/syntaxhighlight/JEditorPaneSyntaxHighlighting.java | ||
---|---|---|
1 | 1 |
package org.gvsig.scripting.swing.impl.syntaxhighlight; |
2 | 2 |
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
5 |
|
|
3 | 6 |
import javax.swing.JEditorPane; |
7 |
import javax.swing.JScrollPane; |
|
8 |
import javax.swing.event.CaretEvent; |
|
9 |
import javax.swing.event.CaretListener; |
|
10 |
import javax.swing.text.BadLocationException; |
|
4 | 11 |
import javax.swing.text.Document; |
12 |
import javax.swing.text.JTextComponent; |
|
5 | 13 |
import javax.swing.text.StyledEditorKit; |
6 | 14 |
|
15 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent; |
|
16 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent.UpdateCaretPositionActionEvent; |
|
7 | 17 |
import org.gvsig.scripting.swing.impl.syntaxhighlight.styles.JavaStyledDocument; |
8 | 18 |
import org.gvsig.scripting.swing.impl.syntaxhighlight.styles.PythonStyledDocument; |
9 | 19 |
|
10 |
public class JEditorPaneSyntaxHighlighting extends JEditorPane { |
|
20 |
public class JEditorPaneSyntaxHighlighting extends JEditorPane implements SyntaxtHighlightTextComponent {
|
|
11 | 21 |
|
12 | 22 |
/** |
13 | 23 |
* |
14 | 24 |
*/ |
15 | 25 |
private static final long serialVersionUID = -4451156833693922180L; |
16 | 26 |
|
27 |
protected ActionListener updateCaretPosition = null; |
|
28 |
|
|
17 | 29 |
public JEditorPaneSyntaxHighlighting() { |
18 | 30 |
|
19 | 31 |
this.setEditorKitForContentType( |
... | ... | |
61 | 73 |
} |
62 | 74 |
} |
63 | 75 |
); |
76 |
|
|
77 |
final JEditorPaneSyntaxHighlighting source = this; |
|
78 |
this.addCaretListener(new CaretListener() { |
|
79 |
public void caretUpdate(CaretEvent e) { |
|
80 |
if( updateCaretPosition== null ) { |
|
81 |
return; |
|
82 |
} |
|
83 |
int lineNumber = 1; |
|
84 |
int columnNumber = 0; |
|
85 |
int currentPosition = getCaretPosition(); |
|
86 |
Document doc = getDocument(); |
|
87 |
|
|
88 |
PythonStyledDocument pydoc = null; |
|
89 |
if( doc instanceof PythonStyledDocument ) { |
|
90 |
pydoc = (PythonStyledDocument) doc; |
|
91 |
} |
|
92 |
|
|
93 |
try { |
|
94 |
String strText = doc.getText(0, currentPosition); |
|
95 |
char arrText[] = strText.toCharArray(); |
|
96 |
for(int i=0; i<strText.length(); i++) { |
|
97 |
if(arrText[i] == '\n') lineNumber++; |
|
98 |
} |
|
99 |
columnNumber = currentPosition - strText.lastIndexOf('\n'); |
|
100 |
} |
|
101 |
catch(BadLocationException ble) { |
|
102 |
System.err.println(ble); |
|
103 |
} |
|
104 |
if( pydoc != null ) { |
|
105 |
pydoc.setPosition(lineNumber, columnNumber); |
|
106 |
} |
|
107 |
updateCaretPosition.actionPerformed( |
|
108 |
new DefaultUpdateCaretPositionActionEvent(source, 1, "position", lineNumber, columnNumber)); |
|
109 |
} |
|
110 |
|
|
111 |
}); |
|
112 |
|
|
64 | 113 |
} |
65 | 114 |
|
115 |
public void addUpdateCaretPositionActionListener(ActionListener updateCaretPosition) { |
|
116 |
this.updateCaretPosition = updateCaretPosition; |
|
117 |
} |
|
118 |
|
|
119 |
public JScrollPane getJScrollPane() { |
|
120 |
return new JScrollPane(this); |
|
121 |
} |
|
122 |
|
|
123 |
public JTextComponent getJTextComponent() { |
|
124 |
return this; |
|
125 |
} |
|
126 |
|
|
127 |
public class DefaultUpdateCaretPositionActionEvent extends ActionEvent implements UpdateCaretPositionActionEvent { |
|
128 |
|
|
129 |
int line = -1; |
|
130 |
int column = -1; |
|
131 |
|
|
132 |
public DefaultUpdateCaretPositionActionEvent(Object source, int id, |
|
133 |
String command, int line, int column) { |
|
134 |
super(source, id, command); |
|
135 |
this.line = line; |
|
136 |
this.column = column; |
|
137 |
} |
|
138 |
|
|
139 |
public int getLine() { |
|
140 |
return this.line; |
|
141 |
} |
|
142 |
|
|
143 |
public int getColumn() { |
|
144 |
return this.column; |
|
145 |
} |
|
146 |
|
|
147 |
public boolean hasLineAndColumn() { |
|
148 |
return this.line >=0 && this.column >= 0; |
|
149 |
} |
|
150 |
|
|
151 |
} |
|
66 | 152 |
} |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.swing/org.gvsig.scripting.swing.impl/pom.xml | ||
---|---|---|
38 | 38 |
<artifactId>org.gvsig.scripting.swing.api</artifactId> |
39 | 39 |
<version>1.0.0-SNAPSHOT</version> |
40 | 40 |
</dependency> |
41 |
<dependency> |
|
42 |
<groupId>javax.help</groupId> |
|
43 |
<artifactId>javahelp</artifactId> |
|
44 |
</dependency> |
|
41 |
<dependency> |
|
42 |
<groupId>javax.help</groupId> |
|
43 |
<artifactId>javahelp</artifactId> |
|
44 |
</dependency> |
|
45 |
<dependency> |
|
46 |
<groupId>com.fifesoft</groupId> |
|
47 |
<artifactId>rsyntaxtextarea</artifactId> |
|
48 |
<version>2.0.2</version> |
|
49 |
</dependency> |
|
45 | 50 |
</dependencies> |
46 | 51 |
<build> |
47 | 52 |
<plugins> |
Also available in: Unified diff