Package totalcross.ui.html
Class Document
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ScrollContainer
-
- totalcross.ui.html.Document
-
- All Implemented Interfaces:
UpdateListener,Scrollable
public class Document extends ScrollContainer
Represents a Html Document. Here is a sample of how to load an image of a document instead of downloading it from a URL:// Extends Document so that we can provide another way to load images, from our internal database class ArticleDocument extends Document { PDBFile cat; DataStream ds; /** The cat parameter should be an already open PDBFile which contains all the images. * Note that the image is in the form "And here's a sample on how to call it:.gif" or " .jpeg". * / public ArticleDocument(XmlReadable doc, PDBFile cat) { this.cat = cat; ds = new DataStream(cat); renderDoc(doc); } protected Image loadImage(String src, URI base) { int dot = src.indexOf('.'); if (dot == -1) throw new RuntimeException("src image not in expected format: "+src); int idx = Convert.toInt(src.substring(0,dot)); String ext = src.substring(dot+1).toLowerCase(); if (cat.setRecordPos(idx)) { int size = cat.getRecordSize(); byte []data = new byte[size]; ds.readBytes(data); return new Image(new ByteArrayStream(data)); } } } String s = ...; // get the html from somewhere and store in a String if (!s.substring(0,10).toLowerCase().startsWith(""; // Displays the xml hcView.setDocument(new ArticleDocument(new XmlReadableString(s),cat)); // cat must be already instantiatedTo change the font size, you must change Style.defaultFontSize. To change the default colors, change UIColors.htmlXXX fields, and don't forget to call htmlContainer.setBackForeColors with these colors.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description URIbaseURIBase URL for this documentbytepasswordModeThe password mode for the Edits.java.lang.StringtitleTitle associated with this document.VectorvFormsAll forms in this document.-
Fields inherited from class totalcross.ui.ScrollContainer
autoScroll, bag, bag0, disabledFlick, flick, hsIgnoreAutoScroll, lastH, lastV, sbH, sbV, shrink2size
-
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastScreenWidth, lastW, lastX, lastY, npback, numChildren, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_FADE, TRANSITION_NONE, TRANSITION_OPEN, TRANSITION_TIME, transitionEffect
-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDocument()Default Constructor.Document(XmlReadable doc)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinitUI()Layout the controls of this document.protected ImageloadImage(java.lang.String src, URI baseURI)Can be overridden by the caller in order to load an image from a different place.protected voidrenderDoc(XmlReadable doc)Renders the document.voidreposition()Reposition this control, calling again setRect with the original parameters.voidscroll(int dir)-
Methods inherited from class totalcross.ui.ScrollContainer
add, addScrollEventHandler, bagSetRect, canScrollContent, canShowScrollBars, disableFlick, enableFlick, flickEnded, flickStarted, getBagChildren, getBagInitialHeight, getBagInitialWidth, getClientRect, getFlick, getPreferredHeight, getPreferredWidth, getRealClientRect, getScrollDistance, getScrollPosition, moveFocusToNextControl, onBoundsChanged, onColorsChanged, onEvent, onFontChanged, onPaint, remove, removeAll, removeScrollEventHandler, resize, resize, scrollContent, scrollPage, scrollToControl, scrollToOrigin, scrollToPage, setBorderStyle, setHandlersVisibility, setHandlersVisibility, setHValue, setScrollBars, setVValue, updateListenerTriggered, wasScrolled
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, isPressed, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resizeHeight, resizeWidth, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
baseURI
public URI baseURI
Base URL for this document
-
title
public java.lang.String title
Title associated with this document.
-
vForms
public Vector vForms
All forms in this document.
-
passwordMode
public byte passwordMode
The password mode for the Edits. Defaults to Edit.PASSWORD_ALL.- See Also:
Edit.PASSWORD,Edit.PASSWORD_ALL
-
-
Constructor Detail
-
Document
public Document(XmlReadable doc) throws IOException, SyntaxException
Constructor- Parameters:
doc- XmlReadable to be read- Throws:
IOExceptionSyntaxException
-
Document
protected Document()
Default Constructor. The document must be rendered usingrenderDoc.
-
-
Method Detail
-
loadImage
protected Image loadImage(java.lang.String src, URI baseURI)
Can be overridden by the caller in order to load an image from a different place. Must return null if not handled/not found. By default, searches for the given file at the loaded libraries (TCZ files).- Parameters:
src- The image namebaseURI- The base URI- Returns:
- an Image
-
renderDoc
protected void renderDoc(XmlReadable doc) throws IOException, SyntaxException
Renders the document.- Parameters:
doc- XmlReadable to be read- Throws:
IOExceptionSyntaxException
-
initUI
public void initUI()
Layout the controls of this document.
-
scroll
public void scroll(int dir)
-
reposition
public void reposition()
Description copied from class:ControlReposition this control, calling again setRect with the original parameters.- Overrides:
repositionin classScrollContainer
-
-