KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > console > AntConsoleColorProvider


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.console;
12
13 import org.eclipse.ant.internal.ui.AntUIPlugin;
14 import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
15 import org.eclipse.ant.internal.ui.launchConfigurations.AntProcess;
16 import org.eclipse.ant.internal.ui.launchConfigurations.AntStreamsProxy;
17 import org.eclipse.debug.core.model.IProcess;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.debug.ui.console.ConsoleColorProvider;
20 import org.eclipse.debug.ui.console.IConsole;
21 import org.eclipse.jface.util.IPropertyChangeListener;
22 import org.eclipse.jface.util.PropertyChangeEvent;
23 import org.eclipse.swt.graphics.Color;
24 import org.eclipse.ui.console.IOConsoleOutputStream;
25
26
27 public class AntConsoleColorProvider extends ConsoleColorProvider implements IPropertyChangeListener {
28
29     
30     
31     /* (non-Javadoc)
32      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#getColor(java.lang.String)
33      */

34     public Color getColor(String JavaDoc streamIdentifer) {
35         if (streamIdentifer.equals(IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM)) {
36             return AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_INFO_COLOR);
37         }
38         if (streamIdentifer.equals(IDebugUIConstants.ID_STANDARD_ERROR_STREAM)) {
39             return AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_ERROR_COLOR);
40         }
41         if (streamIdentifer.equals(AntStreamsProxy.ANT_DEBUG_STREAM)) {
42             return AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR);
43         }
44         if (streamIdentifer.equals(AntStreamsProxy.ANT_VERBOSE_STREAM)) {
45             return AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_VERBOSE_COLOR);
46         }
47         if (streamIdentifer.equals(AntStreamsProxy.ANT_WARNING_STREAM)) {
48             return AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR);
49         }
50         return super.getColor(streamIdentifer);
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#connect(org.eclipse.debug.core.model.IProcess, org.eclipse.debug.ui.console.IConsole)
55      */

56     public void connect(IProcess process, IConsole console) {
57         //Both remote and local Ant builds are guaranteed to have
58
//an AntStreamsProxy. The remote Ant builds make use of the
59
// org.eclipse.debug.core.processFactories extension point
60
AntStreamsProxy proxy = (AntStreamsProxy)process.getStreamsProxy();
61         if (process instanceof AntProcess) {
62             ((AntProcess)process).setConsole(console);
63         }
64         if (proxy != null) {
65             console.connect(proxy.getDebugStreamMonitor(), AntStreamsProxy.ANT_DEBUG_STREAM);
66             console.connect(proxy.getWarningStreamMonitor(), AntStreamsProxy.ANT_WARNING_STREAM);
67             console.connect(proxy.getVerboseStreamMonitor(), AntStreamsProxy.ANT_VERBOSE_STREAM);
68         }
69         
70         AntUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
71         super.connect(process, console);
72     }
73     
74     /* (non-Javadoc)
75      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#isReadOnly()
76      */

77     public boolean isReadOnly() {
78         return true;
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
83      */

84     public void propertyChange(PropertyChangeEvent event) {
85         final String JavaDoc streamId = getStreamId(event.getProperty());
86         if (streamId != null) {
87             AntUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
88                 public void run() {
89                     IOConsoleOutputStream stream = getConsole().getStream(streamId);
90                     if (stream != null) {
91                         stream.setColor(getColor(streamId));
92                     }
93                 }
94             });
95         }
96     }
97
98     private String JavaDoc getStreamId(String JavaDoc colorId) {
99         if (IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR.equals(colorId)) {
100             return AntStreamsProxy.ANT_DEBUG_STREAM;
101         } else if (IAntUIPreferenceConstants.CONSOLE_ERROR_COLOR.equals(colorId)) {
102             return IDebugUIConstants.ID_STANDARD_ERROR_STREAM;
103         } else if (IAntUIPreferenceConstants.CONSOLE_INFO_COLOR.equals(colorId)) {
104             return IDebugUIConstants.ID_STANDARD_OUTPUT_STREAM;
105         } else if (IAntUIPreferenceConstants.CONSOLE_VERBOSE_COLOR.equals(colorId)) {
106             return AntStreamsProxy.ANT_VERBOSE_STREAM;
107         } else if (IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR.equals(colorId)) {
108             return AntStreamsProxy.ANT_WARNING_STREAM;
109         }
110         return null;
111     }
112     
113     /* (non-Javadoc)
114      * @see org.eclipse.debug.ui.console.IConsoleColorProvider#disconnect()
115      */

116     public void disconnect() {
117         AntUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
118         super.disconnect();
119     }
120 }
121
Popular Tags