/********************************************************************** * Copyright (c) 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html  * * Contributors: * IBM - Initial API and implementation **********************************************************************/ package net.sourceforge.phpdt.monitor.ui.internal.viewers; import net.sourceforge.phpdt.monitor.core.MonitorCore; import net.sourceforge.phpdt.monitor.ui.IContentViewer; import net.sourceforge.phpdt.monitor.ui.internal.ContextIds; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.help.WorkbenchHelp; /** * A basic byte viewer. */ public class ByteViewer implements IContentViewer { protected Text text; protected Composite comp; /* (non-Javadoc) * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#dispose() */ public void dispose() { comp.dispose(); } /* (non-Javadoc) * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#setContent() */ public void setContent(byte[] b) { String out = ""; if (b != null) out = MonitorCore.parse(b); String lineSeparator = System.getProperty("line.separator"); int ls = lineSeparator.length(); if (out.length() > ls) { while (out.substring(0, ls).indexOf(lineSeparator) >= 0) out = out.substring(ls, out.length()); } text.setText(out); } /* (non-Javadoc) * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#init(Composite) */ public void init(Composite parent) { comp = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 0; comp.setLayout(layout); GridData data = new GridData(GridData.FILL_BOTH); comp.setLayoutData(data); text = new Text(comp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); Display display = comp.getDisplay(); text.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); text.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); text.setFont(JFaceResources.getTextFont()); WorkbenchHelp.setHelp(text, ContextIds.VIEW_RESPONSE); } }