Statistics
| Revision:

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 / TextEditor.java @ 739

History | View | Annotate | Download (4.63 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
import org.gvsig.scripting.ScriptingExternalFile;
12
import org.gvsig.scripting.ScriptingUnit;
13
import org.gvsig.scripting.swing.api.JEditor;
14
import org.gvsig.scripting.swing.api.JTextEditor;
15
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
16
import org.gvsig.scripting.swing.api.ScriptingUIManager;
17
import org.gvsig.scripting.swing.api.SyntaxtHighlightTextComponent;
18
import org.gvsig.scripting.swing.impl.composer.ChangeListenerSupport;
19

    
20
public class TextEditor extends JPanel implements JTextEditor, JEditor {
21
    private static final long serialVersionUID = 9189395063548155843L;
22
    
23
    protected ScriptingExternalFile unit;
24
    protected boolean modified;
25
    private JTabbedPane tabs;
26
    protected BaseTextEditor textEditor;
27
    protected ExternalFileEditor propertiesPanel;
28
    protected final ChangeListenerSupport changeListeners;
29
    private final ScriptingUIManager uimanager;
30

    
31
    public TextEditor(final ScriptingExternalFile unit) {
32
        this.changeListeners = new ChangeListenerSupport();
33
        this.uimanager = ScriptingSwingLocator.getUIManager();
34
        this.initComponents();
35
        this.set(unit);
36
    }
37

    
38
    @Override
39
    public ScriptingUnit getUnit() {
40
        return this.unit;
41
    }
42

    
43
    protected void setUnit(ScriptingUnit unit) {
44
        this.unit = (ScriptingExternalFile) unit;
45
    }
46
    
47
    protected void setModified(boolean modified) {
48
        this.modified = modified;
49
    }
50
            
51
    protected BaseTextEditor getTextEditor() {
52
        return this.textEditor;
53
    }
54
    
55
    protected JTabbedPane getTabbedPane() {
56
        return this.tabs;
57
    }
58
    
59
    protected JPanel getAdditionalPropetiesPanel() {
60
        return this.propertiesPanel.getAdditionalPanel();
61
    }
62
    
63
    protected ExternalFileEditor getPropertiesPanel() {
64
        return this.propertiesPanel;
65
    }
66
    
67
    protected ChangeListenerSupport getChangeListeners() {
68
        return this.changeListeners;
69
    }
70
    
71
    private void initComponents() {
72
        this.textEditor = new BaseTextEditor();
73
        this.textEditor.addChangeListener(new PropertyChangeListener() {
74
            @Override
75
            public void propertyChange(PropertyChangeEvent evt) {
76
                modified = true;
77
                changeListeners.fireChange(evt);
78
            }
79
        });
80

    
81
        this.propertiesPanel = new ExternalFileEditor(this.unit);
82

    
83
        this.tabs = new JTabbedPane();
84
        this.tabs.setTabPlacement(JTabbedPane.BOTTOM);
85
        this.tabs.addTab(this.uimanager.getTranslation("Contents"), this.textEditor);
86
        this.tabs.addTab(this.uimanager.getTranslation("Properties"), this.propertiesPanel);
87
        this.setLayout(new BorderLayout());
88
        this.add(BorderLayout.CENTER, tabs);
89

    
90
    }
91
    
92
    protected JTabbedPane getTabs() {
93
        return this.tabs;
94
    }
95

    
96
    @Override
97
    public boolean isModified() {
98
        return this.modified;
99
    }
100

    
101
    @Override
102
    public void save() {
103
        this.fetch(unit);
104
    }    
105

    
106
    @Override
107
    public void addChangeListener(PropertyChangeListener listener) {
108
        this.changeListeners.addChangeListener(listener);
109
    }
110
    
111
    @Override
112
    public void set(ScriptingUnit unit) {
113
        this.unit = (ScriptingExternalFile) unit;
114
        this.propertiesPanel.set(unit);
115
        this.textEditor.setText(this.unit.getMimeType(), this.unit.getContentsAsText());
116
    }
117

    
118

    
119
    @Override
120
    public void fetch(ScriptingUnit unit) {
121
        ((ScriptingExternalFile) unit).setContents(this.textEditor.getText());
122
        this.modified = false;
123
    }
124

    
125
    
126
    @Override
127
    public JTextComponent getJTextComponent() {
128
        return this.textEditor.getJTextComponent();
129
    }
130

    
131
    @Override
132
    public SyntaxtHighlightTextComponent getSyntaxtHighlightTextComponent() {
133
        return this.textEditor.getSyntaxtHighlightTextComponent();
134
    }
135

    
136
    @Override
137
    public void selectLine(int line) {
138
        this.textEditor.selectLine(line);
139
    }
140

    
141
    @Override
142
    public int getLineCount() {
143
        return this.textEditor.getLineCount();
144
    }
145

    
146
    @Override
147
    public JComponent asJComponent() {
148
        return this;
149
    }
150

    
151
    @Override
152
    public void gotoline(int line) {
153
        this.textEditor.gotoline(line);
154
    }
155

    
156
    @Override
157
    public void addUpdateCaretPositionActionListener(ActionListener actionlistener) {
158
        this.textEditor.addUpdateCaretPositionActionListener(actionlistener);
159
    }    
160
}