net.cryptea.view.AboutDialog.java Source code

Java tutorial

Introduction

Here is the source code for net.cryptea.view.AboutDialog.java

Source

/*
 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     York Keyser
 */
package net.cryptea.view;

import java.net.URL;

import net.cryptea.core.CrypTeaConstants;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
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.Button;
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 org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

public class AboutDialog extends Dialog {

    public AboutDialog(Shell shell) {
        super(shell);
    }

    @Override
    protected Control createDialogArea(Composite parent) {

        Composite comp = (Composite) super.createDialogArea(parent);
        comp.setLayout(new GridLayout(2, false));
        comp.setData(new GridData());

        Label image = new Label(comp, SWT.NONE);
        image.setImage(createImage());
        image.setData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_CENTER));

        Label text = new Label(comp, SWT.NONE);
        text.setText("It's time for a tea.\nMatcha beta \nwww.cryptea.net");
        text.setData(new GridData(GridData.FILL_BOTH));

        return parent;

    }

    @Override
    protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
        if (id == IDialogConstants.CANCEL_ID)
            return null;
        return super.createButton(parent, id, label, defaultButton);
    }

    @Override
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("About CrypTea 2014");
    }

    @Override
    protected Point getInitialSize() {
        return new Point(450, 200);
    }

    private Image createImage() {
        Bundle bundle = FrameworkUtil.getBundle(AboutDialog.class);
        URL url = FileLocator.find(bundle, new Path(CrypTeaConstants.Images.CRYPTEA_128), null);
        ImageDescriptor imageDcr = ImageDescriptor.createFromURL(url);
        return imageDcr.createImage();
    }
}