processing.app

## Class Toolkit

- Object
- - Toolkit

-     public class Toolkit
      extends Object

  Utility functions for base that require a java.awt.Toolkit object. These are broken out from Base as we start moving toward the possibility of the code running in headless mode.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static KeyStroke` | `WINDOW_CLOSE_KEYSTROKE` Command-W on Mac OS X, Ctrl-W on Windows and Linux

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Toolkit()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addDisabledItem(JMenu menu, String title)`
    `static void` | `beep()`
    `static Shape` | `createRoundRect(float x1, float y1, float x2, float y2, float tl, float tr, float br, float bl)`
    `static void` | `debugOpacity(Component comp)` Do not use or rely upon presence of this method: not approved as final API.
    `static ImageIcon` | `getLibIcon(String filename)` Get an ImageIcon from the Processing 'lib' folder.
    `static Image` | `getLibImage(String filename)` Return an Image object from inside the Processing 'lib' folder.
    `static int` | `getMenuItemIndex(JMenu menu, JMenuItem item)`
    `static Font` | `getMonoFont(int size, int style)`
    `static String[]` | `getMonoFontFamilies()`
    `static String` | `getMonoFontName()`
    `static Font` | `getSansFont(int size, int style)`
    `static Dimension` | `getScreenSize()`
    `static Clipboard` | `getSystemClipboard()`
    `static boolean` | `highResDisplay()`
    `static JCheckBoxMenuItem` | `newJCheckBoxMenuItem(String title, int what)`
    `static JMenuItem` | `newJMenuItem(String title, int what)` A software engineer, somewhere, needs to have his abstraction taken away.
    `static JMenuItem` | `newJMenuItemAlt(String title, int what)` Same as newJMenuItem(), but adds the ALT (on Linux and Windows) or OPTION (on Mac OS X) key as a modifier.
    `static JMenuItem` | `newJMenuItemShift(String title, int what)` Like newJMenuItem() but adds shift as a modifier for the shortcut.
    `static Graphics2D` | `prepareGraphics(Graphics g)` Handles scaling for high-res displays, also sets text anti-aliasing options to be far less ugly than the defaults.
    `static void` | `registerWindowCloseKeys(JRootPane root, ActionListener disposer)` Registers key events for a Ctrl-W and ESC with an ActionListener that will take care of disposing the window.
    `static void` | `setIcon(Frame frame)`
    `static void` | `setIcon(Window window)` Give this Frame the Processing icon set.
    `static void` | `setMenuMnemonics(JMenuBar menubar)` As setMenuMnemonics(JMenuItem...).
    `static void` | `setMenuMnemonics(JMenuItem... menu)` Removes all mnemonics, then sets a mnemonic for each menu and menu item recursively by these rules: It tries to assign one of KDE's defaults. Failing that, it loops through the first letter of each word, where a word is a block of Unicode "alphabetical" chars, looking for an upper-case ASCII mnemonic that is not taken.
    `static void` | `setMenuMnemonics(JPopupMenu menu)` As setMenuMnemonics(JMenuItem...).
    `static void` | `setMenuMnemsInside(JMenu menu)` Calls setMenuMnemonics(JMenuItem...) on the sub-elements only.

    - ### Methods inherited from class Object

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

