- reflow();
- }
-
- /**
- * Draw the files list.
- */
- @Override
- public void draw() {
- CellAttributes color = null;
- int begin = vScroller.getValue();
- int topY = 0;
- for (int i = begin; i < files.size(); i++) {
- String line = renderFile(i);
- if (hScroller.getValue() < line.length()) {
- line = line.substring(hScroller.getValue());
- } else {
- line = "";
- }
- if (i == selectedFile) {
- color = getTheme().getColor("tdirectorylist.selected");
- } else if (isAbsoluteActive()) {
- color = getTheme().getColor("tdirectorylist");
- } else {
- color = getTheme().getColor("tdirectorylist.inactive");
- }
- String formatString = "%-" + Integer.toString(getWidth() - 1) + "s";
- getScreen().putStringXY(0, topY, String.format(formatString, line),
- color);
- topY++;
- if (topY >= getHeight() - 1) {
- break;
- }
- }
-
- if (isAbsoluteActive()) {
- color = getTheme().getColor("tdirectorylist");
- } else {
- color = getTheme().getColor("tdirectorylist.inactive");
- }
-
- // Pad the rest with blank lines
- for (int i = topY; i < getHeight() - 1; i++) {
- getScreen().hLineXY(0, i, getWidth() - 1, ' ', color);
- }
- }
-
- /**
- * Handle mouse press events.
- *
- * @param mouse mouse button press event
- */
- @Override
- public void onMouseDown(final TMouseEvent mouse) {
- if (mouse.isMouseWheelUp()) {
- vScroller.decrement();
- return;
- }
- if (mouse.isMouseWheelDown()) {
- vScroller.increment();
- return;
- }
-
- if ((mouse.getX() < getWidth() - 1)
- && (mouse.getY() < getHeight() - 1)) {
- if (vScroller.getValue() + mouse.getY() < files.size()) {
- selectedFile = vScroller.getValue() + mouse.getY();
- }
- path = files.get(selectedFile);
- dispatch();
- return;
- }
-
- // Pass to children
- super.onMouseDown(mouse);
- }
-
- /**
- * Handle mouse release events.
- *
- * @param mouse mouse button release event
- */
- @Override
- public void onMouseUp(final TMouseEvent mouse) {
- // Pass to children
- super.onMouseDown(mouse);
- }
-
- /**
- * Handle keystrokes.
- *
- * @param keypress keystroke event
- */
- @Override
- public void onKeypress(final TKeypressEvent keypress) {
- if (keypress.equals(kbLeft)) {
- hScroller.decrement();
- } else if (keypress.equals(kbRight)) {
- hScroller.increment();
- } else if (keypress.equals(kbUp)) {
- if (files.size() > 0) {
- if (selectedFile >= 0) {
- if (selectedFile > 0) {
- selectedFile--;
- }
- } else {
- selectedFile = files.size() - 1;
- }
- path = files.get(selectedFile);
- }
- } else if (keypress.equals(kbDown)) {
- if (files.size() > 0) {
- if (selectedFile >= 0) {
- if (selectedFile < files.size() - 1) {
- selectedFile++;
- }
- } else {
- selectedFile = 0;
- }
- path = files.get(selectedFile);
- }
- } else if (keypress.equals(kbPgUp)) {
- vScroller.bigDecrement();
- } else if (keypress.equals(kbPgDn)) {
- vScroller.bigIncrement();
- } else if (keypress.equals(kbHome)) {
- vScroller.toTop();
- if (files.size() > 0) {
- selectedFile = 0;
- path = files.get(selectedFile);
- }
- } else if (keypress.equals(kbEnd)) {
- vScroller.toBottom();
- if (files.size() > 0) {
- selectedFile = files.size() - 1;
- path = files.get(selectedFile);
- }
- } else if (keypress.equals(kbTab)) {
- getParent().switchWidget(true);
- } else if (keypress.equals(kbShiftTab) || keypress.equals(kbBackTab)) {
- getParent().switchWidget(false);
- } else if (keypress.equals(kbEnter)) {
- if (selectedFile >= 0) {
- path = files.get(selectedFile);
- dispatch();
- }
- } else {
- // Pass other keys (tab etc.) on
- super.onKeypress(keypress);
- }