Example usage for org.apache.commons.lang StringUtils rightPad

List of usage examples for org.apache.commons.lang StringUtils rightPad

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils rightPad.

Prototype

public static String rightPad(String str, int size) 

Source Link

Document

Right pad a String with spaces (' ').

Usage

From source file:org.openehr.adl.serializer.AdlStringBuilder.java

public AdlStringBuilder lineComment(String comment) {
    if (comment != null) {
        append(StringUtils.rightPad("", 4)).append("-- ").append(comment);
    }/*from  w  ww  .  j  av  a2 s . c o m*/
    return this;
}

From source file:org.openeos.lanterna.internal.ui.MultiColumnListBox.java

@Override
public void repaint(TextGraphics graphics) {
    graphics.applyTheme(getListItemThemeDefinition(graphics.getTheme()));
    graphics.fillArea(' ');

    TerminalSize preferredSize = getPreferredSize();
    boolean fitsHorizontal = fitsHorizontal(graphics);
    boolean fitsVertical = fitsVertical(graphics);

    if (fitsHorizontal) {
        horizontalOffset = 0;//from   w  w  w . ja v a2  s . co  m
    } else if (preferredSize.getColumns() - horizontalOffset < graphics.getWidth()) {
        horizontalOffset = preferredSize.getColumns() - graphics.getWidth() - SCROLLBAR_WIDTH;
    }

    int actualPosition = 0;
    for (MultiColumnListBoxColumn column : columnList) {
        String header = column.getHeader();
        if (header.length() > column.getSize()) {
            header = header.substring(0, column.getSize());
        }
        drawStringOffset(graphics, horizontalOffset, actualPosition, 0, header);
        drawStringOffset(graphics, horizontalOffset, actualPosition, 1,
                StringUtils.repeat(ACS.SINGLE_LINE_HORIZONTAL + "", column.getSize()));

        actualPosition += column.getSize();
        if (actualPosition - horizontalOffset <= graphics.getWidth()) {
            drawStringOffset(graphics, horizontalOffset, actualPosition, 0, ACS.SINGLE_LINE_VERTICAL + "");
            if (columnList.indexOf(column) == columnList.size() - 1) {
                drawStringOffset(graphics, horizontalOffset, actualPosition, 1, ACS.SINGLE_LINE_T_LEFT + "");
            } else {
                drawStringOffset(graphics, horizontalOffset, actualPosition, 1, ACS.SINGLE_LINE_CROSS + "");
            }
            actualPosition++;
        }
        if (actualPosition - horizontalOffset > graphics.getWidth()) {
            break;
        }
    }
    int headerHeight = 2;
    for (int i = 0; i < graphics.getHeight() && i < rowList.size(); i++) {
        actualPosition = 0;
        if (i >= rowList.size()) {
            break;
        }
        if (hasFocus() && i == selectedIndex) {
            graphics.applyTheme(graphics.getTheme().getDefinition(Theme.Category.LIST_ITEM_SELECTED));
        } else {
            graphics.applyTheme(graphics.getTheme().getDefinition(Theme.Category.LIST_ITEM));

        }
        for (MultiColumnListBoxColumn column : columnList) {
            String[] row = rowList.get(i);
            String actual = row[columnList.indexOf(column)];
            if (actual.length() > column.getSize()) {
                actual = actual.substring(0, column.getSize());
            } else {
                actual = StringUtils.rightPad(actual, column.getSize());
            }
            drawStringOffset(graphics, horizontalOffset, actualPosition, i + headerHeight, actual);
            actualPosition += column.getSize();
            drawStringOffset(graphics, horizontalOffset, actualPosition, i + headerHeight,
                    ACS.SINGLE_LINE_VERTICAL + "");
            actualPosition++;
            if (actualPosition - horizontalOffset > graphics.getWidth()) {
                break;
            }
        }
    }
}

From source file:org.openhab.binding.nikobus.internal.NikobusCommandProvider.java

/**
 * Add a right padded command to the provided builder.
 * /* ww w  . j a va 2s  .  c o  m*/
 * @param builder
 * @param command
 * @param description
 */
