1 32 33 package com.jeantessier.dependency; 34 35 import java.io.*; 36 import java.util.*; 37 38 public abstract class Printer extends VisitorBase { 39 private PrintWriter out; 40 41 private String indentText = " "; 42 private int indentLevel = 0; 43 private boolean showInbounds = true; 44 private boolean showOutbounds = true; 45 private boolean showEmptyNodes = true; 46 47 public Printer(PrintWriter out) { 48 this(new SortedTraversalStrategy(new SelectiveTraversalStrategy()), out); 49 } 50 51 public Printer(TraversalStrategy strategy, PrintWriter out) { 52 super(strategy); 53 54 this.out = out; 55 } 56 57 public String getIndentText() { 58 return indentText; 59 } 60 61 public void setIndentText(String indentText) { 62 this.indentText = indentText; 63 } 64 65 public boolean isShowInbounds() { 66 return showInbounds; 67 } 68 69 public void setShowInbounds(boolean showInbounds) { 70 this.showInbounds = showInbounds; 71 } 72 73 public boolean isShowOutbounds() { 74 return showOutbounds; 75 } 76 77 public void setShowOutbounds(boolean showOutbounds) { 78 this.showOutbounds = showOutbounds; 79 } 80 81 public boolean isShowEmptyNodes() { 82 return showEmptyNodes; 83 } 84 85 public void setShowEmptyNodes(boolean showEmptyNodes) { 86 this.showEmptyNodes = showEmptyNodes; 87 } 88 89 protected Printer append(boolean b) { 90 out.print(b); 91 return this; 92 } 93 94 protected Printer append(char c) { 95 out.print(c); 96 return this; 97 } 98 99 protected Printer append(char[] s) { 100 out.print(s); 101 return this; 102 } 103 104 protected Printer append(double d) { 105 out.print(d); 106 return this; 107 } 108 109 protected Printer append(float f) { 110 out.print(f); 111 return this; 112 } 113 114 protected Printer append(int i) { 115 out.print(i); 116 return this; 117 } 118 119 protected Printer append(long l) { 120 out.print(l); 121 return this; 122 } 123 124 protected Printer append(Object obj) { 125 out.print(obj); 126 return this; 127 } 128 129 protected Printer append(String s) { 130 out.print(s); 131 return this; 132 } 133 134 protected Printer indent() { 135 for (int i=0; i<indentLevel; i++) { 136 append(getIndentText()); 137 } 138 139 return this; 140 } 141 142 protected Printer eol() { 143 out.println(); 144 return this; 145 } 146 147 protected Printer printNodeName(Node node) { 148 return printNodeName(node, node.getName()); 149 } 150 151 protected Printer printNodeName(Node node, String name) { 152 return append(name); 153 } 154 155 protected void raiseIndent() { 156 indentLevel++; 157 } 158 159 protected void lowerIndent() { 160 indentLevel--; 161 } 162 163 protected boolean shouldShowPackageNode(PackageNode node) { 164 boolean result = shouldShowNode(node); 165 166 Iterator i = node.getClasses().iterator(); 167 while (!result && i.hasNext()) { 168 result = shouldShowClassNode((ClassNode) i.next()); 169 } 170 171 return result; 172 } 173 174 protected boolean shouldShowClassNode(ClassNode node) { 175 boolean result = shouldShowNode(node); 176 177 Iterator i = node.getFeatures().iterator(); 178 while (!result && i.hasNext()) { 179 result = shouldShowFeatureNode((FeatureNode) i.next()); 180 } 181 182 return result; 183 } 184 185 protected boolean shouldShowFeatureNode(FeatureNode node) { 186 return shouldShowNode(node); 187 } 188 189 protected boolean shouldShowNode(Node node) { 190 boolean result = isShowEmptyNodes(); 191 192 if (!result) { 193 result = (isShowOutbounds() && !node.getOutboundDependencies().isEmpty()) || (isShowInbounds() && !node.getInboundDependencies().isEmpty()); 194 } 195 196 return result; 197 } 198 } 199 | Popular Tags |