import java.io.File;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
* TDirectoryList shows the files within a directory.
*/
-public final class TDirectoryList extends TList {
+public class TDirectoryList extends TList {
+
+ // ------------------------------------------------------------------------
+ // Variables --------------------------------------------------------------
+ // ------------------------------------------------------------------------
/**
* Files in the directory.
*/
private File path;
+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Public constructor.
+ *
+ * @param parent parent widget
+ * @param path directory path, must be a directory
+ * @param x column relative to parent
+ * @param y row relative to parent
+ * @param width width of text area
+ * @param height height of text area
+ */
+ public TDirectoryList(final TWidget parent, final String path, final int x,
+ final int y, final int width, final int height) {
+
+ this(parent, path, x, y, width, height, null);
+ }
+
+ /**
+ * Public constructor.
+ *
+ * @param parent parent widget
+ * @param path directory path, must be a directory
+ * @param x column relative to parent
+ * @param y row relative to parent
+ * @param width width of text area
+ * @param height height of text area
+ * @param action action to perform when an item is selected
+ */
+ public TDirectoryList(final TWidget parent, final String path, final int x,
+ final int y, final int width, final int height, final TAction action) {
+
+ super(parent, null, x, y, width, height, action);
+ files = new ArrayList<File>();
+ setPath(path);
+ }
+
+ // ------------------------------------------------------------------------
+ // TList ------------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // TDirectoryList ---------------------------------------------------------
+ // ------------------------------------------------------------------------
+
/**
* Set the new path to display.
*
newStrings.add(renderFile(files.size() - 1));
}
}
+ Collections.sort(newStrings);
setList(newStrings);
+
+ // Select the first entry
+ if (getMaxSelectedIndex() >= 0) {
+ setSelectedIndex(0);
+ }
}
/**
return String.format("%-20s %5dk", name, (file.length() / 1024));
}
- /**
- * Public constructor.
- *
- * @param parent parent widget
- * @param path directory path, must be a directory
- * @param x column relative to parent
- * @param y row relative to parent
- * @param width width of text area
- * @param height height of text area
- */
- public TDirectoryList(final TWidget parent, final String path, final int x,
- final int y, final int width, final int height) {
-
- this(parent, path, x, y, width, height, null);
- }
-
- /**
- * Public constructor.
- *
- * @param parent parent widget
- * @param path directory path, must be a directory
- * @param x column relative to parent
- * @param y row relative to parent
- * @param width width of text area
- * @param height height of text area
- * @param action action to perform when an item is selected
- */
- public TDirectoryList(final TWidget parent, final String path, final int x,
- final int y, final int width, final int height, final TAction action) {
-
- super(parent, null, x, y, width, height, action);
- files = new ArrayList<File>();
- setPath(path);
- }
-
}