001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.sourceview;
016:
017: import java.awt.BorderLayout;
018:
019: import javax.swing.JScrollPane;
020: import javax.swing.JTextArea;
021: import javax.swing.event.DocumentEvent;
022: import javax.swing.event.DocumentListener;
023:
024: import com.metaboss.applications.designstudio.Application;
025: import com.metaboss.applications.designstudio.BaseChildPanel;
026: import com.metaboss.applications.designstudio.BaseUserObject;
027: import com.metaboss.applications.designstudio.Application.RefreshEvent;
028: import com.metaboss.applications.designstudio.userobjects.ModelElementAttachmentUserObject;
029:
030: /* Source View Frame class */
031:
032: public class SourceViewPanel extends BaseChildPanel {
033: private JTextArea mTextArea = new JTextArea();
034: private BaseUserObject mObject = null;
035: private boolean mLoading = false;
036:
037: // constructor
038: public SourceViewPanel(BaseUserObject pObject) {
039: super (pObject.getSource());
040:
041: mObject = pObject;
042: setLayout(new BorderLayout());
043:
044: mTextArea.setFont(Application.EDITOR_FONT);
045: mTextArea.setLineWrap(false);
046:
047: loadSource();
048:
049: JScrollPane lPane = new JScrollPane(mTextArea);
050: lPane.setBorder(null);
051: add(lPane, BorderLayout.CENTER);
052:
053: Application
054: .addRefreshListener(new Application.RefreshListener() {
055: public void refresh(RefreshEvent event) {
056: loadSource();
057: }
058: });
059:
060: mTextArea.getDocument().addDocumentListener(
061: new DocumentListener() {
062: public void changedUpdate(DocumentEvent e) {
063: setObjectChanged();
064: }
065:
066: public void insertUpdate(DocumentEvent e) {
067: setObjectChanged();
068: }
069:
070: public void removeUpdate(DocumentEvent e) {
071: setObjectChanged();
072: }
073: });
074: }
075:
076: // load source code into editor
077: public void loadSource() {
078: mLoading = true;
079: try {
080: mTextArea.setText(mObject.getSourceFromAttachment());
081: } finally {
082: mLoading = false;
083: }
084: }
085:
086: // save source editor content
087: public void saveContent() {
088: if (mObject != null) {
089: try {
090: ModelElementAttachmentUserObject.setSourceToAttachment(
091: mObject.getSource(), mTextArea.getText());
092: } catch (Exception e) {
093: e.printStackTrace();
094: }
095: }
096: super .saveContent();
097: }
098:
099: private void setObjectChanged() {
100: if (!mLoading) {
101: setChanged(true);
102: Application.fireObjectEdited(mObject);
103: }
104: }
105: }
|