org.fife.rtext
Class RTextUtilities

java.lang.Object
  extended byorg.fife.rtext.RTextUtilities

public class RTextUtilities
extends java.lang.Object

Collection of tools for use by any of the RText components.

Version:
1.0
Author:
Robert Futrell

Field Summary
static java.lang.String MACRO_EXTENSION
          The extension at the end of all macro files.
 
Constructor Summary
RTextUtilities()
           
 
Method Summary
static void addDefaultCodeTemplates()
          Adds a set of "default" code templates to the text areas.
static void centerSelectionVertically(RSyntaxTextArea textArea)
          Scrolls the selected text of a text area so that it is centered vertically.
static void configureFindInFilesDialog(FindInFilesDialog fnfd)
          Configures a find-in-files dialog for RText.
static javax.swing.JPanel createAssistancePanel(javax.swing.JComponent comp, DecorativeIconPanel iconPanel)
          Creates a panel containing the specified component and an (optional) dedorative (or assistance) icon panel.
static RTextFileChooser createFileChooser(RText rtext)
          Creates and initializes a file chooser suitable for RText.
static boolean enableTemplates(RText rtext, boolean enabled)
          Enables or disables template usage in RText text areas.
static java.lang.String escapeForHTML(java.lang.String s, java.lang.String newlineReplacement)
          Returns a string with characters that are special to HTML (such as <, > and &) replaced by their HTML escape sequences.
static java.lang.String escapeForHTML(java.lang.String s, java.lang.String newlineReplacement, boolean inPreBlock)
          Returns a string with characters that are special to HTML (such as <, > and &) replaced by their HTML escape sequences.
static boolean getDropShadowsEnabledInEditor()
          Returns whether the experimental "drop shadows" option is enabled.
static java.awt.Image getImageFromFile(java.lang.String fileName)
          Returns an image from a file in a safe fashion.
static java.lang.String getLookAndFeelToSave()
          Returns the name of the LookAndFeel to load RText with the next time it starts up.
static java.io.File getMacroDirectory()
          Returns the directory in which the user's macros are stored.
static java.lang.String getMacroName(java.io.File macroFile)
          Returns the name of the macro in the specified file.
static java.util.regex.Pattern getPatternForFileFilter(java.lang.String fileFilter, boolean showErrorDialog)
          Converts a String representing a wildcard file filter into a Pattern containing a regular expression good for finding files that match the wildcard expression.
static java.io.File getPreferencesDirectory()
          Returns the directory in which to load and save user preferences (beyond those saved via the Java preferences API).
static java.lang.String getPrettyStringFor(javax.swing.KeyStroke keyStroke)
          Returns a pretty string value for a KeyStroke, suitable for display as the keystroke's value in a GUI.
static java.io.File[] getSavedMacroFiles()
          Returns all macro files saved in the macro directory.
static java.awt.image.BufferedImage getTranslucentImage(RText rtext, java.awt.Image image, float alpha)
          Returns a translucent version of a given java.awt.Image.
static boolean isPreJava6()
          Returns whether the Java Runtime that RText is running in is 1.4 or 1.5.
static void openAllFilesIn(RText rtext, java.io.File directory)
          Opens all files in the specified directory tree in RText.
static void saveFileChooserFavorites(RText rtext)
          Saves the "Favorite Directories" of RText's file chooser.
static void setDropShadowsEnabledInEditor(boolean enabled)
          Toggles whether the experimental "drop shadows" option is enabled.
static void setLookAndFeel(RText rtext, java.lang.String lnfClassName)
          Sets the Look and Feel for all open RText instances.
static java.lang.String stripBackupExtensions(java.lang.String fileName)
          Strips ".orig", ".bak", and ".old" from the end of a fileName, if they are there.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MACRO_EXTENSION

public static final java.lang.String MACRO_EXTENSION
The extension at the end of all macro files.

See Also:
Constant Field Values
Constructor Detail

RTextUtilities

public RTextUtilities()
Method Detail

addDefaultCodeTemplates

public static final void addDefaultCodeTemplates()
Adds a set of "default" code templates to the text areas.


centerSelectionVertically

public static void centerSelectionVertically(RSyntaxTextArea textArea)
Scrolls the selected text of a text area so that it is centered vertically.

Parameters:
textArea - The text area.

configureFindInFilesDialog

public static final void configureFindInFilesDialog(FindInFilesDialog fnfd)
Configures a find-in-files dialog for RText.

Parameters:
fnfd - The FindInFilesDialog to configure.

createAssistancePanel

public static javax.swing.JPanel createAssistancePanel(javax.swing.JComponent comp,
                                                       DecorativeIconPanel iconPanel)
Creates a panel containing the specified component and an (optional) dedorative (or assistance) icon panel.

Parameters:
comp - The component.
iconPanel - The icon panel. If this is null, then a spacer is used.
Returns:
The panel.

createFileChooser

public static final RTextFileChooser createFileChooser(RText rtext)
Creates and initializes a file chooser suitable for RText.

Parameters:
rtext - The RText instance that will own this file chooser.
Returns:
A file chooser for RText to use.
See Also:
saveFileChooserFavorites(RText)

enableTemplates

public static boolean enableTemplates(RText rtext,
                                      boolean enabled)
Enables or disables template usage in RText text areas.

Parameters:
enabled - Whether templates should be enabled.
Returns:
true if everything went okay; false if the method failed.

escapeForHTML

public static final java.lang.String escapeForHTML(java.lang.String s,
                                                   java.lang.String newlineReplacement)
Returns a string with characters that are special to HTML (such as <, > and &) replaced by their HTML escape sequences.

