Code Search for Developers
 
 
  

Formatter.java from PovClipse at Krugle


Show Formatter.java syntax highlighted

/*
 * PovClipse - Eclipse plugin for editing and rendering Povray sceene files.
 * Copyright (C) 2006-2007  Wolfgang Moestl  wmoestl@web.de
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

package com.wm.povclipse.common;

import java.text.NumberFormat;
import java.util.Locale;

/**
 * Static utility class providing formatting support.
 * @author Wolfgang Möstl
 */
public class Formatter {
	/**
	 * The one-and-only static instance of a <code>NumberFormat</code> 
	 * formatter using the US locale and having a minimum fraction digit
	 * count of 1.<br>
	 * <b>WARNING: DO NOT CHANGE ANY PROPERTIES OF THIS FORMATTER!</b> This
	 * is a static object, beeing shared between multiple objects!
	 */
	public static final NumberFormat floatFormatter = NumberFormat.getNumberInstance(Locale.US);
	
	static {
		floatFormatter.setMinimumFractionDigits(1);
	}
	
	/**
	 * Ensures that the given String has at least the given length.<br>
	 * Please note that longer Strings are <b>NOT</b> truncated!
	 * 
	 * @param in The String to be processed
	 * @param len The minimum Length of the returned String
	 * @param filler The character to be used for filling up the missing lenght
	 * @param append If <code>true</code> the necessary filling characters
	 * will be appended to the given String, otherwise the filling happes by prefixing the String.
	 * @return
	 */
	public static String ensureLenght(String in, int len, char filler, boolean append) {
		if (in.length() >= len) return in;
		
		StringBuffer sb = new StringBuffer(in);
		for (int i=0; i<len - in.length(); i++) {
			if (append)
				sb.append(filler);
			else
				sb.insert(0, filler);
		}
		return sb.toString();		
	}
	
	/**
	 * @return A new instance of a <code>NumberFormat</code> object using the US
	 * locale. It's save to change the formatting options of this object. 
	 */
	public static NumberFormat getNewFloatFormatter() {
		NumberFormat formatter = NumberFormat.getNumberInstance(Locale.US);
		return formatter;
	}
}




See more files for this project here

PovClipse

PovClipse is an eclipse editor plugin for Povray (Persistence of Vision Raytracer) sceene- and include files.\r\nIt features syntax highlighting, code folding, code assist, outline view as well as running Povray using render configurations.

Project homepage: http://sourceforge.net/projects/povclipse
Programming language(s): Java
License: other

  ColorManager.java
  Formatter.java
  IPovrayColorConstants.java
  MessageData.java
  PovClipseHoverPresenter.java
  PovClipseMessageTypeIndication.java