Package jpicedt
Class MiscUtilities
- java.lang.Object
-
- jpicedt.MiscUtilities
-
public class MiscUtilities extends java.lang.ObjectA collection of static utilities methods.Developpers, be careful before adding new methods here : keep in mind that this class MUST remain independent of the jpicedt.ui.* package (as well as of jpicedt.JPicEdt), since it's shipped with the jpicedt's library, which only contains the jpicedt.graphic.* and jpicedt.format.* packages !
- Since:
- jPicEdt 1.3.2
- Version:
- $Id: MiscUtilities.java,v 1.15.2.1 2007/09/02 11:55:59 reynal Exp $
- Author:
- Sylvain Reynal
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONTENT_TYPE_INDEXdefault index in array returned by getAvailableContentTypesstatic java.lang.StringKEY_RECENT_FILEkey used to retrieve the list of recent files from a properties file a ".X" string, where X is a number starting from 1, should be appended to the key beforehands.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddRecentFile(java.util.Properties preferences, java.lang.String newName)Add the given file name to the list of recent files in the given Properties object, trimming the length of the list to 10.static ParsercreateParser()Return a parser dynamically created from the sub-trees found in directory jpicedt.format.*static java.lang.StringformatFontAsProperties(java.awt.Font font)format a given Font to a string, following "Font.decode()" format, ie fontname-style-pointsize, fontname-pointsize, fontname-style or fontname, where style is one of "BOLD", "ITALIC", "BOLDITALIC" (default being PLAIN)static voidformatRenderingHints(java.awt.RenderingHints rh, java.util.Properties preferences)store the given RenderingHints to a Properties objectstatic java.lang.String[]getAvailableContentTypes()static java.lang.String[][]getAvailableContentTypesFileExtensions()static java.lang.String[]getAvailableContentTypesNames()static java.lang.StringgetClipboardStringContent(java.awt.datatransfer.Clipboard clipboard)static ContentTypegetContentTypeFromClassName(java.lang.String contentTypeClassName)static intgetContentTypeIndex(java.lang.String contentTypeClassName)Utility to retrieve the index of the given content-type class name in the array returned bygetAvailableContentTypes; to be used by JComboBox'es.static java.lang.StringgetJPicEdtHome()Returns JPicEdt's install directory w/o trailing "/", provided the command line looks like :static java.io.FilegetOSTmpDir()Return the platform standard tmp dir, or null if none is standardly defined.static voidmain(java.lang.String[] args)static doubleparseDouble(java.lang.String val)Return a double parsed from the given string, possibly formatted with a "%" signstatic booleanparseProperty(java.util.Properties preferences, java.lang.String key, boolean def)static doubleparseProperty(java.util.Properties preferences, java.lang.String key, double def)static intparseProperty(java.util.Properties preferences, java.lang.String key, int def)Return a integer parsed from the value associated with the given key, or "def" in key wasn't found.static java.awt.ColorparseProperty(java.util.Properties preferences, java.lang.String key, java.awt.Color def)static java.util.ArrayListparseRecentFiles(java.util.Properties preferences)static java.awt.RenderingHintsparseRenderingHints(java.util.Properties preferences)Returns a RenderingHints parsed from the given Properties
-
-
-
Field Detail
-
DEFAULT_CONTENT_TYPE_INDEX
public static final int DEFAULT_CONTENT_TYPE_INDEX
default index in array returned by getAvailableContentTypes- See Also:
- Constant Field Values
-
KEY_RECENT_FILE
public static java.lang.String KEY_RECENT_FILE
key used to retrieve the list of recent files from a properties file a ".X" string, where X is a number starting from 1, should be appended to the key beforehands.
-
-
Method Detail
-
getAvailableContentTypes
public static java.lang.String[] getAvailableContentTypes()
- Returns:
- an array containing the class names of the currently available ContentType's [pending] fetch from a Properties on disk ?
-
getAvailableContentTypesNames
public static java.lang.String[] getAvailableContentTypesNames()
- Returns:
- an array containing the class names of the currently available ContentType's [pending] fetch from a Properties on disk ?
-
getAvailableContentTypesFileExtensions
public static java.lang.String[][] getAvailableContentTypesFileExtensions()
- Returns:
- an array containing the class names of the currently available ContentType's [pending] fetch from a Properties on disk ?
-
getContentTypeIndex
public static int getContentTypeIndex(java.lang.String contentTypeClassName)
Utility to retrieve the index of the given content-type class name in the array returned bygetAvailableContentTypes; to be used by JComboBox'es.- Parameters:
contentTypeClassName- e.g. "jpicedt.format.latex.LatexContentType"- Returns:
- DEFAULT_CONTENT_TYPE_INDEX if not found.
-
getContentTypeFromClassName
public static ContentType getContentTypeFromClassName(java.lang.String contentTypeClassName)
- Returns:
- an instanciation of the given content-type class name, or null if class wasn't found
-
createParser
public static Parser createParser()
Return a parser dynamically created from the sub-trees found in directory jpicedt.format.*
-
parseProperty
public static boolean parseProperty(java.util.Properties preferences, java.lang.String key, boolean def)- Returns:
- a boolean built from the value fetched from the given key in the given properties, or the "def" value if the key wasn't found
-
parseProperty
public static java.awt.Color parseProperty(java.util.Properties preferences, java.lang.String key, java.awt.Color def)- Returns:
- a Color built from the value fetched from the given key in the given properties, or the "def" value if the key wasn't found
-
parseProperty
public static double parseProperty(java.util.Properties preferences, java.lang.String key, double def)- Returns:
- a double parsed from the value associated with the given key in the given Properties.
returns "def" in key wasn't found, or if a parsing error occured. If "value" contains
a "%" sign, we use a
NumberFormat.getPercentInstanceto convert it to a double.
-
parseProperty
public static int parseProperty(java.util.Properties preferences, java.lang.String key, int def)Return a integer parsed from the value associated with the given key, or "def" in key wasn't found.
-
parseRenderingHints
public static java.awt.RenderingHints parseRenderingHints(java.util.Properties preferences)
Returns a RenderingHints parsed from the given Properties
-
formatRenderingHints
public static void formatRenderingHints(java.awt.RenderingHints rh, java.util.Properties preferences)store the given RenderingHints to a Properties object
-
parseDouble
public static double parseDouble(java.lang.String val) throws java.lang.NumberFormatException, java.text.ParseExceptionReturn a double parsed from the given string, possibly formatted with a "%" sign- Throws:
java.lang.NumberFormatExceptionjava.text.ParseException
-
formatFontAsProperties
public static java.lang.String formatFontAsProperties(java.awt.Font font)
format a given Font to a string, following "Font.decode()" format, ie fontname-style-pointsize, fontname-pointsize, fontname-style or fontname, where style is one of "BOLD", "ITALIC", "BOLDITALIC" (default being PLAIN)
-
parseRecentFiles
public static java.util.ArrayList parseRecentFiles(java.util.Properties preferences)
- Returns:
- an ArrayList containing recent file names, fetched from the given key (e.g. PEMenuBar.KEY_RECENT_FILE)
-
addRecentFile
public static void addRecentFile(java.util.Properties preferences, java.lang.String newName)Add the given file name to the list of recent files in the given Properties object, trimming the length of the list to 10. If the given name is already in the list, move it to the top.
-
getClipboardStringContent
public static java.lang.String getClipboardStringContent(java.awt.datatransfer.Clipboard clipboard)
- Returns:
- the clipboard content as a String (DataFlavor.stringFlavor) Code snippet adapted from jEdit (Registers.java), http://www.jedit.org. Returns null if clipboard is empty.
-
getJPicEdtHome
public static java.lang.String getJPicEdtHome()
Returns JPicEdt's install directory w/o trailing "/", provided the command line looks like :java -classpath other-class-paths:jpicedt-install-dir/lib/jpicedt.jar jpicedt.JPicEdt(where "/" is replaced by the actual separator for the underlying platform).That is, the old way (java -jar jpicedt.jar) won't work. However, classpath can contain relative pathname (then user.dir get preprended).
Code snippet was adapted from jEdit/JEdit.java (http://www.jedit.org).
- Returns:
- the value of the "user.dir" Java property if "lib/jpicedt.jar" or "jpicedt.jar" wasn't found in the command line.
-
main
public static void main(java.lang.String[] args)
-
getOSTmpDir
public static java.io.File getOSTmpDir()
Return the platform standard tmp dir, or null if none is standardly defined.
-
-