Java tutorial
/************************************************************************************************* * Copyright (c) 2013, Lex @ le boxon de Lex: http://le-boxon-de-lex.fr * * 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; either * version 3 of the License, or (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License along with this program; * if not, see <http://www.gnu.org/licenses>. * * Additional permission under GNU GPL version 3 section 7 * * If you modify this Program, or any covered work, by linking or combining it with Eclipse (or * a modified version of that library), containing parts covered by the terms of Eclipse Public * License (EPL), the licensors of this Program grant you additional permission to convey the * resulting work. Corresponding Source for a non-source form of such a combination shall include * the source code for the parts of D'Aplomb used as well as that of the covered work. ***************************************************************************************************/ package net.leboxondelex.daplomb.ui.dialogs; import java.io.InputStream; import java.net.URI; import java.util.Properties; import net.leboxondelex.daplomb.Activator; import net.leboxondelex.daplomb.translations.Messages; import net.leboxondelex.daplomb.utils.IoUtils; import net.leboxondelex.daplomb.utils.LogUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; /** * @author Lex */ public class AboutDialog extends Dialog { private static final String PRODUCT_VERSION = "version"; //$NON-NLS-1$ private static final String PRODUCT_VERSION_QUALIFIER = "version.qualifier"; //$NON-NLS-1$ private static final String BUILD_QUALIFIER = "build.qualifier"; //$NON-NLS-1$ /** * Constructor. * @param parentShell */ public AboutDialog(Shell parentShell) { super(parentShell); } /* * (non-Javadoc) * @see org.eclipse.jface.dialogs.TitleAreaDialog * #createDialogArea(org.eclipse.swt.widgets.Composite) */ @Override protected Control createDialogArea(Composite parent) { Composite control = (Composite) super.createDialogArea(parent); ((GridLayout) control.getLayout()).numColumns = 2; control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); parent.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); parent.getShell().setText(Messages.getString("AboutHandler.3")); //$NON-NLS-1$ Label l = new Label(control, SWT.NONE); l.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); StringBuilder sb = new StringBuilder(); sb.append(Messages.getString("ApplicationUI.0")); //$NON-NLS-1$ sb.append("\n\n"); //$NON-NLS-1$ Properties properties = parseProductProperties(); String productVersion = properties.getProperty(PRODUCT_VERSION, ""); //$NON-NLS-1$ String productVersionQualifier = properties.getProperty(PRODUCT_VERSION_QUALIFIER, ""); //$NON-NLS-1$ String buildQualifier = properties.getProperty(BUILD_QUALIFIER, ""); //$NON-NLS-1$ sb.append("Version : "); //$NON-NLS-1$ sb.append(productVersion); sb.append(" "); //$NON-NLS-1$ sb.append(productVersionQualifier); sb.append("\nBuild ID : "); //$NON-NLS-1$ sb.append(buildQualifier); sb.append("\n\n"); //$NON-NLS-1$ sb.append(Messages.getString("AboutHandler.13")); //$NON-NLS-1$ sb.append("\n"); //$NON-NLS-1$ sb.append(Messages.getString("AboutHandler.14")); //$NON-NLS-1$ sb.append("\n\n"); //$NON-NLS-1$ sb.append(Messages.getString("AboutHandler.16")); //$NON-NLS-1$ sb.append(Messages.getString("AboutHandler.17")); //$NON-NLS-1$ sb.append(Messages.getString("AboutHandler.18")); //$NON-NLS-1$ sb.append("\n\n"); //$NON-NLS-1$ sb.append("Copyright (c) 2013 - Lex - http://le-boxon-de-lex.fr"); //$NON-NLS-1$ l = new Label(control, SWT.WRAP); l.setText(sb.toString()); l.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); GridDataFactory.swtDefaults().hint(450, SWT.DEFAULT).applyTo(l); return control; } /* * (non-Javadoc) * @see org.eclipse.jface.dialogs.Dialog * #createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ @Override protected void createButtonsForButtonBar(Composite parent) { parent.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); }; /** * Parses the product properties. * @return the properties (not null) */ private Properties parseProductProperties() { Properties properties = new Properties(); InputStream is = null; try { URI uri = new URI("platform:/plugin/" + Activator.PLUGIN_ID + "/build.id.properties"); //$NON-NLS-1$ //$NON-NLS-2$ is = uri.toURL().openStream(); properties.load(is); } catch (Exception e) { LogUtils.log("Error while loading the product's properties.", e); //$NON-NLS-1$ } finally { IoUtils.closeQuietly(is); } return properties; } }