Interface SmileUtilities


public interface SmileUtilities
A collection of utility methods primarily for performing common GUI-related tasks.
  • Field Details

    • SMALL_ICON_SIZE

      static final int SMALL_ICON_SIZE
      The icon size Swing uses for menu items and small toolbar buttons.
      See Also:
    • LARGE_ICON_SIZE

      static final int LARGE_ICON_SIZE
      The icon size Swing uses for large toolbar buttons.
      See Also:
    • FRAME_ICON_SIZES

      static final List<Integer> FRAME_ICON_SIZES
      The icon sizes a window frame asks for, from the title bar (16) up to the task switcher and dock (256). The window system picks the closest match.
  • Method Details

    • getLineOfOffset

      static int getLineOfOffset(JTextComponent editor, int offset)
      Returns the line number given a text offset.
      Parameters:
      editor - the text component.
      offset - the text offset.
      Returns:
      the line number.
    • getOffsetOfLine

      static int getOffsetOfLine(JTextComponent editor, int line)
      Returns the start offset of a line.
      Parameters:
      editor - the text component.
      line - the line number.
      Returns:
      the start offset.
    • getWordAt

      static String getWordAt(JTextComponent editor, int offset) throws BadLocationException
      Returns the word ending at the text offset.
      Parameters:
      editor - the text component.
      offset - the text offset.
      Returns:
      the word ending at the text offset.
      Throws:
      BadLocationException - if the offset is invalid.
    • scaleImageIcon

      static ImageIcon scaleImageIcon(ImageIcon icon, int size)
      Scales an image icon to fit within the desired size, preserving the source aspect ratio. A non-square source keeps its proportions (for example a 64×32 source scaled to 16 becomes 16×8) instead of being stretched to a square.

      Downscaling is done in progressive halving steps. A single bicubic step from a large source (for example a 512px PNG) straight to 16px aliases badly and makes thin strokes shimmer; halving until the image is within twice the target, then taking the final step, keeps the detail.

      The returned icon carries a 2× resolution variant, so Swing picks the sharper bitmap on a HiDPI display instead of upscaling the 1× one.

      Parameters:
      icon - the input image icon.
      size - the desired icon size in logical pixels.
      Returns:
      the scaled image icon.
      Throws:
      IllegalArgumentException - if size is not positive.
    • loadImageIcon

      static ImageIcon loadImageIcon(Class<?> owner, String resource, int size)
      Loads an icon from a classpath resource, scaled to the given size. A missing or undecodable resource is logged and yields an empty icon rather than an exception: a missing decoration must not take down the menu bar that is being built.
      Parameters:
      owner - the class whose package the resource path is relative to.
      resource - the resource path, for example "images/open.png".
      size - the desired icon size in logical pixels.
      Returns:
      the icon, or an empty icon when the resource cannot be loaded.
    • loadActionIcons

      static SmileUtilities.ActionIcons loadActionIcons(Class<?> owner, String resource)
      Loads the small and large variants of an icon from a classpath resource. The small variant is what Swing shows in menu items and small toolbar buttons; the large one is what it shows in a large toolbar.
      Parameters:
      owner - the class whose package the resource path is relative to.
      resource - the resource path, for example "images/open.png".
      Returns:
      the two icon variants.
    • loadFrameIcons

      static List<Image> loadFrameIcons(Class<?> owner, String resource)
      Loads a window frame icon at every size the window system may ask for, for Window.setIconImages(List). Each size is scaled with the same progressive halving as scaleImageIcon(ImageIcon, int), so the small title-bar bitmap stays crisp instead of aliasing from a single large reduction.

      A missing or undecodable resource is logged and yields an empty list rather than an exception, so a missing decoration cannot stop the window from being created.

      Parameters:
      owner - the class whose package the resource path is relative to.
      resource - the resource path, for example "images/smile.png".
      Returns:
      the frame icon bitmaps, one per size, or an empty list when the resource cannot be loaded.
    • show

      static JFrame show(Figure figure)
      Shows the figure in a window.
      Parameters:
      figure - the figure to display.
      Returns:
      a new JFrame that contains the figure.
    • show

      static JFrame show(MultiFigurePane figure)
      Shows the figure in a window.
      Parameters:
      figure - the figure to display.
      Returns:
      a new JFrame that contains the figure.
    • show

      static JFrame show(DataFrame df)
      Shows the data frame in a window.
      Parameters:
      df - the data frame to display.
      Returns:
      a new JFrame that displays the data frame in a table.
    • show

      static JFrame show(DataFrame df, String title)
      Shows the data frame in a window.
      Parameters:
      df - the data frame to display.
      title - the title of the window.
      Returns:
      a new JFrame that displays the data frame in a table.
    • show

      static JFrame show(Matrix matrix)
      Shows the matrix in a window.
      Parameters:
      matrix - the matrix to display.
      Returns:
      a new JFrame that displays the matrix in a table.
    • show

      static JFrame show(Matrix matrix, String title)
      Shows the matrix in a window.
      Parameters:
      matrix - the matrix to display.
      title - the title of the window.
      Returns:
      a new JFrame that displays the matrix in a table.
    • show

      static JFrame show(SparseMatrix matrix)
      Shows the sparse matrix structure in a figure window.
      Parameters:
      matrix - the matrix to display.
      Returns:
      a new JFrame that displays the sparse matrix structure.