Package totalcross.ui.dialog
Class FileChooserBox
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.Window
-
- totalcross.ui.dialog.FileChooserBox
-
public class FileChooserBox extends Window
A class that shows all folders from a startup one to allow the user select a file or a folder. Here's a sample of how to use it:try { FileChooserBox w = new FileChooserBox("Select the folder",new String[]{" This one "," Cancel "}, new FileChooserBox.Filter() { public boolean accept(File f) throws IOException { return f.isDir(); // will only list folders. you may filter by other file types too } }); w.mountTree(Settings.appPath,1); w.popup(); return w.getPressedButtonIndex() == 0 ? w.getAnswer() : null; } catch (IOException e) { return null; }The tree is mounted on demand to speedup the process.Here's a list of customizations you can do:
- You can set a path to be selected initially by setting the
initialPathproperty. - Set the defaultButton property to allow the selection of an item doing a double-click on it.
- You can set a path to be selected initially by setting the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFileChooserBox.FilterInterface used if you want to filter the files that will be added to the tree.-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description protected ButtonbtRefreshprotected java.lang.String[]buttonCaptionsprotected ComboBoxcbRootintdefaultButtonThe button index that will be choosen if the user makes a double-click in an item.static java.lang.String[]defaultButtonCaptionsThe default button captions: " Select " and " Cancel ".protected FileChooserBox.FilterffintfileCountjava.lang.StringinitialPathSelects a file that is in this tree.protected NodelastSelectedstatic java.lang.StringmsgInvalidVolumeMessageThe body of a message box that appears if the user tries to access a volume and an error is issued by the operating system.static java.lang.StringmsgInvalidVolumeTitleThe title of a message box that appears if the user tries to access a volume and an error is issued by the operating system.static java.lang.StringmsgRefreshThe " Refresh " button that's placed after the volume combo.static java.lang.StringmsgVolumeThe "Volume: " label that's placed before the volume combo.booleanmultipleSelectionSet to true to allow multiple selections using a Check drawn before the nodes.booleannewestFirstSet to true to sort the list showing the newest files first, instead of alphabetical orderprotected PushButtonGrouppbgprotected ImageControlpreviewstatic intPREVIEW_HEIGHTThe preview height in percentage of the total height.static java.lang.StringpreviewTitleThe " Preview " button title.protected intselectedIndexbooleanshowInitialPathOnlyOn Win32, we show by default the root drive and expand to the default path.booleanshowPreviewSet to true to use a preview window to show photo thumbnailsprotected TreeModeltmodelprotected Treetree-
Fields inherited from class totalcross.ui.Window
_controlEvent, _dragEvent, _focus, _keyEvent, _mouseEvent, _multiEvent, _penEvent, androidBorderThickness, beepIfOut, blocking, borderStyle, cancelPenUp, canDrag, dragThreshold, fadeOtherWindows, fadeValue, firstFocus, flickEnabled, focusOnPenUp, footerColor, footerH, gradientTitleEndColor, gradientTitleStartColor, headerColor, highlighted, highResPrepared, HORIZONTAL_GRADIENT, ignoreEventOfType, keyHook, lastShiftY, lastSwappedContainer, mainSwapContainer, menubar, multiTouching, needsPaint, NO_BORDER, ORIENTATION_INVERTED, ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT, popped, RECT_BORDER, repaintOnSwap, robot, ROUND_BORDER, rTitle, sameBackgroundColor, shiftH, shiftY, SIP_BOTTOM, SIP_HIDE, SIP_SHOW, SIP_TOP, TAB_BORDER, TAB_ONLY_BORDER, tempTitle, title, titleAlign, titleColor, titleFont, titleGap, topMost, VERTICAL_GRADIENT, zStack
-
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, lastH, lastScreenWidth, lastW, 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, 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 FileChooserBox(java.lang.String caption, java.lang.String[] buttonCaptions, FileChooserBox.Filter ff)Constructs a file chooser with the given parameters.FileChooserBox(FileChooserBox.Filter ff)Constructs a file chooser with "Select a file" as the window title, and "Select" and "Cancel" buttons.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringgetAnswer()Returns the path choosen by the user.intgetPressedButtonIndex()Returns the button index used to close this window.TreegetTree()Returns the tree.voidmountTree(java.lang.String filePath)Call this method to mount the tree, starting from the given path and volume.voidmountTree(java.lang.String filePath, int volume)Deprecated.protected voidmountTree(Node root, File f)voidonEvent(Event e)Called to process key, pen, control and other posted events.protected voidonPopup()Placeholder called imediatly before the popup began.-
Methods inherited from class totalcross.ui.Window
_doPaint, _postEvent, destroyZStack, drawHighlight, getBorderStyle, getClientRect, getClientRect, getDefaultDragThreshold, getFocus, getHighlighted, getPopupCount, getPreferredHeight, getPreferredWidth, getSafeAreaInsets, getTitleFont, getTopMost, handleFocusChangeKeys, isScreenShifted, isSipShown, isSipShown4D, isTopMost, isVisible, loadBehind, makeUnmovable, onClickedOutside, onRobotKey, onUnpop, paintTitle, paintWindowBackground, popup, popupMenuBar, popupNonBlocking, postPopup, postPressedEvent, postUnpop, pumpEvents, removeFocus, repaintActiveWindows, resize, resizeHeight, resizeWidth, screenResized, setBorderStyle, setDeviceTitle, setFocus, setGrabPenEvents, setHighlighted, setMenuBar, setOrientation, setSIP, setTitle, setTitleFont, shiftScreen, swap, swapFocus, unpop, validate
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getChildren, getChildrenCount, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
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, 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, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isVisibleAndInside, onBoundsChanged, onFontChanged, onWindowPaintFinished, post, postEvent, 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, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
pbg
protected PushButtonGroup pbg
-
tree
protected Tree tree
-
lastSelected
protected Node lastSelected
-
ff
protected FileChooserBox.Filter ff
-
defaultButtonCaptions
public static java.lang.String[] defaultButtonCaptions
The default button captions: " Select " and " Cancel ". You can localize them if you want.
-
msgVolume
public static java.lang.String msgVolume
The "Volume: " label that's placed before the volume combo. You can localize it if you want.
-
msgRefresh
public static java.lang.String msgRefresh
The " Refresh " button that's placed after the volume combo. You can localize it if you want.
-
msgInvalidVolumeTitle
public static java.lang.String msgInvalidVolumeTitle
The title of a message box that appears if the user tries to access a volume and an error is issued by the operating system. Defaults to "Error". You can localize it if you want.
-
previewTitle
public static java.lang.String previewTitle
The " Preview " button title. You can localize it if you want.
-
msgInvalidVolumeMessage
public static java.lang.String msgInvalidVolumeMessage
The body of a message box that appears if the user tries to access a volume and an error is issued by the operating system. Defaults to "Unable to read the contents of the selected volume. Make sure the volume is mounted and you have enough privileges to query its contents.". You can localize it if you want.
-
buttonCaptions
protected java.lang.String[] buttonCaptions
-
tmodel
protected TreeModel tmodel
-
selectedIndex
protected int selectedIndex
-
cbRoot
protected ComboBox cbRoot
-
btRefresh
protected Button btRefresh
-
preview
protected ImageControl preview
-
showInitialPathOnly
public boolean showInitialPathOnly
On Win32, we show by default the root drive and expand to the default path. Set this to false to show the initial path only.- Since:
- TotalCross 3.2
-
fileCount
public int fileCount
-
multipleSelection
public boolean multipleSelection
Set to true to allow multiple selections using a Check drawn before the nodes.- Since:
- TotalCross 1.15
-
initialPath
public java.lang.String initialPath
Selects a file that is in this tree.- Since:
- TotalCross 1.25
-
defaultButton
public int defaultButton
The button index that will be choosen if the user makes a double-click in an item. Usually you set this to the index of the "Ok" button.
-
PREVIEW_HEIGHT
public static final int PREVIEW_HEIGHT
The preview height in percentage of the total height. Defaults to 30.- See Also:
- Constant Field Values
-
showPreview
public boolean showPreview
Set to true to use a preview window to show photo thumbnails
-
newestFirst
public boolean newestFirst
Set to true to sort the list showing the newest files first, instead of alphabetical order
-
-
Constructor Detail
-
FileChooserBox
public FileChooserBox(java.lang.String caption, java.lang.String[] buttonCaptions, FileChooserBox.Filter ff)Constructs a file chooser with the given parameters.- Parameters:
caption- The caption to be displayed in the titlebuttonCaptions- The button captions that will be used in the PushButtonGroupff- The Filter. Pass null to accept all files.
-
FileChooserBox
public FileChooserBox(FileChooserBox.Filter ff)
Constructs a file chooser with "Select a file" as the window title, and "Select" and "Cancel" buttons.- Parameters:
ff- The Filter. Pass null to accept all files.
-
-
Method Detail
-
onPopup
protected void onPopup()
Description copied from class:WindowPlaceholder called imediatly before the popup began. The default implementation does nothing.
-
mountTree
@Deprecated public void mountTree(java.lang.String filePath, int volume) throws IOExceptionDeprecated.- Throws:
IOException
-
mountTree
public void mountTree(java.lang.String filePath) throws IOExceptionCall this method to mount the tree, starting from the given path and volume.- Parameters:
filePath- The root from where the tree will be mounted.- Throws:
IOException
-
mountTree
protected void mountTree(Node root, File f) throws IOException
- Throws:
IOException
-
onEvent
public void onEvent(Event e)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
getPressedButtonIndex
public int getPressedButtonIndex()
Returns the button index used to close this window.
-
getAnswer
public java.lang.String getAnswer()
Returns the path choosen by the user. If using the default captions and the cancel button was pressed, returns null. The filename is returned with normal (/) slashes; the path also ends with a slash. If multipleSelections is on, a list of paths, separated by comma (,) is returned.
-
getTree
public Tree getTree()
Returns the tree.
-
-