Class Cursors


  • public class Cursors
    extends Object
    For creating cursors.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • m_Cache

        protected static Map<String,​Cursor> m_Cache
        the cursor cache (name - cursor).
      • m_Pointer

        protected static BufferedImage m_Pointer
        the pointer image.
    • Constructor Detail

      • Cursors

        public Cursors()
    • Method Detail

      • getPointerImage

        protected static BufferedImage getPointerImage()
        Returns the pointer image (loads it on demand).
        Returns:
        the image
      • getPointerHotspot

        protected static Point getPointerHotspot()
        Returns the hotspot for the pointer.
        Returns:
        the hotspot (0-based coordinates)
        See Also:
        getPointerImage()
      • scale

        protected static BufferedImage scale​(BufferedImage img,
                                             double scale)
        Scales the image according to the scale factor.
        Parameters:
        img - the image to scale
        scale - the scale factor
        Returns:
        the scaled image
      • scale

        protected static BufferedImage scale​(ImageIcon icon,
                                             double scale)
        Scales the image icon according to the scale factor.
        Parameters:
        icon - the image to scale
        scale - the scale factor
        Returns:
        the scaled image
      • scale

        protected static Point scale​(Point p,
                                     double scale)
        Scales the hotspot point.
        Parameters:
        p - the hotspot to scale
        scale - the scale factor (1 = 100%)
        Returns:
        the scaled hotspot
      • cache

        protected static Cursor cache​(String name,
                                      ImageIcon img,
                                      Point p,
                                      double scale)
        Creates and caches the cursor.
        Parameters:
        name - the name of the cursor
        img - the image for the cursor
        p - the hotspot
        scale - the scale factor
        Returns:
        the cursor, default cursor if failed to create
      • cache

        protected static Cursor cache​(String name,
                                      BufferedImage img,
                                      Point p,
                                      double scale)
        Creates and caches the cursor.
        Parameters:
        name - the name of the cursor
        img - the image for the cursor
        p - the hotspot
        scale - the scale factor
        Returns:
        the cursor, default cursor if failed to create
      • getCache

        public static Map<String,​Cursor> getCache()
        Returns the cursor cache.
        Returns:
        the cache (name - cursor)
      • disabled

        public static Cursor disabled()
        Creates a disabled pointer cursor.
        Returns:
        the cursor
      • square

        public static Cursor square​(int width)
        Creates a square cursor with the specified width.
        Parameters:
        width - the width of the square
        Returns:
        the cursor
      • square

        public static Cursor square​(int width,
                                    double scale)
        Creates a square cursor with the specified width.
        Parameters:
        width - the width of the square
        scale - for scaling the cursor (1.0 = 100%)
        Returns:
        the cursor
      • squareWithPointer

        public static Cursor squareWithPointer​(int width)
        Creates a square with the specified width overlayed with the cursor.
        Parameters:
        width - the width of the square
        Returns:
        the cursor
      • circle

        public static Cursor circle​(int diameter)
        Creates a circle cursor with the specified diameter.
        Parameters:
        diameter - the diameter of the circle
        Returns:
        the cursor
      • circle

        public static Cursor circle​(int diameter,
                                    double scale)
        Creates a circle cursor with the specified diameter.
        Parameters:
        diameter - the diameter of the circle
        scale - for scaling the cursor (1.0 = 100%)
        Returns:
        the cursor
      • circleWithPointer

        public static Cursor circleWithPointer​(int diameter)
        Creates a circle with the specified diameter overlayed with the cursor.
        Parameters:
        diameter - the diameter of the circle
        Returns:
        the cursor
      • crosshair

        public static Cursor crosshair​(int diameter)
        Creates a cross-hair cursor with the specified diameter.
        Parameters:
        diameter - the diameter of the cross-hair
        Returns:
        the cursor
      • crosshair

        public static Cursor crosshair​(int diameter,
                                       double scale)
        Creates a cross-hair cursor with the specified diameter.
        Parameters:
        diameter - the diameter of the cross-hair
        scale - for scaling the cursor (1.0 = 100%)
        Returns:
        the cursor
      • fromIcon

        public static Cursor fromIcon​(String iconName,
                                      int x,
                                      int y)
        Uses the ADAMS image (located adams.gui.images) as icon.
        Parameters:
        iconName - the name of the image (no path)
        x - the x coordinate for the cursor hotspot
        y - the y coordinate for the cursor hotspot
        Returns:
        the cursor
        Throws:
        IllegalStateException - if the icon doesn't exist
      • fromIcon

        public static Cursor fromIcon​(String iconName,
                                      int x,
                                      int y,
                                      double scale)
        Uses the ADAMS image (located adams.gui.images) as icon.
        Parameters:
        iconName - the name of the image (no path)
        x - the x coordinate for the cursor hotspot
        y - the y coordinate for the cursor hotspot
        scale - for scaling the cursor (1.0 = 100%)
        Returns:
        the cursor
        Throws:
        IllegalStateException - if the icon doesn't exist
      • fromFile

        public static Cursor fromFile​(String fileName,
                                      int x,
                                      int y)
        Uses the image as icon.
        Parameters:
        fileName - the name of the image (incl path)
        x - the x coordinate for the cursor hotspot
        y - the y coordinate for the cursor hotspot
        Returns:
        the cursor
        Throws:
        IllegalStateException - if the icon doesn't exist
      • fromFile

        public static Cursor fromFile​(String fileName,
                                      int x,
                                      int y,
                                      double scale)
        Uses the image as icon.
        Parameters:
        fileName - the name of the image (incl path)
        x - the x coordinate for the cursor hotspot
        y - the y coordinate for the cursor hotspot
        scale - for scaling the cursor (1.0 = 100%)
        Returns:
        the cursor
        Throws:
        IllegalStateException - if the icon doesn't exist
      • fromFile

        public static Cursor fromFile​(File file,
                                      int x,
                                      int y)
        Uses the image as icon.
        Parameters:
        file - the name of the image (incl path)
        x - the x coordinate for the cursor hotspot
        y - the y coordinate for the cursor hotspot
        Returns:
        the cursor
        Throws:
        IllegalStateException - if the icon doesn't exist
      • fromFile

        public static Cursor fromFile​(File file,
                                      int x,
                                      int y,
                                      double scale)
        Uses the image as icon.
        Parameters:
        file - the name of the image (incl path)
        x - the x coordinate for the cursor hotspot
        y - the y coordinate for the cursor hotspot
        scale - for scaling the cursor (1.0 = 100%)
        Returns:
        the cursor
        Throws:
        IllegalStateException - if the icon doesn't exist