private void appendCommand(StringBuilder builder, String command, String description) {
    builder.append("\t");
    builder.append(StringUtils.rightPad(command, 43));
    builder.append(" - ");
    builder.append(description);
    builder.append("\n");
}

From source file:org.openspotlight.graph.query.AbstractGeneralQueryTest.java

/**
 * Prints the result.//from   w  w w.j  ava2 s  .  co m
 * 
 * @param nodes the nodes
 */
protected void printResult(final Collection<Node> nodes) {
    if (printInfo && !nodes.isEmpty()) {
        final StringBuilder buffer = new StringBuilder();
        StringBuilderUtil.append(buffer, "\n\nRESULTS (", nodes.size(), "):\n");
        for (final Node node : nodes) {
            StringBuilderUtil.append(buffer, StringUtils.rightPad(node.getTypeName(), 60),
                    StringUtils.rightPad(node.getName(), 60), session.getParentNode(node).getName(), '\n');
        }
        LOGGER.info(buffer);
    }
}

From source file:org.openspotlight.graph.query.console.command.dynamic.QueryCommand.java

/**
 * Generate output based on result nodes.
 * //from w  w w . j a v  a  2 s  .com
 * @param nodes the nodes
 * @param additionalProperties the additional properties
 * @return the string
 */
protected String generateOutput(final Collection<Node> nodes, final Collection<String> additionalProperties) {
    final StringBuilder buffer = new StringBuilder();
    // Header
    StringBuilderUtil.append(buffer,
            StringUtils.repeat("-", ((3 + additionalProperties.size()) * (COLUMN_SIZE + 3)) + 1), "\n");
    StringBuilderUtil.append(buffer, "|", StringUtils.center("type name", COLUMN_SIZE + 2), "|");
    StringBuilderUtil.append(buffer, StringUtils.center("name", COLUMN_SIZE + 2), "|");
    StringBuilderUtil.append(buffer, StringUtils.center("parent name", COLUMN_SIZE + 2), "|");
    for (final String property : additionalProperties) {
        StringBuilderUtil.append(buffer, StringUtils.center(property, COLUMN_SIZE + 2), "|");
    }
    StringBuilderUtil.append(buffer, "\n");
    StringBuilderUtil.append(buffer,
            StringUtils.repeat("-", ((3 + additionalProperties.size()) * (COLUMN_SIZE + 3)) + 1), "\n");
    if (!nodes.isEmpty()) {
        for (final Node node : nodes) {
            final List<String> output = new LinkedList<String>();
            output.add("| ");
            output.add(
                    StringUtils.rightPad(StringUtils.abbreviate(node.getTypeName(), COLUMN_SIZE), COLUMN_SIZE));
            output.add(" | ");
            output.add(StringUtils.rightPad(StringUtils.abbreviate(node.getName(), COLUMN_SIZE), COLUMN_SIZE));
            output.add(" | ");
            output.add(StringUtils.rightPad(
                    StringUtils.abbreviate(StringKeysSupport.getNodeType(node.getParentId()), COLUMN_SIZE),
                    COLUMN_SIZE));
            output.add(" | ");
            for (final String propertyName : additionalProperties) {
                String propertyValue = "";
                try {
                    propertyValue = node.getPropertyValueAsString(propertyName);
                } catch (final Exception e) {
                }
                output.add(
                        StringUtils.rightPad(StringUtils.abbreviate(propertyValue, COLUMN_SIZE), COLUMN_SIZE));
                output.add(" | ");
            }
            StringBuilderUtil.appendLine(buffer, output);
        }
        StringBuilderUtil.append(buffer, "\n", nodes.size(), " nodes affected.", "\n");
    } else {
        StringBuilderUtil.append(buffer, "\n", "0 nodes affected.", "\n");
    }

    return buffer.toString();
}

From source file:org.openspotlight.graph.query.QueryUtil.java

/**
 * Prints the result.//from   w  ww.  j a v  a  2s  . c o  m
 * 
 * @param nodes the nodes
 */
static void printResult(final Collection<Node> nodes) {
    final StringBuilder buffer = new StringBuilder();
    StringBuilderUtil.append(buffer, "\n\nRESULTS (", nodes.size(), "):\n");
    for (final Node node : nodes) {
        StringBuilderUtil.append(buffer, StringUtils.rightPad(node.getTypeName(), 60),
                StringUtils.rightPad(node.getName(), 60), node.getParentId(), '\n');
    }
    LOGGER.info(buffer);
}

