org.faceless.pdf2.viewer2

## Class Util

- java.lang.Object
- - org.faceless.pdf2.viewer2.Util

-     public final class Util
      extends Object

  A utility class that handles localized Strings, display of error messages and so on. Developers extending the viewer are welcome to use this class

  This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.

  Since:
    2.11 - created from the SuperJOptionPane class

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static BFOLogger` | `LOGGER`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static TransferHandler` | `createTransferHandler(PDFViewer viewer)` Return the TransferHandler to use when copying/pasting text.
    `static void` | `displayThrowable(Throwable throwable, Component parent)` Display an Error message, including the stack trace
    `static String` | `encodeColor(Color c)` Return the standard #RRGGBB representation of a Color
    `static JFileChooser` | `fixFileChooser(JFileChooser chooser)` Attempt to repair a reported bug in the AWT classes where Icons returned from this class a null, causing a NPE deep inside the JFileChooser UI classes.
    `static void` | `fixScrollPaneKeyBindings(JScrollPane scrollpane)` Remove the pageup/pagedown key bindings from ScrollPanes - they're clashing with the pageup/pagedown we're mapping on the DocumentPanel
    `static JTextField` | `getJFileChooserFileName(JFileChooser chooser)` Return the JTextField containing the current filename from the JFileChooser, or null if this can't be determined for the current look-and-feel.
    `static JComponent` | `getRootAncestor(JComponent c)` Get the top-level JComponent above the specified one - typically a JApplet, JWindow or JFrame
    `static int` | `getScreenResolution(Component comp)` Get the screen resolution.
    `static String` | `getUIString(String key)` Return a UIManager string field.
    `static String` | `getUIString(String key, String field1)` Return a UIManager string field with the specified fields replaced
    `static String` | `getUIString(String key, String field1, String field2)` Return a UIManager string field with the specified fields replaced
    `static boolean` | `hasFilePermission()` Return true if the viewer can access the local filesystem
    `static boolean` | `isBrowserApplet(Component c)` Return true if the viewer is running as an Applet inside a web browser, false otherwise
    `static boolean` | `isJNLP(Component c)` Return true if the specified component is running in a JNLP environment, false otherwise
    `static boolean` | `isLAFAqua()` Return true if the LAF uses the Aqua toolkit (OS X)
    `static boolean` | `isLAFGTK()` Return true if the LAF uses the GTK+ toolkit (UNIX)
    `static boolean` | `isLAFMetal()` Return true if the LAF uses the Metal toolkit
    `static boolean` | `isLAFNimbus()` Return true if the LAF uses the Nimbus toolkit
    `static boolean` | `isLAFWindows()` Return true if the LAF uses the Window toolkit
    `static boolean` | `isStandaloneApplet(Component c)` Return true if the viewer is running as an Applet that has been dragged outside of the web browser, false otherwise.
    `static JDialog` | `newJDialog(Component comp, String title, boolean modal)` Create a dialog for the specified component.
    `static boolean` | `openURL(URL url, Component c)` Display a URL in a web browser, if possible
    `static boolean` | `patchJFileChooser(JFileChooser chooser, JComponent patch, boolean add)` Insert an "Option pane" into the JFileChooser.
    `static void` | `setAutoFocusComponent(JComponent component)` Set the supplied component to gain focus when it's newly displayed, even inside a sub-pane in a popup window.
    `static URL` | `toURL(DocumentPanel docpanel, String path)` Attempt to convert a relative URL to an absolute one.

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

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

