01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.codegen.gui.editor;
20:
21: import java.awt.BorderLayout;
22: import java.awt.Component;
23:
24: import javax.swing.JEditorPane;
25: import javax.swing.JScrollPane;
26: import javax.swing.text.JTextComponent;
27:
28: import com.jeta.forms.store.memento.FormMemento;
29: import com.jeta.open.gui.framework.JETAPanel;
30:
31: public class SourceEditor extends JETAPanel {
32: private JTextComponent m_editor;
33:
34: private FormMemento m_form_memento;
35:
36: /**
37: * Creates a SourceEditor instance with the specified generated source code
38: * for the specified form state.
39: */
40: public SourceEditor(String sourceText, FormMemento fm) {
41: setLayout(new BorderLayout());
42: m_form_memento = fm;
43:
44: add(new SourceView(buildView()), BorderLayout.CENTER);
45:
46: initialize(sourceText);
47: setController(new SourceController(this ));
48: }
49:
50: private Component buildView() {
51: JavaKit kit = new JavaKit();
52: JEditorPane editor = new JEditorPane();
53: editor.setEditorKit(kit);
54: // JEditorPane editor = TSEditorUtils.createEditor( kit );
55: // JComponent comp = TSEditorUtils.getExtComponent( editor );
56:
57: m_editor = editor;
58: return new JScrollPane(editor);
59: }
60:
61: FormMemento getFormMemento() {
62: return m_form_memento;
63: }
64:
65: private void initialize(String txt) {
66: m_editor.setText(txt);
67: }
68:
69: public String getText() {
70: return m_editor.getText();
71: }
72:
73: public void setText(String txt) {
74: m_editor.setText(txt);
75:
76: try {
77: m_editor.setCaretPosition(0);
78: } catch (Exception e) {
79: }
80:
81: }
82: }
|