swingwtx.swing
Class SwingWTUtils

java.lang.Object
  extended byswingwtx.swing.SwingWTUtils

public abstract class SwingWTUtils
extends java.lang.Object

Utilities required for SwingWT. Handles management of SWT display, SwingWT event pump and some handy stuff for calculating renderered text size, determining platform, etc.


Field Summary
static int MACOSX_MENUBAR_BOTTOM
          The height of the MacOS X menubar in pixels
static boolean showInternalSWTExceptions
           
 
Constructor Summary
SwingWTUtils()
           
 
Method Summary
static void checkEventDispatcher()
          Checks whether the event dispatch thread is running, and starts it if it isn't.
static void checkShutdownHook()
           
static void clearTempDirectory()
           
static void decrementWindowReferences()
           
static org.eclipse.swt.widgets.Display getDisplay()
           
static int getRenderStringHeight(java.lang.String text)
          Given a piece of text, this routine will evaluate how many pixels high it will be when renderered in the default system font.
static int getRenderStringWidth(java.lang.String text)
          Given a piece of text, this routine will evaluate how many pixels wide it will be when renderered in the default system font.
static int getRetardationInterval()
           
static int getStringBufferIndexOf(java.lang.StringBuffer buffer, java.lang.String string)
          Because GCJ/GIJ Classpath doesn't support StringBuffer.indexOf, we have to have a replacement that uses Strings instead.
static int getStringBufferIndexOf(java.lang.StringBuffer buffer, java.lang.String string, int fromIndex)
          Because GCJ/GIJ Classpath doesn't support StringBuffer.indexOf, we have to have a replacement that uses Strings instead.
static org.eclipse.swt.graphics.Image getSWTImageFromSwingIcon(Component c, Icon icon)
          Renders a Swing Icon onto an SWT image.
static java.lang.String getVersion()
           
static void incrementWindowReferences()
           
static void initialiseMacOSX(java.lang.Runnable run)
          Startup routine for MacOSX programs.
static boolean isEventDispatchRunning()
           
static boolean isMacOSX()
          Returns true if this is a MacOS X platform
static boolean isRetardDispatchThread()
           
static boolean isSWTControlAvailable(org.eclipse.swt.widgets.Control c)
          Determines if an SWT peer is available for use
static boolean isSWTMenuControlAvailable(org.eclipse.swt.widgets.MenuItem c)
          Determines if an SWT menu peer is available for use
static boolean isUrlInJar(java.net.URL url)
           
static boolean isUseSWTFastVirtualTables()
          Returns whether SwingWT is using fast SWT virtual tables
static boolean isWindows()
          Returns true if this is a windows platform
static java.lang.String removeHTML(java.lang.String s)
          Removes HTML tags from a string
static java.lang.String replace(java.lang.String findin, java.lang.String find, java.lang.String replacewith)
          Looks in findin for all occurrences of find and replaces them with replacewith
static void saveImageToGIF(Image image, java.io.OutputStream stream)
          Saves an image to a GIF.
static void saveImageToJPG(Image image, java.io.OutputStream stream)
          Saves an image to a JPEG.
static void saveImageToPNG(Image image, java.io.OutputStream stream)
          Saves an image to a JPEG.
