KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > console > ConsoleColorProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.debug.ui.console;
12
13
14 import org.eclipse.debug.core.model.IProcess;
15 import org.eclipse.debug.core.model.IStreamsProxy;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.swt.graphics.Color;
20
21 /**
22  * Default console color provider for a process. Colors output to standard
23  * out, in, and error, as specified by user preferences.
24  * <p>
25  * Clients implementing a console color provider should subclass this class.
26  * </p>
27  * @since 2.1
28  */

29 public class ConsoleColorProvider implements IConsoleColorProvider {
30
31     private IProcess fProcess;
32     private IConsole fConsole;
33     
34     /* (non-Javadoc)
35      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#connect(org.eclipse.debug.core.model.IProcess, org.eclipse.debug.ui.console.IConsole)
36      */

37     public void connect(IProcess process, IConsole console) {
38         fProcess = process;
39         fConsole = console;
40         IStreamsProxy streamsProxy = fProcess.getStreamsProxy();
41         if (streamsProxy != null) {
42             fConsole.connect(streamsProxy);
43         }
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#disconnect()
48      */

49     public void disconnect() {
50         fConsole = null;
51         fProcess = null;
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#isReadOnly()
56      */

57     public boolean isReadOnly() {
58         return fProcess == null || fProcess.isTerminated();
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#getColor(java.lang.String)
63      */

64     public Color getColor(String JavaDoc streamIdentifer) {
65         if (IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM.equals(streamIdentifer)) {
66             return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR);
67         }
68         if (IDebugUIConstants.ID_STANDARD_ERROR_STREAM.equals(streamIdentifer)) {
69             return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR);
70         }
71         if (IDebugUIConstants.ID_STANDARD_INPUT_STREAM.equals(streamIdentifer)) {
72             return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR);
73         }
74         return null;
75     }
76
77     /**
78      * Returns the process this color provider is providing color for, or
79      * <code>null</code> if none.
80      *
81      * @return the process this color provider is providing color for, or
82      * <code>null</code> if none
83      */

84     protected IProcess getProcess() {
85         return fProcess;
86     }
87     
88     /**
89      * Returns the console this color provider is connected to, or
90      * <code>null</code> if none.
91      *
92      * @return IConsole the console this color provider is connected to, or
93      * <code>null</code> if none
94      */

95     protected IConsole getConsole() {
96         return fConsole;
97     }
98 }
99
Popular Tags