Class SwingHelper

java.lang.Object
com.portal.pfc.ui.SwingHelper

public class SwingHelper extends Object
A general set of methods relating to UI.
  • Constructor Details

    • SwingHelper

      public SwingHelper()
  • Method Details

    • computePopupBounds

      public static Point computePopupBounds(int px, int py, int pw, int ph, Component comp)
      Computes the location on the screen for a Popup taking into account the edges of the screen.
      Parameters:
      px - : x coordinate - relative to the Component (usually 0)
      py - : y coordinate - The height of the control (usually : comp.getBounds().height)
      pw - : width - width of the popup (usually Popup.getSize().width)
      ph - : height - height of the popup (usually Popup.getSize().height)
      comp - : The component the pop-up belongs to. Like a JTextBox.
      Returns:
      Point : The location to set the popup at. With this point, call : Popup.show(comp, Point.x, Point.y);
    • getFrame

      public static JFrame getFrame(Component comp)
      Walks the component hierarchy and returns the JFrame containing the specified component. Correctly handles the case when component is a menu item.
      Parameters:
      comp - The component that the method returns the containing JFrame for.
    • centerFrame

      public static void centerFrame(JFrame jf)
      Centers the specified frame on the screen.
      Parameters:
      jf - JFrame that will be centered.
    • showMessage

      public static int showMessage(String title, Object message, int msgType, int optionType)
    • showMessage

      public static int showMessage(JFrame owner, String title, Object message, int msgType, int optionType)
      This sets up a dialog with the message type and invokes threadSafeRunDialog (see below). This provides a thread safe wrapper for swing's JOptionPane. In the future this will use Portal's icons instead of the ones provided by JOptionPane.

      If title is specified as null, then BMF provides a default title.

      The message type defines the style of the message. The java lookinvalid input: '&feel' manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are:

      JOptionPane.ERROR_MESSAGE
      JOptionPane.INFORMATION_MESSAGE
      JOptionPane.WARNING_MESSAGE
      JOptionPane.QUESTION_MESSAGE
      JOptionPane.PLAIN_MESSAGE

      The option type parameter defines the set of option buttons that appear at the bottom of the dialog box:

      JOptionPane.DEFAULT_OPTION
      JOptionPane.YES_NO_OPTION
      JOptionPane.YES_NO_CANCEL_OPTION
      JOptionPane.OK_CANCEL_OPTION

      Returns one of the following based on the option type:

      JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION, JOptionPane.OK_OPTION, or JOptionPane.CLOSED_OPTION.

    • threadSafeRunDialog

      public static void threadSafeRunDialog(Component comp)
      Runs a dialog in event dispatcher thread. If the parameter is either Window or JInternalFrame then calls show() otherwise calls setVisible( true). Uses threadSafeInvokeAndWait
    • threadSafeInvokeAndWait

      public static void threadSafeInvokeAndWait(Runnable obj)
      This basically is a wrapper for SwingUtilities.invokeAndWait(). This checks to see if we are in the event dispatcher thread already, if so simply calls run on the object, otherwise runs it through SwingUtilities.invokeAndWait. Brings up an exception message dialog in case of any exceptions
    • setPreferredButtonSize

      public static final void setPreferredButtonSize(ArrayList buttonList)
      Sets the preferred button size for the buttons contained in the ArrayList. If buttonList is null or empty, no action will be peformed.
      Parameters:
      buttonList - array of JButtons.