/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core.output; import java.util.WeakHashMap; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.MissingResourceException; import java.io.PipedReader; import java.io.PipedWriter; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.FileWriter; import java.io.File; import java.text.MessageFormat; import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.io.Writer; import java.lang.StringBuffer; import java.util.ArrayList; import java.util.Enumeration; import java.util.Observable; import java.util.Observer; import java.util.Set; import javax.swing.JPanel; import javax.swing.KeyStroke; import javax.swing.JPopupMenu; import javax.swing.JMenuItem; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.text.Keymap; import org.openide.ErrorManager; import org.openide.windows.*; import org.openide.awt.SplittedPanel; import org.openide.awt.MouseUtils; import org.openide.actions.CutAction; import org.openide.actions.DeleteAction; import org.openide.actions.PasteAction; import org.openide.actions.CopyAction; import org.openide.actions.FindAction; import org.openide.util.io.NullOutputStream; import org.openide.util.NbBundle; import org.openide.util.Mutex; import org.openide.util.datatransfer.*; import org.openide.util.actions.ActionPerformer; import org.openide.util.actions.SystemAction; import org.openide.util.actions.CallbackSystemAction; import org.openide.text.Line; import org.openide.filesystems.FileObject; import org.openide.filesystems.Repository; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.cookies.EditorCookie; import org.netbeans.lib.terminalemulator.*; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileSystemCapability; import org.openide.util.Lookup; /** Rewritten and much simplified OutputTabTerm * * @author Tim Boudreau * @version 2.0 */ public class OutputTabTerm extends TopComponent implements InputOutput, PropertyChangeListener { public static final String ICON_RESOURCE = "/org/netbeans/core/resources/frames/output.gif"; // NOI18N private static InputOutput io = null; public OutputTabTerm () { setLayout (new java.awt.BorderLayout()); putClientProperty("PersistenceType", "OnlyOpened"); // NOI18N } public static synchronized InputOutput getIO(String name, boolean newIO) { if (io == null) { io = new OutputTabTerm(); } return io; } public static OutputWriter getStdOut() { return getIO("", false).getOut(); } public void open (Workspace workspace) { //debug("OutputTabTerm.open():"+getName()); // NOI18N Workspace realWorkspace = (workspace == null) ? WindowManager.getDefault().getCurrentWorkspace() : workspace; // dock into outwin mode if not docked yet Mode mode = realWorkspace.findMode("output"); // NOI18N if (mode == null) { mode = realWorkspace.createMode("output", "Booger", // NOI18N OutputTabTerm.class.getResource(ICON_RESOURCE)); } Mode tcMode = realWorkspace.findMode(this); if (tcMode == null) mode.dockInto(this); // behave like superclass super.open(workspace); } public void setCompilationFinished() { //garbage, do nothing } /** Returns standard output top component */ public static TopComponent getStdOutputTab() { return (TopComponent) getIO("", false); } public void setErrVisible(boolean value) { //do nothing } public void setFocusTaken(boolean value) { //do nothing } public void setInputVisible(boolean value) { //do nothing } public void setOutputVisible(boolean value) { //do nothing } public void setErrSeparated(boolean value) { //do nothing } public void closeInputOutput() { } public java.io.Reader flushReader() { return new DummyReader(); } public OutputWriter getErr() { return getOut(); } public java.io.Reader getIn() { return new DummyReader(); } Out out=null; public synchronized OutputWriter getOut() { if (out == null) { out = new Out(); javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(out); add (jsp, java.awt.BorderLayout.CENTER); open(); } return out.writer; } public boolean isClosed() { return getParent() != null; } public boolean isErrSeparated() { return false; } public boolean isFocusTaken() { return hasFocus(); } public void propertyChange(PropertyChangeEvent evt) { } public void select() { requestFocusInWindow(); } private static class DummyWriter extends java.io.Writer { public void close() throws IOException { } public void flush() throws IOException { } public void write(char[] cbuf, int off, int len) throws IOException { } } private static class DummyReader extends java.io.Reader { public void close() throws IOException { } public int read(char[] cbuf, int off, int len) throws IOException { return 0; } } private class Out extends JTextArea { StringBuffer txt = new StringBuffer (1000); OWriter writer = new OWriter(); private void update() { setText (txt.toString()); } private void appendTxt (Object o) { // System.out.println("APPEND: " + o.toString()); this.append(o.toString()); } private class OWriter extends OutputWriter { protected OWriter () { super(new DummyWriter()); } public void println() { appendTxt ("\n"); //NOI18N } public void println(String s, OutputListener l) throws IOException { appendTxt (s); update(); } public void reset() throws IOException { txt = new StringBuffer(); update(); } public void write(int c) { appendTxt (new Integer (c)); } public void write(char buf[], int off, int len) { appendTxt (new String (buf, off, len)); } public void write(char buf[]) { appendTxt (new String(buf)); } public void write(String s, int off, int len) { appendTxt (s.substring(off, off + len)); } } } }