Class DialogUtils

java.lang.Object
edu.cnu.mdi.dialog.DialogUtils

public final class DialogUtils extends Object
Utility methods and response constants used by MDI dialogs.
  • Field Details

    • OK_RESPONSE

      public static final int OK_RESPONSE
      Dialog "Reason" constant
      See Also:
    • CANCEL_RESPONSE

      public static final int CANCEL_RESPONSE
      Dialog "Reason" constant
      See Also:
    • APPLY_RESPONSE

      public static final int APPLY_RESPONSE
      Dialog "Reason" constant
      See Also:
    • DONE_RESPONSE

      public static final int DONE_RESPONSE
      Dialog "Reason" constant
      See Also:
    • YES_RESPONSE

      public static final int YES_RESPONSE
      Dialog "Reason" constant
      See Also:
    • NO_RESPONSE

      public static final int NO_RESPONSE
      Dialog "Reason" constant
      See Also:
  • Method Details

    • centerDialog

      public static void centerDialog(JDialog dialog)
      Center a dialog
      Parameters:
      dialog - the dialog to center
    • upperRightComponent

      public static void upperRightComponent(Component component, int dh, int dv)
      Place a component in the upper right
      Parameters:
      component - The Component to center.
    • padString

      public static String padString(Component c, String inp, String tstr)
      Convenience routine for padding a string using the default font.

      Pads inp with trailing spaces so that, when rendered in c's font, its pixel width approximates tstr's pixel width as closely as possible (adding one space at a time until the width gap stops shrinking).

      Parameters:
      c - the component supplying the font metrics used to measure pixel widths
      inp - the string to be padded; null is treated as empty
      tstr - the target string-- try to return a string that renders at about the same pixel width
      Returns:
      inp (or the empty string) with zero or more trailing spaces appended
    • paddedPanel

      public static JPanel paddedPanel(int hpad, int vpad, Component component)
      Create a nice padded panel.
      Parameters:
      hpad - the pixel pad on the left and right
      vpad - the pixel pad on the top and bottom
      component - the main component placed in the center.
      Returns:
      the padded panel
    • yesNoDialog

      public static int yesNoDialog(String prompt, String... options)
      Create a dialog with a prompt and a set of options
      Parameters:
      prompt - the message displayed to the user
      options - the available response labels
      Returns:
      the selected option index, or -1 if the dialog was closed
    • requestDetailsView

      public static void requestDetailsView(JFileChooser chooser)
      Attempts to place a file chooser in details view.

      This relies on a look-and-feel action name and therefore is not guaranteed to work with every Swing look and feel.

      Parameters:
      chooser - the file chooser