List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:org.acmsl.commons.utils.StringUtils.java
/** * Adds given prefix and suffix to each line of given text. * <code>//from w w w .j a v a 2 s . c o m * applyToEachLine(" line 1 \n and line 2", "||{0}{1}//").equals( * "||line 1//\n|| and line 2//\n") * </code> * 0 - indentation spaces * 1 - trimmed text * @param text the text. * @param format the format. * @return the processed text. */ @NotNull public String applyToEachLine(@NotNull final String text, @NotNull final String format) { @NotNull final StringBuilder result = new StringBuilder(); @NotNull final StringTokenizer t_StringTokenizer = new StringTokenizer(text, "\n", false); int t_iInitialIndent = retrieveMinimumIndentInAllLines(text); @NotNull final StringBuilder t_sbInitialIndent = new StringBuilder(); for (int t_iIndex = 0; t_iIndex < t_iInitialIndent; t_iIndex++) { t_sbInitialIndent.append(" "); } @NotNull final String t_strInitialIndent = t_sbInitialIndent.toString(); boolean t_bFirstLine = true; String t_strCurrentLine; String t_strTrimmedCurrentLine; @NotNull final MessageFormat t_Formatter = new MessageFormat(format); String t_strCurrentIndent = ""; while (t_StringTokenizer.hasMoreTokens()) { t_strCurrentLine = t_StringTokenizer.nextToken(); t_strTrimmedCurrentLine = t_strCurrentLine.trim(); if (!t_bFirstLine) { t_iInitialIndent = t_strCurrentLine.indexOf(t_strTrimmedCurrentLine); if (t_iInitialIndent > t_strInitialIndent.length()) { t_strCurrentIndent = t_strCurrentLine.substring(t_strInitialIndent.length(), t_iInitialIndent); } else { t_strCurrentIndent = ""; } } result.append(t_Formatter.format(new Object[] { t_strCurrentIndent, t_strTrimmedCurrentLine })); result.append("\n"); if (t_bFirstLine) { t_bFirstLine = false; } } return result.toString(); }
From source file:com.netscape.cmscore.apps.CMSEngine.java
public String getUserMessage(Locale locale, String msgID, String params[]) { // if locale is null, try to get it out from session context if (locale == null) { SessionContext sc = SessionContext.getExistingContext(); if (sc != null) locale = (Locale) sc.get(SessionContext.LOCALE); }/*from www . j a v a 2 s. c o m*/ ResourceBundle rb = null; if (locale == null) { rb = ResourceBundle.getBundle("UserMessages", Locale.ENGLISH); } else { rb = ResourceBundle.getBundle("UserMessages", locale); } String msg = rb.getString(msgID); if (params == null) return msg; MessageFormat mf = new MessageFormat(msg); return mf.format(params); }
From source file:com.netscape.cmscore.apps.CMSEngine.java
public String getLogMessage(String msgID, Object params[]) { ResourceBundle rb = ResourceBundle.getBundle("LogMessages"); String msg = rb.getString(msgID); if (params == null) return msg; MessageFormat mf = new MessageFormat(msg); Object escapedParams[] = new Object[params.length]; for (int i = 0; i < params.length; i++) { if (params[i] instanceof String) escapedParams[i] = escapeLogMessageParam((String) params[i]); else//w w w . j a v a 2s. c o m escapedParams[i] = params[i]; } return mf.format(escapedParams); }
From source file:org.talend.designer.runprocess.ui.ProcessComposite.java
public void debug() { setHideconsoleLine(false);/* w w w . j a v a2s . c o m*/ if ((processContext.getProcess()) instanceof org.talend.designer.core.ui.editor.process.Process) { ((org.talend.designer.core.ui.editor.process.Process) processContext.getProcess()) .checkDifferenceWithRepository(); } // final IPreferenceStore preferenceStore = DebugUIPlugin.getDefault().getPreferenceStore(); final IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore(); final boolean oldValueConsoleOnOut = preferenceStore .getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT); final boolean oldValueConsoleOnErr = preferenceStore .getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR); preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, false); preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, false); checkSaveBeforeRunSelection(); if (contextComposite.promptConfirmLauch()) { setRunnable(false); final IContext context = contextComposite.getSelectedContext(); IRunnableWithProgress worker = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { IProcessor processor = ProcessorUtilities.getProcessor(processContext.getProcess(), processContext.getProcess().getProperty(), context); monitor.beginTask("Launching debugger", IProgressMonitor.UNKNOWN); //$NON-NLS-1$ try { // use this function to generate childrens also. ProcessorUtilities.generateCode(processContext.getProcess(), context, false, false, true, monitor); ILaunchConfiguration config = ((Processor) processor).getDebugConfiguration( processContext.getStatisticsPort(), processContext.getTracesPort(), null); // see feature 0004820: The run job doesn't verify if // code is correct before launching if (!JobErrorsChecker.hasErrors(ProcessComposite.this.getShell())) { if (config != null) { // PlatformUI.getWorkbench(). // getActiveWorkbenchWindow // ().addPerspectiveListener(new // DebugInNewWindowListener()); DebugUITools.launch(config, ILaunchManager.DEBUG_MODE); } else { MessageDialog.openInformation(getShell(), Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$ Messages.getString("ProcessDebugDialog.errortext")); //$NON-NLS-1$ } } } catch (ProcessorException e) { IStatus status = new Status(IStatus.ERROR, RunProcessPlugin.PLUGIN_ID, IStatus.OK, "Debug launch failed.", e); //$NON-NLS-1$ RunProcessPlugin.getDefault().getLog().log(status); MessageDialog.openError(getShell(), Messages.getString("ProcessDebugDialog.debugBtn"), ""); //$NON-NLS-1$ //$NON-NLS-2$ } finally { monitor.done(); } } }; IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); try { progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), worker, ResourcesPlugin.getWorkspace().getRoot()); } catch (InvocationTargetException e) { // e.printStackTrace(); ExceptionHandler.process(e); } catch (InterruptedException e) { // e.printStackTrace(); ExceptionHandler.process(e); } } debugMode = true; try { Thread thread = new Thread() { @Override public void run() { while (debugMode) { final IProcess process = DebugUITools.getCurrentProcess(); if (process != null && process.isTerminated()) { getDisplay().asyncExec(new Runnable() { @Override public void run() { setRunnable(true); killBtn.setEnabled(false); preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, oldValueConsoleOnOut); preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, oldValueConsoleOnErr); if (isAddedStreamListener) { process.getStreamsProxy().getOutputStreamMonitor() .removeListener(streamListener); isAddedStreamListener = false; if (processContext.isRunning()) { final String endingPattern = Messages .getString("ProcessComposite.endPattern"); //$NON-NLS-1$ MessageFormat mf = new MessageFormat(endingPattern); String byeMsg; try { byeMsg = "\n" //$NON-NLS-1$ + mf.format(new Object[] { processContext.getProcess().getName(), new Date(), new Integer(process.getExitValue()) }); processContext.addDebugResultToConsole( new ProcessMessage(MsgType.CORE_OUT, byeMsg)); } catch (DebugException e) { // e.printStackTrace(); ExceptionHandler.process(e); } processContext.setRunning(false); } } debugMode = false; } }); } else { if (process != null) { // (one at leat) process // still running getDisplay().asyncExec(new Runnable() { @Override public void run() { setRunnable(false); killBtn.setEnabled(true); processContext.setRunning(true); processContext.setDebugProcess(process); if (!isAddedStreamListener) { process.getStreamsProxy().getOutputStreamMonitor() .addListener(streamListener); // if (clearBeforeExec.getSelection()) { // processContext.clearMessages(); // } // if (watchBtn.getSelection()) { // processContext.switchTime(); // } ClearPerformanceAction clearPerfAction = new ClearPerformanceAction(); clearPerfAction.setProcess(processContext.getProcess()); clearPerfAction.run(); ClearTraceAction clearTraceAction = new ClearTraceAction(); clearTraceAction.setProcess(processContext.getProcess()); clearTraceAction.run(); isAddedStreamListener = true; final String startingPattern = Messages .getString("ProcessComposite.startPattern"); //$NON-NLS-1$ MessageFormat mf = new MessageFormat(startingPattern); String welcomeMsg = mf.format(new Object[] { processContext.getProcess().getName(), new Date() }); processContext.addDebugResultToConsole( new ProcessMessage(MsgType.CORE_OUT, welcomeMsg + "\r\n"));//$NON-NLS-1$ } } }); } else { // no process running getDisplay().asyncExec(new Runnable() { @Override public void run() { setRunnable(true); killBtn.setEnabled(false); } }); } } try { Thread.sleep(2000); } catch (InterruptedException e) { // e.printStackTrace(); ExceptionHandler.process(e); } } } }; thread.start(); } catch (Exception e) { ExceptionHandler.process(e); processContext.addErrorMessage(e); kill(); } }
From source file:Store.SelectedPatient.java
private void btn_printActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_printActionPerformed MessageFormat header = new MessageFormat("Medical Report"); MessageFormat footer = new MessageFormat("page{0,number,integer}"); try {/* w w w .j a v a 2s . c om*/ select_PTable.print(JTable.PrintMode.NORMAL, header, footer); } catch (java.awt.print.PrinterException pe) { System.err.format("Cannot Print", pe.getMessage()); } }
From source file:ImageAnalyzer.java
static String createMsg(String msg, Object[] args) { MessageFormat formatter = new MessageFormat(msg); return formatter.format(args); }
From source file:ImageAnalyzer.java
static String createMsg(String msg, Object arg) { MessageFormat formatter = new MessageFormat(msg); return formatter.format(new Object[] { arg }); }