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     */
021    package csheets;
022    
023    import java.io.File;
024    import java.util.EventObject;
025    
026    import csheets.core.Workbook;
027    
028    /**
029     * A spreadsheet application event is used to notify interested parties that
030     * a workbook has been created, loaded or stored. The event provides
031     * information about the workbook in which the event occurred, and about
032     * the file in which it is stored, if any.
033     * @author Einar Pehrson
034     */
035    public class SpreadsheetAppEvent extends EventObject {
036    
037            /** The serialVersionUID of the SpreadsheetAppEvent.java */
038            private static final long serialVersionUID = -8589956625032669055L;
039    
040            /** The types of events that are fired from a spreadsheet application */
041            public enum Type {
042    
043                    /** Denotes that a workbook was created */
044                    CREATED,
045    
046                    /** Denotes that a workbook was loaded */
047                    LOADED,
048    
049                    /** Denotes that a workbook was unloaded */
050                    UNLOADED,
051    
052                    /** Denotes that a workbook was saved */
053                    SAVED,
054            }
055    
056            /** The workbook that was affected. */
057            private Workbook workbook;
058    
059            /** The file in which the project is stored. */
060            private File file;
061    
062            /** The type of the event */
063            private Type type;
064    
065            /**
066             * Creates a new spreadsheet application event,
067             * belonging to a workbook stored in a file.
068             * @param source the source of the event
069             * @param workbook the workbook that was affected
070             * @param file the file in which the workbook is stored
071             * @param type the type of the event
072             */
073            public SpreadsheetAppEvent(Object source, Workbook workbook,
074                            File file, Type type) {
075                    super(source);
076    
077                    // Stores members
078                    this.workbook = workbook;
079                    this.file = file;
080                    this.type = type;
081            }
082    
083            /**
084             * Returns the workbook that was affected by the event.
085             * @return the affected workbook
086             */
087            public Workbook getWorkbook() {
088                    return workbook;
089            }
090    
091            /**
092             * Returns the file in which the workbook is stored.
093             * @return the file in which the workbook is stored
094             */
095            public File getFile() {
096                    return file;
097            }
098    
099            /**
100             * Returns the type of the event.
101             * @return the type of the event
102             */
103            public Type getType() {
104                    return type;
105            }
106    }