com.crispico.flower.mp.communication.dialog.TextDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.crispico.flower.mp.communication.dialog.TextDialog.java

Source

/* license-start
 * 
 * Copyright (C) 2008 - 2013 Crispico, <http://www.crispico.com/>.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 3.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details, at <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *   Crispico - Initial API and implementation
 *
 * license-end
 */
package com.crispico.flower.mp.communication.dialog;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TextDialog extends Dialog {

    /**
     * Our imposed height.
     */
    private final int HEIGHT = 500;

    /**
     * Our imposed width.
     */
    private final int WIDTH = 500;

    public Text textarea;

    private String message;

    private String title;

    public TextDialog(Shell parentShell, String title, String message) {
        super(parentShell);
        this.message = message;
        this.title = title;
        setShellStyle(getShellStyle() | SWT.CENTER | SWT.RESIZE);
    }

    protected void createButtonsForButtonBar(Composite parent) {
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    }

    /**
     * Override to impose our dimensions.
     */
    @Override
    protected Point getInitialSize() {
        return new Point(WIDTH, HEIGHT);
    }

    /**
     * Creates the dialog components like the browser and the check option.
     */
    @Override
    protected Control createDialogArea(Composite parent) {
        Composite composite = (Composite) super.createDialogArea(parent);

        getShell().setText(title);

        textarea = new Text(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
        GridData gridData = new GridData(GridData.FILL_BOTH);
        textarea.setLayoutData(gridData);
        textarea.setEditable(false);
        textarea.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));

        textarea.setText(message);

        return composite;
    }

}