Package totalcross.ui
Class ImageControl
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.ImageControl
-
public class ImageControl extends Control
A control that can show an image bigger than its area and that can be dragged using a pen to show the hidden parts. Note that, by default, events (and dragging) are disabled. You must call setEventsEnabled to allow dragging.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleanallowBeyondLimitsSet to true to let the image be dragged beyond container limits.intborderColorChange this member to set the border color.booleancenterImageSet to true to center the image in the control when it is loadedintdrawOpDumb field to keep compilation compatibility with TC 1booleanhwScaleSet to true to enable zooming in open gl devices.intlastXThe last position used for X and Y.intlastYThe last position used for X and Y.booleanscaleToFitSet to true to scale the image to fit the bounds.static intscrollValueThe amount to scroll when in penless mode.booleanstrechImageSet to true, with scaleToFit, to strech the image.doubletempHwScaleTemporary values to set the hwScaleW/hwScaleH to during draw.-
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, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description ImageControl()Constructs with no initial image.ImageControl(Image img)Constructs an ImageControl using the given image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImagegetBackground()Returns the background image set with setBackgroundImagegetImage()Returns the current image assigned to this ImageControl.intgetImageHeight()Returns the image's height; when scaling, returns the scaled height.intgetImageWidth()Returns the image's width; when scaling, returns the scaled width.ImagegetOriginalImage()Returns the original image assigned to this ImageControl.intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.ImagegetVisibleImage(boolean includeBackground)Gets an image representing the portion being shown.ControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.booleanmoveTo(int newX, int newY)Moves to the given coordinates, respecting the current moving policy regarding allowBeyondLimits.protected voidonBoundsChanged(boolean screenChanged)Called after a setRect.voidonEvent(Event event)Called to process key, pen, control and other posted events.voidonPaint(Graphics g)Called to draw the control.voidsetBackground(Image img)Sets the given image as a freezed background of this image control.voidsetEventsEnabled(boolean enabled)Pass true to enable dragging and events on the image.voidsetImage(Image img)Sets the image to the given one.voidsetImage(Image img, boolean resetPositions)Sets the image to the given one, optionally resetting the image position.voidsetPressedEventsEnabled(boolean enabled)Pass true to enable this ImageControl to send Press events.-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, clear, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, 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, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onColorsChanged, onFontChanged, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
scrollValue
public static int scrollValue
The amount to scroll when in penless mode. Defaults to 10.
-
centerImage
public boolean centerImage
Set to true to center the image in the control when it is loaded
-
lastX
public int lastX
The last position used for X and Y.
-
lastY
public int lastY
The last position used for X and Y.
-
borderColor
public int borderColor
Change this member to set the border color. You may also set it to -1 if you don't want a border color. Note: starting on TotalCross 3.1, the border is drawn around the color and no longer around the image, because it was not working on OpenGL devices.
-
allowBeyondLimits
public boolean allowBeyondLimits
Set to true to let the image be dragged beyond container limits. Should be false for open gl.
-
drawOp
public int drawOp
Dumb field to keep compilation compatibility with TC 1
-
hwScale
public boolean hwScale
Set to true to enable zooming in open gl devices.
-
tempHwScale
public double tempHwScale
Temporary values to set the hwScaleW/hwScaleH to during draw.
-
scaleToFit
public boolean scaleToFit
Set to true to scale the image to fit the bounds.
-
strechImage
public boolean strechImage
Set to true, with scaleToFit, to strech the image.
-
-
Constructor Detail
-
ImageControl
public ImageControl(Image img)
Constructs an ImageControl using the given image.
-
ImageControl
public ImageControl()
Constructs with no initial image. You must set the image with the setImage method.
-
-
Method Detail
-
setEventsEnabled
public void setEventsEnabled(boolean enabled)
Pass true to enable dragging and events on the image.
-
setPressedEventsEnabled
public void setPressedEventsEnabled(boolean enabled)
Pass true to enable this ImageControl to send Press events. Note that it will disable drag and resize of the image.
-
setImage
public void setImage(Image img)
Sets the image to the given one. If the image size is different, you must explicitly call setRect again if you want to resize the control.
-
setImage
public void setImage(Image img, boolean resetPositions)
Sets the image to the given one, optionally resetting the image position. If the image size is different, you must explicitly call setRect again if you want to resize the control.
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
moveTo
public boolean moveTo(int newX, int newY)Moves to the given coordinates, respecting the current moving policy regarding allowBeyondLimits.- Returns:
- True if the image's position was changed.
-
onBoundsChanged
protected void onBoundsChanged(boolean screenChanged)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
screenChanged- If the bounds were changed due to a screen change (rotation, collapse)
-
onPaint
public void onPaint(Graphics g)
Description copied from class:ControlCalled to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
-
getImageWidth
public int getImageWidth()
Returns the image's width; when scaling, returns the scaled width.
-
getImageHeight
public int getImageHeight()
Returns the image's height; when scaling, returns the scaled height.
-
getPreferredWidth
public int getPreferredWidth()
Description copied from class:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
getImage
public Image getImage()
Returns the current image assigned to this ImageControl.
-
getOriginalImage
public Image getOriginalImage()
Returns the original image assigned to this ImageControl. Note that getImage() returns the image scaled, while getOriginalImage() returns the unscaled image.
-
setBackground
public void setBackground(Image img)
Sets the given image as a freezed background of this image control.
-
getBackground
public Image getBackground()
Returns the background image set with setBackground
-
getVisibleImage
public Image getVisibleImage(boolean includeBackground) throws ImageException
Gets an image representing the portion being shown. If all image is being shown, returns the currently assigned image.- Throws:
ImageException
-
handleGeographicalFocusChangeKeys
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class:ControlUsed by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.- Overrides:
handleGeographicalFocusChangeKeysin classControl- Parameters:
ke- The KeyEvent to be processed- Returns:
- The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
- See Also:
Settings.geographicalFocus
-
-