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 / editors / ScriptEditor.java @ 977
History | View | Annotate | Download (4.83 KB)
1 |
package org.gvsig.scripting.swing.impl.composer.editors; |
---|---|
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 |
|
12 |
import org.gvsig.scripting.ScriptingScript; |
13 |
import org.gvsig.scripting.ScriptingUnit; |
14 |
import org.gvsig.scripting.swing.api.JCodeEditor; |
15 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
16 |
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent; |
17 |
import org.gvsig.scripting.swing.impl.composer.ChangeListenerSupport; |
18 |
import org.gvsig.scripting.swing.impl.composer.JPropertiesScript; |
19 |
|
20 |
public class ScriptEditor extends JPanel implements JCodeEditor { |
21 |
|
22 |
/**
|
23 |
*
|
24 |
*/
|
25 |
private static final long serialVersionUID = 5191252525229037754L; |
26 |
|
27 |
private JTabbedPane tabs; |
28 |
|
29 |
protected ScriptingScript script;
|
30 |
protected final ScriptingUIManager uimanager; |
31 |
protected final ChangeListenerSupport changeListeners; |
32 |
protected BaseTextEditor textEditor;
|
33 |
protected JPropertiesScript propertiesPanel;
|
34 |
protected boolean modified; |
35 |
|
36 |
public ScriptEditor(ScriptingUIManager uimanager, ScriptingScript script) {
|
37 |
this.script = script;
|
38 |
this.uimanager = uimanager;
|
39 |
this.modified = false; |
40 |
this.changeListeners = new ChangeListenerSupport(); |
41 |
initComponents(); |
42 |
this.set(script);
|
43 |
} |
44 |
|
45 |
@Override
|
46 |
public ScriptingScript getScript() {
|
47 |
return (ScriptingScript) this.script; |
48 |
} |
49 |
|
50 |
@Override
|
51 |
public ScriptingUnit getUnit() {
|
52 |
return this.script; |
53 |
} |
54 |
|
55 |
private void initComponents() { |
56 |
this.textEditor = new BaseTextEditor(); |
57 |
this.textEditor.addChangeListener(new PropertyChangeListener() { |
58 |
@Override
|
59 |
public void propertyChange(PropertyChangeEvent evt) { |
60 |
modified = true;
|
61 |
fireChangeEvent(evt); |
62 |
} |
63 |
}); |
64 |
|
65 |
this.propertiesPanel = new JPropertiesScript(this.script); |
66 |
this.propertiesPanel.addChangeListener(new PropertyChangeListener() { |
67 |
@Override
|
68 |
public void propertyChange(PropertyChangeEvent evt) { |
69 |
modified = true;
|
70 |
fireChangeEvent(evt); |
71 |
} |
72 |
}); |
73 |
|
74 |
this.tabs = new JTabbedPane(); |
75 |
this.tabs.setTabPlacement(JTabbedPane.BOTTOM); |
76 |
this.tabs.addTab(this.uimanager.getTranslation("Code"), this.textEditor); |
77 |
this.tabs.addTab(this.uimanager.getTranslation("Properties"), this.propertiesPanel); |
78 |
this.setLayout(new BorderLayout()); |
79 |
this.add(BorderLayout.CENTER, tabs); |
80 |
|
81 |
} |
82 |
|
83 |
protected JTabbedPane getTabs() { |
84 |
return this.tabs; |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public boolean isModified() { |
89 |
return this.modified; |
90 |
} |
91 |
|
92 |
@Override
|
93 |
public void save() { |
94 |
if (this.propertiesPanel != null) { |
95 |
this.propertiesPanel.fectch(script);
|
96 |
} |
97 |
if (this.textEditor != null) { |
98 |
script.setCode(this.textEditor.getText());
|
99 |
} |
100 |
script.save(); |
101 |
this.modified = false; |
102 |
} |
103 |
|
104 |
@Override
|
105 |
public void reload() { |
106 |
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public void addChangeListener(PropertyChangeListener listener) { |
111 |
this.changeListeners.addChangeListener(listener);
|
112 |
} |
113 |
|
114 |
public void fireChangeEvent(String name, Object oldValue) { |
115 |
this.changeListeners.fireChange(name, oldValue);
|
116 |
} |
117 |
|
118 |
public void fireChangeEvent(PropertyChangeEvent evt) { |
119 |
this.changeListeners.fireChange(evt);
|
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void set(ScriptingUnit unit) { |
124 |
this.script = (ScriptingScript) unit;
|
125 |
this.propertiesPanel.set(unit);
|
126 |
this.textEditor.setText(this.script.getMimeType(), this.script.getCode()); |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void fetch(ScriptingUnit unit) { |
131 |
ScriptingScript script = (ScriptingScript) unit; |
132 |
this.propertiesPanel.fectch(unit);
|
133 |
script.setCode(this.textEditor.getText());
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
public JTextComponent getJTextComponent() { |
138 |
return this.textEditor.getJTextComponent(); |
139 |
} |
140 |
|
141 |
@Override
|
142 |
public SyntaxtHighlightTextComponent getSyntaxtHighlightTextComponent() {
|
143 |
return this.textEditor.getSyntaxtHighlightTextComponent(); |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public void selectLine(int line) { |
148 |
this.textEditor.selectLine(line);
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public int getLineCount() { |
153 |
return this.textEditor.getLineCount(); |
154 |
} |
155 |
|
156 |
@Override
|
157 |
public JComponent asJComponent() { |
158 |
return this; |
159 |
} |
160 |
|
161 |
@Override
|
162 |
public void gotoline(int line) { |
163 |
this.textEditor.gotoline(line);
|
164 |
} |
165 |
|
166 |
@Override
|
167 |
public void addUpdateCaretPositionActionListener(ActionListener actionlistener) { |
168 |
this.textEditor.addUpdateCaretPositionActionListener(actionlistener);
|
169 |
} |
170 |
|
171 |
} |