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 org.diyefi.openlogviewer.genericlog.GenericLog;
28  
29  /**
30   *  Typical constructor for this class would look like this <br>
31   * <code>
32   *  public CSVTypeLog(File f) {<br>
33          this.setLogFile(f);<br>
34          this.setDecodedLog(new GenericLog());<br>
35          this.setT(new Thread(this, "CSV Type Log Loading"));<br>
36          this.getT().setPriority(Thread.MAX_PRIORITY);<br>
37          this.getT().start();<br>
38  
39      }</code>
40   * @author Bryan Harris
41   */
42  public abstract class AbstractDecoder implements Runnable {
43  
44  	/**
45  	 * logFile is the <code>File</code> object that points to the file you are
46  	 * attempting to open.
47  	 */
48  	private File logFile;
49  
50  	/**
51  	 * decodedLog is the outcome of parsing the log file, this will be injected into the program
52  	 * through property change listeners and this object will be come null when finished or fail.
53  	 */
54  	private GenericLog decodedLog;
55  
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 final 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  //	/**
77  //	 * BaseDecoder.decodeLog() is an abstract method. Override this method write your parsing code within it, when creating an object that
78  //	 * extends BaseDecoder the rest will be taken care of automatically
79  //	 * @throws IOException
80  //	 */
81  //	abstract void decodeLog() throws IOException;
82  
83  	/**
84  	 * used for getting the decided log for injection to the main pieces of the program that will use it
85  	 * @return GenericLog
86  	 */
87  	public final GenericLog getDecodedLog() {
88  		return decodedLog;
89  	}
90  
91  	/**
92  	 * sets the GenericLog
93  	 * @param decodedLog
94  	 */
95  	public final void setDecodedLog(final GenericLog decodedLog) {
96  		this.decodedLog = decodedLog;
97  	}
98  
99  	/**
100 	 * get the log File
101 	 * @return File
102 	 */
103 	public final File getLogFile() {
104 		return logFile;
105 	}
106 
107 	/**
108 	 * set the log File
109 	 * @param logFile
110 	 */
111 	public final void setLogFile(final File logFile) {
112 		this.logFile = logFile;
113 	}
114 
115 	/**
116 	 * get the thread, use this if you would like to give the thread a name such as "TYPEOFLOG Thread"<br>
117 	 * can also be used to set the thread priority
118 	 * after initialization of all variables required by the extended class you <b>MUST</b> call:<br>
119 	 * this.getT().start();
120 	 * @return the thread that this decoder is running in.
121 	 */
122 	public final Thread getT() {
123 		return t;
124 	}
125 
126 	/**
127 	 * set the Thread
128 	 * @param t
129 	 */
130 	public final void setT(final Thread t) {
131 		this.t = t;
132 	}
133 }