org.eclipse.ui.console.IOConsoleOutputStream Java Examples

The following examples show how to use org.eclipse.ui.console.IOConsoleOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XdsConsole.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
  public void setEncoding(String enc) {
      if (enc != null) {
          // check if the encoding is supported
          try {
              new String(new byte[] { 'z' }, 0, 1, enc); // LSA80 : �����, �� ������� �����? ���� ����� - �� ������ ��� �� �����
              // � �����-������ EncodingUtils � Core?
          } catch (UnsupportedEncodingException e) {
              enc = null;
          }
      }
      encoding = enc;
      synchronized (rgb2streamMap) {
      	for (IOConsoleOutputStream cs : rgb2streamMap.values()) {
      		cs.setEncoding(enc);
      	} 
}
  }
 
Example #2
Source File: XdsConsole.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
  public OutputStream getConsoleStream(ColorStreamType cs) {
      final RGB rgb = cs.getRgb();
      IOConsoleOutputStream stream;
      synchronized (rgb2streamMap) {
      	stream = rgb2streamMap.get(rgb);
      	if (stream == null) {
      		stream = newOutputStream();
      		stream.setEncoding(encoding);
      		rgb2streamMap.put(rgb, stream);
      	}
}
      final IOConsoleOutputStream streamParam = stream;
      Display.getDefault().syncExec(new Runnable(){
	@Override
	public void run() {
		streamParam.setColor(SharedResourceManager.getColor(rgb));
	}
});
      
return stream;
  }
 
Example #3
Source File: XdsConsole.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void outItem(ConsoleTextItem it) {
    if (!isLogFiltered || !it.filterIt) {
        IOConsoleOutputStream str = (IOConsoleOutputStream) getConsoleStream(it.cs);
        if (str != null) {
            try {
                int len = it.line.length() + crlf.length();
                if (it.link != null) {
                    alLinkInfo.add(new LinkInfo(it.link, printedSize.get(), printedSize.get() + len));
                }
                printedSize.addAndGet(len); 
                str.write(it.line);
                str.write(crlf);
            } catch (Exception e) {
                LogHelper.logError(e);
            }
        }
    }
}
 
Example #4
Source File: MessageConsoles.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static IOConsoleOutputStream getConsoleOutputStream(String name, String iconPath) {
    synchronized (lock) {
        IOConsoleOutputStream outputStream = consoleOutputs.get(name);
        if (outputStream == null) {
            MessageConsole console = getConsole(name, iconPath);

            HashMap<IOConsoleOutputStream, String> themeConsoleStreamToColor = new HashMap<IOConsoleOutputStream, String>();
            outputStream = console.newOutputStream();
            themeConsoleStreamToColor.put(outputStream, "console.output");
            console.setAttribute("themeConsoleStreamToColor", themeConsoleStreamToColor);
            ConsoleColorCache.getDefault().keepConsoleColorsSynched(console);
            consoles.put(name, console);
            consoleOutputs.put(name, outputStream);
        }
        return outputStream;
    }
}
 
Example #5
Source File: ConsoleThemer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * applyTheme
 * 
 * @param name
 * @param stream
 * @param defaultColor
 * @return
 */
private void applyTheme(String name, IOConsoleOutputStream stream, Color defaultColor)
{
	Theme theme = ThemePlugin.getDefault().getThemeManager().getCurrentTheme();
	Color color = defaultColor;
	int style = SWT.NONE;

	// grab theme values, if they exist
	if (theme.hasEntry(name))
	{
		TextAttribute attr = theme.getTextAttribute(name);

		color = theme.getForeground(name);
		style = attr.getStyle();
	}

	// apply new values
	stream.setColor(color);
	stream.setFontStyle(style);
}
 
