Source Code Cross Referenced for Workbook.java in  » ERP-CRM-Financial » csheets » csheets » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » csheets » csheets.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.core;
022:
023:        import java.io.IOException;
024:        import java.io.ObjectInputStream;
025:        import java.io.Serializable;
026:        import java.util.ArrayList;
027:        import java.util.Iterator;
028:        import java.util.List;
029:
030:        /**
031:         * A workbook which can contain several spreadsheets.
032:         * @author Einar Pehrson
033:         */
034:        public class Workbook implements  Iterable<Spreadsheet>, Serializable {
035:
036:            /** The unique version identifier used for serialization */
037:            private static final long serialVersionUID = -6324252462576447242L;
038:
039:            /** The spreadsheets of which the workbook consists */
040:            private List<Spreadsheet> spreadsheets = new ArrayList<Spreadsheet>();
041:
042:            /** The cell listeners that have been registered on the cell */
043:            private transient List<WorkbookListener> listeners = new ArrayList<WorkbookListener>();
044:
045:            /** The number of spreadsheets that have been created in the workbook */
046:            private int createdSpreadsheets;
047:
048:            /**
049:             * Creates a new empty workbook.
050:             */
051:            public Workbook() {
052:            }
053:
054:            /**
055:             * Creates a new workbook, which initially contains the given number
056:             * of blank spreadsheets.
057:             * @param sheets the number of sheets to create initially
058:             */
059:            public Workbook(int sheets) {
060:                for (int i = 0; i < sheets; i++)
061:                    spreadsheets.add(new SpreadsheetImpl(this ,
062:                            getNextSpreadsheetTitle()));
063:            }
064:
065:            /**
066:             * Creates a new workbook, using the given content matrix to create
067:             * spreadsheets initially.
068:             * @param contents the content matrices to use when creating spreadsheets
069:             */
070:            public Workbook(String[][]... contents) {
071:                for (String[][] content : contents)
072:                    spreadsheets.add(new SpreadsheetImpl(this ,
073:                            getNextSpreadsheetTitle(), content));
074:            }
075:
076:            /**
077:             * Adds a blank spreadsheet to the end of the workbook.
078:             */
079:            public void addSpreadsheet() {
080:                Spreadsheet spreadsheet = new SpreadsheetImpl(this ,
081:                        getNextSpreadsheetTitle());
082:                spreadsheets.add(spreadsheet);
083:                fireSpreadsheetInserted(spreadsheet, spreadsheets.size() - 1);
084:            }
085:
086:            /**
087:             * Adds a new spreadsheet to the workbook, in which cells are initialized
088:             * with data from the given content matrix.
089:             * @param content the contents of the cells in the spreadsheet
090:             */
091:            public void addSpreadsheet(String[][] content) {
092:                Spreadsheet spreadsheet = new SpreadsheetImpl(this ,
093:                        getNextSpreadsheetTitle(), content);
094:                spreadsheets.add(spreadsheet);
095:                fireSpreadsheetInserted(spreadsheet, spreadsheets.size() - 1);
096:            }
097:
098:            /**
099:             * Returns the title to be used for the next spreadsheet added.
100:             * @return the title to be used for the next spreadsheet added
101:             */
102:            private String getNextSpreadsheetTitle() {
103:                return SpreadsheetImpl.BASE_TITLE + " "
104:                        + (createdSpreadsheets++ + 1);
105:            }
106:
107:            /**
108:             * Adds a new blank spreadsheet to the workbook.
109:             */
110:            public void removeSpreadsheet(Spreadsheet spreadsheet) {
111:                spreadsheets.remove(spreadsheet);
112:                // Remove references to the spreadsheet in remaining spreadsheets!
113:                fireSpreadsheetRemoved(spreadsheet);
114:            }
115:
116:            /**
117:             * Returns the spreadsheet at the given index.
118:             * @param index the index of the spreadsheet in the workbook
119:             * @return the spreadsheet at the given index
120:             * @throws IndexOutOfBoundsException if the index is out of range (index < 0 || index >= |spreadsheets|)
121:             */
122:            public Spreadsheet getSpreadsheet(int index)
123:                    throws IndexOutOfBoundsException {
124:                return spreadsheets.get(index);
125:            }
126:
127:            /**
128:             * Returns the number of spreadsheets in the the workbook.
129:             * @return the number of spreadsheets in the the workbook
130:             */
131:            public int getSpreadsheetCount() {
132:                return spreadsheets.size();
133:            }
134:
135:            /**
136:             * Returns an iterator over the spreadsheets in the workbook.
137:             * @return an iterator over the spreadsheets in the workbook
138:             */
139:            public Iterator<Spreadsheet> iterator() {
140:                return spreadsheets.iterator();
141:            }
142:
143:            /*
144:             * EVENT HANDLING
145:             */
146:
147:            /**
148:             * Registers the given listener on the workbook.
149:             * @param listener the listener to be added
150:             */
151:            public void addWorkbookListener(WorkbookListener listener) {
152:                listeners.add(listener);
153:            }
154:
155:            /**
156:             * Removes the given listener from the workbook.
157:             * @param listener the listener to be removed
158:             */
159:            public void removeWorkbookListener(WorkbookListener listener) {
160:                listeners.remove(listener);
161:            }
162:
163:            /**
164:             * Returns the listeners that have been registered on the workbook.
165:             * @return the listeners that have been registered on the workbook
166:             */
167:            public WorkbookListener[] getWorkbookListeners() {
168:                return listeners
169:                        .toArray(new WorkbookListener[listeners.size()]);
170:            }
171:
172:            /**
173:             * Notifies all registered listeners that a spreadsheet has been inserted.
174:             * @param spreadsheet the spreadsheet that was inserted
175:             * @param index the index at which the spreadsheet was inserted
176:             */
177:            private void fireSpreadsheetInserted(Spreadsheet spreadsheet,
178:                    int index) {
179:                for (WorkbookListener listener : listeners)
180:                    listener.spreadsheetInserted(spreadsheet, index);
181:            }
182:
183:            /**
184:             * Notifies all registered listeners that a spreadsheet has been removed.
185:             * @param spreadsheet the spreadsheet that was removed
186:             */
187:            private void fireSpreadsheetRemoved(Spreadsheet spreadsheet) {
188:                for (WorkbookListener listener : listeners)
189:                    listener.spreadsheetRemoved(spreadsheet);
190:            }
191:
192:            /**
193:             * Notifies all registered listeners that a spreadsheet has been renamed.
194:             * @param spreadsheet the spreadsheet that was renamed
195:             */
196:            @SuppressWarnings("unused")
197:            private void fireSpreadsheetRenamed(Spreadsheet spreadsheet) {
198:                for (WorkbookListener listener : listeners)
199:                    listener.spreadsheetRenamed(spreadsheet);
200:            }
201:
202:            /*
203:             * GENERAL
204:             */
205:
206:            /**
207:             * Customizes deserialization by recreating the listener list.
208:             * @param stream the object input stream from which the object is to be read
209:             * @throws IOException If any of the usual Input/Output related exceptions occur
210:             * @throws ClassNotFoundException If the class of a serialized object cannot be found.
211:             */
212:            private void readObject(ObjectInputStream stream)
213:                    throws IOException, ClassNotFoundException {
214:                stream.defaultReadObject();
215:                listeners = new ArrayList<WorkbookListener>();
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.