- - ### Field Detail

    - #### WINDOW_CLOSE_KEYSTROKE

          public static final KeyStroke WINDOW_CLOSE_KEYSTROKE

      Command-W on Mac OS X, Ctrl-W on Windows and Linux

  - ### Constructor Detail

    - #### Toolkit

          public Toolkit()

  - ### Method Detail

    - #### newJMenuItem

          public static JMenuItem newJMenuItem(String title,
                                               int what)

      A software engineer, somewhere, needs to have his abstraction taken away. In some countries they jail or beat people for crafting the sort of API that would require a five line helper function just to set the shortcut key for a menu item.

    - #### newJMenuItemShift

          public static JMenuItem newJMenuItemShift(String title,
                                                    int what)

      Like newJMenuItem() but adds shift as a modifier for the shortcut.

    - #### newJMenuItemAlt

          public static JMenuItem newJMenuItemAlt(String title,
                                                  int what)

      Same as newJMenuItem(), but adds the ALT (on Linux and Windows) or OPTION (on Mac OS X) key as a modifier. This function should almost never be used, because it's bad for non-US keyboards that use ALT in strange and wondrous ways.

    - #### newJCheckBoxMenuItem

          public static JCheckBoxMenuItem newJCheckBoxMenuItem(String title,
                                                               int what)

    - #### addDisabledItem

          public static void addDisabledItem(JMenu menu,
                                             String title)

    - #### setMenuMnemonics

          public static void setMenuMnemonics(JMenuItem... menu)

      Removes all mnemonics, then sets a mnemonic for each menu and menu item recursively by these rules:
      1. It tries to assign one of KDE's defaults.
      2. Failing that, it loops through the first letter of each word, where a word is a block of Unicode "alphabetical" chars, looking for an upper-case ASCII mnemonic that is not taken. This is to try to be relevant, by using a letter well-associated with the command. (MS guidelines)
      3. Ditto, but with lowercase.
      4. Next, it tries the second ASCII character, if its width >= half the width of 'A'.
      5. If the first letters are all taken/non-ASCII, then it loops through the ASCII letters in the item, widest to narrowest, seeing if any of them is not taken. To improve readability, it discriminates against decenders (qypgj), imagining they have 2/3 their actual width. (MS guidelines: avoid decenders). It also discriminates against vowels, imagining they have 2/3 their actual width. (MS and Gnome guidelines: avoid vowels.)
      6. Failing that, it will loop left-to-right for an available digit. This is a last resort because the normal setMnemonic dislikes them.
      7. If that doesn't work, it doesn't assign a mnemonic.
      As a special case, strings starting "sketchbook → " have that bit ignored because otherwise the Recent menu looks awful. However, the name `"sketchbook → Sketch"`, for example, will have the 'S' of "Sketch" chosen, but the 's' of 'sketchbook will get underlined. No letter by an underscore will be assigned. Disabled on Mac, per Apple guidelines. `menu` may contain nulls. Author: George Bateman. Initial work Myer Nore.
      Parameters:
        `menu` - A menu, a list of menus or an array of menu items to set mnemonics for.

    - #### setMenuMnemonics

          public static void setMenuMnemonics(JMenuBar menubar)

      As setMenuMnemonics(JMenuItem...).

    - #### setMenuMnemonics

          public static void setMenuMnemonics(JPopupMenu menu)

      As setMenuMnemonics(JMenuItem...).

    - #### setMenuMnemsInside

          public static void setMenuMnemsInside(JMenu menu)

      Calls setMenuMnemonics(JMenuItem...) on the sub-elements only.

    - #### getScreenSize

          public static Dimension getScreenSize()

    - #### getLibImage

          public static Image getLibImage(String filename)

      Return an Image object from inside the Processing 'lib' folder. Moved here so that Base can stay headless.

    - #### getLibIcon

          public static ImageIcon getLibIcon(String filename)

      Get an ImageIcon from the Processing 'lib' folder.
      Since:
        3.0a6

    - #### setIcon

          public static void setIcon(Frame frame)

    - #### setIcon

          public static void setIcon(Window window)

      Give this Frame the Processing icon set. Ignored on OS X, because they thought different and made this function set the minified image of the window, not the window icon for the dock or cmd-tab.

    - #### createRoundRect

          public static Shape createRoundRect(float x1,
                                              float y1,
                                              float x2,
                                              float y2,
                                              float tl,
                                              float tr,
                                              float br,
                                              float bl)

    - #### registerWindowCloseKeys

          public static void registerWindowCloseKeys(JRootPane root,
                                                     ActionListener disposer)

      Registers key events for a Ctrl-W and ESC with an ActionListener that will take care of disposing the window.

    - #### beep

          public static void beep()

    - #### getSystemClipboard

          public static Clipboard getSystemClipboard()

    - #### prepareGraphics

          public static Graphics2D prepareGraphics(Graphics g)

      Handles scaling for high-res displays, also sets text anti-aliasing options to be far less ugly than the defaults. Moved to a utility function because it's used in several classes.
      Returns:
        a Graphics2D object, as a bit o sugar

    - #### highResDisplay

          public static boolean highResDisplay()

    - #### getMonoFontFamilies

          public static String[] getMonoFontFamilies()

    - #### getMonoFontName

          public static String getMonoFontName()

    - #### getMonoFont

          public static Font getMonoFont(int size,
                                         int style)

    - #### getSansFont

          public static Font getSansFont(int size,
                                         int style)

    - #### debugOpacity

          public static void debugOpacity(Component comp)

      Do not use or rely upon presence of this method: not approved as final API.

    - #### getMenuItemIndex

          public static int getMenuItemIndex(JMenu menu,
                                             JMenuItem item)