inital plugin from webtools project
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.ui / src / net / sourceforge / phpdt / monitor / ui / internal / viewers / ByteViewer.java
1 /**********************************************************************
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal.viewers;
12  
13 import net.sourceforge.phpdt.monitor.core.MonitorCore;
14 import net.sourceforge.phpdt.monitor.ui.IContentViewer;
15 import net.sourceforge.phpdt.monitor.ui.internal.ContextIds;
16
17 import org.eclipse.jface.resource.JFaceResources;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.swt.widgets.Text;
24 import org.eclipse.ui.help.WorkbenchHelp;
25
26 /**
27  * A basic byte viewer.
28  */
29 public class ByteViewer implements IContentViewer {
30         protected Text text;
31         protected Composite comp;
32
33         /* (non-Javadoc)
34          * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#dispose()
35          */
36         public void dispose() {
37                 comp.dispose();
38         }
39
40         /* (non-Javadoc)
41          * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#setContent()
42          */
43         public void setContent(byte[] b) {
44                 String out = "";
45                 if (b != null)
46                         out = MonitorCore.parse(b);
47
48                 String lineSeparator = System.getProperty("line.separator");
49                 int ls = lineSeparator.length();
50                 if (out.length() > ls) {
51                         while (out.substring(0, ls).indexOf(lineSeparator) >= 0)
52                                 out = out.substring(ls, out.length()); 
53                 }
54                 
55                 text.setText(out);
56         }
57
58         /* (non-Javadoc)
59          * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#init(Composite)
60          */
61         public void init(Composite parent) {
62                 comp = new Composite(parent, SWT.NONE);
63                 GridLayout layout = new GridLayout();
64                 layout.numColumns = 1;
65                 layout.marginHeight = 0;
66                 layout.marginWidth = 0;
67                 comp.setLayout(layout);
68                 GridData data = new GridData(GridData.FILL_BOTH);
69                 comp.setLayoutData(data);
70
71                 text = new Text(comp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
72                 Display display = comp.getDisplay();
73                 text.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
74                 text.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
75                 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
76                 text.setFont(JFaceResources.getTextFont());
77                 WorkbenchHelp.setHelp(text, ContextIds.VIEW_RESPONSE);
78         }
79 }