Class PamUtilsFX

java.lang.Object
pamViewFX.fxNodes.utilsFX.PamUtilsFX

public class PamUtilsFX extends Object
Useful classes for JavaFX library.
Author:
Jamie Macaulay
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static javafx.scene.paint.Color
    addColorTransparancy(javafx.scene.paint.Color color, double opacity)
    Add transparancy to a JavaFX colour
    static javafx.scene.control.MenuItem
    Convert an AWT menu item into an FX menu Item.
    static javafx.scene.paint.Color
    awtToFXColor(Color awtColor)
     
    static String
    color2Hex(javafx.scene.paint.Color color)
     
    static int
    colorToInt(javafx.scene.paint.Color c)
    Convert a colour to an int.
    static JPopupMenu
    contextMenuToSwing(javafx.scene.control.ContextMenu contextMenu)
    Convert a FX context menu to a Swingpopup menu.
    Convert an FX based ColourArrayType to Swing.
    static JMenuItem
    fxMenuItemToSwing(javafx.scene.control.MenuItem fxItem)
    Convert an FX menu item into a Swing menu item.
    static Color
    fxToAWTColor(javafx.scene.paint.Color fxColor)
     
    static javafx.scene.paint.Color
    getDominantColor(javafx.scene.image.Image srcImage)
    Get the average colour of an image.
    static javafx.animation.Timeline
    getFlashTimeLine(javafx.scene.effect.DropShadow shadow, double radius, double duration)
    Get node flash timeline.
    static List<javafx.scene.control.MenuItem>
    Turn the items in a Swing menu into a list of FX menu items.
    static String
    htmlToNormal(String htmlString)
    Convert an html string to normal text.
    static javafx.scene.Node
    iconToFX(Icon icon)
    Convert an icon to an FX node.
    static Icon
    iconToSwing(javafx.scene.Node node)
    Convert an fx node to a Swing icon.
    static javafx.scene.paint.Color
    intToColor(int value)
    Convert an int encoded with a colour to a Color object.
    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.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.
    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.
    static void
    nodeFlashEffect(javafx.scene.Node node, javafx.scene.paint.Color col, double radius, double duration)
    Animates a node with a flash
    static javafx.scene.image.Image
    scale(javafx.scene.image.Image source, int targetWidth, int targetHeight, boolean preserveRatio)
    Scale an image.
    Convert an Swing based ColourArrayType to FX.
    static javafx.scene.control.MenuItem
    Convert a swing menu item to an FX MenuItem.
    Converts a given Image into a BufferedImage http://stackoverflow.com/questions/13605248/java-converting-image-to-bufferedimage
    static String
    toRGBCode(javafx.scene.paint.Color color)
    Get the hex code form a color

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PamUtilsFX

      public PamUtilsFX()
  • Method Details

    • fxColArray2Swing

      public static ColourArray.ColourArrayType fxColArray2Swing(ColourArray.ColourArrayType arrayFX)
      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

      public static ColourArray.ColourArrayType swingColArray2FX(ColourArray.ColourArrayType arraySwing)
      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

      public static javafx.scene.paint.Color awtToFXColor(Color awtColor)
      Parameters:
      awtColor -
      Returns:
    • fxToAWTColor

      public static Color fxToAWTColor(javafx.scene.paint.Color fxColor)
      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

      public static String color2Hex(javafx.scene.paint.Color color)
      Parameters:
      color -
      Returns:
    • jPopMenu2FX

      public 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.
      Parameters:
      jPopupMenu - - the JPopupMenu to deconstruct.
      Returns:
      an array of MenuItemInfos containing info on the items in JPopupMenu.
    • contextMenuToSwing

      public static JPopupMenu contextMenuToSwing(javafx.scene.control.ContextMenu contextMenu)
      Convert a FX context menu to a Swingpopup menu.
      Parameters:
      contextMenu - FX Context menu
      Returns:
      Swing popup menu
    • getSwingMenuItems

      public static List<javafx.scene.control.MenuItem> getSwingMenuItems(JPopupMenu popMenu)
      Turn the items in a Swing menu into a list of FX menu items.
      Parameters:
      popMenu -
      Returns:
    • awtMenuItemToFX

      public static javafx.scene.control.MenuItem awtMenuItemToFX(MenuItem awtItem)
      Convert an AWT menu item into an FX menu Item.
      Parameters:
      awtItem - AWT menu item
      Returns:
      swing menu item.
    • swingMenuItemToFX

      public static javafx.scene.control.MenuItem swingMenuItemToFX(JMenuItem swingItem)
      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

      public static JMenuItem fxMenuItemToSwing(javafx.scene.control.MenuItem fxItem)
      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

      public static javafx.scene.Node iconToFX(Icon icon)
      Convert an icon to an FX node.
      Parameters:
      icon - - the icon to convert
      Returns:
      a node containing the image of the icon.
    • iconToSwing

      public static Icon iconToSwing(javafx.scene.Node node)
      Convert an fx node to a Swing icon.
      Parameters:
      canvas - fx Node
      Returns:
      Swing icon.
    • toBufferedImage

      public static BufferedImage toBufferedImage(Image img)
      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 effect
      col - - the colour of the flash
      radius - - the raioud of the flash
      duration - - 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 flash
      node - - the node for the effect
      col - - the colour of the flash
      Returns:
      flash timeline
    • htmlToNormal

      public static String htmlToNormal(String htmlString)
      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 image
      targetWidth - - the target image width.
      targetHeight - - the target image height.
      preserveRatio - - true to preserve ratio.
      Returns:
      the scaled image.
    • toRGBCode

      public static String toRGBCode(javafx.scene.paint.Color color)
      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