KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > launchConfigurations > AntStreamMonitor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ant.internal.ui.launchConfigurations;
12
13 import org.eclipse.core.runtime.ListenerList;
14 import org.eclipse.debug.core.IStreamListener;
15 import org.eclipse.debug.core.model.IFlushableStreamMonitor;
16
17 /**
18  * Stream monitor implementation for an Ant build process.
19  */

20 public class AntStreamMonitor implements IFlushableStreamMonitor {
21
22     private StringBuffer JavaDoc fContents = new StringBuffer JavaDoc();
23     private ListenerList fListeners = new ListenerList(1);
24     private boolean fBuffered = true;
25     
26     /**
27      * @see org.eclipse.debug.core.model.IStreamMonitor#addListener(org.eclipse.debug.core.IStreamListener)
28      */

29     public void addListener(IStreamListener listener) {
30         fListeners.add(listener);
31     }
32
33     /**
34      * @see org.eclipse.debug.core.model.IStreamMonitor#getContents()
35      */

36     public String JavaDoc getContents() {
37         return fContents.toString();
38     }
39
40     /**
41      * @see org.eclipse.debug.core.model.IStreamMonitor#removeListener(org.eclipse.debug.core.IStreamListener)
42      */

43     public void removeListener(IStreamListener listener) {
44         fListeners.remove(listener);
45     }
46
47     /**
48      * Appends the given message to this stream, and notifies listeners.
49      *
50      * @param message
51      */

52     public void append(String JavaDoc message) {
53         if (isBuffered()) {
54             fContents.append(message);
55         }
56         Object JavaDoc[] listeners = fListeners.getListeners();
57         for (int i = 0; i < listeners.length; i++) {
58             IStreamListener listener = (IStreamListener)listeners[i];
59             listener.streamAppended(message, this);
60         }
61     }
62     /**
63      * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#flushContents()
64      */

65     public void flushContents() {
66         fContents.setLength(0);
67     }
68
69     /**
70      * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#isBuffered()
71      */

72     public boolean isBuffered() {
73         return fBuffered;
74     }
75
76     /**
77      * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#setBuffered(boolean)
78      */

79     public void setBuffered(boolean buffer) {
80         fBuffered = buffer;
81     }
82 }
83
84
Popular Tags