Class SwingUtils

java.lang.Object
VASSAL.tools.swing.SwingUtils

public class SwingUtils extends Object
  • Field Details

    • FONT_HINTS

      public static final Map<?,?> FONT_HINTS
  • Constructor Details

    • SwingUtils

      public SwingUtils()
  • Method Details

    • isMacLegacy

      public static boolean isMacLegacy()
      Supports swapping most Control and Command button functions on Mac so as not to punish long-time users for our "old non-standard implementations"
    • setMacLegacy

      public static void setMacLegacy(boolean b)
      Supports swapping most Control and Command button functions on Mac so as not to punish long-time users for our "old non-standard implementations"
    • descaleTransform

      public static AffineTransform descaleTransform(AffineTransform t)
    • isLeftMouseButton

      @Deprecated(since="2021-12-01", forRemoval=true) public static boolean isLeftMouseButton(MouseEvent e)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      whether the event is effectively for the left button.
    • isRightMouseButton

      @Deprecated(since="2021-12-01", forRemoval=true) public static boolean isRightMouseButton(MouseEvent e)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      whether the event is effectively for the right button.
    • isControlDown

      @Deprecated(since="2021-12-01", forRemoval=true) public static boolean isControlDown(MouseEvent e)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The situation where this was needed with mouse events is now handled by isSelectionToggle(MouseEvent).
      Returns:
      whether the event effectively has Control down.
    • isContextMouseButtonDown

      public static boolean isContextMouseButtonDown(MouseEvent e)
      Returns:
      whether the event has the key/mouse combo for Context Menu active, whether it would raise one "right now" or not. (normally plain right mouse button, but some funky mac bonuses)
    • isMainMouseButtonDown

      public static boolean isMainMouseButtonDown(MouseEvent e)
      Returns:
      whether the event has the key/mouse combo for selecting things down (normally just plain left mouse button, but on Mac only if not pretending to be right button)
    • isSelectionToggle

      public static boolean isSelectionToggle(MouseEvent e)
      Returns:
      whether the event has the key/mouse combo toggling targets in and out of selection (normally Ctrl+Click on most platforms, normally Command+Click on Mac)
    • isModifierKeyDown

      public static boolean isModifierKeyDown(KeyEvent e)
      Parameters:
      e - Key event
      Returns:
      true if CTRL+keystroke on non-Mac or Command+keystroke on Mac
    • getModifierKeyMask

      public static int getModifierKeyMask()
      Returns:
      returns InputEvent.META_DOWN_MASK on Mac or InputEvent.CTRL_DOWN_MASK on others
    • systemToGeneric

      public static KeyStroke systemToGeneric(KeyStroke k)
      Returns:
      translation of keystroke from local system to platform-independent Vassal keystroke (to handle Mac platform support) The main idea here is that on Macs we want the common shortcut keys represented by e.g. Ctrl+C on Windows and Linux platforms to be represented by Command+C on the Mac, and likewise when module designers on Mac implement a Command+C shortcut we want that to appear as Ctrl+C for the same module running on other platforms. But we also support a "legacy" preference to allow Mac users used to Vassal 3.2.17 and prior mappings to continue with them.
    • genericToSystem

      public static KeyStroke genericToSystem(KeyStroke k)
      Returns:
      translation of keystroke from platform-independent Vassal to local system (to handle Mac platform support) The main idea here is that on Macs we want the common shortcut keys represented by e.g. Ctrl+C on Windows and Linux platforms to be represented by Command+C on the Mac, and likewise when module designers on Mac implement a Command+C shortcut we want that to appear as Ctrl+C for the same module running on other platforms. But we also support a "legacy" preference to allow Mac users used to Vassal 3.2.17 and prior mappings to continue with them.
    • getKeyStrokeForEvent

      public static KeyStroke getKeyStrokeForEvent(KeyEvent e)
      Returns:
      translation of KeyEvent (local system) to Vassal (to handle Mac platform support) The main idea here is that on Macs we want the common shortcut keys represented by e.g. Ctrl+C on Windows and Linux platforms to be represented by Command+C on the Mac, and likewise when module designers on Mac implement a Command+C shortcut we want that to appear as Ctrl+C for the same module running on other platforms. But we also support a "legacy" preference to allow Mac users used to Vassal 3.2.17 and prior mappings to continue with them.
    • isDragTrigger

      public static boolean isDragTrigger(DragGestureEvent e)
      Returns:
      whether the drag is non-mouse or effectively from the left button
    • convertKeyEvent

      public static KeyEvent convertKeyEvent(KeyEvent e)
      On Mac Systems, convert the Right-Option modifier (VK_ALT_GRAPH) to be the same as the Left-Option modifier (VK_ALT). This mirrors the equivalency of the left and right ALT keys under windows.
      Parameters:
      e - KeyEvent to be examined
      Returns:
      Updated KeyEvent
    • getScreenBounds

      public static Rectangle getScreenBounds(Component c)
      Returns:
      size of screen accounting for the screen insets (e.g., Windows taskbar)
    • getIndexInParent

      public static int getIndexInParent(Component child, Container parent)
    • getScreenSize

      public static Dimension getScreenSize()
      Return the current screen size, or a dummy screen size if operating in headless mode. In a perfect world, no gui code would ever run in headless mode, but some tests can force some parts of the gui to try and initialise which can cause the tests to fail when running on Travis Ci.
      Returns:
      Screen size
    • getScreenInsets

      public static Insets getScreenInsets(Component c)
      Return the current screen insets, or dummy screen insets if operating in headless mode. In a perfect world, no gui code would ever run in headless mode, but some tests can force some parts of the gui to try and initialise which can cause the tests to fail when running on Travis Ci.
      Returns:
      Screen size
    • ensureOnScreen

      public static void ensureOnScreen(Window window)
      Ensure the supplied Window is on the screen. 1. If either dimension is > available screen size, set the maximum size to the screen size 2. If the bottom of the window is off the screen, slide it up until it is on the screen. 3. If the right hand side of the window is off the screen, slide it left until it is on the screen.
      Parameters:
      window - Window to ensure on screen
    • repack

      public static void repack(Component c)
      Repack the dialog containing component c and ensure it is fully on the screen
      Parameters:
      c - Component contained in Dialog
    • repack

      public static void repack(Window w)
      Repack a dialog or frame and ensure it is fully on the screen Allow it get shorter vertically, but not narrower to keep any user dragged width changes or field width reformats.
      Parameters:
      w - Dialog or Frame
    • repack

      public static void repack(Window w, boolean mayBecomeNarrower)
    • setDefaultButtons

      public static void setDefaultButtons(JRootPane rp, JButton ok, JButton cancel)
      Set up the default Enter/ESC behavior for a dialog or frame
      Parameters:
      rp - Root pane of dialog or frame
      ok - OK button (triggers on ENTER)
      cancel - Cancel button (triggers on ESC)
    • allowUndo

      public static UndoManager allowUndo(JTextComponent field)
      Sets a text component to allow Undo
      Parameters:
      field - the text component