Package pamViewFX.fxNodes.utilsFX
Class PamUtilsFX
java.lang.Object
pamViewFX.fxNodes.utilsFX.PamUtilsFX
Useful classes for JavaFX library.
- Author:
- Jamie Macaulay
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic javafx.scene.paint.ColoraddColorTransparancy(javafx.scene.paint.Color color, double opacity) Add transparancy to a JavaFX colourstatic javafx.scene.control.MenuItemawtMenuItemToFX(MenuItem awtItem) Convert an AWT menu item into an FX menu Item.static javafx.scene.paint.ColorawtToFXColor(Color awtColor) static Stringcolor2Hex(javafx.scene.paint.Color color) static intcolorToInt(javafx.scene.paint.Color c) Convert a colour to an int.static JPopupMenucontextMenuToSwing(javafx.scene.control.ContextMenu contextMenu) Convert a FX context menu to a Swingpopup menu.static ColourArray.ColourArrayTypeConvert an FX based ColourArrayType to Swing.static JMenuItemfxMenuItemToSwing(javafx.scene.control.MenuItem fxItem) Convert an FX menu item into a Swing menu item.static ColorfxToAWTColor(javafx.scene.paint.Color fxColor) static javafx.scene.paint.ColorgetDominantColor(javafx.scene.image.Image srcImage) Get the average colour of an image.static javafx.animation.TimelinegetFlashTimeLine(javafx.scene.effect.DropShadow shadow, double radius, double duration) Get node flash timeline.static List<javafx.scene.control.MenuItem> getSwingMenuItems(JPopupMenu popMenu) Turn the items in a Swing menu into a list of FX menu items.static StringhtmlToNormal(String htmlString) Convert an html string to normal text.static javafx.scene.NodeConvert an icon to an FX node.static IconiconToSwing(javafx.scene.Node node) Convert an fx node to a Swing icon.static javafx.scene.paint.ColorintToColor(int value) Convert an int encoded with a colour to a Color object.static ArrayList<MenuItemInfo> jPopMenu2FX(JPopupMenu jPopupMenu) Extract info from a JpopUpMenu and return an array of MenuItemInfos which contain the information required to construct a JavaFX menu.static javafx.scene.input.MouseEventmouseEvent2NewNode(javafx.scene.input.MouseEvent event, javafx.scene.Node newNode) Converts a mouse event received on one node to mouse event received on another assuming that both nodes are in the same scene.static javafx.scene.input.MouseEventmouseEvent2NewNode(javafx.scene.input.MouseEvent event, javafx.scene.Node newNode, double xOffset, double yOffset) Converts a mouse event received on one node to mouse event received on another assuming that both nodes are in the same scene.static voidnodeFlashEffect(javafx.scene.Node node, javafx.scene.paint.Color col, double radius, double duration) Animates a node with a flashstatic javafx.scene.image.Imagescale(javafx.scene.image.Image source, int targetWidth, int targetHeight, boolean preserveRatio) Scale an image.static ColourArray.ColourArrayTypeswingColArray2FX(ColourArray.ColourArrayType arraySwing) Convert an Swing based ColourArrayType to FX.static javafx.scene.control.MenuItemswingMenuItemToFX(JMenuItem swingItem) Convert a swing menu item to an FX MenuItem.static BufferedImagetoBufferedImage(Image img) Converts a given Image into a BufferedImage http://stackoverflow.com/questions/13605248/java-converting-image-to-bufferedimagestatic StringtoRGBCode(javafx.scene.paint.Color color) Get the hex code form a color
-
Constructor Details
-
PamUtilsFX
public PamUtilsFX()
-
-
Method Details
-
fxColArray2Swing
Convert an FX based ColourArrayType to Swing. Note that swing options that do not exist in FX and vice versa will return null.- Parameters:
arrayFX- - the FX ColourArrayType.- Returns:
- the Swing ColourArrayType;
-
swingColArray2FX
Convert an Swing based ColourArrayType to FX. Note that swing options that do not exist in FX and vice versa will return null.- Parameters:
arraySwing- - the Swing ColourArrayType.- Returns:
- the FX ColourArrayType.
-
awtToFXColor
- Parameters:
awtColor-- Returns:
-
fxToAWTColor
- Parameters:
fxColor-- Returns:
-
mouseEvent2NewNode
public static javafx.scene.input.MouseEvent mouseEvent2NewNode(javafx.scene.input.MouseEvent event, javafx.scene.Node newNode) Converts a mouse event received on one node to mouse event received on another assuming that both nodes are in the same scene. The screen co-ordinates and all other variable are preserved are preserved and the x and Y values converted to the new Node.- Parameters:
event- - the MouseEvent.newNode- - the target node for the mouse event- Returns:
- the new MouseEvent for the new Node.
-
mouseEvent2NewNode
public static javafx.scene.input.MouseEvent mouseEvent2NewNode(javafx.scene.input.MouseEvent event, javafx.scene.Node newNode, double xOffset, double yOffset) Converts a mouse event received on one node to mouse event received on another assuming that both nodes are in the same scene. The screen co-ordinates and all other variable are preserved are preserved and the x and Y values converted to the new Node. Note that the pick result is not preserved.- Parameters:
event- - the MouseEvent.newNode- - the target node for the mouse event.xOffset- - offset x in pixels.yOffset- - offset y in pixels.- Returns:
- the new MouseEvent for the new Node.
-
addColorTransparancy
public static javafx.scene.paint.Color addColorTransparancy(javafx.scene.paint.Color color, double opacity) Add transparancy to a JavaFX colour- Parameters:
color-- Returns:
-
color2Hex
- Parameters:
color-- Returns:
-
jPopMenu2FX
Extract info from a JpopUpMenu and return an array of MenuItemInfos which contain the information required to construct a JavaFX menu.- Parameters:
jPopupMenu- - the JPopupMenu to deconstruct.- Returns:
- an array of MenuItemInfos containing info on the items in JPopupMenu.
-
contextMenuToSwing
Convert a FX context menu to a Swingpopup menu.- Parameters:
contextMenu- FX Context menu- Returns:
- Swing popup menu
-
getSwingMenuItems
Turn the items in a Swing menu into a list of FX menu items.- Parameters:
popMenu-- Returns:
-
awtMenuItemToFX
Convert an AWT menu item into an FX menu Item.- Parameters:
awtItem- AWT menu item- Returns:
- swing menu item.
-
swingMenuItemToFX
Convert a swing menu item to an FX MenuItem. Sub menu's will be preserved.- Parameters:
swingItem- Swing menu item.- Returns:
- FX Menu Item
-
fxMenuItemToSwing
Convert an FX menu item into a Swing menu item. Sub menu's will be preserved.- Parameters:
fxItem- FX Menu item- Returns:
- Swing menu item.
-
iconToFX
Convert an icon to an FX node.- Parameters:
icon- - the icon to convert- Returns:
- a node containing the image of the icon.
-
iconToSwing
Convert an fx node to a Swing icon.- Parameters:
canvas- fx Node- Returns:
- Swing icon.
-
toBufferedImage
Converts a given Image into a BufferedImage http://stackoverflow.com/questions/13605248/java-converting-image-to-bufferedimage- Parameters:
img- The Image to be converted- Returns:
- The converted BufferedImage
-
nodeFlashEffect
public static void nodeFlashEffect(javafx.scene.Node node, javafx.scene.paint.Color col, double radius, double duration) Animates a node with a flash- Parameters:
node- - the node for the effectcol- - the colour of the flashradius- - the raioud of the flashduration- - the duration of the flash in seconds
-
getFlashTimeLine
public static javafx.animation.Timeline getFlashTimeLine(javafx.scene.effect.DropShadow shadow, double radius, double duration) Get node flash timeline. This can be used to make a node flash.- Parameters:
radius- - the raioud of the flashnode- - the node for the effectcol- - the colour of the flash- Returns:
- flash timeline
-
htmlToNormal
Convert an html string to normal text. JavaFX labels do not support html- Parameters:
htmlString- - an html formatted string- Returns:
- a string with basic formatting corresponding to html.
-
getDominantColor
public static javafx.scene.paint.Color getDominantColor(javafx.scene.image.Image srcImage) Get the average colour of an image.- Parameters:
srcImage- - the image- Returns:
- - the average colour of the image.
-
scale
public static javafx.scene.image.Image scale(javafx.scene.image.Image source, int targetWidth, int targetHeight, boolean preserveRatio) Scale an image.- Parameters:
source- - the source imagetargetWidth- - the target image width.targetHeight- - the target image height.preserveRatio- - true to preserve ratio.- Returns:
- the scaled image.
-
toRGBCode
Get the hex code form a color- Parameters:
color- - the color.- Returns:
- the color.
-
colorToInt
public static int colorToInt(javafx.scene.paint.Color c) Convert a colour to an int.- Parameters:
c- - the colour to change.- Returns:
- the int representation of the colour
-
intToColor
public static javafx.scene.paint.Color intToColor(int value) Convert an int encoded with a colour to a Color object.- Parameters:
value- - the int to convert to colour- Returns:
- the Color object for the int
-