static void setEclipsePlugin(boolean b)
          If your code is an Eclipse plugin (ie.
static void setRetardDispatchThread(boolean b)
          Determines whether the event dispatch thread is retarded for extra performance
static void setRetardDispatchThread(boolean b, int ms)
          Determines whether the event dispatch thread is retarded for extra performance
static void setShowSwingWTInfoOnStartup(boolean b)
           
static void setUsesSWTFastVirtualTables(boolean b)
          Set this to true to use fast SWT Virtual tables (off by default)
static void stopEventDispatchRunning()
          Stops the event dispatch thread running (if it isn't running.
static java.net.URL stringToTempFile(byte[] contents, java.lang.String type)
          Given a byte array of content, writes it to a temporary file and then returns the path to it as a URL
static int translateSwingAlignmentConstant(int constant)
          Translates the alignment part of the Swing constants
static int translateSwingOrientationConstant(int constant)
          Translates the orientation part of the Swing constants
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

showInternalSWTExceptions

public static boolean showInternalSWTExceptions

MACOSX_MENUBAR_BOTTOM

public static int MACOSX_MENUBAR_BOTTOM
The height of the MacOS X menubar in pixels

Constructor Detail

SwingWTUtils

public SwingWTUtils()
Method Detail

getVersion

public static java.lang.String getVersion()

incrementWindowReferences

public static void incrementWindowReferences()

decrementWindowReferences

public static void decrementWindowReferences()

setShowSwingWTInfoOnStartup

public static void setShowSwingWTInfoOnStartup(boolean b)

setRetardDispatchThread

public static void setRetardDispatchThread(boolean b)
Determines whether the event dispatch thread is retarded for extra performance


setRetardDispatchThread

public static void setRetardDispatchThread(boolean b,
                                           int ms)
Determines whether the event dispatch thread is retarded for extra performance


setEclipsePlugin

public static void setEclipsePlugin(boolean b)
If your code is an Eclipse plugin (ie. Something outside of SwingWT and your program has started using SWT components in the current VM and an event dispatcher is already going), Call this routine with (true) to have SwingWT use the other program's event dispatcher (rather than it's own thread).


isUseSWTFastVirtualTables

public static boolean isUseSWTFastVirtualTables()
Returns whether SwingWT is using fast SWT virtual tables


setUsesSWTFastVirtualTables

public static void setUsesSWTFastVirtualTables(boolean b)
Set this to true to use fast SWT Virtual tables (off by default)


initialiseMacOSX

public static void initialiseMacOSX(java.lang.Runnable run)
Startup routine for MacOSX programs. This isn't very pretty, but the threading model for java under MacOSX is fundamentally broken and requires the event pump to run on the main thread.

Parameters:
run - The startup code to run (this call will block)

checkEventDispatcher

public static void checkEventDispatcher()
Checks whether the event dispatch thread is running, and starts it if it isn't.


isRetardDispatchThread

public static boolean isRetardDispatchThread()
Returns:
true if the dispatch thread is currently retarded

getRetardationInterval

public static int getRetardationInterval()
Returns:
The dispatch thread retardation in milliseconds

getDisplay

public static org.eclipse.swt.widgets.Display getDisplay()

isSWTControlAvailable

public static boolean isSWTControlAvailable(org.eclipse.swt.widgets.Control c)
Determines if an SWT peer is available for use


isSWTMenuControlAvailable

public static boolean isSWTMenuControlAvailable(org.eclipse.swt.widgets.MenuItem c)
Determines if an SWT menu peer is available for use


isEventDispatchRunning

public static boolean isEventDispatchRunning()

stopEventDispatchRunning

public static void stopEventDispatchRunning()
Stops the event dispatch thread running (if it isn't running. does nothing).


isUrlInJar

public static boolean isUrlInJar(java.net.URL url)
                          throws java.io.IOException
Parameters:
url - The path to inspect.
Returns:
TRUE if the passed URL is contained in a JAR file.
Throws:
java.io.IOException

stringToTempFile

public static java.net.URL stringToTempFile(byte[] contents,
                                            java.lang.String type)
                                     throws java.io.IOException
Given a byte array of content, writes it to a temporary file and then returns the path to it as a URL

Parameters:
contents - The content of the file
type - The file extension to use
Throws:
java.io.IOException - if an error occurs

clearTempDirectory

public static void clearTempDirectory()

checkShutdownHook

public static void checkShutdownHook()

isWindows

public static boolean isWindows()
Returns true if this is a windows platform


isMacOSX

public static boolean isMacOSX()
Returns true if this is a MacOS X platform


saveImageToJPG

public static void saveImageToJPG(Image image,
                                  java.io.OutputStream stream)
Saves an image to a JPEG. Not sure where to put this since the only support Java has for this, is in a hidden com.sun.jpeg.JPEGEncoder class which is not part of the formal interface. Anyway, I'm sticking it here.


saveImageToGIF

public static void saveImageToGIF(Image image,
                                  java.io.OutputStream stream)
Saves an image to a GIF. Not sure where to put this since the only support Java has for this, is in a hidden com.sun.gif.GIFEncoder class which is not part of the formal interface. Anyway, I'm sticking it here.


saveImageToPNG

public static void saveImageToPNG(Image image,
                                  java.io.OutputStream stream)
Saves an image to a JPEG. Not sure where to put this since the only support Java has for this, is in a hidden com.sun.png.PNGEncoder class which is not part of the formal interface. Anyway, I'm sticking it here.


getRenderStringWidth

public static int getRenderStringWidth(java.lang.String text)
Given a piece of text, this routine will evaluate how many pixels wide it will be when renderered in the default system font. This is used by JTable and JList to determine the column widths


getRenderStringHeight

public static int getRenderStringHeight(java.lang.String text)
Given a piece of text, this routine will evaluate how many pixels high it will be when renderered in the default system font. This is used by JPanel to determine the extra height needed on the insets for laying out purposes


getStringBufferIndexOf

public static int getStringBufferIndexOf(java.lang.StringBuffer buffer,
                                         java.lang.String string)
Because GCJ/GIJ Classpath doesn't support StringBuffer.indexOf, we have to have a replacement that uses Strings instead.

Parameters:
buffer - The StringBuffer to find in
string - The String to find
Returns:
The index of the string or -1 if it wasn't found

getStringBufferIndexOf

public static int getStringBufferIndexOf(java.lang.StringBuffer buffer,
                                         java.lang.String string,
                                         int fromIndex)
Because GCJ/GIJ Classpath doesn't support StringBuffer.indexOf, we have to have a replacement that uses Strings instead.

Parameters:
buffer - The StringBuffer to find in
string - The String to find
fromIndex - The char index to search from
Returns:
The index of the string or -1 if it wasn't found

getSWTImageFromSwingIcon

public static org.eclipse.swt.graphics.Image getSWTImageFromSwingIcon(Component c,
                                                                      Icon icon)
Renders a Swing Icon onto an SWT image. Used by SwingWT to render all images onto components.

Parameters:
icon - The icon to render
Returns:
An SWT image to assign to the component

translateSwingAlignmentConstant

public static int translateSwingAlignmentConstant(int constant)
Translates the alignment part of the Swing constants


translateSwingOrientationConstant

public static int translateSwingOrientationConstant(int constant)
Translates the orientation part of the Swing constants


removeHTML

public static java.lang.String removeHTML(java.lang.String s)
Removes HTML tags from a string

Parameters:
s - The string to remove HTML tags from

replace

public static java.lang.String replace(java.lang.String findin,
                                       java.lang.String find,
                                       java.lang.String replacewith)
Looks in findin for all occurrences of find and replaces them with replacewith

Parameters:
findin - The string to find occurrences in
find - The string to find
replacewith - The string to replace found occurrences with
Returns:
A string with all occurrences of find replaced.