Package jpicedt

Class MiscUtilities


  • public class MiscUtilities
    extends java.lang.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.15.2.1 2007/09/02 11:55:59 reynal Exp $
    Author:
    Sylvain Reynal
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_CONTENT_TYPE_INDEX
      default index in array returned by getAvailableContentTypes
      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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      static Parser createParser()
      Return a parser dynamically created from the sub-trees found in directory jpicedt.format.*
      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)
      static void formatRenderingHints​(java.awt.RenderingHints rh, java.util.Properties preferences)
      store the given RenderingHints to a Properties object
      static java.lang.String[] getAvailableContentTypes()  
      static java.lang.String[][] getAvailableContentTypesFileExtensions()  
      static java.lang.String[] getAvailableContentTypesNames()  
      static java.lang.String getClipboardStringContent​(java.awt.datatransfer.Clipboard clipboard)  
      static ContentType getContentTypeFromClassName​(java.lang.String contentTypeClassName)  
      static int getContentTypeIndex​(java.lang.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 java.lang.String getJPicEdtHome()
      Returns JPicEdt's install directory w/o trailing "/", provided the command line looks like :
      static java.io.File getOSTmpDir()
      Return the platform standard tmp dir, or null if none is standardly defined.
      static void main​(java.lang.String[] args)  
      static double parseDouble​(java.lang.String val)
      Return a double parsed from the given string, possibly formatted with a "%" sign
      static boolean parseProperty​(java.util.Properties preferences, java.lang.String key, boolean def)  
      static double parseProperty​(java.util.Properties preferences, java.lang.String key, double def)  
      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.
      static java.awt.Color parseProperty​(java.util.Properties preferences, java.lang.String key, java.awt.Color def)  
      static java.util.ArrayList parseRecentFiles​(java.util.Properties preferences)  
      static java.awt.RenderingHints parseRenderingHints​(java.util.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 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 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​(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.getPercentInstance to 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.ParseException
        Return a double parsed from the given string, possibly formatted with a "%" sign
        Throws:
        java.lang.NumberFormatException
        java.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.