Parameters:
s - The input string.
newlineReplacement - What to replace newline characters with. If this is null, they are simply removed.
Returns:
The escaped version of s.

escapeForHTML

public static final java.lang.String escapeForHTML(java.lang.String s,
                                                   java.lang.String newlineReplacement,
                                                   boolean inPreBlock)
Returns a string with characters that are special to HTML (such as <, > and &) replaced by their HTML escape sequences.

Parameters:
s - The input string.
newlineReplacement - What to replace newline characters with. If this is null, they are simply removed.
inPreBlock - Whether this HTML will be in within pre tags. If this is true, spaces will be kept as-is; otherwise, they will be converted to " ".
Returns:
The escaped version of s.

getDropShadowsEnabledInEditor

public static boolean getDropShadowsEnabledInEditor()
Returns whether the experimental "drop shadows" option is enabled.

Returns:
Whether drop shadows are enabled.
See Also:
setDropShadowsEnabledInEditor(boolean)

getImageFromFile

public static java.awt.Image getImageFromFile(java.lang.String fileName)
Returns an image from a file in a safe fashion.

Parameters:
fileName - The file from which to get the image (must be .jpg, .gif or .png).
Returns:
The image contained in the file, or null if the image file was invalid.

getLookAndFeelToSave

public static java.lang.String getLookAndFeelToSave()
Returns the name of the LookAndFeel to load RText with the next time it starts up. This may not be the same thing as the currently active LAF, if the user chose a LAF that used custom window decorations, for example.

Returns:
The name of the LookAndFeel to save in the RText preferences.

getMacroDirectory

public static final java.io.File getMacroDirectory()
Returns the directory in which the user's macros are stored.

Returns:
The macro directory, or null if it cannot be found or created.

getMacroName

public static final java.lang.String getMacroName(java.io.File macroFile)
Returns the name of the macro in the specified file.

Parameters:
macroFile - A file containing an RTextArea macro. If this file is null, then null is returned.
Returns:
The name of the macro.

getPreferencesDirectory

public static java.io.File getPreferencesDirectory()
Returns the directory in which to load and save user preferences (beyond those saved via the Java preferences API).

Returns:
The directory.

getPrettyStringFor

public static java.lang.String getPrettyStringFor(javax.swing.KeyStroke keyStroke)
Returns a pretty string value for a KeyStroke, suitable for display as the keystroke's value in a GUI.

Parameters:
keyStroke - The keystroke.
Returns:
The string value of the keystroke.

getPatternForFileFilter

public static java.util.regex.Pattern getPatternForFileFilter(java.lang.String fileFilter,
                                                              boolean showErrorDialog)
Converts a String representing a wildcard file filter into a Pattern containing a regular expression good for finding files that match the wildcard expression.

Example: For

String regEx = RTextUtilities.getPatternForFileFilter("*.c");

the returned pattern will match ^.*\.c$.

Parameters:
fileFilter - The file filter for which to create equivalent regular expressions. This filter can currently only contain the wildcards '*' and '?'.
showErrorDialog - If true, an error dialog is displayed if an error occurs.
Returns:
A Pattern representing an equivalent regular expression for the string passed in. If an error occurs, null is returned.

getSavedMacroFiles

public static final java.io.File[] getSavedMacroFiles()
Returns all macro files saved in the macro directory.

Returns:
An array of files containing macros in the macro directory. If the macro directory cannot be found or is empty, an empty array is returned.

getTranslucentImage

public static java.awt.image.BufferedImage getTranslucentImage(RText rtext,
                                                               java.awt.Image image,
                                                               float alpha)
Returns a translucent version of a given java.awt.Image.

Parameters:
image - The java.awt.Image on which to apply the alpha filter.
alpha - The alpha value to use when defining how translucent you want the image to be. This should be in the range 0.0f to 1.0f.

isPreJava6

public static final boolean isPreJava6()
Returns whether the Java Runtime that RText is running in is 1.4 or 1.5.

Returns:
Whether the current JVM is pre-Java 6.

openAllFilesIn

public static void openAllFilesIn(RText rtext,
                                  java.io.File directory)
Opens all files in the specified directory tree in RText.

Parameters:
rtext - The RText instance in which to open the files.
directory - The top of the directory tree, all files in which you want opened in RText.

saveFileChooserFavorites

public static void saveFileChooserFavorites(RText rtext)
Saves the "Favorite Directories" of RText's file chooser. It is assumed that the file chooser has been created via createFileChooser(RText) before calling this method. If an error occurs saving the favorites, an error message is displayed.

Parameters:
rtext - The parent RText instance.
See Also:
createFileChooser(RText)

setDropShadowsEnabledInEditor

public static void setDropShadowsEnabledInEditor(boolean enabled)
Toggles whether the experimental "drop shadows" option is enabled. Note that this may do nothing if we're running on Java 1.4 or 1.5, or the current system does not support translucent windows.

Parameters:
enabled - Whether the option is enabled.
See Also:
getDropShadowsEnabledInEditor()

setLookAndFeel

public static void setLookAndFeel(RText rtext,
                                  java.lang.String lnfClassName)
Sets the Look and Feel for all open RText instances.

Parameters:
rtext - An RText instance to display a message if an exception is thrown.
lnfClassName - The class name of the Look and Feel to set.

stripBackupExtensions

public static java.lang.String stripBackupExtensions(java.lang.String fileName)
Strips ".orig", ".bak", and ".old" from the end of a fileName, if they are there.

Parameters:
fileName - The file name.
Returns:
The same file name, with any of the above extensions removed.