Package com.iizigo.term
Class TermUtil
java.lang.Object
com.iizigo.term.TermUtil
Utilities class.
- Author:
- Christopher Mindus
Field Summary
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic Font
deriveFont
(Graphics g, Font font, int cxFont, int cyFont) Derives a new font from another one by scaling it.static String[]
Get available fonts.static String[]
Get available monospaced fonts.static FontMetrics
getFontMetrics
(Component c, Font f) Gets the FontMetrics from the component in question or default toolkit if component is null.static FontMetrics
Gets the FontMetrics from the default toolkit.static Graphics2D
Gets a screen compatible Graphics2D instance that is preset for font (text) anti-aliasing and fractional metrics (instead of Integers).static Graphics2D
getGraphics
(JComponent component) Gets the graphics of a JComponent.static boolean
Checks if a font is available.static void
setTextAntiAlias
(Graphics g, boolean on) Sets or removes text anti-aliasing (only when using Java2D).
Field Details
INSETS_0
An easy way to donew Insets(0,0,0,0)
.
Constructor Details
TermUtil
public TermUtil()
Method Details
getAvailableFonts
Get available fonts.Workaround for JDK 1.7 Bug ID 7083197: Font returns BOLD version if i ask for PLAIN after getAllFonts() call.
- Returns:
- list of available font names or null if error.
hasFont
Checks if a font is available.- Parameters:
font
- The font name.- Returns:
- true if font exists, false otherwise.
getGraphics
Gets a screen compatible Graphics2D instance that is preset for font (text) anti-aliasing and fractional metrics (instead of Integers).- Returns:
- The Graphics2D instance: DO NOT FORGET TO CALL
dispose()
on it when you are done with it.
getGraphics
Gets the graphics of a JComponent. If the methodJComponent.getGraphics()
returnsnull
, the Graphics2D fromgetGraphics()
is returned.The Graphics2D instance is preset for font (text) anti-aliasing and fractional metrics (instead of Integers).
- Parameters:
component
- The JComponent.- Returns:
- The Graphics2D instance: DO NOT FORGET TO CALL
dispose()
on it when you are done with it.
getFontMetrics
Gets the FontMetrics from the default toolkit. This method is deprecated in the Toolkit implementation, so it may be removed. Use this method for safety.- Returns:
- The font metrics for the screen.
getFontMetrics
Gets the FontMetrics from the component in question or default toolkit if component is null. This method is deprecated in the Toolkit implementation, so it may be removed. Use this method for safety.- Parameters:
c
- The component, or null for none.f
- The font.- Returns:
- The font metrics for the component or the screen.
getAvailableMonospacedFonts
Get available monospaced fonts.- Returns:
- list of available font names or null if error.
deriveFont
Derives a new font from another one by scaling it.- Parameters:
g
- The Graphics2D object.font
- The font.cxFont
- The width of the font in pixels.cyFont
- The height of the font in pixels.- Returns:
- The new font with the specified size.
setTextAntiAlias
Sets or removes text anti-aliasing (only when using Java2D).- Parameters:
g
- The graphics.on
- The flag.