Class TermUtil

java.lang.Object
com.iizigo.term.TermUtil

public class TermUtil extends Object
Utilities class.
Author:
Christopher Mindus
  • Field Details

    • INSETS_0

      public static final Insets INSETS_0
      An easy way to do new Insets(0,0,0,0).
  • Constructor Details

    • TermUtil

      public TermUtil()
  • Method Details

    • getAvailableFonts

      public static String[] 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

      public static boolean hasFont(String font)
      Checks if a font is available.
      Parameters:
      font - The font name.
      Returns:
      true if font exists, false otherwise.
    • getGraphics

      public static Graphics2D 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

      public static Graphics2D getGraphics(JComponent component)
      Gets the graphics of a JComponent. If the method 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).

      Parameters:
      component - The JComponent.
      Returns:
      The Graphics2D instance: DO NOT FORGET TO CALL dispose() on it when you are done with it.
    • getFontMetrics

      public static FontMetrics getFontMetrics(Font f)
      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

      public static FontMetrics getFontMetrics(Component c, Font f)
      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

      public static String[] getAvailableMonospacedFonts()
      Get available monospaced fonts.
      Returns:
      list of available font names or null if error.
    • deriveFont

      public static Font deriveFont(Graphics g, Font font, int cxFont, int cyFont)
      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

      public static void setTextAntiAlias(Graphics g, boolean on)
      Sets or removes text anti-aliasing (only when using Java2D).
      Parameters:
      g - The graphics.
      on - The flag.