From d19bff6ab2d7450525d8c748b8a63e4d15c21aa9 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 29 Aug 2022 09:22:35 +0100 Subject: [PATCH] show tooltips on some download states --- gui/griffon-app/i18n/messages.properties | 4 ++ .../views/com/muwire/gui/MainFrameView.groovy | 3 +- .../muwire/gui/DownloadStateRenderer.groovy | 43 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gui/src/main/groovy/com/muwire/gui/DownloadStateRenderer.groovy diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 7bbfb608..49edf18f 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -808,6 +808,10 @@ TOOLTIP_DOWNLOAD_PAUSE=Pause the selected downloads TOOLTIP_DOWNLOAD_CANCEL=Cancel the selected downloads TOOLTIP_DOWNLOAD_PREVIEW=Preview the selected downloads TOOLTIP_DOWNLOAD_CLEAR_DONE=Remove finished and failed downloads from list +TOOLTIP_DOWNLOAD_STATE_HASHLIST=Fetching hash list, download will start shortly +TOOLTIP_DOWNLOAD_STATE_FAILED=Download failed, MuWire will retry +TOOLTIP_DOWNLOAD_STATE_REJECTED=Slot limit on the uploader reached, MuWIre will retry +TOOLTIP_DOWNLOAD_STATE_HOPELESS=Download cannot complete, MuWire will not retry ### Tooltips for the Library tab TOOLTIP_LIBRARY_TREE=View your shared files as a tree diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 04939ea0..e3420757 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -285,7 +285,7 @@ class MainFrameView { downloadsTable = table(id : "downloads-table", autoCreateRowSorter : true, rowHeight : rowHeight) { tableModel(list: model.downloads) { closureColumn(header: trans("NAME"), preferredWidth: 300, type: String, read : {row -> HTMLSanitizer.sanitize(row.downloader.file.getName())}) - closureColumn(header: trans("STATUS"), preferredWidth: 50, type: String, read : {row -> trans(row.downloader.getCurrentState().name())}) + closureColumn(header: trans("STATUS"), preferredWidth: 50, type: Downloader.DownloadState, read : { row -> row.downloader.getCurrentState()}) closureColumn(header: trans("PROGRESS"), preferredWidth: 70, type: Downloader, read: { row -> row.downloader }) closureColumn(header: trans("SPEED"), preferredWidth: 50, type:String, read :{row -> formatSize(row.downloader.speed(),"B_SEC") @@ -1003,6 +1003,7 @@ class MainFrameView { centerRenderer.setHorizontalAlignment(JLabel.CENTER) downloadsTable.setDefaultRenderer(Integer.class, centerRenderer) downloadsTable.setDefaultRenderer(Downloader.class, new DownloadProgressRenderer()) + downloadsTable.setDefaultRenderer(Downloader.DownloadState.class, new DownloadStateRenderer()) downloadsTable.rowSorter.addRowSorterListener({ evt -> lastDownloadSortEvent = evt }) downloadsTable.rowSorter.setSortsOnUpdates(true) diff --git a/gui/src/main/groovy/com/muwire/gui/DownloadStateRenderer.groovy b/gui/src/main/groovy/com/muwire/gui/DownloadStateRenderer.groovy new file mode 100644 index 00000000..bccc2e8b --- /dev/null +++ b/gui/src/main/groovy/com/muwire/gui/DownloadStateRenderer.groovy @@ -0,0 +1,43 @@ +package com.muwire.gui + +import com.muwire.core.download.Downloader + +import javax.swing.JComponent +import javax.swing.JTable +import javax.swing.table.DefaultTableCellRenderer + +import static com.muwire.gui.Translator.trans + +class DownloadStateRenderer extends DefaultTableCellRenderer { + @Override + JComponent getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column) + if (value == null) + return this //TODO investigate + + Downloader.DownloadState state = (Downloader.DownloadState) value + setText(trans(state.name())) + + String tooltipKey = null + switch(state) { + case Downloader.DownloadState.HASHLIST : tooltipKey = "TOOLTIP_DOWNLOAD_STATE_HASHLIST"; break + case Downloader.DownloadState.FAILED : tooltipKey = "TOOLTIP_DOWNLOAD_STATE_FAILED"; break + case Downloader.DownloadState.REJECTED : tooltipKey = "TOOLTIP_DOWNLOAD_STATE_REJECTED"; break + case Downloader.DownloadState.HOPELESS : tooltipKey = "TOOLTIP_DOWNLOAD_STATE_HOPELESS"; break + } + + if (tooltipKey != null) + setToolTipText(trans(tooltipKey)) + + if (isSelected) { + setForeground(table.getSelectionForeground()) + setBackground(table.getSelectionBackground()) + } else { + setForeground(table.getForeground()) + setBackground(table.getBackground()) + } + + this + } +}