D:\NewZebra\JavaApplications\DesignPatternsProject\src\structural_patterns\pdf_facade_pattern\TextObjectDisplayer.java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package structural_patterns.pdf_facade_pattern;
21
22
23
24 @author
25
26
27
28 import java.io.*;
29 import java.text.*;
30 import java.util.*;
31 import java.lang.*;
32 import java.awt.event.*;
33 import java.awt.*;
34 import javax.swing.*;
35
36 public class TextObjectDisplayer extends TextImageBaseAssembler {
37
38 TextBaseProduct textBaseProductHandle = null;
39 String path = null;
40 String objectName = null;
41
42
43
44 public TextObjectDisplayer(String passedPath, String passedFileName) {
45 path = passedPath;
46 objectName = passedFileName;
47 factoryMethod();
48 }
49
50
51
52 public String who_am_I(){
53 return("TextObjectDisplayer - it displays Java object into TextArea");
54
55 }
56
57
58
59 public void factoryMethod(){
60
61 String objectFileName;
62
63 try
64 {
65 objectFileName = path + PDF_Base.FILE_Separator + objectName;
66 FileInputStream getStoredObjects = new FileInputStream(objectFileName);
67
68 ObjectInputStream objectStorageHandle = new ObjectInputStream (getStoredObjects);
69
70 textBaseProductHandle = (TextBaseProduct)objectStorageHandle.readObject();
71 }
72 catch(IOException eIOException)
73 {
74 System.out.println("GettingObjects eIOException");
75 System.out.println("eIOException: " + eIOException.getMessage());
76 textBaseProductHandle = null;
77 }
78 catch(ClassNotFoundException eClassNotFoundException)
79 {
80 System.out.println("StoringObjects eIOException");
81 System.out.println("ClassNotFoundException: " + eClassNotFoundException.getMessage());
82 textBaseProductHandle = null;
83 }
84 }
85
86
87
88 public int populateTextArea(JTextArea passedJTextArea, Font passedFont){
89 if(null == textBaseProductHandle)
90 return(-1);
91 if(null == textBaseProductHandle.linesOfTextVecxtor)
92 return(-1);
93
94 int count;
95 int lineCount = 0;
96 int pageNumber = 1;
97 int vectorSize = textBaseProductHandle.linesOfTextVecxtor.size();
98 String line = "";
99 String newLine = "\n";
100
101 passedJTextArea.setFont(passedFont);
102
103 for(count =0; count < vectorSize; count++)
104 {
105 line = (String)textBaseProductHandle.linesOfTextVecxtor.elementAt(count);
106 lineCount++;
107 if(line.equalsIgnoreCase(PDF_Base.PAGE_BREAK))
108 {
109 for(int addLines = lineCount; addLines < PDF_Base.MAX_LINES_PER_PAGE; addLines++)
110 passedJTextArea.append(newLine);
111 passedJTextArea.append("Page " + pageNumber + newLine + newLine);
112 lineCount = 0;
113 pageNumber++;
114 }
115 else
116 passedJTextArea.append(line + newLine);
117 }
118 passedJTextArea.append(newLine + newLine + newLine);
119 passedJTextArea.moveCaretPosition(0);
120 return(0);
121 }
122
123
124
125 public static void main (String[] args)
126 {
127 TextObjectDisplayer textObjectDisplayerHandle = new TextObjectDisplayer("D:\\Java\\JavaCourse_New\\DataObjectsStorage", "Command_2.data");
128 }
129
130 }
131
132