Class SwingUtils
java.lang.Object
VASSAL.tools.swing.SwingUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic UndoManager
allowUndo
(JTextComponent field) Sets a text component to allow Undostatic KeyEvent
On Mac Systems, convert the Right-Option modifier (VK_ALT_GRAPH) to be the same as the Left-Option modifier (VK_ALT).static AffineTransform
static void
ensureOnScreen
(Window window) Ensure the supplied Window is on the screen. 1.static KeyStroke
static int
getIndexInParent
(Component child, Container parent) static KeyStroke
static int
static Rectangle
static Insets
Return the current screen insets, or dummy screen insets if operating in headless mode.static Dimension
Return the current screen size, or a dummy screen size if operating in headless mode.static boolean
static boolean
Deprecated, for removal: This API element is subject to removal in a future version.static boolean
static boolean
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofisMainMouseButtonDown(MouseEvent)
static boolean
Supports swapping most Control and Command button functions on Mac so as not to punish long-time users for our "old non-standard implementations"static boolean
static boolean
static boolean
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofisContextMouseButtonDown(MouseEvent)
static boolean
static void
Repack the dialog containing component c and ensure it is fully on the screenstatic void
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.static void
static void
setDefaultButtons
(JRootPane rp, JButton ok, JButton cancel) Set up the default Enter/ESC behavior for a dialog or framestatic 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"static KeyStroke
-
Field Details
-
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
-
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.in favor ofisMainMouseButtonDown(MouseEvent)
- 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.in favor ofisContextMouseButtonDown(MouseEvent)
- Returns:
- whether the event is effectively for the right button.
-
isControlDown
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 byisSelectionToggle(MouseEvent)
.- Returns:
- whether the event effectively has Control down.
-
isContextMouseButtonDown
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- Returns:
- whether the drag is non-mouse or effectively from the left button
-
convertKeyEvent
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
-
getIndexInParent
-
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
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
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
Repack the dialog containing component c and ensure it is fully on the screen- Parameters:
c
- Component contained in Dialog
-
repack
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
-
setDefaultButtons
-
allowUndo
Sets a text component to allow Undo- Parameters:
field
- the text component
-
isSelectionToggle(MouseEvent)
.