Example #6
Source File: EmacsPlusConsole.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
protected void printMessage(String message, Color c, int style) {

		if (message != null) {
			IOConsoleOutputStream outputStream = getOutputStream();
			outputStream.setActivateOnWrite(true);
			if (c != null) {
				outputStream.setColor(c);
			}
			outputStream.setFontStyle(style);
			try {
				outputStream.write(message);
				outputStream.flush();
				outputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
 
Example #7
Source File: FormulaConsoleAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
	console.activate();
	IOConsoleOutputStream out = console.newOutputStream();
	IOConsoleOutputStream err = console.newOutputStream();
	Repl repl = new Repl(console.getInputStream(),
			new PrintStream(out), new PrintStream(err));
	repl.start();
	return Status.OK_STATUS;
}
 
Example #8
Source File: FileConsoleMonitorThread.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public FileConsoleMonitorThread(String consoleName, File inputFile, IOConsoleOutputStream output) {

		this.inputFile = inputFile;
		this.output = output;

		setPriority(Thread.MIN_PRIORITY + 1);
		setDaemon(true);
		setName(consoleName + " MonitorThread"); //$NON-NLS-1$
	}
 
Example #9
Source File: Py2To3.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected int doActionOnResource(IResource next, IProgressMonitor monitor) {
    this.refresh = new ArrayList<IContainer>();
    AbstractRunner runner = UniversalRunner.getRunner(natureUsed);
    if (next instanceof IContainer) {
        this.refresh.add((IContainer) next);
    } else {
        this.refresh.add(next.getParent());
    }

    String dir = next.getLocation().toOSString();
    File workingDir = new File(dir);
    if (!workingDir.exists()) {
        Log.log("Received file that does not exist for 2to3: " + workingDir);
        return 0;
    }
    if (!workingDir.isDirectory()) {
        workingDir = workingDir.getParentFile();
        if (!workingDir.isDirectory()) {
            Log.log("Unable to find working dir for 2to3. Found invalid: " + workingDir);
            return 0;
        }
    }
    ArrayList<String> parametersWithResource = new ArrayList<String>(parameters);
    parametersWithResource.add(0, dir);
    Tuple<String, String> tup = runner.runCodeAndGetOutput(RUN_2_TO_3_CODE,
            parametersWithResource.toArray(new String[0]), workingDir, monitor);
    IOConsoleOutputStream out = MessageConsoles.getConsoleOutputStream("2To3", UIConstants.PY_INTERPRETER_ICON);
    try {
        out.write(tup.o1);
        out.write("\n");
        out.write(tup.o2);
    } catch (IOException e) {
        Log.log(e);
    }
    return 1;
}
 
Example #10
Source File: JythonPlugin.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new Python interpreter (with jython) and returns it.
 *
 * Note that if the sys is not shared, clients should be in a Thread for it to be really separate).
 */
public static IPythonInterpreter newPythonInterpreter(boolean redirect, boolean shareSys) {
    setupJython(); //Important: setup the pythonpath for the jython process.

    IPythonInterpreter interpreter;
    if (shareSys) {
        interpreter = new PythonInterpreterWrapper();
    } else {
        interpreter = new PythonInterpreterWrapperNotShared();
    }
    if (redirect) {
        interpreter.setOut(new ScriptOutput(new ICallback0<IOConsoleOutputStream>() {

            @Override
            public IOConsoleOutputStream call() {
                getConsole(); //Just to make sure it's initialized.
                return fOutputStream;
            }
        }));

        interpreter.setErr(new ScriptOutput(new ICallback0<IOConsoleOutputStream>() {

            @Override
            public IOConsoleOutputStream call() {
                getConsole(); //Just to make sure it's initialized.
                return fErrorStream;
            }
        }));
    } else {
        interpreter.setErr(NullOutputStream.singleton);
        interpreter.setOut(NullOutputStream.singleton);
    }
    return interpreter;
}
 
Example #11
Source File: ScriptOutput.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * OutputStream interface
 */
@Override
public void write(int b) throws IOException {
    if (writeToConsole) {
        IOConsoleOutputStream out = getOutputStream();
        out.write(b);
    }
}
 
Example #12
Source File: ScriptOutput.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor - Uses the properties from the JyScriptingPreferencesPage to know if we should write to
 * the console or not
 * 
 * @param color the color of the output written
 */
public ScriptOutput(ICallback0<IOConsoleOutputStream> outputStream) {
    this(outputStream, JyScriptingPreferencesPage.getShowScriptingOutput());
    IPropertyChangeListener listener = new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            writeToConsole = JyScriptingPreferencesPage.getShowScriptingOutput();
        }
    };
    JythonPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(listener);
}
 