From source file:org.pentaho.di.ui.core.WidgetUtils.java

public static CTabFolder createTabFolder(Composite composite, FormData fd, String... titles) {
    Composite container = new Composite(composite, SWT.NONE);
    WidgetUtils.setFormLayout(container, 0);
    container.setLayoutData(fd);//ww w  . ja  v a  2  s  .co  m

    CTabFolder tabFolder = new CTabFolder(container, SWT.NONE);
    tabFolder.setLayoutData(new FormDataBuilder().fullSize().result());

    for (String title : titles) {
        if (title.length() < 8) {
            title = StringUtils.rightPad(title, 8);
        }
        Composite tab = new Composite(tabFolder, SWT.NONE);
        WidgetUtils.setFormLayout(tab, ConstUI.MEDUIM_MARGIN);

        CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
        tabItem.setText(title);
        tabItem.setControl(tab);
    }

    tabFolder.setSelection(0);
    return tabFolder;
}

From source file:org.projectforge.business.fibu.datev.BuchungssatzImportRow.java

/**
 * Achtung: Diese Klasse ruft ggf. korrigierend und ndernd check() auf.
 * @see java.lang.Object#toString()/*from www. java2s.  c o m*/
 * @see #check()
 */
public String toString() {
    check(); // Leider muss dieser modifizierende check() ausgefhrt werden, da auf die aufrufende Klasse ExcelImport kein Einfluss
    // genommen werden kann.
    String txt = StringUtils.abbreviate(text, 30);
    DayHolder day = new DayHolder(datum);
    return StringUtils.leftPad(NumberHelper.getAsString(satzNr), 4) + " "
            + StringUtils.leftPad(day.isoFormat(), 10)
            + StringUtils.leftPad(
                    NumberHelper.getAsString(betrag, NumberHelper.getCurrencyFormat(Locale.GERMAN)), 12)
            + " " + kost1 != null ? StringUtils.leftPad(kost1.toString(), 12)
                    : "-           " + " " + kost2 != null ? StringUtils.leftPad(kost2.toString(), 12)
                            : "-           " + " " + StringUtils.rightPad(txt, 30);
}

From source file:org.projectforge.business.fibu.datev.KontenplanExcelRow.java

public String toString() {
    String txt = StringUtils.abbreviate(bezeichnung, 30);
    return StringUtils.leftPad(NumberHelper.getAsString(konto), 5) + " " + StringUtils.rightPad(txt, 30);
}

From source file:org.projectforge.business.fibu.kost.BusinessAssessment.java

private void asLine(final StringBuffer buf, final String no, final String title, final BigDecimal amount,
        final int indent, final int scale, final String unit, final boolean html) {
    if (html == true) {
        buf.append("  <tr><td>").append(no).append("</td><td class=\"indent-").append(indent).append("\">");
    } else {//  w w  w .j a  v a2s.  com
        buf.append(StringUtils.leftPad(no, 4));
    }
    int length = 25;
    for (int i = 0; i < indent; i++) {
        if (html == false) {
            buf.append(" ");
        }
        length--; // One space lost.
    }
    if (html == true) {
        buf.append(HtmlHelper.escapeHtml(StringUtils.defaultString(title), false)).append("</td>");
    } else {
        buf.append(" ").append(StringUtils.rightPad(StringUtils.defaultString(title), length)).append(" ");
    }
    if (html == true) {
        buf.append("<td style=\"text-align: right;\">");
    }
    if (amount != null && amount.compareTo(BigDecimal.ZERO) != 0) {
        String value;
        if ("".equals(unit) == true) {
            value = CurrencyFormatter.format(amount);
        } else {
            final NumberFormat format = NumberHelper.getNumberFractionFormat(ThreadLocalUserContext.getLocale(),
                    scale);
            value = format.format(amount) + " " + unit;
        }
        buf.append(StringUtils.leftPad(value, 18));
    }
    if (html == true) {
        buf.append("</td></tr>\n");
    } else {
        buf.append("\n");
    }
}