List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size)
Right pad a String with spaces (' ').
From source file:raptor.swt.chat.ChatConsoleController.java
protected void onOutputTextRightClick(MouseEvent e) { int caretPosition = 0; String word = ""; boolean wasSelectedText = false; try {/* w ww . j a va 2 s .c o m*/ caretPosition = chatConsole.getOutputText().getOffsetAtLocation(new Point(e.x, e.y)); chatConsole.getOutputText().getSelectionText(); word = chatConsole.getOutputText().getSelectionText(); wasSelectedText = !word.isEmpty(); if (StringUtils.isBlank(word)) { word = ChatUtils.getWord(chatConsole.getOutputText(), caretPosition); wasSelectedText = false; } else { word = connector.removeLineBreaks(word); } } catch (Throwable t) { } final String finalWord = word; Menu menu = new Menu(chatConsole.getShell(), SWT.POP_UP); if (wasSelectedText) { MenuItem copyItem = new MenuItem(menu, SWT.PUSH); copyItem.setText(local.getString("chatConsCont24")); copyItem.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { chatConsole.outputText.copy(); } }); } MenuItem pasteItem = new MenuItem(menu, SWT.PUSH); pasteItem.setText(local.getString("chatConsCont31")); pasteItem.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { chatConsole.outputText.paste(); } }); if (StringUtils.isNotBlank(finalWord)) { if (getPreferences().getBoolean(CHAT_COMMAND_LINE_SPELL_CHECK)) { new MenuItem(menu, SWT.SEPARATOR); MenuItem showWordsThatStartWithAction = new MenuItem(menu, SWT.PUSH); showWordsThatStartWithAction.setText(local.getString("chatConsCont25") + finalWord); showWordsThatStartWithAction.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { BrowserUtils.openUrl("https://duckduckgo.com/q=" + finalWord); } }); } if (getPreferences().getBoolean(CHAT_COMMAND_LINE_SPELL_CHECK)) { new MenuItem(menu, SWT.SEPARATOR); MenuItem showWordsThatStartWithAction = new MenuItem(menu, SWT.PUSH); showWordsThatStartWithAction.setText(local.getString("chatConsCont26") + word + "'"); showWordsThatStartWithAction.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String[] words = DictionaryService.getInstance().getWordsThatStartWith(finalWord); StringBuilder output = new StringBuilder(2000); if (words == null || words.length == 0) { output.append(local.getString("chatConsCont27")); } else { output.append(local.getString("chatConsCont28")).append(finalWord).append(":\n"); int count = 0; for (int i = 0; i < words.length; i++) { output.append(StringUtils.rightPad(words[i], 20)); count++; if (count == 3) { output.append("\n"); count = 0; } } } onAppendChatEventToInputText(new ChatEvent(null, ChatType.INTERNAL, output.toString())); } }); } if (getPreferences().getBoolean(CHAT_COMMAND_LINE_SPELL_CHECK) && word != null && !isSpelledCorrectly(null, word)) { MenuItem addWord = new MenuItem(menu, SWT.PUSH); addWord.setText(local.getString("chatConsCont29") + word + local.getString("chatConsCont30")); addWord.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { DictionaryService.getInstance().addWord(finalWord); } }); } } if (menu.getItemCount() > 0) { if (LOG.isDebugEnabled()) { LOG.debug("Showing popup with " + menu.getItemCount() + " items." + chatConsole.inputText.toDisplay(e.x, e.y)); } menu.setLocation(chatConsole.outputText.toDisplay(e.x, e.y)); menu.setVisible(true); while (!menu.isDisposed() && menu.isVisible()) { if (!chatConsole.getDisplay().readAndDispatch()) { chatConsole.getDisplay().sleep(); } } } menu.dispose(); }
From source file:raptor.swt.ErrorDialog.java
/** * Creates the dialog's contents// www.java2 s . c o m * * @param shell * the dialog window */ @Override protected void createContents(final Shell shell) { shell.setLayout(new GridLayout(1, false)); // Display the input box errorText = new StyledText(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER); errorText.setEditable(false); String line = StringUtils.rightPad("", 80) + "\n"; errorText.setText(line + line + line + line + line + line + line + line + line + line + line); errorText.setWordWrap(true); errorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Button ok = new Button(shell, SWT.PUSH); ok.setText("OK"); ok.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 1, 1)); ok.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { input = ""; shell.close(); } }); }
From source file:stroom.index.server.BenchmarkIndex.java
@Override public void run() { init();//from ww w. j ava 2 s. c o m final long batchStartTime = System.currentTimeMillis(); final IndexShardWriterImpl[] writers = new IndexShardWriterImpl[indexShards.length]; for (int i = 0; i < writers.length; i++) { final IndexShard indexShard = indexShards[i]; writers[i] = new IndexShardWriterImpl(indexShardService, indexFields, indexShard.getIndex(), indexShard); writers[i].setRamBufferSizeMB(ramBufferMbSize); writers[i].open(true); } final AtomicLong atomicLong = new AtomicLong(); final long indexStartTime = System.currentTimeMillis(); final ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(jobSize); for (int i = 0; i < jobSize; i++) { final Runnable r = () -> { long myId; while ((myId = atomicLong.incrementAndGet()) < docCount) { try { final int idx = (int) (myId % writers.length); writers[idx].addDocument(getDocument(myId)); } catch (final Exception e) { e.printStackTrace(); } } }; threadPoolExecutor.execute(r); } threadPoolExecutor.shutdown(); // Wait for termination. while (!threadPoolExecutor.isTerminated()) { // Wait 1 second. ThreadUtil.sleep(1000); final long docsSoFar = atomicLong.get(); final long secondsSoFar = (System.currentTimeMillis() - batchStartTime) / 1000; for (int i = 0; i < writers.length; i++) { final IndexShardWriterImpl impl = writers[i]; final IndexShard indexShard = indexShards[i]; if (secondsSoFar > 0) { final long docsPerSecond = docsSoFar / secondsSoFar; impl.sync(); LOGGER.info("run() - " + StringUtils.rightPad(ModelStringUtil.formatCsv(docsSoFar), 10) + " doc ps " + ModelStringUtil.formatCsv(docsPerSecond) + " (" + indexShard.getFileSizeString() + ")"); } if (nextCommit != null && docsSoFar > nextCommit) { impl.flush(); nextCommit = ((docsSoFar / commitCount) * commitCount) + commitCount; LOGGER.info("run() - commit " + docsSoFar + " next commit is " + nextCommit); } } } final long indexEndTime = System.currentTimeMillis(); final long secondsSoFar = (System.currentTimeMillis() - batchStartTime) / 1000; final long docsPerSecond = atomicLong.get() / secondsSoFar; for (final IndexShardWriter writer : writers) { writer.close(); } final long batchEndTime = System.currentTimeMillis(); LOGGER.info("runWrite() - Complete"); LOGGER.info("====================="); LOGGER.info(""); LOGGER.info("Using Args"); LOGGER.info("=========="); LoggerPrintStream traceStream = LoggerPrintStream.create(LOGGER, false); traceArguments(traceStream); traceStream.close(); LOGGER.info(""); LOGGER.info("Stats"); LOGGER.info("====="); LOGGER.info("Open Time " + toMsNiceString(indexStartTime - batchStartTime)); LOGGER.info("Index Time " + toMsNiceString(indexEndTime - indexStartTime)); LOGGER.info("Close Time " + toMsNiceString(batchEndTime - indexEndTime)); LOGGER.info("Total Time " + toMsNiceString(batchEndTime - batchStartTime)); LOGGER.info(""); LOGGER.info("Final Docs PS " + ModelStringUtil.formatCsv(docsPerSecond)); traceStream = LoggerPrintStream.create(LOGGER, false); for (int i = 0; i < writers.length; i++) { LOGGER.info(""); final IndexShardWriterImpl impl = writers[i]; LOGGER.info("Writer " + StringUtils.leftPad(String.valueOf(i), 2)); LOGGER.info("========="); impl.trace(traceStream); } traceStream.close(); LOGGER.info(""); LOGGER.info("Search"); LOGGER.info("====="); try { final IndexShardSearcherImpl[] reader = new IndexShardSearcherImpl[indexShards.length]; final IndexReader[] readers = new IndexReader[indexShards.length]; for (int i = 0; i < reader.length; i++) { reader[i] = new IndexShardSearcherImpl(indexShards[i]); reader[i].open(); readers[i] = reader[i].getReader(); } for (final String arg : docArgs) { doSearchOnField(readers, arg); } doSearchOnField(readers, "multifield"); doSearchOnField(readers, "dupfield"); LOGGER.info("====="); for (int i = 0; i < reader.length; i++) { reader[i].close(); } } catch (final Exception ex) { ex.printStackTrace(); } }
From source file:stroom.util.AbstractCommandLineTool.java
private void doTraceArguments(final PrintStream printStream) throws Exception { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); for (final PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { // Only do properties with getters if (pd.getWriteMethod() != null) { // Simple getter ? String suffix = " (default)"; if (map.containsKey(pd.getName())) { suffix = " (arg)"; }/*from w w w .ja v a2 s.co m*/ String value = ""; if (pd.getReadMethod() != null && pd.getReadMethod().getParameterTypes().length == 0) { value = String.valueOf(pd.getReadMethod().invoke(this)); } else { // No simple getter Field field = null; try { field = this.getClass().getDeclaredField(pd.getName()); } catch (final NoSuchFieldException nsfex) { // Ignore } if (field != null) { field.setAccessible(true); value = String.valueOf(field.get(this)); } else { value = "?"; } } printStream.println(StringUtils.rightPad(pd.getName(), maxPropLength) + " = " + value + suffix); } } }
From source file:stroom.util.StreamRestoreTool.java
public ArrayList<KeyCount> writeTable(final Collection<KeyCount> values, final String heading) { writeLine("========================"); writeLine(heading);// ww w. j a v a 2s .c om writeLine("========================"); final ArrayList<KeyCount> list = new ArrayList<>(); list.addAll(values); sort(list); for (final KeyCount keyCount : list) { writeLine(StringUtils.rightPad(keyCount.getKey().toString(), KEY_PAD) + StringUtils.leftPad(ModelStringUtil.formatCsv(keyCount.getCount()), COUNT_PAD)); } writeLine("========================"); return list; }
From source file:xc.mst.bo.record.RecordCounts.java
public String toString(String repoName) { StringBuilder sb = new StringBuilder(); // This is for the purpose of making the totals appear last List<String> keys = new ArrayList<String>(); for (String type : counts.keySet()) { if (!type.equals(TOTALS) && !type.equals(OTHER)) { keys.add(type);/*from w ww . j av a 2s . co m*/ } } keys.add(OTHER); keys.add(TOTALS); for (String type : keys) { Map<String, AtomicInteger> counts4Type = counts.get(type); if (counts4Type == null) continue; type = StringUtils.rightPad(type, 25); int col = 0; List<String> colNames = new ArrayList<String>(); colNames.addAll(INCOMING_STATUS_COLUMN_NAMES); if (RecordCounts.OUTGOING.equals(this.incomingOutgoing)) { colNames.addAll(UPD_PREV_COLUMN_NAMES.values()); } else { colNames.add(UNEXPECTED_ERROR); } String date = "all time "; LOG.debug("TOTALS_DATE.getTime(): " + TOTALS_DATE.getTime()); LOG.debug("this.harvestStartDate.getTime(): " + this.harvestStartDate.getTime()); if (this.harvestStartDate.getTime() != TOTALS_DATE.getTime()) { LOG.debug("new Util().printDateTime(this.harvestStartDate): " + new Util().printDateTime(this.harvestStartDate)); LOG.debug("new Util().printDateTime(TOTALS_DATE): " + new Util().printDateTime(TOTALS_DATE)); date = new Util().printDateTime(this.harvestStartDate); } for (String updateType : colNames) { if (col == 0) sb.append("\n" + incomingOutgoing + " " + date + " " + type + " "); long num = 0; if (counts4Type.get(updateType) != null) { num = counts4Type.get(updateType).get(); } DecimalFormat myFormatter = new DecimalFormat("###,###,###"); String line = StringUtils.leftPad(updateType, 25) + ": " + StringUtils.leftPad(myFormatter.format(num), 12) + " "; sb.append(line); if (++col == 3) { col = 0; } } } return sb.toString(); }