Class SWTGraphicUtil
- java.lang.Object
-
- org.eclipse.nebula.widgets.opal.commons.SWTGraphicUtil
-
public class SWTGraphicUtil extends java.lang.ObjectThis class is a singleton that provides useful methods
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSWTGraphicUtil()Constructor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddDisposer(org.eclipse.swt.widgets.Widget widget, org.eclipse.swt.graphics.Resource resource)Dispose safely any SWT resource when a widget is disposedstatic voidapplyHTMLFormating(org.eclipse.swt.custom.StyledText styledText)Apply a very basic pseudo-HTML formating to a text stored in a StyledText widget.static org.eclipse.swt.graphics.ImageDatablur(org.eclipse.swt.graphics.ImageData originalImageData, int radius)private static org.eclipse.swt.graphics.RGB[]blurRow(org.eclipse.swt.graphics.ImageData originalImageData, int row, int radius)Average blurs a given row of image data.static org.eclipse.swt.graphics.FontbuildFontFrom(org.eclipse.swt.widgets.Control control, int style)Build a font from a given control.static org.eclipse.swt.graphics.FontbuildFontFrom(org.eclipse.swt.widgets.Control control, int style, int size)Build a font from a given control.static voidcenterShell(org.eclipse.swt.widgets.Shell shell)Center a shell on the primary monitorstatic intcomputeWidth(java.lang.String text)static org.eclipse.swt.graphics.ImagecreateImageFromFile(java.lang.String fileName)Loads an image and create a SWT Image corresponding to this filestatic org.eclipse.swt.graphics.ImagecreateReflectedImage(org.eclipse.swt.graphics.Image source)Create a reflected image of a source Inspired by Daniel Spiewak work (http://www.eclipsezone.com/eclipse/forums/t91013.html)static org.eclipse.swt.graphics.ImagecreateReflectedResizedImage(org.eclipse.swt.graphics.Image source, int newWidth, int newHeight)Create a reflected and resized version of an imagestatic voiddisableAllChildrenWidgets(org.eclipse.swt.widgets.Control control)Disable all widgets of a controlstatic voidenableAllChildrenWidgets(org.eclipse.swt.widgets.Control control)Enable all widgets of a controlstatic org.eclipse.swt.graphics.RectanglegetBoundsOfMonitorOnWhichShellIsDisplayed(org.eclipse.swt.widgets.Shell shell)static org.eclipse.swt.graphics.ColorgetColorSafely(int r, int g, int b)Create a color that is disposed automaticallystatic org.eclipse.swt.graphics.ColorgetDefaultColor(org.eclipse.swt.widgets.Control control, int red, int green, int blue)static booleanisMacOS()static org.eclipse.swt.graphics.Imageresize(org.eclipse.swt.graphics.Image source, int newWidth, int newHeight)Returns a new scaled image.static voidsafeDispose(org.eclipse.swt.graphics.Resource resource)Dispose safely any SWT resource
-
-
-
Method Detail
-
addDisposer
public static void addDisposer(org.eclipse.swt.widgets.Widget widget, org.eclipse.swt.graphics.Resource resource)Dispose safely any SWT resource when a widget is disposed- Parameters:
widget- widget attached to the resourceresource- the resource to dispose
-
safeDispose
public static void safeDispose(org.eclipse.swt.graphics.Resource resource)
Dispose safely any SWT resource- Parameters:
resource- the resource to dispose
-
getColorSafely
public static org.eclipse.swt.graphics.Color getColorSafely(int r, int g, int b)Create a color that is disposed automatically- Parameters:
r- red componentg- green componentb- blue component- Returns:
- the color
-
createImageFromFile
public static org.eclipse.swt.graphics.Image createImageFromFile(java.lang.String fileName)
Loads an image and create a SWT Image corresponding to this file- Parameters:
fileName- file name of the image- Returns:
- an image
- See Also:
Image
-
createReflectedImage
public static org.eclipse.swt.graphics.Image createReflectedImage(org.eclipse.swt.graphics.Image source)
Create a reflected image of a source Inspired by Daniel Spiewak work (http://www.eclipsezone.com/eclipse/forums/t91013.html)- Parameters:
source- source to be reflected- Returns:
- the source image with a reflection
-
resize
public static org.eclipse.swt.graphics.Image resize(org.eclipse.swt.graphics.Image source, int newWidth, int newHeight)Returns a new scaled image.- Parameters:
source- the image to be scalednewWidth- new width of the imagenewHeight- new height of the image- Returns:
- a scaled image of the source
-
createReflectedResizedImage
public static org.eclipse.swt.graphics.Image createReflectedResizedImage(org.eclipse.swt.graphics.Image source, int newWidth, int newHeight)Create a reflected and resized version of an image- Parameters:
source- source image to be scaled and reflectednewWidth- new width of the scaled imagenewHeight- new height of the scaled image- Returns:
- the resized and reflected image
-
centerShell
public static void centerShell(org.eclipse.swt.widgets.Shell shell)
Center a shell on the primary monitor- Parameters:
shell- shell to center
-
getBoundsOfMonitorOnWhichShellIsDisplayed
public static org.eclipse.swt.graphics.Rectangle getBoundsOfMonitorOnWhichShellIsDisplayed(org.eclipse.swt.widgets.Shell shell)
- Parameters:
shell-- Returns:
- the bounds of the monitor on which the shell is running
-
applyHTMLFormating
public static void applyHTMLFormating(org.eclipse.swt.custom.StyledText styledText)
Apply a very basic pseudo-HTML formating to a text stored in a StyledText widget. Supported tags are , , ,, , and - Parameters:
styledText- styled text that contains an HTML text
-
blur
public static org.eclipse.swt.graphics.ImageData blur(org.eclipse.swt.graphics.ImageData originalImageData, int radius)- Parameters:
originalImageData- The ImageData to be average blurred. Transparency information will be ignored.radius- the number of radius pixels to consider when blurring image.- Returns:
- A blurred copy of the image data, or null if an error occured.
-
blurRow
private static org.eclipse.swt.graphics.RGB[] blurRow(org.eclipse.swt.graphics.ImageData originalImageData, int row, int radius)Average blurs a given row of image data. Returns the blurred row as a matrix of separated RGB values.
-
enableAllChildrenWidgets
public static void enableAllChildrenWidgets(org.eclipse.swt.widgets.Control control)
Enable all widgets of a control- Parameters:
control- control to enable/disableenable-trueto enable,falseto disable
-
disableAllChildrenWidgets
public static void disableAllChildrenWidgets(org.eclipse.swt.widgets.Control control)
Disable all widgets of a control- Parameters:
control- control to enable/disableenable-trueto enable,falseto disable
-
buildFontFrom
public static org.eclipse.swt.graphics.Font buildFontFrom(org.eclipse.swt.widgets.Control control, int style)Build a font from a given control. Useful if we just want a bold label for example- Parameters:
control- control that handle the default fontstyle- new style- Returns:
- a font with the given style
-
buildFontFrom
public static org.eclipse.swt.graphics.Font buildFontFrom(org.eclipse.swt.widgets.Control control, int style, int size)Build a font from a given control. Useful if we just want a bold label for example- Parameters:
control- control that handle the default fontstyle- new style- Returns:
- a font with the given style
-
isMacOS
public static boolean isMacOS()
- Returns:
trueif the operating system is MacOS, false otherwise
-
getDefaultColor
public static org.eclipse.swt.graphics.Color getDefaultColor(org.eclipse.swt.widgets.Control control, int red, int green, int blue)- Parameters:
control-red-green-blue-- Returns:
- a color that will be disposed when
controlis disposed
-
computeWidth
public static int computeWidth(java.lang.String text)
- Parameters:
text-- Returns:
- the width of text
-
-