/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

  1. package org.jsdoctoolkit.model;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.OutputStream;
  7. import java.io.PrintStream;
  8. import java.util.Hashtable;
  9. import java.util.Iterator;
  10. import javax.swing.ComboBoxModel;
  11. import javax.swing.DefaultComboBoxModel;
  12. import javax.swing.filechooser.FileFilter;
  13. import javax.swing.tree.DefaultTreeModel;
  14. import org.jsdoctoolkit.business.JsDocParameter;
  15. import org.jsdoctoolkit.business.FolderNode;
  16. public class MainModel extends AbstractModel{
  17. public final static String DEFAULT_LANG = "defaultLang";
  18. public final static String WD_NAME = "workingDirectory";
  19. public final static String OUTPUT_NAME = "js_docs_out";
  20. private FolderNode rootNode;
  21. private DefaultTreeModel treeModel;
  22. public static boolean isDevelopperMode = false;
  23. private static Hashtable<String, String> parameters;
  24. public static String ON = "on";
  25. public static String OFF = "off";
  26. private JsDocParameter jsDocParameter = null;
  27. public MainModel() {
  28. jsDocParameter = new JsDocParameter();
  29. }
  30. /**
  31. * @param b
  32. */
  33. public void setDevelopperMode(boolean b) {
  34. isDevelopperMode = b;
  35. }
  36. /**
  37. * @return Returns the isDevelopperMode.
  38. */
  39. public static boolean isDevelopperMode() {
  40. return isDevelopperMode;
  41. }
  42. public void run(OutputStream os){
  43. org.mozilla.javascript.tools.shell.Main.setOut(new PrintStream(os));
  44. org.mozilla.javascript.tools.shell.Main.main(getJsDocParameter().getArguments());
  45. }
  46. /**
  47. * @return the jsDocParameter
  48. */
  49. public JsDocParameter getJsDocParameter() {
  50. return jsDocParameter;
  51. }
  52. /**
  53. * @param jsDocParameter the jsDocParameter to set
  54. */
  55. public void setJsDocParameter(JsDocParameter jsDocParameter) {
  56. this.jsDocParameter = jsDocParameter;
  57. }
  58. public ComboBoxModel getTemplatesList() {
  59. DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
  60. File rootTpl = new File("templates");
  61. if(rootTpl.isDirectory()){
  62. File[] fileList = rootTpl.listFiles();
  63. for(File f : fileList){
  64. if(f.isDirectory()){
  65. //TODO filter this directory if the publish.hs file was not found
  66. f.listFiles();
  67. dcbm.addElement(f);
  68. }
  69. }
  70. }
  71. return dcbm;
  72. }
  73. public File getWorkingDirectoryFile() {
  74. return new File(getJsDocParameter().getWorkingDirectory());
  75. }
  76. public File getOutputDirectoryFile() {
  77. return new File(getJsDocParameter().getOutputDirectory());
  78. }
  79. public DefaultTreeModel getTreeModel() {
  80. if (this.treeModel == null) {
  81. // initFileNode(getRootNode());
  82. getRootNode().init(getJsDocParameter().getSubLevel(), 0);
  83. this.treeModel = new DefaultTreeModel(getRootNode());
  84. }
  85. return this.treeModel;
  86. }
  87. public void resetTreeModel() {
  88. this.treeModel = null;
  89. }
  90. private FolderNode getRootNode() {
  91. if (this.rootNode == null) {
  92. this.rootNode = new FolderNode(getWorkingDirectoryFile(), FolderNode.TYPE_WD);
  93. }
  94. return this.rootNode;
  95. }
  96. }