1 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 34 public Color getColor(String 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 56 public void connect(IProcess process, IConsole console) { 57 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 77 public boolean isReadOnly() { 78 return true; 79 } 80 81 84 public void propertyChange(PropertyChangeEvent event) { 85 final String streamId = getStreamId(event.getProperty()); 86 if (streamId != null) { 87 AntUIPlugin.getStandardDisplay().asyncExec(new Runnable () { 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 getStreamId(String 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 116 public void disconnect() { 117 AntUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); 118 super.disconnect(); 119 } 120 } 121 | Popular Tags |