PageRenderTime 36ms CodeModel.GetById 22ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/branches/jsdoc_tk_gui/src/org/jsdoctoolkit/model/MainModel.java

http://jsdoc-toolkit.googlecode.com/
Java | 142 lines | 82 code | 46 blank | 14 comment | 7 complexity | c8747bdde8654593eaa99a451b122ad9 MD5 | raw file
  1package org.jsdoctoolkit.model;
  2
  3import java.io.File;
  4import java.io.FileNotFoundException;
  5import java.io.FileOutputStream;
  6import java.io.IOException;
  7import java.io.OutputStream;
  8import java.io.PrintStream;
  9import java.util.Hashtable;
 10import java.util.Iterator;
 11
 12import javax.swing.ComboBoxModel;
 13import javax.swing.DefaultComboBoxModel;
 14import javax.swing.filechooser.FileFilter;
 15import javax.swing.tree.DefaultTreeModel;
 16
 17import org.jsdoctoolkit.business.JsDocParameter;
 18import org.jsdoctoolkit.business.FolderNode;
 19
 20public class MainModel extends AbstractModel{
 21
 22    public final static String DEFAULT_LANG = "defaultLang";
 23
 24    public final static String WD_NAME = "workingDirectory";
 25
 26    public final static String OUTPUT_NAME = "js_docs_out";
 27    
 28    private FolderNode rootNode;
 29
 30    private DefaultTreeModel treeModel;
 31    
 32    
 33    
 34
 35    public static boolean isDevelopperMode = false;
 36
 37
 38    private static Hashtable<String, String> parameters;
 39
 40
 41    public static String ON = "on";
 42
 43    public static String OFF = "off";
 44    
 45    private JsDocParameter jsDocParameter = null;
 46
 47    public MainModel() {
 48    	jsDocParameter = new JsDocParameter();
 49    }
 50
 51    /**
 52     * @param b
 53     */
 54    public void setDevelopperMode(boolean b) {
 55        isDevelopperMode = b;
 56    }
 57
 58    /**
 59     * @return Returns the isDevelopperMode.
 60     */
 61    public static boolean isDevelopperMode() {
 62        return isDevelopperMode;
 63    }
 64    
 65    public void run(OutputStream os){
 66    	
 67    	org.mozilla.javascript.tools.shell.Main.setOut(new PrintStream(os));
 68	
 69    	org.mozilla.javascript.tools.shell.Main.main(getJsDocParameter().getArguments());
 70    }
 71
 72	/**
 73	 * @return the jsDocParameter
 74	 */
 75	public JsDocParameter getJsDocParameter() {
 76		return jsDocParameter;
 77	}
 78
 79	/**
 80	 * @param jsDocParameter the jsDocParameter to set
 81	 */
 82	public void setJsDocParameter(JsDocParameter jsDocParameter) {
 83		this.jsDocParameter = jsDocParameter;
 84	}
 85
 86	public ComboBoxModel getTemplatesList() {
 87		DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
 88		File rootTpl = new File("templates");
 89		
 90
 91		
 92		if(rootTpl.isDirectory()){
 93			
 94			File[] fileList = rootTpl.listFiles();
 95			
 96			for(File f : fileList){
 97				
 98				if(f.isDirectory()){
 99					
100					//TODO filter this directory if the publish.hs file was not found
101					f.listFiles();
102					
103					dcbm.addElement(f);
104				}
105				
106			}
107		}
108
109		
110		
111		return dcbm;
112	}
113
114	public File getWorkingDirectoryFile() {
115		return new File(getJsDocParameter().getWorkingDirectory());
116	}
117	
118	public File getOutputDirectoryFile() {
119		return new File(getJsDocParameter().getOutputDirectory());
120	}
121	
122	
123    public DefaultTreeModel getTreeModel() {
124        if (this.treeModel == null) {
125            // initFileNode(getRootNode());
126            getRootNode().init(getJsDocParameter().getSubLevel(), 0);
127            this.treeModel = new DefaultTreeModel(getRootNode());
128        }
129        return this.treeModel;
130    }
131
132    public void resetTreeModel() {
133        this.treeModel = null;
134    }
135
136    private FolderNode getRootNode() {
137        if (this.rootNode == null) {
138            this.rootNode = new FolderNode(getWorkingDirectoryFile(), FolderNode.TYPE_WD);
139        }
140        return this.rootNode;
141    }
142}