public class FileChooserBox extends Window
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:
initialPath
property.
Modifier and Type | Class and Description |
---|---|
static interface |
FileChooserBox.Filter
Interface used if you want to filter the files that will be added to the tree.
|
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
protected Button |
btRefresh |
protected java.lang.String[] |
buttonCaptions |
protected ComboBox |
cbRoot |
int |
defaultButton
The button index that will be choosen if the user makes a double-click in an item.
|
static java.lang.String[] |
defaultButtonCaptions
The default button captions: " Select " and " Cancel ".
|
protected FileChooserBox.Filter |
ff |
int |
fileCount |
java.lang.String |
initialPath
Selects a file that is in this tree.
|
protected Node |
lastSelected |
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.
|
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.
|
static java.lang.String |
msgRefresh
The " Refresh " button that's placed after the volume combo.
|
static java.lang.String |
msgVolume
The "Volume: " label that's placed before the volume combo.
|
boolean |
multipleSelection
Set to true to allow multiple selections using a Check drawn before the nodes.
|
boolean |
newestFirst
Set to true to sort the list showing the newest files first, instead of alphabetical order
|
protected PushButtonGroup |
pbg |
protected ImageControl |
preview |
static int |
PREVIEW_HEIGHT
The preview height in percentage of the total height.
|
static java.lang.String |
previewTitle
The " Preview " button title.
|
protected int |
selectedIndex |
boolean |
showInitialPathOnly
On Win32, we show by default the root drive and expand to the default path.
|
boolean |
showPreview
Set to true to use a preview window to show photo thumbnails
|
protected TreeModel |
tmodel |
protected Tree |
tree |
_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
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, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, numChildren, started, tabOrder, tail, TRANSITION_TIME
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 and Description |
---|
FileChooserBox(FileChooserBox.Filter ff)
Constructs a file chooser with "Select a file" as the window title, and "Select" and "Cancel" buttons.
|
FileChooserBox(java.lang.String caption,
java.lang.String[] buttonCaptions,
FileChooserBox.Filter ff)
Constructs a file chooser with the given parameters.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAnswer()
Returns the path choosen by the user.
|
int |
getPressedButtonIndex()
Returns the button index used to close this window.
|
Tree |
getTree()
Returns the tree.
|
protected void |
mountTree(Node root,
File f) |
void |
mountTree(java.lang.String filePath)
Call this method to mount the tree, starting from the given path and volume.
|
void |
mountTree(java.lang.String filePath,
int volume)
Deprecated.
|
void |
onEvent(Event e)
Called to process key, pen, control and other posted events.
|
protected void |
onPopup()
Placeholder called imediatly before the popup began.
|
_doPaint, _postEvent, destroyZStack, drawHighlight, getBorderStyle, getClientRect, getClientRect, getDefaultDragThreshold, getFocus, getHighlighted, getPopupCount, getPreferredHeight, getPreferredWidth, 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
add, add, add, add, add, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getChildren, getChildrenCount, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, setBorderRadius, setEnabled, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_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, isVisibleAndInside, onBoundsChanged, onFontChanged, onWindowPaintFinished, post, postEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, 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
protected PushButtonGroup pbg
protected Tree tree
protected Node lastSelected
protected FileChooserBox.Filter ff
public static java.lang.String[] defaultButtonCaptions
public static java.lang.String msgVolume
public static java.lang.String msgRefresh
public static java.lang.String msgInvalidVolumeTitle
public static java.lang.String previewTitle
public static java.lang.String msgInvalidVolumeMessage
protected java.lang.String[] buttonCaptions
protected TreeModel tmodel
protected int selectedIndex
protected ComboBox cbRoot
protected Button btRefresh
protected ImageControl preview
public boolean showInitialPathOnly
public int fileCount
public boolean multipleSelection
public java.lang.String initialPath
public int defaultButton
public static final int PREVIEW_HEIGHT
public boolean showPreview
public boolean newestFirst
public FileChooserBox(java.lang.String caption, java.lang.String[] buttonCaptions, FileChooserBox.Filter ff)
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.public FileChooserBox(FileChooserBox.Filter ff)
ff
- The Filter. Pass null to accept all files.protected void onPopup()
Window
@Deprecated public void mountTree(java.lang.String filePath, int volume) throws IOException
IOException
public void mountTree(java.lang.String filePath) throws IOException
filePath
- The root from where the tree will be mounted.IOException
protected void mountTree(Node root, File f) throws IOException
IOException
public void onEvent(Event e)
Control
public int getPressedButtonIndex()
public java.lang.String getAnswer()
public Tree getTree()