001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc;
005:
006: import com.tc.admin.common.OutputStreamListener;
007: import com.tc.admin.common.StreamReader;
008: import com.tc.admin.common.TextComponentHelper;
009: import com.tc.admin.common.TextPaneUpdater;
010: import com.tc.admin.common.XTextPane;
011:
012: import javax.swing.JPopupMenu;
013: import javax.swing.SwingUtilities;
014: import javax.swing.UIManager;
015:
016: public class ProcessOutputView extends XTextPane {
017: private StreamReader m_errorStreamReader;
018: private StreamReader m_outputStreamReader;
019: private String m_listenerTrigger;
020: private OutputStreamListener m_listener;
021:
022: public ProcessOutputView() {
023: super ();
024: }
025:
026: protected TextComponentHelper createHelper() {
027: return new Helper();
028: }
029:
030: class Helper extends TextComponentHelper {
031: Helper() {
032: super (ProcessOutputView.this );
033: }
034:
035: protected void addCutAction(JPopupMenu popup) {/**/
036: }
037:
038: protected void addPasteAction(JPopupMenu popup) {/**/
039: }
040: }
041:
042: public void setListener(OutputStreamListener listener) {
043: m_listener = listener;
044:
045: if (m_errorStreamReader != null) {
046: m_errorStreamReader.setTriggerListener(m_listener);
047: }
048: if (m_outputStreamReader != null) {
049: m_outputStreamReader.setTriggerListener(m_listener);
050: }
051: }
052:
053: public OutputStreamListener getListener() {
054: return m_listener;
055: }
056:
057: public void setListenerTrigger(String trigger) {
058: m_listenerTrigger = trigger;
059:
060: if (m_errorStreamReader != null) {
061: m_errorStreamReader.setTrigger(trigger);
062: }
063: if (m_outputStreamReader != null) {
064: m_outputStreamReader.setTrigger(trigger);
065: }
066: }
067:
068: public String getListenerTrigger() {
069: return m_listenerTrigger;
070: }
071:
072: public void start(Process process) {
073: if (m_errorStreamReader != null || m_outputStreamReader != null) {
074: stop();
075: }
076:
077: m_errorStreamReader = new StreamReader(
078: process.getErrorStream(), new TextPaneUpdater(this ),
079: m_listener, m_listenerTrigger);
080: m_errorStreamReader.start();
081:
082: m_outputStreamReader = new StreamReader(process
083: .getInputStream(), new TextPaneUpdater(this ),
084: m_listener, m_listenerTrigger);
085: m_outputStreamReader.start();
086: }
087:
088: public void stop() {
089: m_errorStreamReader.finish();
090: m_outputStreamReader.finish();
091: }
092:
093: public void append(String text) {
094: SwingUtilities.invokeLater(new TextPaneUpdater(this , text));
095: }
096:
097: public void stopAndClear() {
098: stop();
099: setContent("");
100: }
101:
102: class TextClearer implements Runnable {
103: public void run() {
104: ProcessOutputView.this .setText("");
105: }
106: }
107:
108: public void setEnabled(boolean enabled) {
109: String key = enabled ? "TextPane.foreground"
110: : "TextPane.inactiveForeground";
111: setForeground(UIManager.getColor(key));
112: }
113:
114: public boolean isEnabled() {
115: return true;
116: }
117: }
|