*
* The MIT License (MIT)
*
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
private int maxLineWidth;
/**
- * The action to perform when the user selects an item (clicks or enter).
+ * The action to perform when the user selects an item (double-clicks or
+ * enter).
*/
- private TAction enterAction = null;
+ protected TAction enterAction = null;
+
+ /**
+ * The action to perform when the user selects an item (single-click).
+ */
+ protected TAction singleClickAction = null;
/**
* The action to perform when the user navigates with keyboard.
*/
- private TAction moveAction = null;
+ protected TAction moveAction = null;
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
}
if ((mouse.getX() < getWidth() - 1)
- && (mouse.getY() < getHeight() - 1)) {
+ && (mouse.getY() < getHeight() - 1)
+ ) {
if (getVerticalValue() + mouse.getY() < strings.size()) {
selectedString = getVerticalValue() + mouse.getY();
+ dispatchSingleClick();
}
return;
}
@Override
public void onMouseDoubleClick(final TMouseEvent mouse) {
if ((mouse.getX() < getWidth() - 1)
- && (mouse.getY() < getHeight() - 1)) {
+ && (mouse.getY() < getHeight() - 1)
+ ) {
if (getVerticalValue() + mouse.getY() < strings.size()) {
selectedString = getVerticalValue() + mouse.getY();
dispatchEnter();
}
/**
- * Draw the files list.
+ * Draw the list.
*/
@Override
public void draw() {
color = getTheme().getColor("tlist.inactive");
}
String formatString = "%-" + Integer.toString(getWidth() - 1) + "s";
- getScreen().putStringXY(0, topY, String.format(formatString, line),
- color);
+ putStringXY(0, topY, String.format(formatString, line), color);
topY++;
if (topY >= getHeight() - 1) {
break;
// Pad the rest with blank lines
for (int i = topY; i < getHeight() - 1; i++) {
- getScreen().hLineXY(0, i, getWidth() - 1, ' ', color);
+ hLineXY(0, i, getWidth() - 1, ' ', color);
}
}
selectedString = index;
}
+ /**
+ * Get a selectable string by index.
+ *
+ * @param idx index into list
+ * @return the string at idx in the list
+ */
+ public final String getListItem(final int idx) {
+ return strings.get(idx);
+ }
+
/**
* Get the selected string.
*
return strings.size() - 1;
}
+ /**
+ * Get a copy of the list of strings to display.
+ *
+ * @return the list of strings
+ */
+ public final List<String> getList() {
+ return new ArrayList<String>(strings);
+ }
+
/**
* Set the new list of strings to display.
*
}
}
+ /**
+ * Perform single-click action.
+ */
+ public void dispatchSingleClick() {
+ assert (selectedString >= 0);
+ assert (selectedString < strings.size());
+ if (singleClickAction != null) {
+ singleClickAction.DO();
+ }
+ }
+
}