Utilities (SelekTOR Java Documentation)
Date: 2018-05-25

lib

## Class Utilities

- java.lang.Object
- - lib.Utilities

-     public final class Utilities
      extends java.lang.Object

  Author:
    Alistair Neil

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Utilities()` Constructor

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `adjustTableColumnWidth(javax.swing.JTable table, java.lang.String... test)` Adjust specified column width based on the width of a test string
    `static void` | `editFile(java.lang.String path)` Open the desktop default file editor
    `static java.lang.String` | `generateSecretKey(int length)` Generate secret key.
    `static java.lang.String` | `getListAsCSV(java.util.ArrayList<java.lang.String> al)` Covert list to csv
    `static java.lang.String` | `getSha1Sum(java.lang.String filepath)` Calculate the sha1 checksum of a given file
    `static java.lang.String` | `getSHAHash(java.lang.String password)` Get SHAHash using given password string
    `static java.lang.String` | `getTextFromFile(java.lang.String filepath)` Retrieve text from a text file
    `static java.lang.String` | `getTextFromResource(java.lang.String resourcepath)` Retrieve text from a resource text file
    `static java.lang.String` | `getTorHashPassword(java.lang.String secret)`
    `static boolean` | `isNewerVersion(java.lang.String localversion, java.lang.String remoteversion)` Check for newer appversion
    `static void` | `loadUIStyle(java.lang.String theme)` Initialises the UI Look and Feel
    `static java.lang.String` | `openFileChooser(java.awt.Frame parent, java.lang.String folder, javax.swing.filechooser.FileFilter filter, int mode)` Opens java file chooser dialog, convenience method.
    `static boolean` | `openFileExternally(java.lang.String strUrl)` Launch the desktops default file handling program
    `static void` | `preloadFileChooser()` Preloads filechooser in background so it will open instantly when requested
    `static void` | `registerWindow()` Creates a hidden dummy window for registration to various docks/launchers Fixes the neverending launching indicator
    `static byte[]` | `S2KRFC2440(java.lang.String secret)` Secret to key, Algorithm info taken from http://sunsite.icm.edu.pl/gnupg/rfc2440-3.html

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Utilities

          public Utilities()

      Constructor

  - ### Method Detail

    - #### getListAsCSV

          public static java.lang.String getListAsCSV(java.util.ArrayList<java.lang.String> al)

      Covert list to csv
      Parameters:
        `al` -
      Returns:
        String of comma separated values

    - #### preloadFileChooser

          public static void preloadFileChooser()

      Preloads filechooser in background so it will open instantly when requested

    - #### openFileChooser

          public static java.lang.String openFileChooser(java.awt.Frame parent,
                                                         java.lang.String folder,
                                                         javax.swing.filechooser.FileFilter filter,
                                                         int mode)

      Opens java file chooser dialog, convenience method. Returns filepath if successful and null if not
      Parameters:
        `parent` -
        `folder` -
        `filter` - Extension filter
        `mode` - Fileselection mode
      Returns:
        String Filepath

    - #### isNewerVersion

          public static boolean isNewerVersion(java.lang.String localversion,
                                               java.lang.String remoteversion)

      Check for newer appversion
      Parameters:
        `localversion` -
        `remoteversion` -
      Returns:
        True if newer

    - #### editFile

          public static void editFile(java.lang.String path)

      Open the desktop default file editor
      Parameters:
        `path` - Path to file

    - #### openFileExternally

          public static boolean openFileExternally(java.lang.String strUrl)

      Launch the desktops default file handling program
      Parameters:
        `strUrl` -
      Returns:
        Returns true if successful

    - #### loadUIStyle

          public static void loadUIStyle(java.lang.String theme)

      Initialises the UI Look and Feel
      Parameters:
        `theme` -

    - #### adjustTableColumnWidth

          public static void adjustTableColumnWidth(javax.swing.JTable table,
                                                    java.lang.String... test)

      Adjust specified column width based on the width of a test string
      Parameters:
        `table` -
        `test` -

    - #### generateSecretKey

          public static java.lang.String generateSecretKey(int length)

      Generate secret key.
      Parameters:
        `length` -
      Returns:
        String key

    - #### getTorHashPassword

          public static java.lang.String getTorHashPassword(java.lang.String secret)

    - #### S2KRFC2440

          public static byte[] S2KRFC2440(java.lang.String secret)

      Secret to key, Algorithm info taken from http://sunsite.icm.edu.pl/gnupg/rfc2440-3.html
      Parameters:
        `secret` -
      Returns:
        hashed key for the given secret

    - #### getSHAHash

          public static java.lang.String getSHAHash(java.lang.String password)

      Get SHAHash using given password string
      Parameters:
        `password` -
      Returns:
        SHAhash string

    - #### getTextFromResource

          public static java.lang.String getTextFromResource(java.lang.String resourcepath)

      Retrieve text from a resource text file
      Parameters:
        `resourcepath` -
      Returns:
        String text

    - #### getTextFromFile

          public static java.lang.String getTextFromFile(java.lang.String filepath)

      Retrieve text from a text file
      Parameters:
        `filepath` -
      Returns:
        String text

    - #### getSha1Sum

          public static java.lang.String getSha1Sum(java.lang.String filepath)

      Calculate the sha1 checksum of a given file
      Parameters:
        `filepath` -
      Returns:
        Checksum as a hex string

    - #### registerWindow

          public static void registerWindow()

      Creates a hidden dummy window for registration to various docks/launchers Fixes the neverending launching indicator