public class Plaf extends Object
Modifier and Type | Field and Description |
---|---|
static int |
COMPONENT_PRINT |
static int |
DISCRETE_PRINT |
static String[] |
fonts
The available fonts (non-null once retrieved).
|
static int |
HOST_PRINT |
static boolean |
is64bit
The Java architecture is 64 bit.
|
static boolean |
isARM64
Flag for ARM64 or Aarch64 (Windows, Linux and macOS).
|
static boolean |
isJava_9
If Java is 9 or better.
|
static boolean |
isMac
The Mac OS variable indicator.
|
static boolean |
isUnix
The Unix OS variable indicator.
|
static boolean |
isWin10
The indicator for Windows 10
(Windows 10+, Windows Server 2012+ or better).
|
static boolean |
isWin11
The indicator for Windows "11"
(Windows 11+, Windows Server 2022+ or better).
|
static boolean |
isWin12
The indicator for Windows "12".
|
static boolean |
isWin7
The indicator for Windows 7, Windows Server 2008 R2 or better.
|
static boolean |
isWin8
The indicator for Windows 8, Windows Server 2012 or better.
|
static boolean |
isWindows
The Windows OS variable indicator.
|
static double |
java2D_UIScale
The Java2D scaling setting parsed from System property "sun.java2d.uiScale" = double,
e.g.
|
static String |
javaName
The Java VM name.
|
static String |
javaVendor
The Java Vendor name.
|
static int |
javaVer
The Java version "number" 8, 9, 10, 11, 12, 13, 14, ...
|
static String |
javaVersion
The Java version, 1.8[.nn], 9.nn , 10.nn ..., 17.nn, ...
|
static int |
LAF_GTK |
static int |
LAF_MAC |
static int |
LAF_METAL |
static int |
LAF_MOTIF |
static int |
LAF_NIMBUS |
static int |
LAF_WIN_STD
LAF variables.
|
static int |
LAF_WIN_XP |
static int |
LINE_ALTERNATE |
static int |
LINE_DASHDOT |
static int |
LINE_DASHDOUBLEDOT |
static int |
LINE_DOT |
static int |
LINE_DOUBLEDOT |
static int |
LINE_INVISIBLE |
static int |
LINE_LONGDASH |
static int |
LINE_SHORTDASH |
static int |
LINE_SOLID
The line types.
|
static int |
MAX_JAVA_VERSION
Current maximum supported Java version: 23.
|
static int |
MIN_JAVA_VERSION
Minimum supported Java version: 8.
|
static String[] |
monospacedFonts
The mono-spaced fonts, null when not yet set.
|
static String |
osName
The OS name.
|
static String |
osVersion
The OS version.
|
static Plaf |
plaf
The reference to the Plaf single instance.
|
static byte |
printVer3
Flag indicating native printing using NetPhantom NPCDDE.DLL as in version 3
is requested if possible, set zero for none, 1 for included in client JAR,
2 for loading in (Windows) path.
|
static int |
REPORT_PRINT
The print defined print types.
|
static int |
SCREEN_PRINT |
static Toolkit |
toolkit
The toolkit,
null if headless. |
static boolean |
usePrintDialog
Flag to use print dialog.
|
Modifier and Type | Method and Description |
---|---|
static Object |
addKeyListener(KeyListener listener)
Adds a key listener and returns it "on" state for the keys VK_CAPS_LOCK,
VK_NUM_LOCK and VK_SCROLL_LOCK.
|
static void |
assignScaling(double scale)
Assigns the effective scaling.
|
static int |
bgLine(Graphics g,
int x1,
int y1,
int x2,
int y2,
int type,
int phase)
Draws a "Business Graphics" line between two points with the current color
and the same behavior as for "Java lines".
|
static void |
bgMark(Graphics g,
int x,
int y,
int type,
Color fill)
Draws a marker at the specified point.
|
static void |
bgRect(Graphics g,
int x,
int y,
int cx,
int cy,
int lineType,
Color lineColor,
int pattern,
Color foreground,
Color background)
Draws a rectangle for Business Graphics with the specified line color and
type with a fore-/background color of a specified pattern.
|
static PKeyEvent |
copyKeyEvent(Component c,
KeyEvent e)
Copies one KeyEvent into another.
|
static Transferable |
createTransferable(String string,
Image image)
Creates a transferable used by clipboard and drag-drop.
|
static Font |
deriveFont(Graphics g,
Font font,
int cxFont,
int cyFont)
Derives a new font from another one by scaling it.
|
static void |
drawString(Graphics g,
String text,
int x,
int y)
Draws a string hopefully with the correct anti-aliasing using
SwingUtilities2.
|
static void |
drawString2(Graphics g,
String text,
int x,
int y)
Draws a string with SwingUtilities2 without performing any font
anti-aliasing actions.
|
static void |
drawStringUnderlineCharAt(Graphics g,
String text,
int underlinedIndex,
int x,
int y)
Draws a string hopefully with the correct anti-aliasing using
SwingUtilities2.
|
static void |
drawStringUnderlineCharAt2(Graphics g,
String text,
int underlinedIndex,
int x,
int y)
Draws a string hopefully with the correct anti-aliasing using
SwingUtilities2.
|
static Component |
findFocusOwner(Container c)
Finds the focus owner.
|
static String[] |
getAvailableFonts()
Get available fonts.
|
static String[] |
getAvailableMonospacedFonts()
Get available monospaced fonts.
|
static String |
getClipboardString()
Gets the text from the clipboard.
|
static Color |
getControlBGColor()
Gets the color for background of controls.
|
static Rectangle |
getDesktopBounds(Component c)
Gets the desktop width for a particular window.
|
static Rectangle |
getDesktopBounds(int x,
int y)
Gets the desktop rectangle for a point when multiple monitors are used,
also supports single monitors.
|
static double |
getEffectiveScaling()
Gets the effective scaling applied to the UI.
|
Component |
getFocusOwner()
Gets the current focus owner.
|
static FontMetrics |
getFontMetrics(Component c,
Font f)
Gets the FontMetrics from the component in question or default toolkit if
component is null.
|
static FontMetrics |
getFontMetrics(Font f)
Gets the FontMetrics from the default toolkit.
|
static Graphics2D |
getGraphics()
Gets a screen compatible Graphics2D instance that is preset for font (text)
anti-aliasing and fractional metrics (instead of Integers).
|
static Graphics2D |
getGraphics(Graphics g)
Gets the graphics of a JComponent.
|
static Graphics2D |
getGraphics(JComponent component)
Gets the graphics of a JComponent.
|
static long |
getHWND(Component c)
Gets the HWND associated with the component.
|
static String |
getKeyModifiersText(int modifiers)
Gets the modifiers String (such as Alt+Ctrl+Shift+) [note the extra '+' sign],
or the special Command button for Mac.
|
static KeyStroke |
getKeyStroke(int keyCode,
int modifiers)
Gets a KeyStroke depending on platform.
|
static int |
getLAF()
Get the look-and-feel.
|
static boolean |
getLockingKeyState(int keyCode)
Returns whether the given locking key on the keyboard is currently in its
"on" state.
|
static Rectangle |
getNormalBounds(JInternalFrame f)
Gets the un-maximized window bounds.
|
static String |
getPrintFontName(String name)
Gets an alternate font name for printing (tries to use e.g.
|
static PrintJob |
getPrintJob(Frame frame,
String title,
int type,
boolean useDefault)
Gets the print job.
|
static PrintJob |
getPrintJob(Frame frame,
String title,
int type,
boolean useDefault,
int landscape)
Gets the print job.
|
static Rectangle |
getScreenRect()
Gets the screen size as a rectangle.
|
static double |
getSystemScaling()
Returns the system scaling in effect.
|
static Window |
getWindowForComponent(Component c)
Finds the Window for a component.
|
static boolean |
hasFont(String font)
Checks if a font is available.
|
static UITweaks |
initializeLAF(LookAndFeel laf,
double scale)
Initializes LAF.
|
void |
invokeAction(AbstractButton action,
boolean doInvoke)
Invokes a button action (check box, radio button, push button or a menu
item).
|
static boolean |
isContextMenu(KeyEvent e)
Checks if a key event is a pop-up window (context) menu display action,
i.e.
|
static boolean |
isContextMenu(MouseEvent e)
Checks if a mouse event is the context menu trigger.
|
static boolean |
isGTKLF()
Checks if it's GTK L&F.
|
static boolean |
isJavaScalingEnabled()
Returns whether the System Java scaling is in effect or not.
|
static boolean |
isMacLF()
Checks if it's a Mac look-and-feel (running on Mac).
|
static boolean |
isMaximized(Frame f)
Checks if a frame is maximized.
|
static boolean |
isMetalLF()
Checks if it's Metal L&F.
|
static boolean |
isMotifLF()
Checks if it's Motif L&F.
|
static boolean |
isNimbusLF()
Checks if it's a Nimbus look-and-feel.
|
static boolean |
isRightCtrl(KeyEvent e)
Checks if the rightmost control key in an event (typically VK_CONTROL).
|
static boolean |
isWindows()
Checks if it's the Windows operating systems.
|
static boolean |
isWindowsLF()
Checks if it's Windows L&F (standard or XP).
|
static boolean |
isWindowsXPLF()
Checks if it's Windows L&F using XP style.
|
static void |
maximize(Frame f)
Maximizes a frame.
|
static String |
onAWTInit()
Returns information about the system.
|
static void |
printWindow(LogEvent logger,
Component componentToPrint,
boolean useDefault)
Prints a top-level window (Frame or Dialog) or an internal frame.
|
static void |
removeKeyListener(Object listener)
Removes a key listener and returns it "on" state for the keys VK_CAPS_LOCK,
VK_NUM_LOCK and VK_SCROLL_LOCK.
|
static void |
restorePrintFocus(Component afterPrinting)
Restores focus after a Java2D printing.
|
static boolean |
setAntiAlias(Graphics g,
boolean on)
Sets or removes anti-aliasing (only when using Java2D).
|
static boolean |
setClipboard(Image image)
Sets the clipboard with an Image.
|
static boolean |
setClipboard(String string)
Sets the clipboard with a String.
|
static boolean |
setClipboard(String string,
Image image)
Sets the clipboard with a String and an Image.
|
static void |
setControlBGColor(Component c)
Sets the color for background of controls for a component.
|
static void |
setFocus(JComponent jc)
Sets focus to a component.
|
static void |
setIconImage(Container c,
ImageIcon icon)
Sets the ImageIcon for a JFrame (or Frame), JDialog (or Dialog) or
JInternalFrame.
|
static void |
setIconImages(Container c,
ArrayList<ImageIcon> icons)
Sets the ImageIcon(s) for a JFrame (or Frame), JDialog (or Dialog) or
JInternalFrame.
|
static void |
setIconImages(Container c,
ImageIcon... icons)
Sets the ImageIcon(s) for a JFrame (or Frame), JDialog (or Dialog) or
JInternalFrame.
|
static void |
setIconImages(Container c,
List<Image> images)
Sets the icon images to a JInternalFrame or Window.
|
static void |
setLockingKeyState(int keyCode,
boolean on)
Sets the state of the given locking key on the keyboard, JDK 1.3 or better.
|
void |
setMnemonic(AbstractButton b,
char ch,
int index)
Sets the mnemonic for an abstract button.
|
static boolean |
setTextAntiAlias(Graphics g,
boolean on)
Sets or removes text anti-aliasing (only when using Java2D), in combination
with fractional metrics to improve scaled or derived fonts.
|
static boolean |
showDocument(URL url)
Shows a document using the current browser (if it's an applet), or tries to
launch Microsoft "explorer.exe" (under Windows) with the external form of
the
url . |
static void |
togglePrintDialog()
Toggles the usePrintDialog flag.
|
static void |
updateLAF(LookAndFeel lookAndFeel)
Updates the look and feel flags.
|
static boolean |
usePrintDialog()
Gets the usePrintDialog flag.
|
public static byte printVer3
public static final int REPORT_PRINT
public static final int HOST_PRINT
public static final int COMPONENT_PRINT
public static final int DISCRETE_PRINT
public static final int SCREEN_PRINT
public static final int LINE_SOLID
public static final int LINE_ALTERNATE
public static final int LINE_DOT
public static final int LINE_SHORTDASH
public static final int LINE_DASHDOT
public static final int LINE_DOUBLEDOT
public static final int LINE_LONGDASH
public static final int LINE_DASHDOUBLEDOT
public static final int LINE_INVISIBLE
public static final Plaf plaf
public static boolean usePrintDialog
public static final int MIN_JAVA_VERSION
public static final int MAX_JAVA_VERSION
public static final String javaName
public static final String javaVendor
public static final String javaVersion
public static final boolean isJava_9
public static final int javaVer
public static final boolean is64bit
public static final String osName
public static final String osVersion
public static final boolean isWindows
public static final boolean isMac
public static final boolean isWin7
public static final boolean isWin8
public static final boolean isWin10
public static final boolean isWin11
public static final boolean isWin12
public static final boolean isUnix
public static final boolean isARM64
public static final int LAF_WIN_STD
public static final int LAF_WIN_XP
public static final int LAF_METAL
public static final int LAF_MOTIF
public static final int LAF_GTK
public static final int LAF_NIMBUS
public static final int LAF_MAC
public static final double java2D_UIScale
-Dsun.java2d.uiScale=1.5
[CASE SENSITIVE "sun.java2d.uiScale"]
for scaling of 1.5 or 150%. If zero
or 0.0d
this setting is not found.public static String[] fonts
public static String[] monospacedFonts
public static final Toolkit toolkit
null
if headless.public static boolean isJavaScalingEnabled()
For Java 8, it is always false. For Java 9, it is set to
false
upon loading of this class and the system property
sun.java2d.uiScale.enabled
is false
, e.g. from
Java command line -Dsun.java2d.uiScale.enabled=false
.
public static double getSystemScaling()
#enableJavaScaling(boolean)
, the value
returned will always be 1.0.public static void assignScaling(double scale)
scale
- The scale value should be between 0.5 and 8.0.public static double getEffectiveScaling()
public static KeyStroke getKeyStroke(int keyCode, int modifiers)
public static String getKeyModifiersText(int modifiers)
public static void togglePrintDialog()
public static boolean usePrintDialog()
public static PrintJob getPrintJob(Frame frame, String title, int type, boolean useDefault)
public static PrintJob getPrintJob(Frame frame, String title, int type, boolean useDefault, int landscape)
public static Color getControlBGColor()
public static void setControlBGColor(Component c)
public static Rectangle getScreenRect()
public static Rectangle getDesktopBounds(int x, int y)
public static Rectangle getDesktopBounds(Component c)
public static boolean isWindows()
public static void updateLAF(LookAndFeel lookAndFeel)
lookAndFeel
- The look-and-feel.public static String onAWTInit()
public static UITweaks initializeLAF(LookAndFeel laf, double scale)
laf
- The look-and-feel.scale
- The scaling factor, "1.0" for no scaling.null
it's the same look-and-feel with same scaling.public static boolean isWindowsLF()
public static boolean isWindowsXPLF()
public static boolean isMetalLF()
public static boolean isGTKLF()
public static boolean isMotifLF()
public static boolean isNimbusLF()
public static boolean isMacLF()
public static int getLAF()
public static String[] getAvailableFonts()
public static boolean hasFont(String font)
font
- The font name.public static String[] getAvailableMonospacedFonts()
public static FontMetrics getFontMetrics(Font f)
public static FontMetrics getFontMetrics(Component c, Font f)
c
- The component, or null for none.f
- The font.public static void printWindow(LogEvent logger, Component componentToPrint, boolean useDefault)
public static void setFocus(JComponent jc)
public static Window getWindowForComponent(Component c)
public Component getFocusOwner()
public static boolean showDocument(URL url)
url
.
"Desktop.getDesktop().browse(uri)" is first tried, and if it worked, no further processing is done.
url
- The URL, mailto:... or http[s]:..., file:.., etc.public void invokeAction(AbstractButton action, boolean doInvoke)
doInvoke
flag is true.public void setMnemonic(AbstractButton b, char ch, int index)
public static void drawString(Graphics g, String text, int x, int y)
Hopefully will be working fine with anti-aliasing if
Graphics g
parameter is Graphics2D
, otherwise no
anti-aliasing action will be taken.
g
- Graphics to draw with.text
- String to draw.x
- x coordinate to draw at.y
- y coordinate to draw at.public static void drawString2(Graphics g, String text, int x, int y)
g
- Graphics to draw with.text
- String to draw.x
- x coordinate to draw at.y
- y coordinate to draw at.public static void drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
Hopefully will be working fine with anti-aliasing if
Graphics g
parameter is Graphics2D
, otherwise no
anti-aliasing action will be taken.
g
- Graphics to draw with.text
- String to draw.underlinedIndex
- Index of character in text to underline.x
- x coordinate to draw at.y
- y coordinate to draw at.public static void drawStringUnderlineCharAt2(Graphics g, String text, int underlinedIndex, int x, int y)
Hopefully will be working fine with anti-aliasing if
Graphics g
parameter is Graphics2D
, otherwise no
anti-aliasing action will be taken.
g
- Graphics to draw with.text
- String to draw.underlinedIndex
- Index of character in text to underline.x
- x coordinate to draw at.y
- y coordinate to draw at.public static Graphics2D getGraphics()
dispose()
on it when you are done with it.public static Graphics2D getGraphics(JComponent component)
JComponent.getGraphics()
returns null
, the
Graphics2D from getGraphics()
is returned.
The Graphics2D instance is preset for font (text) anti-aliasing and fractional metrics (instead of Integers).
component
- The JComponent.dispose()
on it when you are done with it.public static Graphics2D getGraphics(Graphics g)
JComponent.getGraphics()
returns null
, the
Graphics2D from getGraphics()
is returned.
The Graphics2D instance is preset for font (text) anti-aliasing and fractional metrics (instead of Integers).
component
- The JComponent.g
- The Graphics.null
if g
is not
an instance of Graphics2D. All JComponent instances have
a Graphics2D instance.public static boolean getLockingKeyState(int keyCode)
public static void setLockingKeyState(int keyCode, boolean on)
public static PKeyEvent copyKeyEvent(Component c, KeyEvent e)
public static Object addKeyListener(KeyListener listener)
public static void removeKeyListener(Object listener)
listener
- The instance of an AWTEventListener, returned by the
addKeyListener
method.public static void maximize(Frame f)
public static boolean isMaximized(Frame f)
public static Rectangle getNormalBounds(JInternalFrame f)
public static boolean isRightCtrl(KeyEvent e)
public static String getPrintFontName(String name)
public static void restorePrintFocus(Component afterPrinting)
public static Font deriveFont(Graphics g, Font font, int cxFont, int cyFont)
public static boolean setAntiAlias(Graphics g, boolean on)
public static boolean setTextAntiAlias(Graphics g, boolean on)
public static int bgLine(Graphics g, int x1, int y1, int x2, int y2, int type, int phase)
When not using Java 2, the line will be dotted if horizontal or vertical if the line type is not solid (=). The width will be 1.
If the line is invisible, it won't be drawn!
Valid line types are:
SOLID = 0 ALTERNATE = 1 DOT = 2 SHORTDASH = 3 DASHDOT = 4 DOUBLEDOT = 5 LONGDASH = 6 DASHDOUBLEDOT = 7 INVISIBLE = 8
public static void bgMark(Graphics g, int x, int y, int type, Color fill)
The marker types are:
0 = CROSS 1 = PLUS 2 = DIAMOND 3 = SQUARE 4 = SIXPOINTSTAR 5 = EIGHTPOINTSTAR 6 = SOLIDDIAMOND 7 = SOLIDSQUARE 8 = SMALLCIRCLE 9 = DOT 10 = BLANKThe only marker that can be filled in the SQUARE.
public static void bgRect(Graphics g, int x, int y, int cx, int cy, int lineType, Color lineColor, int pattern, Color foreground, Color background)
The patterns are:
0 = SOLID 1 = DENSE1 2 = DENSE2 3 = DENSE3 4 = DENSE4 5 = DENSE5 6 = DENSE6 7 = DENSE7 8 = DENSE8 9 = VERT 10 = HORIZ 11 = DIAG1 12 = DIAG2 13 = DIAG3 14 = DIAG4 15 = NOSHADE (no pattern, only foreground) 16 = HALFTONE 17 = CROSS1 18 = CROSS2 19 = CROSS3The color in the Graphics can be set to any of the color parameters in this function, so don't assume
public static boolean isContextMenu(KeyEvent e)
public static boolean isContextMenu(MouseEvent e)
public static void setIconImage(Container c, ImageIcon icon)
Multiple images are supported for [J]Frame and [J]Dialog.
If the c
parameter is a JInternalFrame, the
setFrameIcon
method is used. Otherwise, the
setIconImages
will be attempted.
public static void setIconImages(Container c, ArrayList<ImageIcon> icons)
If the c
parameter is a JInternalFrame, the
setFrameIcon
method is used. Otherwise, the
setIconImages
will be attempted.
public static void setIconImages(Container c, ImageIcon... icons)
If the c
parameter is a JInternalFrame, the
setFrameIcon
method is used. Otherwise, the
setIconImages
will be attempted.
c
- The container (Window/Frame/Dialog/JFrame/JDialog or JInternalFrame).icons
- The icons to set.public static void setIconImages(Container c, List<Image> images)
c
- The container (Window/Frame/Dialog/JFrame/JDialog or JInternalFrame).images
- The images list.public static String getClipboardString()
public static boolean setClipboard(String string)
public static boolean setClipboard(Image image)
public static boolean setClipboard(String string, Image image)
public static Transferable createTransferable(String string, Image image)
public static long getHWND(Component c)
This call only works in Java 8 to 15 and returns zero for Java 16 or better.
c
- The component.0L
when not available.Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© © Mindus SARL, 2024. All rights reserved.