/******************************************************************************* * Copyright (c) 2013 hangum. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * hangum - initial API and implementation ******************************************************************************/ package com.hangum.tadpole.commons.dialogs.message; import java.io.InputStream; import org.apache.log4j.Logger; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import com.hangum.tadpole.commons.Messages; import com.hangum.tadpole.commons.google.analytics.AnalyticCaller; import com.hangum.tadpole.commons.libs.core.message.CommonMessages; import com.hangum.tadpole.commons.util.GlobalImageUtils; /** * tadpole message dialog * * @author nilriri * */ public class TadpoleImageViewDialog extends TitleAreaDialog { private static final Logger logger = Logger.getLogger(TadpoleImageViewDialog.class); private String title; private InputStream stream; /** * Create the dialog. * * @param parentShell */ public TadpoleImageViewDialog(Shell parentShell, String title, InputStream stream) { super(parentShell); setShellStyle(SWT.MAX | SWT.RESIZE | SWT.TITLE | SWT.APPLICATION_MODAL); this.title = title; this.stream = stream; } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.get().ImageViewer); newShell.setImage(GlobalImageUtils.getTadpoleIcon()); } /** * Create contents of the dialog. * * @param parent */ @Override protected Control createDialogArea(Composite parent) { setMessage(title); setTitle(Messages.get().ImageViewer); Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); ScrolledComposite scrolledComposite = new ScrolledComposite(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setExpandVertical(true); Label labelImage = new Label(scrolledComposite, SWT.CENTER); Image image = new Image(labelImage.getDisplay(), stream); labelImage.setImage(image); scrolledComposite.setContent(labelImage); scrolledComposite.setMinSize(labelImage.computeSize(SWT.DEFAULT, SWT.DEFAULT)); // google analytic AnalyticCaller.track(this.getClass().getName()); return area; } /** * Create contents of the button bar. * * @param parent */ @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, CommonMessages.get().Close, true); //$NON-NLS-1$ } /** * Return the initial size of the dialog. */ @Override protected Point getInitialSize() { return new Point(450, 422); } }