freemind.main
Class Tools

java.lang.Object
  extended by freemind.main.Tools

public class Tools
extends java.lang.Object

Author:
foltin

Nested Class Summary
static class Tools.BooleanHolder
           
static class Tools.DesEncrypter
          from: http://javaalmanac.com/egs/javax.crypto/PassKey.html
static class Tools.IntHolder
           
static class Tools.ObjectHolder
           
static class Tools.Pair
           
static class Tools.SingleDesEncrypter
           
static class Tools.TripleDesEncrypter
           
 
Field Summary
static java.util.Set executableExtensions
           
static java.lang.String JAVA_VERSION
           
 
Constructor Summary
Tools()
           
 
Method Summary
static void addEscapeActionToDialog(javax.swing.JDialog dialog)
           
static void addEscapeActionToDialog(javax.swing.JDialog dialog, javax.swing.Action action)
           
static void addKeyActionToDialog(javax.swing.JDialog dialog, javax.swing.Action action, java.lang.String keyStroke, java.lang.String actionId)
           
static java.lang.String BooleanToXml(boolean col)
           
static java.lang.String byteArrayToUTF8String(byte[] compressedData)
           
static java.lang.String colorToXml(java.awt.Color col)
           
static java.lang.String compareText(java.lang.String pText1, java.lang.String pText2)
           
static java.lang.String compress(java.lang.String message)
           
static void convertPointFromAncestor(java.awt.Component source, java.awt.Point p, java.awt.Component c)
           
static void convertPointToAncestor(java.awt.Component source, java.awt.Point point, java.lang.Class ancestorClass)
           
static void convertPointToAncestor(java.awt.Component c, java.awt.Point p, java.awt.Component destination)
           
static void copyStream(java.io.InputStream in, java.io.OutputStream out, boolean pCloseOutput)
           
static java.lang.String dateToString(java.util.Date date)
           
static java.lang.String decompress(java.lang.String compressedMessage)
           
static boolean executableByExtension(java.lang.String file)
           
static java.lang.String expandFileName(java.lang.String file)
          Replaces a ~ in a filename with the users home directory