Example #13
Source File: ConsoleThemePageParticipant.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public void init(IPageBookViewPage page, IConsole console)
{
	if (console instanceof TextConsole)
	{
		TextConsole textConsole = (TextConsole) console;
		Object themeConsoleStreamToColor = textConsole.getAttribute(THEME_CONSOLE_STREAM_TO_COLOR_ATTRIBUTE);
		if (themeConsoleStreamToColor instanceof Map<?, ?>)
		{
			Map m = (Map) themeConsoleStreamToColor;
			Set<Map.Entry> entrySet = m.entrySet();
			for (Map.Entry entry : entrySet)
			{
				if (!(entry.getKey() instanceof IOConsoleOutputStream) || !(entry.getValue() instanceof String))
				{
					return; // Cannot handle it.
				}
			}
			this.extension = new ConsoleThemer(textConsole, (Map) themeConsoleStreamToColor);
		}
		if (page instanceof TextConsolePage)
		{
			TextConsolePage tcp = (TextConsolePage) page;
			TextViewerThemer themer = new TextViewerThemer(tcp.getViewer());
			themer.apply();
		}
	}
	this.page = page;
}
 
Example #14
Source File: EmacsPlusConsole.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
private IOConsoleOutputStream getOutputStream() {
	return newOutputStream();			
}
 
Example #15
Source File: RuntimeConsoleUtil.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
public static IOConsoleOutputStream getOutputStream() {
    IOConsoleOutputStream outputStream = findConsole().newOutputStream();
    outputStream.setEncoding(System.getProperty("sun.jnu.encoding", "UTF-8"));
    return outputStream;
}
 
Example #16
Source File: ConsoleThemer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * applyTheme
 */
private void applyTheme()
{
	IWorkbench workbench = null;

	try
	{
		workbench = PlatformUI.getWorkbench();
	}
	catch (IllegalStateException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}

	if (workbench != null)
	{
		final Display display = workbench.getDisplay();

		display.syncExec(new Runnable()
		{
			@SuppressWarnings("unchecked")
			public void run()
			{
				// set colors
				ThemePlugin plugin = ThemePlugin.getDefault();
				ColorManager colorManager = plugin.getColorManager();
				Theme theme = plugin.getThemeManager().getCurrentTheme();

				// set background color
				// NOTE: we have to force the background color to change; otherwise, even
				// with a forced redraw, the background will not be drawn
				fConsole.setBackground(null);
				fConsole.setBackground(colorManager.getColor(theme.getBackground()));

				// set default stream colors
				// Note that some colors are repeated because they're used in different scenarios.
				HashMap<String, Color> colorNameToDefault = new HashMap<String, Color>();
				Color blue = display.getSystemColor(SWT.COLOR_DARK_BLUE);
				Color green = display.getSystemColor(SWT.COLOR_DARK_GREEN);
				Color yellow = display.getSystemColor(SWT.COLOR_DARK_YELLOW);
				Color red = display.getSystemColor(SWT.COLOR_DARK_RED);

				colorNameToDefault.put(CONSOLE_ERROR, red);

				// Info is the same as input color
				colorNameToDefault.put(CONSOLE_INFO, green);
				colorNameToDefault.put(CONSOLE_INPUT, green);

				// For CONSOLE_OUTPUT stream we should use the foreground color of the theme
				colorNameToDefault.put(CONSOLE_OUTPUT, colorManager.getColor(theme.getForeground()));

				// Prompt is the same as trace color.
				colorNameToDefault.put(CONSOLE_PROMPT, blue);
				colorNameToDefault.put(CONSOLE_TRACE, blue);
				colorNameToDefault.put(CONSOLE_WARNING, yellow);

				Set<Map.Entry> entrySet = fThemeConsoleStreamToColor.entrySet();
				for (Map.Entry entry : entrySet)
				{
					if (entry.getValue() instanceof String && entry.getKey() instanceof IOConsoleOutputStream)
					{
						String colorName = (String) entry.getValue();
						IOConsoleOutputStream stream = (IOConsoleOutputStream) entry.getKey();
						applyTheme(colorName, stream, colorNameToDefault.get(colorName));
					}
				}

				refresh();
			}

		});
	}
}
 
Example #17
Source File: ScriptOutput.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @return the output stream to use
 */
