KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > SheetSettings


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl;
21
22 import common.Assert;
23
24 import jxl.format.PageOrientation;
25 import jxl.format.PaperSize;
26
27 /**
28  * This is a bean which client applications may use to get/set various
29  * properties which are associated with a particular worksheet, such
30  * as headers and footers, page orientation etc.
31  */

32 public final class SheetSettings
33 {
34   /**
35    * The page orientation
36    */

37   private PageOrientation orientation;
38
39   /**
40    * The paper size for printing
41    */

42   private PaperSize paperSize;
43
44   /**
45    * Indicates whether or not this sheet is protected
46    */

47   private boolean sheetProtected;
48
49   /**
50    * Indicates whether or not this sheet is hidden
51    */

52   private boolean hidden;
53
54   /**
55    * Indicates whether or not this sheet is selected
56    */

57   private boolean selected;
58
59   /**
60    * The header
61    */

62   private HeaderFooter header;
63
64   /**
65    * The margin allocated for any page headers, in inches
66    */

67   private double headerMargin;
68
69   /**
70    * The footer
71    */

72   private HeaderFooter footer;
73
74   /**
75    * The margin allocated for any page footers, in inches
76    */

77   private double footerMargin;
78
79   /**
80    * The scale factor used when printing
81    */

82   private int scaleFactor;
83
84   /**
85    * The zoom factor used when viewing. Note the difference between
86    * this and the scaleFactor which is used when printing
87    */

88   private int zoomFactor;
89
90   /**
91    * The page number at which to commence printing
92    */

93   private int pageStart;
94
95   /**
96    * The number of pages into which this excel sheet is squeezed widthwise
97    */

98   private int fitWidth;
99
100   /**
101    * The number of pages into which this excel sheet is squeezed heightwise
102    */

103   private int fitHeight;
104
105   /**
106    * The horizontal print resolution
107    */

108   private int horizontalPrintResolution;
109
110   /**
111    * The vertical print resolution
112    */

113   private int verticalPrintResolution;
114
115   /**
116    * The margin from the left hand side of the paper in inches
117    */

118   private double leftMargin;
119
120   /**
121    * The margin from the right hand side of the paper in inches
122    */

123   private double rightMargin;
124
125   /**
126    * The margin from the top of the paper in inches
127    */

128   private double topMargin;
129
130   /**
131    * The margin from the bottom of the paper in inches
132    */

133   private double bottomMargin;
134
135   /**
136    * Indicates whether to fit the print to the pages or scale the output
137    * This field is manipulated indirectly by virtue of the setFitWidth/Height
138    * methods
139    */

140   private boolean fitToPages;
141
142   /**
143    * Indicates whether grid lines should be displayed
144    */

145   private boolean showGridLines;
146
147   /**
148    * Indicates whether grid lines should be printed
149    */

150   private boolean printGridLines;
151
152   /**
153    * Indicates whether sheet headings should be printed
154    */

155   private boolean printHeaders;
156
157   /**
158    * Indicates whether the sheet should display zero values
159    */

160   private boolean displayZeroValues;
161
162   /**
163    * The password for protected sheets
164    */

165   private String JavaDoc password;
166
167   /**
168    * The password hashcode - used when copying sheets
169    */

170   private int passwordHash;
171
172   /**
173    * The default column width, in characters
174    */

175   private int defaultColumnWidth;
176
177   /**
178    * The default row height, in 1/20th of a point
179    */

180   private int defaultRowHeight;
181
182   /**
183    * The horizontal freeze pane
184    */

185   private int horizontalFreeze;
186
187   /**
188    * The vertical freeze position
189    */

190   private int verticalFreeze;
191
192   /**
193    * The number of copies to print
194    */

195   private int copies;
196
197   // ***
198
// The defaults
199
// **
200
private static final PageOrientation defaultOrientation =
201     PageOrientation.PORTRAIT;
202   private static final PaperSize defaultPaperSize = PaperSize.A4;
203   private static final double defaultHeaderMargin = 0.5;
204   private static final double defaultFooterMargin = 0.5;
205   private static final int defaultPrintResolution = 0x12c;
206   private static final double defaultWidthMargin = 0.75;
207   private static final double defaultHeightMargin = 1;
208
209   private static final int defaultDefaultColumnWidth = 8;
210   private static final int defaultZoomFactor = 100;
211
212   // The publicly accessible values
213
/**
214    * The default value for the default row height
215    */

216   public static final int DEFAULT_DEFAULT_ROW_HEIGHT = 0xff;
217
218   /**
219    * Default constructor
220    */

221   public SheetSettings()
222   {
223     orientation = defaultOrientation;
224     paperSize = defaultPaperSize;
225     sheetProtected = false;
226     hidden = false;
227     selected = false;
228     headerMargin = defaultHeaderMargin;
229     footerMargin = defaultFooterMargin;
230     horizontalPrintResolution = defaultPrintResolution;
231     verticalPrintResolution = defaultPrintResolution;
232     leftMargin = defaultWidthMargin;
233     rightMargin = defaultWidthMargin;
234     topMargin = defaultHeightMargin;
235     bottomMargin = defaultHeightMargin;
236     fitToPages = false;
237     showGridLines = true;
238     printGridLines = false;
239     printHeaders = false;
240     displayZeroValues = true;
241     defaultColumnWidth = defaultDefaultColumnWidth;
242     defaultRowHeight = DEFAULT_DEFAULT_ROW_HEIGHT;
243     zoomFactor = defaultZoomFactor;
244     horizontalFreeze = 0;
245     verticalFreeze = 0;
246     copies = 1;
247     header = new HeaderFooter();
248     footer = new HeaderFooter();
249   }
250
251   /**
252    * Copy constructor. Called when copying sheets
253    * @param copy the settings to copy
254    */

255   public SheetSettings(SheetSettings copy)
256   {
257     Assert.verify(copy != null);
258
259     orientation = copy.orientation;
260     paperSize = copy.paperSize;
261     sheetProtected = copy.sheetProtected;
262     hidden = copy.hidden;
263     selected = false; // don't copy the selected flag
264
headerMargin = copy.headerMargin;
265     footerMargin = copy.footerMargin;
266     scaleFactor = copy.scaleFactor;
267     pageStart = copy.pageStart;
268     fitWidth = copy.fitWidth;
269     fitHeight = copy.fitHeight;
270     horizontalPrintResolution = copy.horizontalPrintResolution;
271     verticalPrintResolution = copy.verticalPrintResolution;
272     leftMargin = copy.leftMargin;
273     rightMargin = copy.rightMargin;
274     topMargin = copy.topMargin;
275     bottomMargin = copy.bottomMargin;
276     fitToPages = copy.fitToPages;
277     password = copy.password;
278     passwordHash = copy.passwordHash;
279     defaultColumnWidth = copy.defaultColumnWidth;
280     defaultRowHeight = copy.defaultRowHeight;
281     zoomFactor = copy.zoomFactor;
282     showGridLines = copy.showGridLines;
283     displayZeroValues = copy.displayZeroValues;
284     horizontalFreeze = copy.horizontalFreeze;
285     verticalFreeze = copy.verticalFreeze;
286     copies = copy.copies;
287     header = new HeaderFooter(copy.header);
288     footer = new HeaderFooter(copy.footer);
289   }
290
291   /**
292    * Sets the paper orientation for printing this sheet
293    *
294    * @param po the orientation
295    */

296   public void setOrientation(PageOrientation po)
297   {
298     orientation = po;
299   }
300
301   /**
302    * Accessor for the orientation
303    *
304    * @return the orientation
305    */

306   public PageOrientation getOrientation()
307   {
308     return orientation;
309   }
310
311   /**
312    * Sets the paper size to be used when printing this sheet
313    *
314    * @param ps the paper size
315    */

316   public void setPaperSize(PaperSize ps)
317   {
318     paperSize = ps;
319   }
320
321   /**
322    * Accessor for the paper size
323    *
324    * @return the paper size
325    */

326   public PaperSize getPaperSize()
327   {
328     return paperSize;
329   }
330
331   /**
332    * Queries whether this sheet is protected (ie. read only)
333    *
334    * @return TRUE if this sheet is read only, FALSE otherwise
335    */

336   public boolean isProtected()
337   {
338     return sheetProtected;
339   }
340
341   /**
342    * Sets the protected (ie. read only) status of this sheet
343    *
344    * @param p the protected status
345    */

346   public void setProtected(boolean p)
347   {
348     sheetProtected = p;
349   }
350
351   /**
352    * Sets the margin for any page headers
353    *
354    * @param d the margin in inches
355    */

356   public void setHeaderMargin(double d)
357   {
358     headerMargin = d;
359   }
360
361   /**
362    * Accessor for the header margin
363    *
364    * @return the header margin
365    */

366   public double getHeaderMargin()
367   {
368     return headerMargin;
369   }
370
371   /**
372    * Sets the margin for any page footer
373    *
374    * @param d the footer margin in inches
375    */

376   public void setFooterMargin(double d)
377   {
378     footerMargin = d;
379   }
380
381   /**
382    * Accessor for the footer margin
383    *
384    * @return the footer margin
385    */

386   public double getFooterMargin()
387   {
388     return footerMargin;
389   }
390
391   /**
392    * Sets the hidden status of this worksheet
393    *
394    * @param h the hidden flag
395    */

396   public void setHidden(boolean h)
397   {
398     hidden = h;
399   }
400
401   /**
402    * Accessor for the hidden nature of this sheet
403    *
404    * @return TRUE if this sheet is hidden, FALSE otherwise
405    */

406   public boolean isHidden()
407   {
408     return hidden;
409   }
410
411   /**
412    * Sets this sheet to be when it is opened in excel
413    *
414    * @deprecated use overloaded version which takes a boolean
415    */

416   public void setSelected()
417   {
418     setSelected(true);
419   }
420
421   /**
422    * Sets this sheet to be when it is opened in excel
423    *
424    * @param s sets whether this sheet is selected or not
425    */

426   public void setSelected(boolean s)
427   {
428     selected = s;
429   }
430
431   /**
432    * Accessor for the selected nature of the sheet
433    *
434    * @return TRUE if this sheet is selected, FALSE otherwise
435    */

436   public boolean isSelected()
437   {
438     return selected;
439   }
440
441   /**
442    * Sets the scale factor for this sheet to be used when printing. The
443    * parameter is a percentage, therefore setting a scale factor of 100 will
444    * print at normal size, 50 half size, 200 double size etc
445    *
446    * @param sf the scale factor as a percentage
447    */

448   public void setScaleFactor(int sf)
449   {
450     scaleFactor = sf;
451     fitToPages = false;
452   }
453
454   /**
455    * Accessor for the scale factor
456    *
457    * @return the scale factor
458    */

459   public int getScaleFactor()
460   {
461     return scaleFactor;
462   }
463
464   /**
465    * Sets the page number at which to commence printing
466    *
467    * @param ps the page start number
468    */

469   public void setPageStart(int ps)
470   {
471     pageStart = ps;
472   }
473
474   /**
475    * Accessor for the page start
476    *
477    * @return the page start
478    */

479   public int getPageStart()
480   {
481     return pageStart;
482   }
483
484   /**
485    * Sets the number of pages widthwise which this sheet should be
486    * printed into
487    *
488    * @param fw the number of pages
489    */

490   public void setFitWidth(int fw)
491   {
492     fitWidth = fw;
493     fitToPages = true;
494   }
495
496   /**
497    * Accessor for the fit width
498    *
499    * @return the number of pages this sheet will be printed into widthwise
500    */

501   public int getFitWidth()
502   {
503     return fitWidth;
504   }
505
506   /**
507    * Sets the number of pages vertically that this sheet will be printed into
508    *
509    * @param fh the number of pages this sheet will be printed into heightwise
510    */

511   public void setFitHeight(int fh)
512   {
513     fitHeight = fh;
514     fitToPages = true;
515   }
516
517   /**
518    * Accessor for the fit height
519    *
520    * @return the number of pages this sheet will be printed into heightwise
521    */

522   public int getFitHeight()
523   {
524     return fitHeight;
525   }
526
527   /**
528    * Sets the horizontal print resolution
529    *
530    * @param hpw the print resolution
531    */

532   public void setHorizontalPrintResolution(int hpw)
533   {
534     horizontalPrintResolution = hpw;
535   }
536
537   /**
538    * Accessor for the horizontal print resolution
539    *
540    * @return the horizontal print resolution
541    */

542   public int getHorizontalPrintResolution()
543   {
544     return horizontalPrintResolution;
545   }
546
547   /**
548    * Sets the vertical print reslution
549    *
550    * @param vpw the vertical print resolution
551    */

552   public void setVerticalPrintResolution(int vpw)
553   {
554     verticalPrintResolution = vpw;
555   }
556
557   /**
558    * Accessor for the vertical print resolution
559    *
560    * @return the vertical print resolution
561    */

562   public int getVerticalPrintResolution()
563   {
564     return verticalPrintResolution;
565   }
566
567   /**
568    * Sets the right margin
569    *
570    * @param m the right margin in inches
571    */

572   public void setRightMargin(double m)
573   {
574     rightMargin = m;
575   }
576
577   /**
578    * Accessor for the right margin
579    *
580    * @return the right margin in inches
581    */

582   public double getRightMargin()
583   {
584     return rightMargin;
585   }
586
587   /**
588    * Sets the left margin
589    *
590    * @param m the left margin in inches
591    */

592   public void setLeftMargin(double m)
593   {
594     leftMargin = m;
595   }
596
597   /**
598    * Accessor for the left margin
599    *
600    * @return the left margin in inches
601    */

602   public double getLeftMargin()
603   {
604     return leftMargin;
605   }
606
607   /**
608    * Sets the top margin
609    *
610    * @param m the top margin in inches
611    */

612   public void setTopMargin(double m)
613   {
614     topMargin = m;
615   }
616
617   /**
618    * Accessor for the top margin
619    *
620    * @return the top margin in inches
621    */

622   public double getTopMargin()
623   {
624     return topMargin;
625   }
626
627   /**
628    * Sets the bottom margin
629    *
630    * @param m the bottom margin in inches
631    */

632   public void setBottomMargin(double m)
633   {
634     bottomMargin = m;
635   }
636
637   /**
638    * Accessor for the bottom margin
639    *
640    * @return the bottom margin in inches
641    */

642   public double getBottomMargin()
643   {
644     return bottomMargin;
645   }
646
647   /**
648    * Gets the default margin width
649    *
650    * @return the default margin width
651    */

652   public double getDefaultWidthMargin()
653   {
654     return defaultWidthMargin;
655   }
656
657   /**
658    * Gets the default margin height
659    *
660    * @return the default margin height
661    */

662   public double getDefaultHeightMargin()
663   {
664     return defaultHeightMargin;
665   }
666
667   /**
668    * Accessor for the fit width print flag
669    * @return TRUE if the print is to fit to pages, false otherwise
670    */

671   public boolean getFitToPages()
672   {
673     return fitToPages;
674   }
675
676   /**
677    * Accessor for the fit to pages flag
678    * @param b TRUE to fit to pages, FALSE to use a scale factor
679    */

680   public void setFitToPages(boolean b)
681   {
682     fitToPages = b;
683   }
684
685   /**
686    * Accessor for the password
687    *
688    * @return the password to unlock this sheet, or NULL if not protected
689    */

690   public String JavaDoc getPassword()
691   {
692     return password;
693   }
694
695   /**
696    * Sets the password for this sheet
697    *
698    * @param s the password
699    */

700   public void setPassword(String JavaDoc s)
701   {
702     password = s;
703   }
704
705   /**
706    * Accessor for the password hash - used only when copying sheets
707    *
708    * @return passwordHash
709    */

710   public int getPasswordHash()
711   {
712     return passwordHash;
713   }
714
715   /**
716    * Accessor for the password hash - used only when copying sheets
717    *
718    * @param ph the password hash
719    */

720   public void setPasswordHash(int ph)
721   {
722     passwordHash = ph;
723   }
724
725   /**
726    * Accessor for the default column width
727    *
728    * @return the default column width, in characters
729    */

730   public int getDefaultColumnWidth()
731   {
732     return defaultColumnWidth;
733   }
734
735   /**
736    * Sets the default column width
737    *
738    * @param w the new default column width
739    */

740   public void setDefaultColumnWidth(int w)
741   {
742     defaultColumnWidth = w;
743   }
744
745   /**
746    * Accessor for the default row height
747    *
748    * @return the default row height, in 1/20ths of a point
749    */

750   public int getDefaultRowHeight()
751   {
752     return defaultRowHeight;
753   }
754
755   /**
756    * Sets the default row height
757    *
758    * @param h the default row height, in 1/20ths of a point
759    */

760   public void setDefaultRowHeight(int h)
761   {
762     defaultRowHeight = h;
763   }
764
765   /**
766    * Accessor for the zoom factor. Do not confuse zoom factor (which relates
767    * to the on screen view) with scale factor (which refers to the scale factor
768    * when printing)
769    *
770    * @return the zoom factor as a percentage
771    */

772   public int getZoomFactor()
773   {
774     return zoomFactor;
775   }
776
777   /**
778    * Sets the zoom factor. Do not confuse zoom factor (which relates
779    * to the on screen view) with scale factor (which refers to the scale factor
780    * when printing)
781    *
782    * @param zf the zoom factor as a percentage
783    */

784   public void setZoomFactor(int zf)
785   {
786     zoomFactor = zf;
787   }
788
789   /**
790    * Accessor for the displayZeroValues property
791    *
792    * @return TRUE to display zero values, FALSE not to bother
793    */

794   public boolean getDisplayZeroValues()
795   {
796     return displayZeroValues;
797   }
798
799   /**
800    * Sets the displayZeroValues property
801    *
802    * @param b TRUE to show zero values, FALSE not to bother
803    */

804   public void setDisplayZeroValues(boolean b)
805   {
806     displayZeroValues = b;
807   }
808
809   /**
810    * Accessor for the showGridLines property
811    *
812    * @return TRUE if grid lines will be shown, FALSE otherwise
813    */

814   public boolean getShowGridLines()
815   {
816     return showGridLines;
817   }
818
819   /**
820    * Sets the showGridLines property
821    *
822    * @param b TRUE to show grid lines on this sheet, FALSE otherwise
823    */

824   public void setShowGridLines(boolean b)
825   {
826     showGridLines = b;
827   }
828
829   /**
830    * Accessor for the printGridLines property
831    *
832    * @return TRUE if grid lines will be printed, FALSE otherwise
833    */

834   public boolean getPrintGridLines()
835   {
836     return printGridLines;
837   }
838
839    /**
840    * Sets the printGridLines property
841    *
842    * @param b TRUE to print grid lines on this sheet, FALSE otherwise
843    */

844   public void setPrintGridLines(boolean b)
845   {
846     printGridLines = b;
847   }
848
849   /**
850    * Accessor for the printHeaders property
851    *
852    * @return TRUE if headers will be printed, FALSE otherwise
853    */

854   public boolean getPrintHeaders()
855   {
856     return printHeaders;
857   }
858
859    /**
860    * Sets the printHeaders property
861    *
862    * @param b TRUE to print headers on this sheet, FALSE otherwise
863    */

864   public void setPrintHeaders(boolean b)
865   {
866     printHeaders = b;
867   }
868
869   /**
870    * Gets the row at which the pane is frozen horizontally
871    *
872    * @return the row at which the pane is horizontally frozen, or 0 if there
873    * is no freeze
874    */

875   public int getHorizontalFreeze()
876   {
877     return horizontalFreeze;
878   }
879
880   /**
881    * Sets the row at which the pane is frozen horizontally
882    *
883    * @param row the row number to freeze at
884    */

885   public void setHorizontalFreeze(int row)
886   {
887     horizontalFreeze = Math.max(row, 0);
888   }
889
890   /**
891    * Gets the column at which the pane is frozen vertically
892    *
893    * @return the column at which the pane is vertically frozen, or 0 if there
894    * is no freeze
895    */

896   public int getVerticalFreeze()
897   {
898     return verticalFreeze;
899   }
900
901   /**
902    * Sets the row at which the pane is frozen vertically
903    *
904    * @param col the column number to freeze at
905    */

906   public void setVerticalFreeze(int col)
907   {
908     verticalFreeze = Math.max(col, 0);
909   }
910
911   /**
912    * Sets the number of copies
913    *
914    * @param c the number of copies
915    */

916   public void setCopies(int c)
917   {
918     copies = c;
919   }
920
921   /**
922    * Accessor for the number of copies to print
923    *
924    * @return the number of copies
925    */

926   public int getCopies()
927   {
928     return copies;
929   }
930
931   /**
932    * Accessor for the header
933    *
934    * @return the header
935    */

936   public HeaderFooter getHeader()
937   {
938     return header;
939   }
940
941   /**
942    * Sets the header
943    *
944    * @param h the header
945    */

946   public void setHeader(HeaderFooter h)
947   {
948     header = h;
949   }
950
951   /**
952    * Sets the footer
953    *
954    * @param f the footer
955    */

956   public void setFooter(HeaderFooter f)
957   {
958     footer = f;
959   }
960
961   /**
962    * Accessor for the footer
963    *
964    * @return the footer
965    */

966   public HeaderFooter getFooter()
967   {
968     return footer;
969   }
970 }
971
Popular Tags