001: /*
002: * Author: Chris Seguin
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package org.acm.seguin.print;
010:
011: import java.io.File;
012: import java.io.FileWriter;
013: import java.io.PrintWriter;
014: import java.io.IOException;
015: import org.acm.seguin.util.FileSettings;
016: import org.acm.seguin.util.MissingSettingsException;
017: import org.acm.seguin.awt.ExceptionPrinter;
018:
019: /**
020: * Stores the pretty printer settings. Allows the user to reload or write
021: * them to a file.
022: *
023: *@author Chris Seguin
024: */
025: public class PrintingSettings {
026: private int textFontSize;
027: private int textSpace;
028: private int headerBlock;
029: private int filenameFont;
030: private int dateFont;
031: private int linesPerPage;
032:
033: /**
034: * Constructor for the PrintingSettings object
035: */
036: public PrintingSettings() {
037: init();
038: }
039:
040: /**
041: * Sets the TextFontSize attribute of the PrintingSettings object
042: *
043: *@param value The new TextFontSize value
044: */
045: public void setTextFontSize(int value) {
046: if (value != textFontSize) {
047: textFontSize = value;
048: save();
049: }
050: }
051:
052: /**
053: * Sets the TextSpace attribute of the PrintingSettings object
054: *
055: *@param value The new TextSpace value
056: */
057: public void setTextSpace(int value) {
058: if (value != textSpace) {
059: textSpace = value;
060: save();
061: }
062: }
063:
064: /**
065: * Sets the HeaderBlockHeight attribute of the PrintingSettings object
066: *
067: *@param value The new HeaderBlockHeight value
068: */
069: public void setHeaderBlockHeight(int value) {
070: if (value != headerBlock) {
071: headerBlock = value;
072: save();
073: }
074: }
075:
076: /**
077: * Sets the FilenameFontSize attribute of the PrintingSettings object
078: *
079: *@param value The new FilenameFontSize value
080: */
081: public void setFilenameFontSize(int value) {
082: if (value != filenameFont) {
083: filenameFont = value;
084: save();
085: }
086: }
087:
088: /**
089: * Sets the DateFontSize attribute of the PrintingSettings object
090: *
091: *@param value The new DateFontSize value
092: */
093: public void setDateFontSize(int value) {
094: if (value != dateFont) {
095: dateFont = value;
096: save();
097: }
098: }
099:
100: /**
101: * Sets the LinesPerPage attribute of the PrintingSettings object
102: *
103: *@param value The new LinesPerPage value
104: */
105: public void setLinesPerPage(int value) {
106: if (linesPerPage != value) {
107: linesPerPage = value;
108: save();
109: }
110: }
111:
112: /**
113: * Gets the TextFontSize attribute of the PrintingSettings object
114: *
115: *@return The TextFontSize value
116: */
117: public int getTextFontSize() {
118: return textFontSize;
119: }
120:
121: /**
122: * Gets the TextSpace attribute of the PrintingSettings object
123: *
124: *@return The TextSpace value
125: */
126: public int getTextSpace() {
127: return textSpace;
128: }
129:
130: /**
131: * Gets the HeaderBlockHeight attribute of the PrintingSettings object
132: *
133: *@return The HeaderBlockHeight value
134: */
135: public int getHeaderBlockHeight() {
136: return headerBlock;
137: }
138:
139: /**
140: * Gets the FilenameFontSize attribute of the PrintingSettings object
141: *
142: *@return The FilenameFontSize value
143: */
144: public int getFilenameFontSize() {
145: return filenameFont;
146: }
147:
148: /**
149: * Gets the DateFontSize attribute of the PrintingSettings object
150: *
151: *@return The DateFontSize value
152: */
153: public int getDateFontSize() {
154: return dateFont;
155: }
156:
157: /**
158: * Gets the LinesPerPage attribute of the PrintingSettings object
159: *
160: *@return The LinesPerPage value
161: */
162: public int getLinesPerPage() {
163: return linesPerPage;
164: }
165:
166: /**
167: * Description of the Method
168: */
169: public void save() {
170: try {
171: File directory = FileSettings.getRefactorySettingsRoot();
172: if (!directory.exists()) {
173: directory.mkdirs();
174: }
175:
176: FileWriter output = new FileWriter(new File(directory,
177: "printing.settings"));
178: PrintWriter printer = new PrintWriter(output);
179: write(printer);
180: printer.close();
181: output.close();
182: init();
183: } catch (IOException ioe) {
184: ExceptionPrinter.print(ioe, false);
185: }
186: }
187:
188: /**
189: * Description of the Method
190: */
191: private void defaults() {
192: textFontSize = 10;
193: textSpace = 0;
194: headerBlock = 30;
195: filenameFont = 14;
196: dateFont = 8;
197: linesPerPage = 36;
198: }
199:
200: /**
201: * Sets the default values for these
202: */
203: private void init() {
204: defaults();
205:
206: try {
207: FileSettings setting = FileSettings
208: .getRefactorySettings("printing");
209: setting.setReloadNow(true);
210:
211: textFontSize = setting.getInteger("text.font.size");
212: textSpace = setting.getInteger("text.space");
213: headerBlock = setting.getInteger("header.space");
214: filenameFont = setting.getInteger("filename.font.size");
215: dateFont = setting.getInteger("date.font.size");
216: linesPerPage = setting.getInteger("lines.per.page");
217: } catch (MissingSettingsException mse) {
218: // Expected
219: }
220: }
221:
222: /**
223: * Writes the values back to the disk
224: *
225: *@param printer the output writer
226: */
227: private void write(PrintWriter printer) {
228: printer
229: .println("# This is the font size for the text of the file");
230: printer.println("text.font.size=" + textFontSize);
231: printer.println(" ");
232: printer
233: .println("# This is the number of pixels to skip between");
234: printer.println("# lines in the text of the file");
235: printer.println("text.space=" + textSpace);
236: printer.println(" ");
237: printer.println("# The header block is 30 pixels high");
238: printer.println("header.space=" + headerBlock);
239: printer.println(" ");
240: printer
241: .println("# The name of the file is specified with this parameter");
242: printer.println("filename.font.size=" + filenameFont);
243: printer.println(" ");
244: printer
245: .println("# The date that the file was printed and the number");
246: printer.println("# of pages is in this font size");
247: printer.println("date.font.size=" + dateFont);
248: printer.println(" ");
249: printer
250: .println("# The number of lines on a page. This is an estimate");
251: printer
252: .println("# that is updated by the software each time a new set of");
253: printer.println("# values is changed");
254: printer.println("lines.per.page=" + linesPerPage);
255: }
256: }
|