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.ui.ctrl;
022    
023    import java.util.EventObject;
024    
025    import csheets.core.Cell;
026    import csheets.core.Spreadsheet;
027    import csheets.core.Workbook;
028    
029    /**
030     * A selection application event is used to notify interested parties that
031     * a new active workbook, spreadsheet and/or cell is selected.
032     * @author Einar Pehrson
033     */
034    @SuppressWarnings("serial")
035    public class SelectionEvent extends EventObject {
036    
037            /** The new active workbook */
038            private Workbook workbook;
039    
040            /** The new active spreadsheet. */
041            private Spreadsheet spreadsheet;
042    
043            /** The new active cell. */
044            private Cell cell;
045    
046            /** The previous active workbook (or the same as the new one if it didn't change) */
047            private Workbook prevWorkbook;
048    
049            /** The previous active spreadsheet (or the same as the new one if it didn't change) */
050            private Spreadsheet prevSpreadsheet;
051    
052            /** The previous active cell */
053            private Cell prevCell;
054    
055            /**
056             * Creates a new selection event.
057             * @param source the source of the event
058             * @param workbook the active workbook
059             * @param spreadsheet the active spreadsheet
060             * @param cell the active cell
061             * @param prevWorkbook the previous active workbook (or the same as the new one if it didn't change)
062             * @param prevSpreadsheet the previous active spreadsheet (or the same as the new one if it didn't change)
063             * @param prevCell the previous active cell
064             */
065            public SelectionEvent(Object source,
066                            Workbook workbook, Spreadsheet spreadsheet, Cell cell,
067                            Workbook prevWorkbook, Spreadsheet prevSpreadsheet, Cell prevCell) {
068                    super(source);
069    
070                    // Stores members
071                    this.workbook = workbook;
072                    this.spreadsheet = spreadsheet;
073                    this.cell = cell;
074                    this.prevWorkbook = prevWorkbook;
075                    this.prevSpreadsheet = prevSpreadsheet;
076                    this.prevCell = prevCell;
077            }
078    
079            /**
080             * Returns the active workbook.
081             * @return the active workbook
082             */
083            public Workbook getWorkbook() {
084                    return workbook;
085            }
086    
087            /**
088             * Returns the active spreadsheet.
089             * @return the active spreadsheet
090             */
091            public Spreadsheet getSpreadsheet() {
092                    return spreadsheet;
093            }
094    
095            /**
096             * Returns the active cell.
097             * @return the active cell
098             */
099            public Cell getCell() {
100                    return cell;
101            }
102    
103            /**
104             * Returns the previous active workbook.
105             * @return the previous active workbook (or the same as the new one if it didn't change)
106             */
107            public Workbook getPreviousWorkbook() {
108                    return prevWorkbook;
109            }
110    
111            /**
112             * Returns the previous active spreadsheet.
113             * @return the previous active spreadsheet (or the same as the new one if it didn't change)
114             */
115            public Spreadsheet getPreviousSpreadsheet() {
116                    return prevSpreadsheet;
117            }
118    
119            /**
120             * Returns the previous active cell.
121             * @return the previous active cell
122             */
123            public Cell getPreviousCell() {
124                    return prevCell;
125            }
126    
127            /**
128             * Returns whether the event was caused by the active workbook being changed
129             * @return true if the active workbook and the previous active workbook are not the same
130             */
131            public boolean isWorkbookChanged() {
132                    return workbook != prevWorkbook;
133            }
134    
135            /**
136             * Returns whether the event was caused by the active spreadsheet being changed
137             * @return true if the active spreadsheet and the previous active spreadsheet are not the same
138             */
139            public boolean isSpreadsheetChanged() {
140                    return spreadsheet != prevSpreadsheet;
141            }
142    
143            /**
144             * Returns whether the event was caused by the active cell being changed
145             * @return true if the active cell and the previous active cell are not the same
146             */
147            public boolean isCellChanged() {
148                    return cell != prevCell;
149            }
150    }