D:\NewZebra\JavaApplications\DesignPatternsProject\src\structural_patterns\pdf_facade_pattern\TextObjectDisplayer.java
  1 /* 
  2  * TextObjectDisplayer.java
  3  *
  4  * Disclaimer:
  5  * ZebraSoft.com disclaims all warrantees with regard to documents/programs, including 
  6  * all implied warranties. In no event shall ZebraSoft.com be liable for indirect or 
  7  * consequential damages or any damages whatsoever resulting from loss of use, data or 
  8  * profits arising out of the use of documents/programs.
  9  * 
 10  * All content included on this site, such as text, graphics, logos, button icons, 
 11  * images, audio clips, video clips, digital downloads, programs, data compilations, 
 12  * and software, is the property of ZebraSoft.com or its content suppliers and 
 13  * protected by United States and international copyright laws. 
 14  *
 15  * This site or any portion of this site may not be reproduced, duplicated, 
 16  * copied, sold, resold, visited, or otherwise exploited for any commercial 
 17  * purpose without express written consent of ZebraSoft.com.
 18  */
 19 
 20 package structural_patterns.pdf_facade_pattern;
 21 
 22 /**
 23  *    
 24  * @author Sam Eldin
 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     /** Creates a new instance of TextObjectDisplayer */
 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             // Write object with ObjectOutputStream
 68             ObjectInputStream objectStorageHandle = new  ObjectInputStream (getStoredObjects);
 69             // Read an object
 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