http://www.jpicedt.org

jpicedt
Class MiscUtilities

java.lang.Object
  extended by jpicedt.MiscUtilities

public class MiscUtilities
extends Object

A 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.24 2013/03/27 06:53:01 vincentb1 Exp $
Author:
Sylvain Reynal

Nested Class Summary
static class MiscUtilities.ContentTypeBasics
           
 
Field Summary
static int DEFAULT_CONTENT_TYPE_INDEX
          default index in array returned by getAvailableContentTypes
static 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 Summary
static void addRecentFile(Properties preferences, 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 ExtractionParsing createParser()
          Return a parser dynamically created from the sub-trees found in directory jpicedt.format
static String formatFontAsProperties(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 void formatRenderingHints(RenderingHints rh, Properties preferences)
          store the given RenderingHints to a Properties object
static String[] getAvailableContentTypes()
           
static String[][] getAvailableContentTypesFileExtensions()
           
static String[] getAvailableContentTypesNames()
           
static String getClipboardStringContent(Clipboard clipboard)
           
static ContentType getContentTypeFromClassName(String contentTypeClassName)
           
static int getContentTypeIndex(String contentTypeClassName)
          Utility to retrieve the index of the given content-type class name in the array returned by getAvailableContentTypes ; to be used by JComboBox'es.
static 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 / may be replaced by the actual respective separator for files on the underlying platform).
static File getOSTmpDir()
          Return the platform standard tmp dir, or null if none is standardly defined.
static void main(String[] args)
           
static double parseDouble(String val)
          Return a double parsed from the given string, possibly formatted with a "%" sign
static boolean parseProperty(Properties preferences, String key, boolean def)
           
static Color parseProperty(Properties preferences, String key, Color def)
           
static double parseProperty(Properties preferences, String key, double def)
           
static int parseProperty(Properties preferences, String key, int def)
          Return a integer parsed from the value associated with the given key, or "def" in key wasn't found.
static ArrayList<String> parseRecentFiles(Properties preferences)
           
static RenderingHints parseRenderingHints(Properties preferences)
          Returns a RenderingHints parsed from the given Properties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 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 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 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 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(String contentTypeClassName)
Utility to retrieve the index of the given content-type class name in the array returned by getAvailableContentTypes ; 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(String contentTypeClassName)
Returns:
an instanciation of the given content-type class name, or null if class wasn't found

createParser

public static ExtractionParsing createParser()
Return a parser dynamically created from the sub-trees found in directory jpicedt.format.*


parseProperty

public static boolean parseProperty(Properties preferences,
                                    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 Color parseProperty(Properties preferences,
                                  String key,
                                  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(Properties preferences,
                                   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.getPercentInstance to convert it to a double.

parseProperty

public static int parseProperty(Properties preferences,
                                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 RenderingHints parseRenderingHints(Properties preferences)
Returns a RenderingHints parsed from the given Properties


formatRenderingHints

public static void formatRenderingHints(RenderingHints rh,
                                        Properties preferences)
store the given RenderingHints to a Properties object


parseDouble

public static double parseDouble(String val)
                          throws NumberFormatException,
                                 ParseException
Return a double parsed from the given string, possibly formatted with a "%" sign

Throws:
NumberFormatException
ParseException

formatFontAsProperties

public static String formatFontAsProperties(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 ArrayList<String> parseRecentFiles(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(Properties preferences,
                                 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 String getClipboardStringContent(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 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 / may be replaced by the actual respective separator for files on the underlying platform).

For Windows platform, the install directory is tried to be detected 1st with the MSWindows file-separator (\), and if this does not work, a subsequent trial is made with /.

That is, the old way (java -jar jpicedt.jar) won't work. However, classpath can contain relative pathname (then user.dir get prepended).

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" wasn't found in the command line.

main

public static void main(String[] args)

getOSTmpDir

public static File getOSTmpDir()
Return the platform standard tmp dir, or null if none is standardly defined.


http://www.jpicedt.org

Submit a bug : syd@jpicedt.org