Package org.jampa.gui.aboutcredits

Source Code of org.jampa.gui.aboutcredits.AboutCreditsPage

/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* 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.
*/

package org.jampa.gui.aboutcredits;

import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.about.InstallationPage;
import org.jampa.logging.Log;

public class AboutCreditsPage extends InstallationPage {

  private static final String CREDITS_PATH = "org/jampa/gui/aboutcredits/credits.html"; //$NON-NLS-1$
  private static final String ERROR_TEXT = "Error"; //$NON-NLS-1$
 
  private String _data;
 
  public AboutCreditsPage() {
    loadCredits();
  }
 
  private void loadCredits() {
    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(CREDITS_PATH);
    if (stream != null) {
      StringWriter writer = new StringWriter();
      InputStreamReader streamReader = new InputStreamReader(stream);

      BufferedReader buffer = new BufferedReader(streamReader);
      String line = null;
      try {
        while ( null != (line = buffer.readLine())) {         
          writer.write(line + '\n');                       
        }
       
        _data = writer.toString();
      } catch (IOException e) {
        Log.getInstance(AboutCreditsPage.class).warn("Error while loading credits file: " + e.getStackTrace());
        _data = ERROR_TEXT;
     
    } else {
      Log.getInstance(AboutCreditsPage.class).warn("Credits file not found.");
      _data = ERROR_TEXT;
    }
  }

  @Override
  public void createControl(Composite parent) {
   
    parent.setLayout(new GridLayout(1, false));
   
    Browser browser = new Browser(parent, SWT.BORDER);
    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true))
   
    browser.setText(_data);
   
    browser.addLocationListener(new LocationListener() {
      public void changed(LocationEvent event) {
      }
      public void changing(LocationEvent event) {
        // Cancel default link processing.
        event.doit = false;
       
        try {
          Desktop.getDesktop().browse(new URI(event.location));
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (URISyntaxException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    });   
  }

}
TOP

Related Classes of org.jampa.gui.aboutcredits.AboutCreditsPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.