001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.debugger.ui.output;
021:
022: import java.awt.EventQueue;
023: import java.text.DateFormat;
024: import java.text.SimpleDateFormat;
025: import java.util.Date;
026:
027: import org.openide.util.NbBundle;
028: import org.openide.windows.IOProvider;
029: import org.openide.windows.InputOutput;
030: import org.openide.windows.OutputWriter;
031: import org.openide.windows.WindowManager;
032: import org.openide.windows.TopComponent;
033:
034: import org.netbeans.modules.bpel.debugger.api.Tracer;
035:
036: /**
037: * @author Vladimir Yaroslavskiy
038: * @version 2005.10.14
039: */
040: public class BpelOutputView implements Tracer {
041:
042: BpelOutputView(String name) {
043: //System.out.println();
044: //System.out.println("INIT TRACER: " + name);
045:
046: myDateFormat = new SimpleDateFormat("HH:mm:ss"); // NOI18N
047: final String title;
048:
049: if (name == null) {
050: title = NbBundle.getMessage(BpelOutputView.class,
051: "CTL_DebuggerConsoleName"); // NOI18N
052: } else {
053: title = NbBundle.getMessage(BpelOutputView.class,
054: "CTL_DebuggerConsole", name); // NOI18N
055: }
056:
057: if (EventQueue.isDispatchThread()) {
058: prepareOutput(title);
059: } else {
060: EventQueue.invokeLater(new Runnable() {
061: public void run() {
062: prepareOutput(title);
063: }
064: });
065: }
066:
067: }
068:
069: /**{@inheritDoc}*/
070: public void println(final String message) {
071: if (EventQueue.isDispatchThread()) {
072: myOutputWriter.println(myDateFormat.format(new Date())
073: + " " + message); // NOI18N
074: } else {
075: EventQueue.invokeLater(new Runnable() {
076: public void run() {
077: myOutputWriter.println(myDateFormat
078: .format(new Date())
079: + " " + message); // NOI18N
080: }
081: });
082: }
083: }
084:
085: /**{@inheritDoc}*/
086: public void println(final Throwable exception) {
087: if (EventQueue.isDispatchThread()) {
088: exception.printStackTrace(myOutputWriter);
089: } else {
090: EventQueue.invokeLater(new Runnable() {
091: public void run() {
092: exception.printStackTrace(myOutputWriter);
093: }
094: });
095: }
096: }
097:
098: /**{@inheritDoc}*/
099: public void println(String message, Throwable exception) {
100: println(message);
101: println(exception);
102: }
103:
104: /**{@inheritDoc}*/
105: public void debug(String message) {
106: if (ourEnabled) {
107: println(message);
108: }
109: }
110:
111: /**{@inheritDoc}*/
112: public void debug(Throwable exception) {
113: if (ourEnabled) {
114: println(exception);
115: }
116: }
117:
118: /**{@inheritDoc}*/
119: public void debug(String message, Throwable exception) {
120: if (ourEnabled) {
121: println(message, exception);
122: }
123: }
124:
125: private void prepareOutput(String title) {
126: TopComponent topComponent = WindowManager.getDefault()
127: .findTopComponent("output"); // NOI18N
128:
129: if (topComponent != null) {
130: topComponent.open();
131: topComponent.requestActive();
132: }
133:
134: InputOutput inputOutput = IOProvider.getDefault().getIO(title,
135: false);
136: inputOutput.setFocusTaken(false);
137: inputOutput.select();
138: myOutputWriter = inputOutput.getOut();
139: }
140:
141: private DateFormat myDateFormat;
142: private OutputWriter myOutputWriter;
143: private static boolean ourEnabled = System
144: .getProperty("org.netbeans.modules.bpel.debugger.debug") // NOI18N
145: != null;
146: }
|