totalcross.ui.dialog
Class FileChooserBox

totalcross.lang.Object
  extended by totalcross.ui.gfx.GfxSurface
      extended by totalcross.ui.Control
          extended by totalcross.ui.Container
              extended by totalcross.ui.Window
                  extended by 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 totalcross.lang.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.


Nested Class Summary
static interface FileChooserBox.Filter
          Interface used if you want to filter the files that will be added to the tree.
 
Field Summary
protected  String[] buttonCaptions
           
protected  FileChooserBox.Filter ff
           
protected  Node lastSelected
           
 boolean multipleSelection
          Set to true to allow multiple selections using a Check drawn before the nodes.
protected  PushButtonGroup pbg
           
protected  int selectedIndex
           
protected  Vector selectedNodes
           
protected  TreeModel tmodel
           
protected  totalcross.ui.dialog.FileChooserBox.LoadOnDemandTree tree
           
 
Fields inherited from class totalcross.ui.Window
_controlEvent, _dragEvent, _draggingEvent, _focus, _keyEvent, _penEvent, beepIfOut, blocking, borderStyle, cancelPenUp, canDrag, dragEventTime, dragThreshold, fadeOtherWindows, fadeValue, firstFocus, flickEnabled, flickHighSpeedDecay, flickInitialInverval, flickLowSpeedDecay, flickPixelThresholdHoriz, flickPixelThresholdVert, flickSpeedLowBound, flickStartThreshold, flickTimer, gradientTitleEndColor, gradientTitleStartColor, highlighted, highResPrepared, HORIZONTAL_GRADIENT, ignoreEventOfType, isFlicking, lastSwappedContainer, mainSwapContainer, menubar, needsPaint, NO_BORDER, popped, RECT_BORDER, ROUND_BORDER, rTitle, SIP_BOTTOM, SIP_DISABLE_NUMERICPAD, SIP_ENABLE_NUMERICPAD, SIP_HIDE, SIP_SHOW, SIP_TOP, TAB_BORDER, TAB_ONLY_BORDER, title, titleColor, titleFont, topMost, triggeredFlickDirection, VERTICAL_GRADIENT, zStack
 
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, nextTransitionEffect, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_NONE, TRANSITION_OPEN, transitionEffect
 
Fields inherited from class totalcross.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, CENTER, CENTER_OF, clearValueInt, clearValueStr, enabled, enableUpdateScreen, FILL, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, foreColor, height, isHighlighting, KEEP, LEFT, onEventFirst, parent, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, setFont, setH, setRel, setW, setX, setY, TOP, transparentBackground, uiCE, uiFlat, uiPalm, uiVista, visible, width, WILL_RESIZE, x, y
 
Constructor Summary
FileChooserBox(FileChooserBox.Filter ff)
          Constructs a file chooser with "Select a file" as the window title, and "Select" and "Cancel" buttons.
FileChooserBox(String caption, String[] buttonCaptions, FileChooserBox.Filter ff)
          Constructs a file chooser with the given parameters.
 
Method Summary
 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(String filePath, int volume)
          Call this method to mount the tree, starting from the given path and volume.
 void onEvent(Event e)
          Called to process key, pen, control and other posted events.
protected  void onPopup()
          Placeholder called imediatly before the popup began.
 
Methods inherited from class totalcross.ui.Window
_doPaint, _postEvent, destroyZStack, drawHighlight, getBorderStyle, getClientRect, getClientRect, getFocus, getHighlighted, getPreferredHeight, getPreferredWidth, getTitleFont, getTopMost, handleFocusChangeKeys, isFlickEnabled, isFlicking, isTopMost, isVisible, loadBehind, makeUnmovable, onClickedOutside, onUnpop, paintTitle, popup, popupMenuBar, popupNonBlocking, postPopup, postPressedEvent, postUnpop, pumpEvents, releaseFlickTimer, removeFocus, repaintActiveWindows, resize, resizeHeight, resizeWidth, screenResized, setBorderStyle, setDeviceTitle, setFlickEnabled, setFocus, setGrabPenEvents, setHighlighted, setMenuBar, setSIP, setTitle, setTitleFont, swap, swapFocus, unpop, validate
 
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, broadcastEvent, clear, findChild, findNearestChild, findNextFocusControl, getChildren, getFocusableControls, getInsets, incLastX, incLastY, initUI, onAddAgain, onColorsChanged, onPaint, onRemove, paintChildren, remove, removeAll, setEnabled, setHighlighting, setInsets, swapToTopmostWindow
 
Methods inherited from class totalcross.ui.Control
_onEvent, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addPenListener, addPressListener, addTimer, addTimer, addTimerListener, addWindowListener, changeHighlighted, contains, getAbsoluteRect, getBackColor, getEventListeners, getFont, getForeColor, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getWidth, getX, getX2, getY, getY2, handleGeographicalFocusChangeKeys, isDisplayed, isEnabled, isInsideOrNear, isVisibleAndInside, onBoundsChanged, onFontChanged, onWindowPaintFinished, postEvent, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removePenListener, removePressListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pbg

protected PushButtonGroup pbg

tree

protected totalcross.ui.dialog.FileChooserBox.LoadOnDemandTree tree

lastSelected

protected Node lastSelected

ff

protected FileChooserBox.Filter ff

buttonCaptions

protected String[] buttonCaptions

tmodel

protected TreeModel tmodel

selectedIndex

protected int selectedIndex

selectedNodes

protected Vector selectedNodes

multipleSelection

public boolean multipleSelection
Set to true to allow multiple selections using a Check drawn before the nodes.

Since:
TotalCross 1.15
Constructor Detail

FileChooserBox

public FileChooserBox(String caption,
                      String[] buttonCaptions,
                      FileChooserBox.Filter ff)
Constructs a file chooser with the given parameters.

Parameters:
caption - The caption to be displayed in the title
buttonCaptions - The button captions that will be used in the PushButtonGroup
ff - 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: Window
Placeholder called imediatly before the popup began. The default implementation does nothing.

Overrides:
onPopup in class Window

mountTree

public void mountTree(String filePath,
                      int volume)
               throws IOException
Call this method to mount the tree, starting from the given path and volume.

Parameters:
filePath - The root from where the tree will be mounted.
volume - The volume used in Palm OS only. Usually 1 is the NVFS volume, and 2 is the card slot.
Throws:
IOException

mountTree

protected void mountTree(Node root,
                         File f)
                  throws IOException
Throws:
IOException

onEvent

public void onEvent(Event e)
Description copied from class: Control
Called to process key, pen, control and other posted events.

Overrides:
onEvent in class Control
Parameters:
e - the event to process
See Also:
Event, KeyEvent, PenEvent

getPressedButtonIndex

public int getPressedButtonIndex()
Returns the button index used to close this window.


getAnswer

public 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.