X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTDirectoryList.java;h=9ff0b6bfde9ac1ec5e85fbb1a19a4179b5227a10;hb=615a0d99fd0aa4437116dd083147f9150d5e6527;hp=71be2ab5d2ddaa3f97ef17488fa2a1d4b007ee0f;hpb=e16dda65585466c8987bd1efd718431450a96605;p=nikiroo-utils.git diff --git a/src/jexer/TDirectoryList.java b/src/jexer/TDirectoryList.java index 71be2ab..9ff0b6b 100644 --- a/src/jexer/TDirectoryList.java +++ b/src/jexer/TDirectoryList.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2016 Kevin Lamonte + * Copyright (C) 2017 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,12 +30,17 @@ package jexer; 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. @@ -47,6 +52,53 @@ public final class TDirectoryList extends TList { */ 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(); + setPath(path); + } + + // ------------------------------------------------------------------------ + // TList ------------------------------------------------------------------ + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // TDirectoryList --------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Set the new path to display. * @@ -72,7 +124,13 @@ public final class TDirectoryList extends TList { newStrings.add(renderFile(files.size() - 1)); } } + Collections.sort(newStrings); setList(newStrings); + + // Select the first entry + if (getMaxSelectedIndex() >= 0) { + setSelectedIndex(0); + } } /** @@ -100,39 +158,4 @@ public final class TDirectoryList extends TList { 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(); - setPath(path); - } - }