git://git.nikiroo.be
/
nikiroo-utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update entries
[nikiroo-utils.git]
/
src
/
jexer
/
TList.java
diff --git
a/src/jexer/TList.java
b/src/jexer/TList.java
index 46c9307b95eba5cf9f68ed59d82ed4893ca7f1f2..3aed01ed21c25131d2e70e96efdf4d4bd9039ed3 100644
(file)
--- a/
src/jexer/TList.java
+++ b/
src/jexer/TList.java
@@
-3,7
+3,7
@@
*
* The MIT License (MIT)
*
*
* The MIT License (MIT)
*
- * Copyright (C) 201
7
Kevin Lamonte
+ * Copyright (C) 201
9
Kevin Lamonte
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@
-61,14
+61,20
@@
public class TList extends TScrollableWidget {
private int maxLineWidth;
/**
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.
*/
/**
* The action to perform when the user navigates with keyboard.
*/
- pr
ivate
TAction moveAction = null;
+ pr
otected
TAction moveAction = null;
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
@@
-170,9
+176,11
@@
public class TList extends TScrollableWidget {
}
if ((mouse.getX() < getWidth() - 1)
}
if ((mouse.getX() < getWidth() - 1)
- && (mouse.getY() < getHeight() - 1)) {
+ && (mouse.getY() < getHeight() - 1)
+ ) {
if (getVerticalValue() + mouse.getY() < strings.size()) {
selectedString = getVerticalValue() + mouse.getY();
if (getVerticalValue() + mouse.getY() < strings.size()) {
selectedString = getVerticalValue() + mouse.getY();
+ dispatchSingleClick();
}
return;
}
}
return;
}
@@
-189,7
+197,8
@@
public class TList extends TScrollableWidget {
@Override
public void onMouseDoubleClick(final TMouseEvent mouse) {
if ((mouse.getX() < getWidth() - 1)
@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();
if (getVerticalValue() + mouse.getY() < strings.size()) {
selectedString = getVerticalValue() + mouse.getY();
dispatchEnter();
@@
-329,7
+338,7
@@
public class TList extends TScrollableWidget {
}
/**
}
/**
- * Draw the
files
list.
+ * Draw the list.
*/
@Override
public void draw() {
*/
@Override
public void draw() {
@@
-355,8
+364,7
@@
public class TList extends TScrollableWidget {
color = getTheme().getColor("tlist.inactive");
}
String formatString = "%-" + Integer.toString(getWidth() - 1) + "s";
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;
topY++;
if (topY >= getHeight() - 1) {
break;
@@
-371,7
+379,7
@@
public class TList extends TScrollableWidget {
// Pad the rest with blank lines
for (int i = topY; i < getHeight() - 1; i++) {
// 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);
}
}
}
}
@@
-397,6
+405,16
@@
public class TList extends TScrollableWidget {
selectedString = index;
}
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.
*
/**
* Get the selected string.
*
@@
-418,6
+436,15
@@
public class TList extends TScrollableWidget {
return strings.size() - 1;
}
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.
*
/**
* Set the new list of strings to display.
*
@@
-451,4
+478,15
@@
public class TList extends TScrollableWidget {
}
}
}
}
+ /**
+ * Perform single-click action.
+ */
+ public void dispatchSingleClick() {
+ assert (selectedString >= 0);
+ assert (selectedString < strings.size());
+ if (singleClickAction != null) {
+ singleClickAction.DO();
+ }
+ }
+
}
}