com.tensegrity.gui.swt
Class SwtUtil

java.lang.Object
  extended bycom.tensegrity.gui.swt.SwtUtil

public class SwtUtil
extends java.lang.Object

This class consists of common swt utility methods. This is the place for small convenience methods, which should not be reimplemtented each time they are used.

Version:
$Id: SwtUtil.java,v 1.29 2006/03/02 11:42:01 BurkhardWick Exp $
Author:
S�bastien Guyon

Nested Class Summary
static interface SwtUtil.CommandItem
          The CommandItem encapsulates the basic behavior for an item which is associated to a Command.
static class SwtUtil.ItemCommand
          TODO AH: Comment
 
Field Summary
static int SWT_VERSION_3_0
          Supported Versions of SWT are 3.0 and 3.1
static int SWT_VERSION_3_1
          Supported Versions of SWT are 3.0 and 3.1
static int SWT_VERSION_NOT_SUPPORTED
          Supported Versions of SWT are 3.0 and 3.1
 
Method Summary
static org.eclipse.swt.widgets.ToolItem addToToolBar(UIManager uiManager, org.eclipse.swt.widgets.ToolBar toolbar, Command command, org.eclipse.swt.graphics.Image icon)
           TODO AH: Comment method
static boolean canWriteFormat(java.lang.String formatName)
          Returns true if the specified format name can be written
static void center(org.eclipse.swt.widgets.Control control)
          Centers the given control relative to its display's monitor.
static java.lang.String filterHtml(java.lang.String txt)
          Filters out any html tags in the given String
static int getKeyMask(org.eclipse.swt.events.MouseEvent event)
           This routine returns the KeyStroke mask corresponding to the passed MouseEvent.
static int getMouseButton(org.eclipse.swt.events.MouseEvent event)
          Returns the mouse button from the given MouseEvent
static int getSWTVersion()
          Returns the version of SWT which is currently running.
static boolean isXMLFile(java.io.File file)
          Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition.
static boolean isXMLFile(java.io.InputStream is)
          Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition.
static org.eclipse.swt.graphics.ImageData loadImage(java.lang.Class referenceClass, java.lang.String imagepath)
           
static org.eclipse.swt.graphics.ImageData loadImage(java.net.URL url)
           
static boolean saveImageAs(org.eclipse.swt.graphics.Image image, java.io.File file, int format)
           Saves image in file with format format.
static boolean saveImageAs(org.eclipse.swt.graphics.Image image, java.io.OutputStream os, int format)
           This method saves the passed image into an OutputStream.
static void showError(org.eclipse.swt.widgets.Shell parent, java.lang.String message, java.lang.String title)
          Shows a modal error dialog.
static int showYesNo(org.eclipse.swt.widgets.Shell parent, java.lang.String message)
          Method showYesNo shows a MessageBox with a Yes/No button bar.
static int showYesNo(org.eclipse.swt.widgets.Shell parent, java.lang.String message, java.lang.String title)
          Method showYesNo shows a MessageBox with a Yes/No button bar.
static int showYesNo(org.eclipse.swt.widgets.Shell parent, java.lang.String message, java.lang.String title, int messageType)
          Method showYesNo shows a MessageBox with a Yes/No button bar.
static int showYesNoCancel(org.eclipse.swt.widgets.Shell parent, java.lang.String message)
          Method showYesNoCancel shows a messagebox with a Yes/No/Cancel button bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SWT_VERSION_3_0

public static final int SWT_VERSION_3_0
Supported Versions of SWT are 3.0 and 3.1

See Also:
Constant Field Values

SWT_VERSION_3_1

public static final int SWT_VERSION_3_1
Supported Versions of SWT are 3.0 and 3.1

See Also:
Constant Field Values

SWT_VERSION_NOT_SUPPORTED

public static final int SWT_VERSION_NOT_SUPPORTED
Supported Versions of SWT are 3.0 and 3.1

See Also:
Constant Field Values
Method Detail

getMouseButton

public static final int getMouseButton(org.eclipse.swt.events.MouseEvent event)
Returns the mouse button from the given MouseEvent

Parameters:
event - the given MouseEvent
Returns:
the mouse button as defined by the constants used in MouseInfo.

getKeyMask

public static final int getKeyMask(org.eclipse.swt.events.MouseEvent event)

This routine returns the KeyStroke mask corresponding to the passed MouseEvent.

Parameters:
event - the MouseEvent from which the keymask must be retrieved.
Returns:
one of:

saveImageAs

public static final boolean saveImageAs(org.eclipse.swt.graphics.Image image,
                                        java.io.OutputStream os,
                                        int format)

This method saves the passed image into an OutputStream.