private IOConsoleOutputStream getOutputStream() throws MalformedURLException {
    return out.call();
}
 
Example #18
Source File: LogViewerConsole.java    From LogViewer with Eclipse Public License 2.0 4 votes vote down vote up
public IOConsoleOutputStream getOutStream() {
	if (outStream == null)
		outStream = newOutputStream();
	return outStream;
}
 
Example #19
Source File: LogViewer.java    From LogViewer with Eclipse Public License 2.0 4 votes vote down vote up
public IOConsoleOutputStream getConsoleStream() {
    if (console == null)
        createConsole();
    return console.getOutStream();
}
 
Example #20
Source File: FindBugs2Eclipse.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("boxing")
private void reportExtraData(AnalysisData data) {
    SortedBugCollection bugCollection = reporter.getBugCollection();
    if (bugCollection == null) {
        return;
    }
    if (FindBugsConsole.getConsole() == null) {
        return;
    }
    IOConsoleOutputStream out = FindBugsConsole.getConsole().newOutputStream();
    PrintWriter pw = new PrintWriter(out);

    ProjectStats stats = bugCollection.getProjectStats();
    Footprint footprint = new Footprint(stats.getBaseFootprint());
    Profiler profiler = stats.getProfiler();
    Profile profile = profiler.getProfile(ClassDataAnalysisEngine.class);
    long totalClassReadTime = TimeUnit.MILLISECONDS.convert(profile.getTotalTime(), TimeUnit.NANOSECONDS);
    long totalTime = TimeUnit.MILLISECONDS.convert(footprint.getClockTime(), TimeUnit.MILLISECONDS);

    double classReadSpeed = totalClassReadTime > 0 ? data.byteSize * 1000.0 / totalClassReadTime : 0;
    double classCountSpeed = totalTime > 0 ? data.classCount * 1000.0 / totalTime : 0;
    double classPart = totalTime > 0 ? totalClassReadTime * 100.0 / totalTime : 0;
    double appPart = data.byteSize > 0 ? data.byteSizeApp * 100.0 / data.byteSize : 0;
    double bytesPerClass = data.classCount > 0 ? ((double) data.byteSize) / data.classCount : 0;
    long peakMemory = footprint.getPeakMemory() / (1024 * 1024);
    pw.printf("%n");
    pw.printf("Total bugs            : %1$ 20d %n", stats.getTotalBugs());
    pw.printf("Peak memory (MB)      : %1$ 20d %n", peakMemory);
    pw.printf("Total classes         : %1$ 20d %n", data.classCount);
    pw.printf("Total time (msec)     : %1$ 20d %n", totalTime);
    pw.printf("Class read time (msec): %1$ 20d %n", totalClassReadTime);
    pw.printf("Class read time (%%)   : %1$ 20.0f %n", classPart);
    pw.printf("Total bytes read      : %1$ 20d %n", data.byteSize);
    pw.printf("Application bytes     : %1$ 20d %n", data.byteSizeApp);
    pw.printf("Application bytes (%%) : %1$ 20.0f %n", appPart);
    pw.printf("Avg. bytes per class  : %1$ 20.0f %n", bytesPerClass);
    pw.printf("Analysis class/sec    : %1$ 20.0f %n", classCountSpeed);
    pw.printf("Read     bytes/sec    : %1$ 20.0f %n", classReadSpeed);
    pw.printf("            MB/sec    : %1$ 20.1f %n", classReadSpeed / (1024 * 1024));
    pw.flush();

    pw.close();

}
 
Example #21
Source File: ToolsConsole.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public IOConsoleOutputStreamExt(IOConsoleOutputStream console) {
	this.console = assertNotNull(console);
}
 
Example #22
Source File: ToolsConsole.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public IOConsoleOutputStream console() {
	return console;
}
 
Example #23
Source File: Reporter.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void setReportingStream(IOConsoleOutputStream stream) {
    this.stream = stream;
}
 
Example #24
Source File: ScriptOutput.java    From Pydev with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Constructor - the user is able to define whether he wants to write to the console or not.
 * 
 * @param color the color of the output written
 */
public ScriptOutput(ICallback0<IOConsoleOutputStream> outputStream, boolean writeToConsole) {
    this.writeToConsole = writeToConsole;
    out = outputStream;
}