You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/07/12 01:36:16 UTC
[groovy] 01/03: GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (ObjectBrowser)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 8ce727449c02cc066dc31674c51e5d2e6acc1a07
Author: Sandip Chitale <sa...@gmail.com>
AuthorDate: Sun Jul 10 02:04:02 2022 -0700
GROOVY-10686: Add tooltips for Object/AST browser to display contents for narrow columns (ObjectBrowser)
---
.../groovy/console/ui/CellValueToolTipJTable.groovy | 15 +++++++++++++++
.../main/groovy/groovy/console/ui/ObjectBrowser.groovy | 10 ++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy
new file mode 100644
index 0000000000..23960d0452
--- /dev/null
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/CellValueToolTipJTable.groovy
@@ -0,0 +1,15 @@
+package groovy.console.ui
+
+import javax.swing.JTable
+import java.awt.event.MouseEvent
+
+class CellValueToolTipJTable extends JTable {
+ public String getToolTipText(MouseEvent me) {
+ int viewRowIndex = rowAtPoint(me.point)
+ int viewColumnIndex = columnAtPoint(me.point)
+
+ def value = getValueAt(viewRowIndex, viewColumnIndex)
+
+ return (value != null ? String.valueOf(value) : null)
+ }
+}
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
index 315c3c5be1..df3d210d33 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ObjectBrowser.groovy
@@ -26,6 +26,7 @@ import javax.swing.WindowConstants
import java.awt.FlowLayout
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
+import javax.swing.ToolTipManager
import static javax.swing.ListSelectionModel.SINGLE_SELECTION
@@ -92,7 +93,7 @@ class ObjectBrowser {
tabbedPane(constraints: CENTER) {
if (inspector.object?.class?.array) {
scrollPane(name: ' Array data ') {
- arrayTable = table(selectionMode: SINGLE_SELECTION) {
+ arrayTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
tableModel(list: inspector.object.toList().withIndex()) {
closureColumn(header: 'Index', read: { it[1] })
closureColumn(header: 'Value', read: { it[0] })
@@ -110,7 +111,7 @@ class ObjectBrowser {
}
} else if (inspector.object instanceof Collection) {
scrollPane(name: ' Collection data ') {
- collectionTable = table(selectionMode: SINGLE_SELECTION) {
+ collectionTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
tableModel(list: inspector.object.withIndex()) {
closureColumn(header: 'Index', read: { it[1] })
closureColumn(header: 'Value', read: { it[0] })
@@ -128,7 +129,7 @@ class ObjectBrowser {
}
} else if (inspector.object instanceof Map) {
scrollPane(name: ' Map data ') {
- mapTable = table(selectionMode: SINGLE_SELECTION) {
+ mapTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
tableModel(list: inspector.object.entrySet().withIndex()) {
closureColumn(header: 'Index', read: { it[1] })
closureColumn(header: 'Key', read: { it[0].key })
@@ -136,6 +137,7 @@ class ObjectBrowser {
closureColumn(header: 'Raw Value', read: { it[0].value })
}
}
+ ToolTipManager.sharedInstance().registerComponent(mapTable)
mapTable.columnModel.getColumn(3).with {
minWidth = 0
maxWidth = 0
@@ -148,7 +150,7 @@ class ObjectBrowser {
}
scrollPane(name: ' Properties (includes public fields) ') {
def data = Inspector.sort(inspector.propertiesWithInfo.toList(), comparator)
- fieldTable = table(selectionMode: SINGLE_SELECTION) {
+ fieldTable = table(new CellValueToolTipJTable(), selectionMode: SINGLE_SELECTION) {
tableModel(list: data) {
closureColumn(header: 'Name', read: { it.v2[MEMBER_NAME_IDX] })
closureColumn(header: 'Value', read: { it.v2[MEMBER_VALUE_IDX] })