Parameters:
image - this is the image to save.
os - the OutputStream where the image is saved.
format - the file format. One of:
  • SWT.IMAGE_BMP
  • SWT.IMAGE_GIF
  • SWT.IMAGE_JPEG
  • SWT.IMAGE_PNG
Returns:
true if the the operation was successful, false otherwise.

saveImageAs

public static final boolean saveImageAs(org.eclipse.swt.graphics.Image image,
                                        java.io.File file,
                                        int format)

Saves image in file with format format.

Parameters:
image - this is the image to save.
file - the destination file
format - the file format. One of:
  • SWT.IMAGE_BMP
  • SWT.IMAGE_GIF
  • SWT.IMAGE_JPEG
  • SWT.IMAGE_PNG
Returns:
true if the the operation was successful, false otherwise.

loadImage

public static final org.eclipse.swt.graphics.ImageData loadImage(java.lang.Class referenceClass,
                                                                 java.lang.String imagepath)

loadImage

public static final org.eclipse.swt.graphics.ImageData loadImage(java.net.URL url)

canWriteFormat

public static boolean canWriteFormat(java.lang.String formatName)
Returns true if the specified format name can be written

Parameters:
formatName - the name of the format, for example gif.
Returns:
true iff the format can be written.

showError

public static final void showError(org.eclipse.swt.widgets.Shell parent,
                                   java.lang.String message,
                                   java.lang.String title)
Shows a modal error dialog.

Parameters:
parent - the parent Shell for this message box. If parent is null, the method tries to use a default shell.
message - the message string to display in the dialog.
title - The title string to display in the dialog.

showYesNoCancel

public static int showYesNoCancel(org.eclipse.swt.widgets.Shell parent,
                                  java.lang.String message)
Method showYesNoCancel shows a messagebox with a Yes/No/Cancel button bar.

Parameters:
parent - the parent Shell for this message box.
message - the message as String
Returns:
int the return value which is one of:
  • SWT.YES
  • SWT.NO
  • SWT.CANCEL

showYesNo

public static int showYesNo(org.eclipse.swt.widgets.Shell parent,
                            java.lang.String message)
Method showYesNo shows a MessageBox with a Yes/No button bar.

Parameters:
parent - the parent Shell for this message box.
message - the message as String
Returns:
int the return value which is one of:
  • SWT.YES
  • SWT.NO

showYesNo

public static int showYesNo(org.eclipse.swt.widgets.Shell parent,
                            java.lang.String message,
                            java.lang.String title)
Method showYesNo shows a MessageBox with a Yes/No button bar.

Parameters:
parent - the parent Shell for this message box.
message - the message as String.
title - the title for the MessageBox.
Returns:
int the return value which is one of:
  • SWT.YES
  • SWT.NO

showYesNo

public static int showYesNo(org.eclipse.swt.widgets.Shell parent,
                            java.lang.String message,
                            java.lang.String title,
                            int messageType)
Method showYesNo shows a MessageBox with a Yes/No button bar. This method allows you to change the icon, which is displayed on the MessageBox.

Parameters:
parent - the parent component for this message box.
message - the message as String.
title - the title for the MessageBox.
messageType - one of the following constants:
  • SWT.ICON_ERROR
  • SWT.ICON_INFORMATION
  • SWT.ICON_QUESTION
  • SWT.ICON_WARNING
  • SWT.ICON_WORKING
Returns:
int the return value which is one of:
  • SWT.YES
  • SWT.NO

isXMLFile

public static boolean isXMLFile(java.io.File file)
Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition. If such a definition is found the method returns true, otherwise false.

Parameters:
file - the File to examine.
Returns:
boolean true iff the file is an xml file.

isXMLFile

public static boolean isXMLFile(java.io.InputStream is)
Method isXMLFile reads the first line of the file and checks whether it starts with the typical xml definition. If such a definition is found the method returns true, otherwise false. The stream has to support marking!

Parameters:
is - the InputStream to examine
Returns:
boolean true iff the file is an xml file.

addToToolBar

public static org.eclipse.swt.widgets.ToolItem addToToolBar(UIManager uiManager,
                                                            org.eclipse.swt.widgets.ToolBar toolbar,
                                                            Command command,
                                                            org.eclipse.swt.graphics.Image icon)

TODO AH: Comment method

Parameters:
uiManager -
toolbar -
command -
icon -
Returns:

filterHtml

public static final java.lang.String filterHtml(java.lang.String txt)
Filters out any html tags in the given String

Parameters:
txt - a String probably containing html tags
Returns:
same String without html tags

getSWTVersion

public static int getSWTVersion()
Returns the version of SWT which is currently running. At this stage only versions 3.0 and 3.1 are supported.

Returns:
one of

center

public static final void center(org.eclipse.swt.widgets.Control control)
Centers the given control relative to its display's monitor. NOTE: this method supports multiple monitors.

Parameters:
control - the Control to be centered


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.