KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > console > MessageConsoleStream


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.console;
12
13 import java.io.IOException JavaDoc;
14
15 /**
16  * Used to write messages to a message console. A message console may have more
17  * than one stream connected to it. Each stream may be displayed in a different
18  * color.
19  * <p>
20  * Clients are not intended to subclass or instantiate this class. Instances
21  * are created via a {@link org.eclipse.ui.console.MessageConsole}.
22  * </p>
23  * <p>
24  * Clients should avoid writing large amounts of output to this stream in the UI
25  * thread. The console needs to process the output in the UI thread and if the client
26  * hogs the UI thread writing output to the console, the console will not be able
27  * to process the output.
28  * </p>
29  * <p>
30  * Since 3.1, this class extends {@link org.eclipse.ui.console.IOConsoleOutputStream}.
31  * </p>
32  * @since 3.0
33  */

34 public class MessageConsoleStream extends IOConsoleOutputStream {
35     
36     private MessageConsole fMessageConsole;
37     
38     /**
39      * Constructs a new stream connected to the given console.
40      *
41      * @param console the console to write messages to
42      */

43     public MessageConsoleStream(MessageConsole console) {
44         super(console);
45         fMessageConsole = console;
46     }
47     
48     /**
49      * Appends the specified message to this stream.
50      *
51      * @param message message to append
52      */

53     public void print(String JavaDoc message) {
54         try {
55             write(message);
56         } catch (IOException JavaDoc e) {
57             ConsolePlugin.log(e);
58         }
59     }
60     
61     
62     /**
63      * Appends a line separator string to this stream.
64      */

65     public void println() {
66         try {
67             write("\n"); //$NON-NLS-1$
68
} catch (IOException JavaDoc e) {
69             ConsolePlugin.log(e);
70         }
71     }
72     
73     /**
74      * Appends the specified message to this stream, followed by a line
75      * separator string.
76      *
77      * @param message message to print
78      */

79     public void println(String JavaDoc message) {
80         print(message + "\n"); //$NON-NLS-1$
81
}
82     
83     /**
84      * Returns the console this stream is connected to.
85      *
86      * @return the console this stream is connected to
87      */

88     public MessageConsole getConsole() {
89         return fMessageConsole;
90     }
91 }
92
Popular Tags