static java.lang.String expandPlaceholders(java.lang.String message, java.lang.String s1)
          Example: expandPlaceholders("Hello $1."
static java.lang.String expandPlaceholders(java.lang.String message, java.lang.String s1, java.lang.String s2)
           
static java.lang.String expandPlaceholders(java.lang.String message, java.lang.String s1, java.lang.String s2, java.lang.String s3)
           
static java.net.URL fileToUrl(java.io.File pFile)
           
static java.lang.String firstLetterCapitalized(java.lang.String text)
           
static byte[] fromBase64(java.lang.String base64String)
           
static java.io.Reader getActualReader(java.io.File file)
          Creates a default reader that just reads the given file.
static java.util.Set getAvailableFontFamilyNames()
           
static java.util.Vector getAvailableFontFamilyNamesAsVector()
           
static java.lang.String getExtension(java.io.File f)
          Returns the lowercase of the extension of a file.
static java.lang.String getExtension(java.lang.String s)
          Returns the lowercase of the extension of a file name.
static java.lang.String getFile(java.io.File pInputFile)
          In case of trouble, the method returns null.
static java.lang.String getFileNameProposal(MindMapNode node)
           
static javax.swing.KeyStroke getKeyStroke(java.lang.String keyStrokeDescription)
           
static java.io.Reader getUpdateReader(java.io.File file, java.lang.String xsltScript, FreeMindMain frame)
          Creates a reader that pipes the input file through a XSLT-Script that updates the version to the current.
static java.net.URL getURLWithoutReference(java.net.URL input)
          Returns the same URL as input with the addition, that the reference part "#..." is filtered out.
static boolean isAbsolutePath(java.lang.String path)
           
static boolean isAvailableFontFamily(java.lang.String fontFamilyName)
           
static boolean isMacOsX()
           
static boolean isPreferenceTrue(java.lang.String option)
          Tests a string to be equals with "true".
static java.lang.String listToString(java.util.List list)
           
static void logTransferable(java.awt.datatransfer.Transferable t)
           
static java.lang.String PointToXml(java.awt.Point col)
           
static void printStackTrace()
          Logs the stacktrace via a dummy exception.
static java.lang.String removeExtension(java.lang.String s)
           
static java.lang.String removeMnemonic(java.lang.String rawLabel)
           
static java.lang.String removeTranslateComment(java.lang.String inputString)
          Removes the "TranslateMe" sign from the end of not translated texts.
static java.lang.String replaceUtf8AndIllegalXmlChars(java.lang.String fileContents)
           
static void restoreAntialiasing(java.awt.Graphics2D g, java.lang.Object renderingHint)
           
static boolean safeEquals(java.awt.Color color1, java.awt.Color color2)
           
static boolean safeEquals(java.lang.Object obj1, java.lang.Object obj2)
           
static boolean safeEquals(java.lang.String string1, java.lang.String string2)
           
static boolean safeEquals(Tools.BooleanHolder holder, Tools.BooleanHolder holder2)
           
static boolean safeEqualsIgnoreCase(java.lang.String string1, java.lang.String string2)
           
static void setDialogLocationRelativeTo(javax.swing.JDialog dialog, java.awt.Component c)
           
static void setHidden(java.io.File file, boolean hidden, boolean synchronously)
           
static void setLabelAndMnemonic(javax.swing.AbstractButton btn, java.lang.String inLabel)
          Ampersand indicates that the character after it is a mnemo, unless the character is a space.
static void setLabelAndMnemonic(javax.swing.Action action, java.lang.String inLabel)
          Ampersand indicates that the character after it is a mnemo, unless the character is a space.
static java.util.List stringToList(java.lang.String string)
          Converts a String in the format "value;value;value" to a List with the values (as strings)
static java.lang.String toBase64(byte[] byteBuffer)
           
static java.lang.String toBase64(java.lang.String text)
          Method to be called from XSLT
static java.lang.String toRelativeURL(java.net.URL base, java.net.URL target)
          This method converts an absolute url to an url relative to a given base-url.
static java.awt.Font updateFontSize(java.awt.Font font, float zoom, int normalFontSize)
          Adapts the font size inside of a component to the zoom
static java.lang.String urlGetFile(java.net.URL url)
          This is a correction of a method getFile of a class URL.
static java.io.File urlToFile(java.net.URL pUrl)
           
static byte[] uTF8StringToByteArray(java.lang.String uncompressedData)
           
static void waitForEventQueue()
           
static boolean xmlToBoolean(java.lang.String string)
           
static java.awt.Color xmlToColor(java.lang.String string)
           
static java.util.Date xmlToDate(java.lang.String xmlString)
          Extracts a long from xml.
static java.awt.Point xmlToPoint(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

executableExtensions

public static final java.util.Set executableExtensions

JAVA_VERSION

public static final java.lang.String JAVA_VERSION
Constructor Detail

Tools

public Tools()
Method Detail

executableByExtension

public static boolean executableByExtension(java.lang.String file)

colorToXml

public static java.lang.String colorToXml(java.awt.Color col)

xmlToColor

public static java.awt.Color xmlToColor(java.lang.String string)

PointToXml

public static java.lang.String PointToXml(java.awt.Point col)

xmlToPoint

public static java.awt.Point xmlToPoint(java.lang.String string)

BooleanToXml

public static java.lang.String BooleanToXml(boolean col)

xmlToBoolean

public static boolean xmlToBoolean(java.lang.String string)

stringToList

public static java.util.List stringToList(java.lang.String string)
Converts a String in the format "value;value;value" to a List with the values (as strings)


listToString

public static java.lang.String listToString(java.util.List list)

expandFileName

public static java.lang.String expandFileName(java.lang.String file)
Replaces a ~ in a filename with the users home directory


getAvailableFontFamilyNames

public static java.util.Set getAvailableFontFamilyNames()

getAvailableFontFamilyNamesAsVector

public static java.util.Vector getAvailableFontFamilyNamesAsVector()

isAvailableFontFamily

public static boolean isAvailableFontFamily(java.lang.String fontFamilyName)

getExtension

public static java.lang.String getExtension(java.io.File f)
Returns the lowercase of the extension of a file. Example: getExtension("fork.pork.MM") == freemind.main.FreeMindCommon.FREEMIND_FILE_EXTENSION_WITHOUT_DOT


getExtension

public static java.lang.String getExtension(java.lang.String s)
Returns the lowercase of the extension of a file name. Example: getExtension("fork.pork.MM") == freemind.main.FreeMindCommon.FREEMIND_FILE_EXTENSION_WITHOUT_DOT


removeExtension

public static java.lang.String removeExtension(java.lang.String s)

isAbsolutePath

public static boolean isAbsolutePath(java.lang.String path)

urlGetFile

public static java.lang.String urlGetFile(java.net.URL url)
This is a correction of a method getFile of a class URL. Namely, on Windows it returned file paths like /C: etc., which are not valid on Windows. This correction is heuristic to a great extend. One of the reasons is that file:// is basically no protocol at all, but rather something every browser and every system uses slightly differently.


toRelativeURL

public static java.lang.String toRelativeURL(java.net.URL base,
                                             java.net.URL target)
This method converts an absolute url to an url relative to a given base-url. The algorithm is somewhat chaotic, but it works (Maybe rewrite it). Be careful, the method is ".mm"-specific. Something like this should be included in the librarys, but I couldn't find it. You can create a new absolute url with "new URL(URL context, URL relative)".


isPreferenceTrue

public static boolean isPreferenceTrue(java.lang.String option)
Tests a string to be equals with "true".

Returns:
true, iff the String is "true".

safeEquals

public static boolean safeEquals(java.lang.String string1,
                                 java.lang.String string2)

safeEquals

public static boolean safeEquals(java.lang.Object obj1,
                                 java.lang.Object obj2)

safeEqualsIgnoreCase

public static boolean safeEqualsIgnoreCase(java.lang.String string1,
                                           java.lang.String string2)

safeEquals

public static boolean safeEquals(java.awt.Color color1,
                                 java.awt.Color color2)

firstLetterCapitalized

public static java.lang.String firstLetterCapitalized(java.lang.String text)

setHidden

public static void setHidden(java.io.File file,
                             boolean hidden,
                             boolean synchronously)

expandPlaceholders

public static java.lang.String expandPlaceholders(java.lang.String message,
                                                  java.lang.String s1)
Example: expandPlaceholders("Hello $1.","Dolly"); => "Hello Dolly."


expandPlaceholders

public static java.lang.String expandPlaceholders(java.lang.String message,
                                                  java.lang.String s1,
                                                  java.lang.String s2)

expandPlaceholders

public static java.lang.String expandPlaceholders(java.lang.String message,
                                                  java.lang.String s1,
                                                  java.lang.String s2,
                                                  java.lang.String s3)

toBase64

public static java.lang.String toBase64(byte[] byteBuffer)

toBase64

public static java.lang.String toBase64(java.lang.String text)
Method to be called from XSLT


fromBase64

public static byte[] fromBase64(java.lang.String base64String)
Throws:
java.io.IOException

compress

public static java.lang.String compress(java.lang.String message)

decompress

public static java.lang.String decompress(java.lang.String compressedMessage)

byteArrayToUTF8String

public static java.lang.String byteArrayToUTF8String(byte[] compressedData)

uTF8StringToByteArray

public static byte[] uTF8StringToByteArray(java.lang.String uncompressedData)

xmlToDate

public static java.util.Date xmlToDate(java.lang.String xmlString)
Extracts a long from xml. Only useful for dates.


dateToString

public static java.lang.String dateToString(java.util.Date date)

safeEquals

public static boolean safeEquals(Tools.BooleanHolder holder,
                                 Tools.BooleanHolder holder2)

setDialogLocationRelativeTo

public static void setDialogLocationRelativeTo(javax.swing.JDialog dialog,
                                               java.awt.Component c)

getUpdateReader

public static java.io.Reader getUpdateReader(java.io.File file,
                                             java.lang.String xsltScript,
                                             FreeMindMain frame)
                                      throws java.io.IOException
Creates a reader that pipes the input file through a XSLT-Script that updates the version to the current.

Throws:
java.io.IOException

replaceUtf8AndIllegalXmlChars

public static java.lang.String replaceUtf8AndIllegalXmlChars(java.lang.String fileContents)

getActualReader

public static java.io.Reader getActualReader(java.io.File file)
                                      throws java.io.FileNotFoundException
Creates a default reader that just reads the given file.

Throws:
java.io.FileNotFoundException

getFile

public static java.lang.String getFile(java.io.File pInputFile)
In case of trouble, the method returns null.

Parameters:
pInputFile - the file to read.
Returns:
the complete content of the file. or null if an exception has occured.

logTransferable

public static void logTransferable(java.awt.datatransfer.Transferable t)

addEscapeActionToDialog

public static void addEscapeActionToDialog(javax.swing.JDialog dialog)

addEscapeActionToDialog

public static void addEscapeActionToDialog(javax.swing.JDialog dialog,
                                           javax.swing.Action action)

addKeyActionToDialog

public static void addKeyActionToDialog(javax.swing.JDialog dialog,
                                        javax.swing.Action action,
                                        java.lang.String keyStroke,
                                        java.lang.String actionId)

removeTranslateComment

public static java.lang.String removeTranslateComment(java.lang.String inputString)
Removes the "TranslateMe" sign from the end of not translated texts.


getURLWithoutReference

public static java.net.URL getURLWithoutReference(java.net.URL input)
                                           throws java.net.MalformedURLException
Returns the same URL as input with the addition, that the reference part "#..." is filtered out.

Throws:
java.net.MalformedURLException

copyStream

public static void copyStream(java.io.InputStream in,
                              java.io.OutputStream out,
                              boolean pCloseOutput)
                       throws java.io.IOException
Throws:
java.io.IOException

convertPointToAncestor

public static void convertPointToAncestor(java.awt.Component c,
                                          java.awt.Point p,
                                          java.awt.Component destination)

convertPointFromAncestor

public static void convertPointFromAncestor(java.awt.Component source,
                                            java.awt.Point p,
                                            java.awt.Component c)

convertPointToAncestor

public static void convertPointToAncestor(java.awt.Component source,
                                          java.awt.Point point,
                                          java.lang.Class ancestorClass)

setLabelAndMnemonic

public static void setLabelAndMnemonic(javax.swing.AbstractButton btn,
                                       java.lang.String inLabel)
Ampersand indicates that the character after it is a mnemo, unless the character is a space. In "Find & Replace", ampersand does not label mnemo, while in "&About", mnemo is "Alt + A".


setLabelAndMnemonic

public static void setLabelAndMnemonic(javax.swing.Action action,
                                       java.lang.String inLabel)
Ampersand indicates that the character after it is a mnemo, unless the character is a space. In "Find & Replace", ampersand does not label mnemo, while in "&About", mnemo is "Alt + A".


isMacOsX

public static boolean isMacOsX()

removeMnemonic

public static java.lang.String removeMnemonic(java.lang.String rawLabel)

getKeyStroke

public static javax.swing.KeyStroke getKeyStroke(java.lang.String keyStrokeDescription)

fileToUrl

public static java.net.URL fileToUrl(java.io.File pFile)
                              throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

urlToFile

public static java.io.File urlToFile(java.net.URL pUrl)
                              throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException

restoreAntialiasing

public static void restoreAntialiasing(java.awt.Graphics2D g,
                                       java.lang.Object renderingHint)

getFileNameProposal

public static java.lang.String getFileNameProposal(MindMapNode node)

waitForEventQueue

public static void waitForEventQueue()

printStackTrace

public static void printStackTrace()
Logs the stacktrace via a dummy exception.


updateFontSize

public static java.awt.Font updateFontSize(java.awt.Font font,
                                           float zoom,
                                           int normalFontSize)
Adapts the font size inside of a component to the zoom

Parameters:
c - component
zoom - zoom factor
normalFontSize - "unzoomed" normal font size.
Returns:
a copy of the input font (if the size was effectively changed) with the correct scale.

compareText

public static java.lang.String compareText(java.lang.String pText1,
                                           java.lang.String pText2)