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
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal.viewers;
13 import java.io.ByteArrayInputStream;
15 import net.sourceforge.phpdt.monitor.ui.IContentViewer;
16 import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.graphics.ImageData;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
29 public class ImageViewer implements IContentViewer {
30 protected Composite rootComp;
31 protected Composite viewerComp;
32 protected Label messageLabel;
35 * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#init(Composite)
37 public void init(Composite parent) {
40 viewerComp = new Composite(parent, SWT.NONE);
41 GridLayout layout = new GridLayout();
42 layout.numColumns = 1;
43 layout.marginHeight = 0;
44 layout.marginWidth = 0;
45 viewerComp.setLayout(layout);
46 GridData data = new GridData(GridData.FILL_BOTH);
47 viewerComp.setLayoutData(data);
49 messageLabel = new Label(viewerComp, SWT.NONE);
50 messageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
54 * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#setContent()
56 public void setContent(byte[] b) {
57 if (b == null || b.length == 0) {
58 messageLabel.setText("<" + MonitorUIPlugin.getResource("%imageViewInvalid") + ">");
64 int len = b.length - 1;
65 while(b[trimFront] == cr || b[trimFront] == lf)
67 while(b[len - trimBack] == cr || b[len - trimBack] == lf)
70 if (trimFront + trimBack > 0) {
72 b = new byte[temp.length - trimBack - trimFront];
73 for(int i = trimFront; i < temp.length - trimBack; i++) {
74 b[i - trimFront] = temp[i];
78 ImageData imgD = new ImageData(new ByteArrayInputStream(b));
79 Image img = new Image(null, imgD);
80 messageLabel.setImage(img);
81 } catch(Exception e) {
82 messageLabel.setText("<" + MonitorUIPlugin.getResource("%imageViewInvalid") + ">");
86 viewerComp.layout(true);
90 * @see net.sourceforge.phpdt.monitor.ui.IContentViewer#dispose()
92 public void dispose() {