View Javadoc

1   /* Open Log Viewer
2    *
3    * Copyright 2011
4    *
5    * This file is part of the OpenLogViewer project.
6    *
7    * OpenLogViewer software is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * OpenLogViewer software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with any OpenLogViewer software.  If not, see http://www.gnu.org/licenses/
19   *
20   * I ask that if you make any changes to this file you fork the code on github.com!
21   *
22   */
23  
24  package org.diyefi.openlogviewer.decoder;
25  
26  import java.io.File;
27  import java.io.IOException;
28  import org.diyefi.openlogviewer.genericlog.GenericLog;
29  
30  /**
31   *  Typical constructor for this class would look like this <br>
32   * <code>
33   *  public CSVTypeLog(File f) {<br>
34          this.setLogFile(f);<br>
35          this.setDecodedLog(new GenericLog());<br>
36          this.setT(new Thread(this, "CSV Type Log Loading"));<br>
37          this.getT().setPriority(Thread.MAX_PRIORITY);<br>
38          this.getT().start();<br>
39  
40      }</code>
41   * @author Bryan Harris
42   * @version 0.1.3
43   */
44  public abstract class BaseDecoder implements Runnable {
45  
46      /**
47       * logFile is the <code>File</code> object that points to the file you are
48       * attempting to open.
49       */
50      private File logFile;
51      /**
52       * decodedLog is the outcome of parsing the log file, this will be injected into the program
53       * through property change listeners and this object will be come null when finished or fail.
54       */
55      private GenericLog decodedLog;
56      /**
57       * this object is threaded so that the gui does not freeze while parsing
58       */
59      private Thread t;
60  
61      /**
62       * Overriden Run from the Runnable Interface to do the work for us in a threaded fashion.
63       */
64      @Override
65      public void run() {
66          try {
67              this.getDecodedLog().setLogStatus(GenericLog.LOG_LOADING);
68              decodeLog();
69              this.getDecodedLog().setLogStatus(GenericLog.LOG_LOADED);
70          } catch (IOException IOE) {
71              this.getDecodedLog().setLogStatus(GenericLog.LOG_NOT_LOADED);
72              System.out.println("Error Loading Log: " +IOE.getMessage());
73          }
74      }
75      /**
76       * BaseDecoder.decodeLog() is an abstract method. Override this method write your parsing code within it, when creating an object that
77       * extends BaseDecoder the rest will be taken care of automatically
78       * @throws IOException
79       */
80      abstract void decodeLog() throws IOException;
81  
82      /**
83       * used for getting the decided log for injection to the main pieces of the program that will use it
84       * @return GenericLog
85       */
86      public GenericLog getDecodedLog() {
87          return decodedLog;
88      }
89      /**
90       * sets the GenericLog
91       * @param decodedLog
92       */
93      public void setDecodedLog(GenericLog decodedLog) {
94          this.decodedLog = decodedLog;
95      }
96      /**
97       * get the log File
98       * @return File
99       */
100     public File getLogFile() {
101         return logFile;
102     }
103     /**
104      * set the log File
105      * @param logFile
106      */
107     public void setLogFile(File logFile) {
108         this.logFile = logFile;
109     }
110     /**
111      * get the thread, use this if you would like to give the thread a name such as "TYPEOFLOG Thread"<br>
112      * can also be used to set the thread priority
113      * after initialization of all variables required by the extended class you <b>MUST</b> call:<br>
114      * this.getT().start();
115      * @return
116      */
117     public Thread getT() {
118         return t;
119     }
120     /**
121      * set the Thread
122      * @param t
123      */
124     public void setT(Thread t) {
125         this.t = t;
126     }
127 
128 
129 
130 }