Android Open Source - Tree-Task Text Tree Builder






From Project

Back to project page Tree-Task.

License

The source code is released under:

Apache License

If you think the Android project Tree-Task listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ghsoft.treetask;
//from w  w  w .  j  a  v  a  2  s  . c o  m
public class TextTreeBuilder {

  private Task task;
  private boolean useTabs, useHead, useNums, useDescription, useProg;

  public TextTreeBuilder(Task task) {
    this.task = task;
    this.useTabs = false;
    this.useHead = false;
    this.useNums = true;
    this.useDescription = true;
    this.useProg = true;
  }

  public void setTask(Task t) {
    this.task = t;
  }

  public void setTabs(boolean tabs) {
    this.useTabs = tabs;
  }

  public void setHead(boolean useHead) {
    this.useHead = useHead;
  }

  public void setNums(boolean nums) {
    this.useNums = nums;
  }

  public void setUseDescription(boolean des) {
    this.useDescription = des;
  }

  public void setUseProgress(boolean prog) {
    this.useProg = prog;
  }

  public String getText() {
    String out = "";
    String tabs = "";
    String index = useNums ? "1" : "";

    if (useHead)
      out += drawNode(index, tabs, (TaskNode) task.getHead().getTask());
    else
      out += drawNode(index, tabs, (TaskNode) task);

    return out;
  }

  private String drawNode(String uri, String tabs, TaskNode t) {

    int index = 0;
    String out = "";

    out += tabs + (uri != "" ? uri + ": " : "") + t.getName() + (useProg ? " - " + t.completion() + "%" : "");

    if (t.getDescription().length() > 0 && useDescription) {
      out += "\n";
      out += tabs + t.getDescription();
    }

    out += "\n";
    out += "\n";
    String nextURI = "";
    tabs += useTabs ? "\t" : "";

    for (int i = 0; i < t.numChildren(); i++) {
      index++;
      nextURI = useNums ? uri + "." + index : "";
      if (t.getChild(i) instanceof TaskNode) {
        out += drawNode(nextURI, tabs, (TaskNode) t.getChild(i));
      } else {
        out += drawLeaf(nextURI, tabs, (TaskLeaf) t.getChild(i));
      }

    }

    return out;
  }

  private String drawLeaf(String uri, String tabs, TaskLeaf t) {

    String out = "";

    out += tabs + (uri != "" ? uri + ": " : "") + t.getName() + (useProg ? " - " + t.completion() + "%" : "");
    if (t.getDescription().length() > 0 && useDescription) {
      out += "\n";
      out += tabs + t.getDescription();
    }
    out += "\n";
    out += "\n";

    return out;
  }

}




Java Source Code List

com.ghsoft.treetask.MetaData.java
com.ghsoft.treetask.TaskDummy.java
com.ghsoft.treetask.TaskHead.java
com.ghsoft.treetask.TaskLeaf.java
com.ghsoft.treetask.TaskManager.java
com.ghsoft.treetask.TaskNode.java
com.ghsoft.treetask.Task.java
com.ghsoft.treetask.TextTreeBuilder.java
com.ghsoft.treetaskapp.About.java
com.ghsoft.treetaskapp.EditTask.java
com.ghsoft.treetaskapp.ExportView.java
com.ghsoft.treetaskapp.HtmlTreeBuilder.java
com.ghsoft.treetaskapp.MainListItem.java
com.ghsoft.treetaskapp.MainViewFragment.java
com.ghsoft.treetaskapp.Main.java
com.ghsoft.treetaskapp.ModifyTaskActivity.java
com.ghsoft.treetaskapp.NewTask.java
com.ghsoft.treetaskapp.NewTreeTask.java
com.ghsoft.treetaskapp.NewTreeView.java
com.ghsoft.treetaskapp.Settings.java
com.ghsoft.treetaskapp.TaskViewListItem.java
com.ghsoft.treetaskapp.TaskView.java
com.ghsoft.treetaskapp.TreeTaskProgressBar.java
com.ghsoft.treetaskapp.TreeView.java