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 / DefaultJCodeEditor.java @ 639
History | View | Annotate | Download (3.58 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.beans.PropertyChangeEvent; |
6 |
import java.beans.PropertyChangeListener; |
7 |
import javax.swing.JComponent; |
8 |
import javax.swing.JPanel; |
9 |
import javax.swing.JTabbedPane; |
10 |
import javax.swing.text.JTextComponent; |
11 |
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; |
12 |
|
13 |
import org.gvsig.scripting.ScriptingBaseScript; |
14 |
import org.gvsig.scripting.ScriptingScript; |
15 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
16 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
17 |
|
18 |
public class DefaultJCodeEditor extends JPanel implements JCodeEditor { |
19 |
|
20 |
/**
|
21 |
*
|
22 |
*/
|
23 |
private static final long serialVersionUID = 5191252525229037754L; |
24 |
|
25 |
protected JTabbedPane tabs; |
26 |
protected EditorHelper editorHelper;
|
27 |
|
28 |
protected ScriptingBaseScript script;
|
29 |
protected ScriptingUIManager uimanager;
|
30 |
protected ChangeListenerSupport changeListeners;
|
31 |
|
32 |
protected boolean modified; |
33 |
|
34 |
public DefaultJCodeEditor(ScriptingUIManager uimanager, ScriptingScript script) {
|
35 |
this.script = script;
|
36 |
this.uimanager = uimanager;
|
37 |
this.editorHelper = new EditorHelper(uimanager, this.getScript()); |
38 |
modified = false;
|
39 |
this.changeListeners = new ChangeListenerSupport(); |
40 |
makeUI(); |
41 |
} |
42 |
|
43 |
@Override
|
44 |
public void addUpdateCaretPositionActionListener(ActionListener actionlistener) { |
45 |
this.editorHelper.getCodePanel().addUpdateCaretPositionActionListener(actionlistener);
|
46 |
} |
47 |
|
48 |
@Override
|
49 |
public void addChangeListener(PropertyChangeListener listener) { |
50 |
this.changeListeners.addChangeListener(listener);
|
51 |
} |
52 |
|
53 |
@Override
|
54 |
public ScriptingScript getScript() {
|
55 |
return (ScriptingScript) this.script; |
56 |
} |
57 |
|
58 |
private void makeUI() { |
59 |
tabs = new JTabbedPane(); |
60 |
tabs.setTabPlacement(JTabbedPane.BOTTOM);
|
61 |
tabs.addTab(this.uimanager.getTranslation("Code"), editorHelper.getCodePanel()); |
62 |
tabs.addTab(this.uimanager.getTranslation("Properties"), editorHelper.getPropertiesPanel()); |
63 |
this.setLayout(new BorderLayout()); |
64 |
this.add(BorderLayout.CENTER, tabs); |
65 |
this.editorHelper.getCodePanel().addChangeListener(new PropertyChangeListener() { |
66 |
@Override
|
67 |
public void propertyChange(PropertyChangeEvent evt) { |
68 |
modified = true;
|
69 |
changeListeners.fireChange(evt); |
70 |
} |
71 |
}); |
72 |
this.editorHelper.getPropertiesPanel().addChangeListener(new PropertyChangeListener() { |
73 |
@Override
|
74 |
public void propertyChange(PropertyChangeEvent evt) { |
75 |
modified = true;
|
76 |
changeListeners.fireChange(evt); |
77 |
} |
78 |
}); |
79 |
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public boolean isModified() { |
84 |
return this.modified; |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public void save() { |
89 |
this.editorHelper.saveScript();
|
90 |
this.modified = false; |
91 |
} |
92 |
|
93 |
@Override
|
94 |
public JTextComponent getJTextComponent() { |
95 |
return this.editorHelper.getCodePanel().getJTextComponent(); |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public void reload() { |
100 |
|
101 |
} |
102 |
|
103 |
@Override
|
104 |
public void selectLine(int line) { |
105 |
this.editorHelper.getCodePanel().selectLine(line);
|
106 |
} |
107 |
|
108 |
@Override
|
109 |
public int getLineCount() { |
110 |
JTextComponent textComponent = this.editorHelper.getCodePanel().getJTextComponent(); |
111 |
if( textComponent instanceof RSyntaxTextArea ) { |
112 |
return ((RSyntaxTextArea)textComponent).getLineCount();
|
113 |
} |
114 |
return 0; |
115 |
} |
116 |
|
117 |
@Override
|
118 |
public JComponent asJComponent() { |
119 |
return this; |
120 |
} |
121 |
} |