Class JMathComponent

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.SwingConstants

    public final class JMathComponent
    extends javax.swing.JComponent
    implements javax.swing.SwingConstants
    Displays MathML content in a Swing Component.

    There are two properties which expose the actual content, accessible though getDocument() / setDocument(org.w3c.dom.Node) for content already available as a DOM model, and getContent() and setContent(String) for content available as a String.

    This class exposes most of the rendering parameters as standard bean attributes. If you need to set additional attributes, you may use the setParameter(Parameter, Object) function.

    Please use only the attributes exposed through the attached JMathComponentBeanInfo class. Additional attributes, such as Component.getFont() and setFont(Font) are provided for Swing compatibility, but they may not work exactly as expected.

    Version:
    $Revision: 5a7becda9147 $
    See Also:
    MathComponent, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
      • Fields inherited from interface javax.swing.SwingConstants

        BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
    • Constructor Summary

      Constructors 
      Constructor Description
      JMathComponent()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.String getContent()
      Tries to return the content as a String.
      org.w3c.dom.Node getDocument()  
      java.lang.String getFontsDoublestruck()
      Font list for Doublestruck.
      java.lang.String getFontsFraktur()
      Font list for Fraktur.
      float getFontSize()  
      java.lang.String getFontsMonospaced()
      Font list for Monospaced.
      java.lang.String getFontsSanserif()
      Font list for Sans-Serif.
      java.lang.String getFontsScript()
      Font list for Script.
      java.lang.String getFontsSerif()
      Font list for Serif (the default MathML font).
      java.awt.Color getForeground()
      int getHorizontalAlignment()
      Horizontal alignment, as defined by JLabel.getHorizontalAlignment().
      MutableLayoutContext getParameters()  
      java.awt.Dimension getPreferredSize()
      Gets the preferred size of this component.
      MathComponentUI getUI()  
      java.lang.String getUIClassID()  
      int getVerticalAlignment()
      Vertical alignment, as defined by JLabel.getVerticalAlignment().
      void setBackground​(java.awt.Color c)
      void setContent​(java.lang.String contentString)
      Set the content from a String containing the MathML content.
      void setDebug​(boolean dbg)
      Enables, or disables the debug mode.
      void setDocument​(org.w3c.dom.Node doc)  
      void setFont​(java.awt.Font f)
      Deprecated.
      use separate setters.
      void setFontsDoublestruck​(java.lang.String newFonts)
      Font list for Doublestruck.
      void setFontsFraktur​(java.lang.String newFonts)
      Font list for Fraktur.
      void setFontSize​(float fontSize)
      sets the font size used.
      void setFontsMonospaced​(java.lang.String newFonts)
      Font list for Monospaced.
      void setFontsSanserif​(java.lang.String newFonts)
      Font list for Sans-Serif.
      void setFontsScript​(java.lang.String newFonts)
      Font list for Script.
      void setFontsSerif​(java.lang.String newFonts)
      Font list for Serif (the default MathML font).
      void setForeground​(java.awt.Color fg)
      void setHorizontalAlignment​(int hAlignment)
      Horizontal alignment, as defined by JLabel.setHorizontalAlignment(int).
      void setOpaque​(boolean opaque)
      void setParameter​(Parameter key, java.lang.Object newValue)
      Sets a generic rendering parameter.
      void setParameters​(java.util.Map<Parameter,​java.lang.Object> newValues)
      Sets generic rendering parameters.
      void setSize​(int width, int height)
      void setVerticalAlignment​(int vAlignment)
      Vertical alignment, as defined by JLabel.setVerticalAlignment(int).
      void updateUI()
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JMathComponent

        public JMathComponent()
        Default constructor.
    • Method Detail

      • getContent

        public java.lang.String getContent()
        Tries to return the content as a String.

        This transforms the internal DOM tree back into a string, which may is not guaranteed to be the literally same as the original content. However, it will represent the same XML document.

        Returns:
        the content string.
      • getDocument

        public org.w3c.dom.Node getDocument()
        Returns:
        the document
      • getFontsDoublestruck

        public java.lang.String getFontsDoublestruck()
        Font list for Doublestruck. Please see Parameter#FontsDoublestruck for an explanation of this parameter.
        Returns:
        The list for Doublestruck.
        See Also:
        Parameter#FontsDoublestruck
      • getFontsFraktur

        public java.lang.String getFontsFraktur()
        Font list for Fraktur. Please see Parameter#FontsFraktur for an explanation of this parameter.
        Returns:
        The list for Fraktur.
        See Also:
        Parameter#FontsFraktur
      • getFontSize

        public float getFontSize()
        Returns:
        the fontSize
      • getFontsMonospaced

        public java.lang.String getFontsMonospaced()
        Font list for Monospaced. Please see Parameter#FontsMonospaced for an explanation of this parameter.
        Returns:
        The list for monospaced.
        See Also:
        Parameter#FontsMonospaced
      • getFontsSanserif

        public java.lang.String getFontsSanserif()
        Font list for Sans-Serif. Please see Parameter#FontsSanserif for an explanation of this parameter.
        Returns:
        The list for sansserif.
        See Also:
        Parameter#FontsSanserif
      • getFontsScript

        public java.lang.String getFontsScript()
        Font list for Script. Please see Parameter#FontsScript for an explanation of this parameter.
        Returns:
        The list for Script.
        See Also:
        Parameter#FontsScript
      • getFontsSerif

        public java.lang.String getFontsSerif()
        Font list for Serif (the default MathML font). Please see Parameter#FontsSerif for an explanation of this parameter.
        Returns:
        The list for serif.
        See Also:
        Parameter#FontsSerif
      • getForeground

        public java.awt.Color getForeground()
        Overrides:
        getForeground in class java.awt.Component
      • getHorizontalAlignment

        public int getHorizontalAlignment()
        Horizontal alignment, as defined by JLabel.getHorizontalAlignment().

        Supported are: SwingConstants.LEADING, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.TRAILING, SwingConstants.RIGHT.

        Returns:
        the horizontalAlignment
        See Also:
        JLabel.getHorizontalAlignment()
      • getPreferredSize

        public java.awt.Dimension getPreferredSize()
        Gets the preferred size of this component.
        Overrides:
        getPreferredSize in class javax.swing.JComponent
        Returns:
        A dimension object indicating this component's preferred size.
      • getUI

        public MathComponentUI getUI()
        Overrides:
        getUI in class javax.swing.JComponent
        Returns:
        the UI implementation.
      • getUIClassID

        public java.lang.String getUIClassID()
        Overrides:
        getUIClassID in class javax.swing.JComponent
        Returns:
        The default UI class
      • getVerticalAlignment

        public int getVerticalAlignment()
        Vertical alignment, as defined by JLabel.getVerticalAlignment().

        Supported are: SwingConstants.TOP, SwingConstants.CENTER, SwingConstants.BOTTOM.

        Returns:
        the verticalAlignment
        See Also:
        JLabel.getVerticalAlignment()
      • setBackground

        public void setBackground​(java.awt.Color c)
        Overrides:
        setBackground in class javax.swing.JComponent
      • setContent

        public void setContent​(java.lang.String contentString)
        Set the content from a String containing the MathML content.
        Parameters:
        contentString - the content to set.
      • setDebug

        public void setDebug​(boolean dbg)
        Enables, or disables the debug mode.
        Parameters:
        dbg - Debug mode.
      • setDocument

        public void setDocument​(org.w3c.dom.Node doc)
        Parameters:
        doc - the document to set
      • setFont

        @Deprecated
        public void setFont​(java.awt.Font f)
        Deprecated.
        use separate setters.
        Font emulator for standard component behavior.

        Emulates the standard setFont function by setting the font Size and adding the font to the front of the serif font list.

        Please use the separate setters if possible.

        Overrides:
        setFont in class javax.swing.JComponent
        Parameters:
        f - font to set.
        See Also:
        setFontSize(float), setFontsSerif(String)
      • setFontsDoublestruck

        public void setFontsDoublestruck​(java.lang.String newFonts)
        Font list for Doublestruck. Please see Parameter.FONTS_DOUBLESTRUCK for an explanation of this parameter.
        Parameters:
        newFonts - new list for Doublestruck (comma seraparated).
        See Also:
        Parameter.FONTS_DOUBLESTRUCK
      • setFontsFraktur

        public void setFontsFraktur​(java.lang.String newFonts)
        Font list for Fraktur. Please see Parameter.FONTS_FRAKTUR for an explanation of this parameter.
        Parameters:
        newFonts - new list for Fraktur (comma seraparated).
        See Also:
        Parameter.FONTS_FRAKTUR
      • setParameter

        public void setParameter​(Parameter key,
                                 java.lang.Object newValue)
        Sets a generic rendering parameter.
        Parameters:
        key - Key for the parameter
        newValue - newValue
      • setParameters

        public void setParameters​(java.util.Map<Parameter,​java.lang.Object> newValues)
        Sets generic rendering parameters.
        Parameters:
        newValues - map of parameter keys to new values
      • setFontSize

        public void setFontSize​(float fontSize)
        sets the font size used.
        Parameters:
        fontSize - the font size.
      • setFontsMonospaced

        public void setFontsMonospaced​(java.lang.String newFonts)
        Font list for Monospaced. Please see Parameter.FONTS_MONOSPACED for an explanation of this parameter.
        Parameters:
        newFonts - new list for Monospaced (comma seraparated).
        See Also:
        Parameter.FONTS_MONOSPACED
      • setFontsSanserif

        public void setFontsSanserif​(java.lang.String newFonts)
        Font list for Sans-Serif. Please see Parameter.FONTS_SANSSERIF for an explanation of this parameter.
        Parameters:
        newFonts - new list for sansserif (comma seraparated).
        See Also:
        Parameter.FONTS_SANSSERIF
      • setFontsScript

        public void setFontsScript​(java.lang.String newFonts)
        Font list for Script. Please see Parameter.FONTS_SCRIPT for an explanation of this parameter.
        Parameters:
        newFonts - new list for Script (comma seraparated).
        See Also:
        Parameter.FONTS_SCRIPT
      • setFontsSerif

        public void setFontsSerif​(java.lang.String newFonts)
        Font list for Serif (the default MathML font). Please see Parameter.FONTS_SERIF for an explanation of this parameter.
        Parameters:
        newFonts - new list for serif (comma seraparated).
        See Also:
        Parameter.FONTS_SERIF
      • setForeground

        public void setForeground​(java.awt.Color fg)
        Overrides:
        setForeground in class javax.swing.JComponent
      • setHorizontalAlignment

        public void setHorizontalAlignment​(int hAlignment)
        Horizontal alignment, as defined by JLabel.setHorizontalAlignment(int).

        Supported are: SwingConstants.LEADING, SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.TRAILING, SwingConstants.RIGHT.

        Parameters:
        hAlignment - the horizontalAlignment to set
        See Also:
        JLabel.setHorizontalAlignment(int)
      • setOpaque

        public void setOpaque​(boolean opaque)
        Overrides:
        setOpaque in class javax.swing.JComponent
      • setVerticalAlignment

        public void setVerticalAlignment​(int vAlignment)
        Vertical alignment, as defined by JLabel.setVerticalAlignment(int).

        Supported are: SwingConstants.TOP, SwingConstants.CENTER, SwingConstants.BOTTOM.

        Parameters:
        vAlignment - the verticalAlignment to set
        See Also:
        JLabel.setVerticalAlignment(int)
      • updateUI

        public void updateUI()
        Overrides:
        updateUI in class javax.swing.JComponent
      • setSize

        public void setSize​(int width,
                            int height)
        Overrides:
        setSize in class java.awt.Component