public class HTMLComponent
ImplementsActionListener, Animation, Editable, IOCallback, Iterable<Component>, StyleListener
Constructors
public HTMLComponent() | Constructs HTMLComponent |
public HTMLComponent(DocumentRequestHandler handler) | Constructs HTMLComponent |
Methods
public static void addFont(String fontKey, Font font) | Sets the given Codename One font for use with HTMLComponents. |
public static void addSpecialKey(String specialKeyName, int specialKeyCode) | Adds support for a special key to be used as an accesskey. |
public static void setMaxThreads(int threadsNum) | Sets the maximum number of threads to use for image download |
public static void setCSSSupportedMediaTypes(String[] supportedMediaTypes) | Sets the supported CSS media types to the given strings. |
public void setParser(HTMLParser parser) | Sets a custom HTMLParser for this HTMLComponent By default, a new HTMLParser instance is created for each HTMLComponent, use this method if you have a custom parser. |
public void addCharEntity(String symbol, int code) | Adds the given symbol and code to the user defined char entities table. |
public void addCharEntitiesRange(String[] symbols, int startcode) | Adds the given symbols array to the user defined char entities table with the startcode provided as the code of the first string, startcode+1 for the second etc. Some strings in the symbols array may be null thus skipping code numbers. |
public DocumentRequestHandler getRequestHandler() | Returns the document request handler |
public void setRequestHandler(DocumentRequestHandler handler) | Changes the document request handler |
public DocumentInfo getDocumentInfo() | Returns the DocumentInfo that currently represents the document loaded/shown |
public HTMLCallback getHTMLCallback() | Returns the HTMLCallback that is set on this HTMLComponent |
public void setHTMLCallback(HTMLCallback callback) | Sets an HTMLCallback to listen to this HTMLCOmponent |
public void setDefaultFont(String fontKey, Font font) | Sets the default font for this HTMLComponent |
public void setShowImages(boolean show) | Sets whether this HTMLComponent will download and show linked images or not |
public void setIgnoreCSS(boolean ignore) | Sets whether this HTMLComponent will ignore all CSS.directives. |
public void scrollPixels(int pixels, boolean animate) | Scrolls the HTMLComponent several pixels forward/backward. |
public void scrollPages(int pages, boolean animate) | Scrolls the HTMLComponent several pages forward/backward. |
public void scrollToElement(HTMLElement element, boolean animate) | Scrolls the HTMLComponent to the specified element |
public void setBodyText(String htmlText) | Sets the given string containing HTML code as this HTMLComponent’s body |
public boolean setBodyText(String htmlText, String encoding) | Sets the given string containing HTML code as this HTMLComponent’s body. |
public boolean setHTML(String htmlText, String encoding, String title, boolean isFullHTML) | Sets the given string containing HTML code either as this HTMLComponent’s body or as the full HTML. |
public void cancel() | Cancels the loading of the current page |
public void setPage(String pageURL) | Sets this HTMLComponent to render the document in the specified URL |
public void setPageStyle(Style pageStyle) | Sets the style of the page, allowing for example to set transparency to the main page. |
public void setPageUIID(String pageUIID) | Sets the UIID of the page (the internal container) This applies not only to the current page, but rather to all pages created with this HTMLComponent instance. |
public void streamReady(InputStream is, DocumentInfo docInfo) | This method should be called only by AsyncDocumentRequestHandler implementations after an async fetch of a document |
public void setDOM(HTMLElement dom, String baseURL) | Sets this HTMLComponent to render the document in the specified DOM |
public HTMLElement getDOM() | Returns the DOM representing this document |
public void setDOM(HTMLElement dom) | Sets this HTMLComponent to render the document in the specified DOM. |
public void refreshDOM() | Refreshes the current DOM so it any changes done after loading will be rendered. |
public boolean isEventsEnabled() | Returns the current status of the events enabled flag |
public void setEventsEnabled(boolean enabled) | Sets whether the active controls in the HTML will trigger events, and whether the DOM will change dynamically due to user input. |
public void setAutoFocusOnFirstLink(boolean autoFocus) | Determines whether to auto-focus on the first link after page load Note that focusing will happen only if the link is within a visible range (no scrolling is performed since this is rarely a wanted behaviour in this case) |
public boolean animate() | Allows the animation to reduce “repaint” calls when it returns false. |
public String getTitle() | Returns the HTML page’s title as described in its TITLE tag |
public String getPageURL() | Returns the page’s URL |
public int getPageStatus() | Returns the page status |
protected void initComponent() | Overrides initComponent to add the key listeners to the access keys when the component is first added to the form/displayed This is useful when the component is added only after the page was read |
protected void deinitialize() | If the component is taken off for any reason, makes sure access keys are not active |
public void layoutContainer() | {Performs the layout of the container if a layout is necessary} |
public void actionPerformed(ActionEvent evt) | {Invoked when an action occurred on a component} |
public String[] getPropertyNames() | A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code |
public Class[] getPropertyTypes() | Matches the property names method (see that method for further details). |
public Object getPropertyValue(String name) | Returns the current value of the property name, this method is used by the GUI builder |
public String setPropertyValue(String name, Object value) | Sets a new value to the given property, returns an error message if failed and null if successful. |
public boolean isSupressExceptions() | |
public void setSupressExceptions(boolean supressExceptions) |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From Container
encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyTypeNames, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
HTMLComponent
public HTMLComponent()HTMLComponent
public HTMLComponent(DocumentRequestHandler handler)Parameters
handlerDocumentRequestHandler- The HttpRequestHandler to which all requests for links will be sent
Method details
addFont
public static void addFont(String fontKey, Font font)Sets the given Codename One font for use with HTMLComponents.
The font key can contain information about the following attributes:
- The font family - i.e. Arial, Times New Roman etc.
- The font size - in pixels (i.e. 12, 14 etc.)
- The font style - bold, italic or both (no need to specify plain)
- The font tag assignments - if this font should be used for any HTML specific tags they should be specified - i.e. h1, kbd etc.
The key is just a concatenation of all attributes seperated with a dot. Examples for valid keys: arial.12 - Describes a plain font from the arial family in size 12 arial.16.bold - A bold arial font in size 16 courier.italic.bold.20 - A bold and italic courier font in size 20 arial.20.h1 - A plain arial font, size 20, that should be used for contents of the H1 tag code.kbd.samp - A font that should be used for the CODE, KBD and SAMP tags
Note that the order of the attributes is not important and also that the case is ignored. This means that arial.12.bold.italic.h3 is equivalent to itALIc.H3.arial.BOLD.12
Also note that while you do not have to provide all the info for the font, but the info helps the rendering engine to reuse fonts when suitable. For example, if you have a 16px arial bold font which you want to use for H2, you can simply add it as “h2”, but if you add it as “arial.16.bold.h2” then if the current font is arial.16 and the renderer encounters a B tag, it will know it can use the font you added as the bold counterpart of the current font.
When adding system fonts there is no need to describe the font, the usage of setFont with system fonts is usually just to assign them for tags. The rendering engine knows to derive bold/italic/bigger/smaller fonts from other system fonts (default or tag fonts) even if not added.
Parameters
fontKeyString- The font key in the format described above
fontFont- The actual Codename One font object
addSpecialKey
public static void addSpecialKey(String specialKeyName, int specialKeyCode)Parameters
specialKeyNameString- The name of the special key as denoted in CSS files
specialKeyCodeint- The special key code
setMaxThreads
public static void setMaxThreads(int threadsNum)Parameters
threadsNumint- the maximum number of threads to use for image download
setCSSSupportedMediaTypes
public static void setCSSSupportedMediaTypes(String[] supportedMediaTypes)Parameters
supportedMediaTypesString[]- A string array containing the media types that should be supported
setParser
public void setParser(HTMLParser parser)Parameters
parserHTMLParser- The HTMLParser to use
addCharEntity
public void addCharEntity(String symbol, int code)Parameters
symbolString- The symbol to add
codeint- The symbol’s code
addCharEntitiesRange
public void addCharEntitiesRange(String[] symbols, int startcode)Parameters
symbolsString[]- The symbols to add
startcodeint- The symbol’s code
getRequestHandler
public DocumentRequestHandler getRequestHandler()Returns
setRequestHandler
public void setRequestHandler(DocumentRequestHandler handler)Parameters
handlerDocumentRequestHandler- the new document request handler
getDocumentInfo
public DocumentInfo getDocumentInfo()Returns
getHTMLCallback
public HTMLCallback getHTMLCallback()Returns
setHTMLCallback
public void setHTMLCallback(HTMLCallback callback)Parameters
callbackHTMLCallback- The HTMLCallback that will receive events
setDefaultFont
public void setDefaultFont(String fontKey, Font font)Parameters
fontKeyString- The font key in the format described in setFont (Can be null for default font, but it is recommended to add a descriptive key if this is a bitmap font to enable the font engine to use it in other cases as well)
fontFont- The actual Codename One font object
setShowImages
public void setShowImages(boolean show)Parameters
showboolean- true to show images, false otherwise
setIgnoreCSS
public void setIgnoreCSS(boolean ignore)Parameters
ignoreboolean- true to ignore CSS directives, false otherwise
scrollPixels
public void scrollPixels(int pixels, boolean animate)Parameters
pixelsint- The number of pixels to scroll (positive for forward and negative for backward)
animateboolean- true to animate the scrolling, false otherwise
scrollPages
public void scrollPages(int pages, boolean animate)Parameters
pagesint- The number of pages to scroll (positive for forward and negative for backward)
animateboolean- true to animate the scrolling, false otherwise
scrollToElement
public void scrollToElement(HTMLElement element, boolean animate)Parameters
elementHTMLElement- The element to scroll to (must be contained in the document)
animateboolean- true to animate the scrolling, false otherwise
Throws
IllegalArgumentException- if the element is not contained in the current document.
setBodyText
public void setBodyText(String htmlText)Parameters
htmlTextString- The HTML body to set
setBodyText
public boolean setBodyText(String htmlText, String encoding)Parameters
htmlTextString- The HTML body to set
encodingString- The encoding to use when reading the HTML i.e. UTF8, ISO-8859-1 etc.
Returns
setHTML
public boolean setHTML(String htmlText, String encoding, String title, boolean isFullHTML)Parameters
htmlTextString- The HTML to set
encodingString- The encoding to use when reading the HTML i.e. UTF8, ISO-8859-1 etc.
titleString- The HTML title, or null if none (Used only when isFullHTML is false)
isFullHTMLboolean- true if this is a full HTML document (with html/body tags), false if this HTML should be used as the HTMLComponent’s body
Returns
cancel
public void cancel()setPage
public void setPage(String pageURL)Parameters
pageURLString- The URL containing the HTML document
setPageStyle
public void setPageStyle(Style pageStyle)Parameters
pageStyleStyle- The style to set to the page
setPageUIID
public void setPageUIID(String pageUIID)Parameters
pageUIIDString- The UIID that should be applied to the page
streamReady
public void streamReady(InputStream is, DocumentInfo docInfo)Parameters
isInputStream- The InputStream of the document
docInfoDocumentInfo- The document info
setDOM
public void setDOM(HTMLElement dom, String baseURL)Parameters
domHTMLElement- An HTMLElement representing the root of the HTML document
baseURLString- The base URL for this DOM (Necessary if document references relative links)
Throws
IllegalArgumentException- if the HTMLElement supplied is not an ‘html’ tag
getDOM
public HTMLElement getDOM()Returns
Throws
IllegalStateException- if the page is still loading
setDOM
public void setDOM(HTMLElement dom)Parameters
domHTMLElement- An HTMLElement representing the root of the HTML document
Throws
IllegalArgumentException- if the HTMLElement supplied is not an ‘html’ tag
refreshDOM
public void refreshDOM()isEventsEnabled
public boolean isEventsEnabled()Returns
setEventsEnabled
public void setEventsEnabled(boolean enabled)Parameters
enabledboolean- true to enable event dispatching, false otherwise
setAutoFocusOnFirstLink
public void setAutoFocusOnFirstLink(boolean autoFocus)Parameters
autoFocusboolean- true to auto-focus, false otherwise
animate
public boolean animate()com.codename1.ui.Display class.Returns
getTitle
public String getTitle()Returns
getPageURL
public String getPageURL()Returns
getPageStatus
public int getPageStatus()Returns
initComponent
protected void initComponent()deinitialize
protected void deinitialize()layoutContainer
public void layoutContainer()actionPerformed
public void actionPerformed(ActionEvent evt)Parameters
evtActionEvent- event object describing the source of the action as well as its trigger
getPropertyNames
public String[] getPropertyNames()Returns
getPropertyTypes
public Class[] getPropertyTypes()Returns
getPropertyValue
public Object getPropertyValue(String name)Parameters
nameString- the name of the property
Returns
setPropertyValue
public String setPropertyValue(String name, Object value)Parameters
nameString- the name of the property
valueObject- new value for the property
Returns
isSupressExceptions
public boolean isSupressExceptions()Returns
setSupressExceptions
public void setSupressExceptions(boolean supressExceptions)Parameters
supressExceptionsboolean- the supressExceptions to set