- - ### Field Detail

    - #### LOGGER

          public static final BFOLogger LOGGER

  - ### Method Detail

    - #### displayThrowable

          public static void displayThrowable(Throwable throwable,
                                              Component parent)

      Display an Error message, including the stack trace
      Parameters:
        `throwable` - the Throwable object this error relates to
        `parent` - the parent component (not used)

    - #### isLAFAqua

          public static boolean isLAFAqua()

      Return true if the LAF uses the Aqua toolkit (OS X)

    - #### isLAFGTK

          public static boolean isLAFGTK()

      Return true if the LAF uses the GTK+ toolkit (UNIX)

    - #### isLAFNimbus

          public static boolean isLAFNimbus()

      Return true if the LAF uses the Nimbus toolkit

    - #### isLAFWindows

          public static boolean isLAFWindows()

      Return true if the LAF uses the Window toolkit

    - #### isLAFMetal

          public static boolean isLAFMetal()

      Return true if the LAF uses the Metal toolkit

    - #### isBrowserApplet

          public static boolean isBrowserApplet(Component c)

      Return true if the viewer is running as an Applet inside a web browser, false otherwise
      Parameters:
        `c` - the Component
      Since:
        2.11.1

    - #### isStandaloneApplet

          public static boolean isStandaloneApplet(Component c)

      Return true if the viewer is running as an Applet that has been dragged outside of the web browser, false otherwise.
      Parameters:
        `c` - the Component
      Since:
        2.11.1

    - #### isJNLP

          public static boolean isJNLP(Component c)

      Return true if the specified component is running in a JNLP environment, false otherwise
      Parameters:
        `c` - the Component
      Since:
        2.11.1

    - #### openURL

          public static boolean openURL(URL url,
                                        Component c)

      Display a URL in a web browser, if possible
      Parameters:
        `url` - the URL to open
        `c` - the Component
      Returns:
        true if the URL could be opened, false otherwise
      Since:
        2.11.1

    - #### getUIString

          public static String getUIString(String key)

      Return a UIManager string field. Identical to getUIString except this method never returns null - if the String isn't found, the key is returned.
      Since:
        2.16.2

    - #### getUIString

          public static String getUIString(String key,
                                           String field1)

      Return a UIManager string field with the specified fields replaced
      Parameters:
        `key` - the message key,
        `field1` - the field to be substituted for {1}
      Returns:
        the modified string

    - #### getUIString

          public static String getUIString(String key,
                                           String field1,
                                           String field2)

      Return a UIManager string field with the specified fields replaced
      Parameters:
        `key` - the message key,
        `field1` - the field to be substituted for {1}
        `field2` - the field to be substituted for {2}
      Returns:
        the modified string

    - #### fixScrollPaneKeyBindings

          public static void fixScrollPaneKeyBindings(JScrollPane scrollpane)

      Remove the pageup/pagedown key bindings from ScrollPanes - they're clashing with the pageup/pagedown we're mapping on the DocumentPanel

    - #### toURL

          public static URL toURL(DocumentPanel docpanel,
                                  String path)

      Attempt to convert a relative URL to an absolute one. URL is assumed to be relative to the file. If we don't have that info but we're loaded from an applet, then attempt to load URL relative to the applet base. Otherwise, take your best shot.

    - #### hasFilePermission

          public static boolean hasFilePermission()

      Return true if the viewer can access the local filesystem

    - #### encodeColor

          public static String encodeColor(Color c)

      Return the standard #RRGGBB representation of a Color

    - #### getScreenResolution

          public static int getScreenResolution(Component comp)

      Get the screen resolution. Same as Toolkit.getScreenResolution, except it allows us to override it using the PDFViewer "dpi" property

    - #### newJDialog

          public static JDialog newJDialog(Component comp,
                                           String title,
                                           boolean modal)

      Create a dialog for the specified component. This will search up the Swing hierarchy until the first Frame, Dialog or Window is found and return a dialog on that object. This caters for situations where the viewer itself is running in a JDialog.

      Note the JDialog(Window) constructor will do the same, but that's Java 6 only.

      Parameters:
        `comp` - the Component creating the dialog
        `title` - the title of the dialog, or `null` for no title
        `modal` - whether the dialog is to be modal or not.
      Since:
        2.13.1

    - #### fixFileChooser

          public static JFileChooser fixFileChooser(JFileChooser chooser)

      Attempt to repair a reported bug in the AWT classes where Icons returned from this class a null, causing a NPE deep inside the JFileChooser UI classes.

    - #### createTransferHandler

          public static TransferHandler createTransferHandler(PDFViewer viewer)

      Return the TransferHandler to use when copying/pasting text. By default this is a `RichTextTransferHandler`, but this can be overridden by setting the property "TransferHandler" on the PDFViewer `PropertyManager`. to the full class-name of the TransferHandler.
      Since:
        2.16.1

    - #### setAutoFocusComponent

          public static void setAutoFocusComponent(JComponent component)

      Set the supplied component to gain focus when it's newly displayed, even inside a sub-pane in a popup window.
      Parameters:
        `component` - the component

    - #### patchJFileChooser

          public static boolean patchJFileChooser(JFileChooser chooser,
                                                  JComponent patch,
                                                  boolean add)

      Insert an "Option pane" into the JFileChooser. This has to be done differently for each look and feel - if it can't be done, this method will return false. Don't blame us for this horror, blame Sun.
      Since:
        2.16.2

    - #### getJFileChooserFileName

          public static JTextField getJFileChooserFileName(JFileChooser chooser)

      Return the JTextField containing the current filename from the JFileChooser, or null if this can't be determined for the current look-and-feel.
      Since:
        2.16.2

    - #### getRootAncestor

          public static JComponent getRootAncestor(JComponent c)

      Get the top-level JComponent above the specified one - typically a JApplet, JWindow or JFrame

Copyright © 2001-2015 Big Faceless Organization