Message

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

public String setItemAlignedText(String str_text, int padding, int space, boolean

isDigit) {

String txt = "";

String txt_space = "";


if (str_text.length() > space) {
String[] wordsInItemName = str_text.split(" ");
if (wordsInItemName.length == 0 || wordsInItemName.length == 1) {
//str_text = str_text.substring(0, space - 3).trim() + "...";
for (int i = 0; i < str_text.length(); i++) {
if (i > 1 && i % space == 0) {
txt = txt + "\n";
for (int n = 0; n < padding; n++) {
txt = txt + " ";
}

txt = txt + str_text.charAt(i);


} else {
txt = txt + str_text.charAt(i);
}
}

/* for (int j = 0; j < space - (space_cnt + 1); j++) {


txt_space = txt_space + " ";
}*/
return txt + txt_space;
} else {
int availableSpace = space;
for (int i = 0; i < wordsInItemName.length; i++) {
if (wordsInItemName[i].length() < availableSpace) {
txt += wordsInItemName[i] + " ";
availableSpace = availableSpace -
(wordsInItemName[i].length() + 1);
} else if (wordsInItemName[i].length() == availableSpace) {
txt += wordsInItemName[i];
availableSpace = 0;
} else {
if(i!=0) {
txt = txt + "\n";
for (int n = 0; n < padding; n++) {
txt += " ";
}
}
if (wordsInItemName[i].length() < space) {
txt += wordsInItemName[i] + " ";
availableSpace = space - (wordsInItemName[i].length() +
1);
} else if (wordsInItemName[i].length() == space) {
txt += wordsInItemName[i];
availableSpace = 0;
} else {
int ac =wordsInItemName[i].length();
for (int j = 0; j < wordsInItemName[i].length(); j++) {
if (j > 0 && j % space == 0) {
txt = txt + "\n";
for (int n = 0; n < padding; n++) {
txt = txt + " ";
}
txt = txt + wordsInItemName[i].charAt(j);
ac=0;
} else {
txt = txt + wordsInItemName[i].charAt(j);
ac++;
}
}
txt+=" ";
availableSpace = space;
availableSpace = availableSpace - (ac+1);
}
}
}

/*for (int j = 0; j < availableSpace; j++) {


txt_space = txt_space + " ";
}*/
return txt + txt_space;
}
} else {
String str_space = "";
for (int i = 0; i < space - str_text.length(); i++)
str_space = str_space + " ";

if (isDigit)
str_text = str_space + str_text;
else
str_text = str_text + str_space;

return str_text;
}
}

You might also like