Package jexer.backend

Class SwingComponent


  • public class SwingComponent
    extends java.lang.Object
    Wrapper for integrating with Swing, because JFrame and JComponent have separate hierarchies.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean tripleBuffer
      If true, use triple buffering when drawing to a JFrame.
    • Constructor Summary

      Constructors 
      Constructor Description
      SwingComponent​(javax.swing.JComponent component)
      Construct using a JComponent.
      SwingComponent​(javax.swing.JFrame frame)
      Construct using a JFrame.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addComponentListener​(java.awt.event.ComponentListener l)
      Adds the specified component listener to receive component events from this component.
      void addKeyListener​(java.awt.event.KeyListener l)
      Adds the specified key listener to receive key events from this component.
      void addMouseListener​(java.awt.event.MouseListener l)
      Adds the specified mouse listener to receive mouse events from this component.
      void addMouseMotionListener​(java.awt.event.MouseMotionListener l)
      Adds the specified mouse motion listener to receive mouse motion events from this component.
      void addMouseWheelListener​(java.awt.event.MouseWheelListener l)
      Adds the specified mouse wheel listener to receive mouse wheel events from this component.
      void addWindowListener​(java.awt.event.WindowListener l)
      Adds the specified window listener to receive window events from this window.
      void dispose()
      Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children.
      java.awt.image.BufferStrategy getBufferStrategy()
      Get the BufferStrategy object needed for triple-buffering.
      javax.swing.JComponent getComponent()
      Get the JComponent reference.
      java.awt.Font getFont()
      Gets the font of this component.
      javax.swing.JFrame getFrame()
      Get the JFrame reference.
      java.awt.Graphics getGraphics()
      Creates a graphics context for this component.
      int getHeight()
      Returns the current height of this component.
      java.awt.Insets getInsets()
      If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
      int getWidth()
      Returns the current width of this component.
      void paint​(java.awt.Graphics g)
      Paints this component.
      void repaint()
      Repaints this component.
      void repaint​(int x, int y, int width, int height)
      Repaints the specified rectangle of this component.
      void requestFocusInWindow()
      Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window.
      void setDimensions​(int width, int height)
      Resize the component to match the font dimensions.
      void setFont​(java.awt.Font f)
      Sets the font of this component.
      void setMouseStyle​(java.lang.String style)
      Set the mouse cursor style.
      void setTitle​(java.lang.String title)
      Set the window title.
      void setupComponent()
      Setup to render to an existing JComponent.
      void setupFrame()
      Setup to render to an existing JFrame.
      void setVisible​(boolean b)
      Shows or hides this Window depending on the value of parameter b.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • tripleBuffer

        public static boolean tripleBuffer
        If true, use triple buffering when drawing to a JFrame.
    • Constructor Detail

      • SwingComponent

        public SwingComponent​(javax.swing.JFrame frame)
        Construct using a JFrame.
        Parameters:
        frame - the JFrame to draw to
      • SwingComponent

        public SwingComponent​(javax.swing.JComponent component)
        Construct using a JComponent.
        Parameters:
        component - the JComponent to draw to
    • Method Detail

      • getBufferStrategy

        public java.awt.image.BufferStrategy getBufferStrategy()
        Get the BufferStrategy object needed for triple-buffering.
        Returns:
        the BufferStrategy
        Throws:
        java.lang.IllegalArgumentException - if this function is called when not rendering to a JFrame
      • getFrame

        public javax.swing.JFrame getFrame()
        Get the JFrame reference.
        Returns:
        the frame, or null if this is drawing to a JComponent
      • getComponent

        public javax.swing.JComponent getComponent()
        Get the JComponent reference.
        Returns:
        the component, or null if this is drawing to a JFrame
      • setupComponent

        public void setupComponent()
        Setup to render to an existing JComponent.
      • setupFrame

        public void setupFrame()
        Setup to render to an existing JFrame.
      • setMouseStyle

        public void setMouseStyle​(java.lang.String style)
        Set the mouse cursor style.
        Parameters:
        style - the cursor style string, one of: "default", "none", "hand", "text", "move", or "crosshair"
      • setTitle

        public void setTitle​(java.lang.String title)
        Set the window title.
        Parameters:
        title - the new title
      • paint

        public void paint​(java.awt.Graphics g)
        Paints this component.
        Parameters:
        g - the graphics context to use for painting
      • repaint

        public void repaint()
        Repaints this component.
      • repaint

        public void repaint​(int x,
                            int y,
                            int width,
                            int height)
        Repaints the specified rectangle of this component.
        Parameters:
        x - the x coordinate
        y - the y coordinate
        width - the width
        height - the height
      • getInsets

        public java.awt.Insets getInsets()
        If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
        Returns:
        the value of the insets property
      • getWidth

        public int getWidth()
        Returns the current width of this component.
        Returns:
        the current width of this component
      • getHeight

        public int getHeight()
        Returns the current height of this component.
        Returns:
        the current height of this component
      • getFont

        public java.awt.Font getFont()
        Gets the font of this component.
        Returns:
        this component's font; if a font has not been set for this component, the font of its parent is returned
      • setFont

        public void setFont​(java.awt.Font f)
        Sets the font of this component.
        Parameters:
        f - the font to become this component's font; if this parameter is null then this component will inherit the font of its parent
      • setVisible

        public void setVisible​(boolean b)
        Shows or hides this Window depending on the value of parameter b.
        Parameters:
        b - if true, make visible, else make invisible
      • getGraphics

        public java.awt.Graphics getGraphics()
        Creates a graphics context for this component. This method will return null if this component is currently not displayable.
        Returns:
        a graphics context for this component, or null if it has none
      • dispose

        public void dispose()
        Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable.
      • setDimensions

        public void setDimensions​(int width,
                                  int height)
        Resize the component to match the font dimensions.
        Parameters:
        width - the new width in pixels
        height - the new height in pixels
      • addComponentListener

        public void addComponentListener​(java.awt.event.ComponentListener l)
        Adds the specified component listener to receive component events from this component. If listener l is null, no exception is thrown and no action is performed.
        Parameters:
        l - the component listener
      • addKeyListener

        public void addKeyListener​(java.awt.event.KeyListener l)
        Adds the specified key listener to receive key events from this component. If l is null, no exception is thrown and no action is performed.
        Parameters:
        l - the key listener.
      • addMouseListener

        public void addMouseListener​(java.awt.event.MouseListener l)
        Adds the specified mouse listener to receive mouse events from this component. If listener l is null, no exception is thrown and no action is performed.
        Parameters:
        l - the mouse listener
      • addMouseMotionListener

        public void addMouseMotionListener​(java.awt.event.MouseMotionListener l)
        Adds the specified mouse motion listener to receive mouse motion events from this component. If listener l is null, no exception is thrown and no action is performed.
        Parameters:
        l - the mouse motion listener
      • addMouseWheelListener

        public void addMouseWheelListener​(java.awt.event.MouseWheelListener l)
        Adds the specified mouse wheel listener to receive mouse wheel events from this component. Containers also receive mouse wheel events from sub-components.
        Parameters:
        l - the mouse wheel listener
      • addWindowListener

        public void addWindowListener​(java.awt.event.WindowListener l)
        Adds the specified window listener to receive window events from this window. If l is null, no exception is thrown and no action is performed.
        Parameters:
        l - the window listener
      • requestFocusInWindow

        public void requestFocusInWindow()
        Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window.