mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 17:01:16 +00:00
ICU-5287 make the tabber more flexible
X-SVN-Rev: 19944
This commit is contained in:
parent
e3d2129414
commit
c5470ce06f
2 changed files with 40 additions and 15 deletions
|
@ -65,6 +65,7 @@ public class BagFormatter {
|
|||
private static final String NULL_VALUE = "_NULL_VALUE_";
|
||||
private int fullTotal = -1;
|
||||
private String lineSeparator = "\r\n";
|
||||
private Tabber tabber = new Tabber.MonoTabber();
|
||||
|
||||
/**
|
||||
* Compare two UnicodeSets, and show the differences
|
||||
|
@ -466,7 +467,6 @@ public class BagFormatter {
|
|||
|
||||
private class MyVisitor extends Visitor {
|
||||
private PrintWriter output;
|
||||
Tabber.MonoTabber myTabber;
|
||||
String commentSeparator;
|
||||
int counter;
|
||||
int valueSize;
|
||||
|
@ -475,23 +475,24 @@ public class BagFormatter {
|
|||
public void doAt(Object c, PrintWriter output) {
|
||||
this.output = output;
|
||||
counter = 0;
|
||||
myTabber = new Tabber.MonoTabber();
|
||||
myTabber.add(mergeRanges ? 14 : 6,Tabber.LEFT);
|
||||
|
||||
tabber.clear();
|
||||
tabber.add(mergeRanges ? 14 : 6,Tabber.LEFT);
|
||||
|
||||
if (propName.length() > 0) myTabber.add(propName.length() + 2,Tabber.LEFT);
|
||||
if (propName.length() > 0) tabber.add(propName.length() + 2,Tabber.LEFT);
|
||||
|
||||
valueSize = getValueSource().getMaxWidth(shortValue);
|
||||
if (DEBUG) System.out.println("ValueSize: " + valueSize);
|
||||
if (valueSize > 0) myTabber.add(valueSize + 2,Tabber.LEFT); // value
|
||||
if (valueSize > 0) tabber.add(valueSize + 2,Tabber.LEFT); // value
|
||||
|
||||
myTabber.add(3,Tabber.LEFT); // comment character
|
||||
tabber.add(3,Tabber.LEFT); // comment character
|
||||
|
||||
labelSize = getLabelSource(true).getMaxWidth(shortLabel);
|
||||
if (labelSize > 0) myTabber.add(labelSize + 1,Tabber.LEFT); // value
|
||||
if (labelSize > 0) tabber.add(labelSize + 1,Tabber.LEFT); // value
|
||||
|
||||
if (mergeRanges && showCount) myTabber.add(5,Tabber.RIGHT);
|
||||
if (mergeRanges && showCount) tabber.add(5,Tabber.RIGHT);
|
||||
|
||||
if (showLiteral != null) myTabber.add(4,Tabber.LEFT);
|
||||
if (showLiteral != null) tabber.add(4,Tabber.LEFT);
|
||||
//myTabber.add(7,Tabber.LEFT);
|
||||
|
||||
commentSeparator = (showCount || showLiteral != null
|
||||
|
@ -499,8 +500,8 @@ public class BagFormatter {
|
|||
|| getNameSource() != UnicodeLabel.NULL)
|
||||
? "\t #" : "";
|
||||
|
||||
if (DEBUG) System.out.println("Tabber: " + myTabber.toString());
|
||||
if (DEBUG) System.out.println("Tabber: " + myTabber.process("a\tb\td\td\tf\tg\th"));
|
||||
if (DEBUG) System.out.println("Tabber: " + tabber.toString());
|
||||
if (DEBUG) System.out.println("Tabber: " + tabber.process("a\tb\td\td\tf\tg\th"));
|
||||
doAt(c);
|
||||
}
|
||||
|
||||
|
@ -555,7 +556,7 @@ public class BagFormatter {
|
|||
String label = getLabelSource(true).getValue(thing, ",", true);
|
||||
if (label.length() != 0) label = " " + label;
|
||||
output.print(
|
||||
myTabber.process(
|
||||
tabber.process(
|
||||
hex(thing)
|
||||
+ value
|
||||
+ commentSeparator
|
||||
|
@ -609,7 +610,7 @@ public class BagFormatter {
|
|||
}
|
||||
|
||||
output.print(
|
||||
myTabber.process(
|
||||
tabber.process(
|
||||
hex(start, end)
|
||||
+ pn
|
||||
+ value
|
||||
|
@ -1083,5 +1084,13 @@ public class BagFormatter {
|
|||
public void setFixName(Transliterator fixName) {
|
||||
this.fixName = fixName;
|
||||
}
|
||||
|
||||
public Tabber getTabber() {
|
||||
return tabber;
|
||||
}
|
||||
|
||||
public void setTabber(Tabber tabber) {
|
||||
this.tabber = tabber;
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2002-2005, International Business Machines Corporation and *
|
||||
* Copyright (C) 2002-2006, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -46,6 +46,10 @@ public abstract class Tabber {
|
|||
private String postfix = "";
|
||||
|
||||
public abstract void process_field(int count, String source, int start, int limit, StringBuffer output);
|
||||
|
||||
public Tabber clear() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class MonoTabber extends Tabber {
|
||||
int minGap = 0;
|
||||
|
@ -53,6 +57,13 @@ public abstract class Tabber {
|
|||
private List stops = new ArrayList();
|
||||
private List types = new ArrayList();
|
||||
|
||||
public Tabber clear() {
|
||||
stops.clear();
|
||||
types.clear();
|
||||
minGap = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < stops.size(); ++i) {
|
||||
|
@ -79,7 +90,7 @@ public abstract class Tabber {
|
|||
/**
|
||||
* Adds relative tab stop and how to align the text UP TO that stop
|
||||
*/
|
||||
public MonoTabber add(int fieldWidth, byte type) {
|
||||
public Tabber add(int fieldWidth, byte type) {
|
||||
int last = getStop(stops.size()-1);
|
||||
stops.add(new Integer(last + fieldWidth));
|
||||
types.add(new Integer(type));
|
||||
|
@ -197,4 +208,9 @@ public abstract class Tabber {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Tabber add(int i, byte left2) {
|
||||
// does nothing unless overridden
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue