001/* 002 * Copyright (c) 2005 Einar Pehrson <einar@pehrson.nu>. 003 * 004 * This file is part of 005 * CleanSheets - a spreadsheet application for the Java platform. 006 * 007 * CleanSheets is free software; you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation; either version 2 of the License, or 010 * (at your option) any later version. 011 * 012 * CleanSheets is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with CleanSheets; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 */ 021package csheets.ui.ctrl; 022 023import java.awt.event.ActionEvent; 024import java.awt.event.KeyEvent; 025import java.io.BufferedReader; 026import java.io.IOException; 027import java.io.InputStream; 028import java.io.InputStreamReader; 029 030import javax.swing.ImageIcon; 031import javax.swing.JOptionPane; 032 033import csheets.CleanSheets; 034 035/** 036 * An action for displaying the about window. 037 * @author Einar Pehrson 038 */ 039@SuppressWarnings("serial") 040public class AboutAction extends BaseAction { 041 042 /** The text to display in the about dialog */ 043 private String text; 044 045 /** 046 * Creates a new about action. 047 */ 048 public AboutAction() { 049 InputStream stream = CleanSheets.class.getResourceAsStream( 050 "res/doc/about.txt"); 051 if (stream != null) { 052 // Loads text from file 053 try { 054 BufferedReader br = new BufferedReader(new InputStreamReader(stream)); 055 int availableBytes = stream.available(); 056 char[] chars = new char[availableBytes]; 057 br.read(chars, 0, availableBytes); 058 text = new String(chars); 059 } catch (Exception ex) { 060 text = "An error occurred when loading the text."; 061 } finally { 062 try { 063 stream.close(); 064 } catch (IOException e) {} 065 } 066 } else 067 setEnabled(false); 068 } 069 070 protected String getName() { 071 return "About..."; 072 } 073 074 protected void defineProperties() { 075 putValue(MNEMONIC_KEY, KeyEvent.VK_A); 076 putValue(SMALL_ICON, new ImageIcon(CleanSheets.class.getResource("res/img/about.gif"))); 077 } 078 079 public void actionPerformed(ActionEvent e) { 080 JOptionPane.showMessageDialog(null, 081 text, 082 "About CleanSheets", 083 JOptionPane.INFORMATION_MESSAGE, 084 new ImageIcon(CleanSheets.class.getResource("res/img/sheet.gif"))); 085 } 086}