From 6d56c19583de7938da2d0e99364f66aaaf2e64e0 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 7 Aug 2022 15:42:08 +0100 Subject: [PATCH] tooltips and option to copy chat links to clipboard --- gui/griffon-app/i18n/messages.properties | 4 ++ gui/griffon-app/resources/copy.png | Bin 0 -> 1147 bytes .../com/muwire/gui/chat/MuLinkPanel.groovy | 42 +++++++++++++----- 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 gui/griffon-app/resources/copy.png diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 58a1b1b3..ec496991 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -926,5 +926,9 @@ TOOLTIP_PROFILE_VIEWER_ADD_CONTACT=Add this user as a trusted contact TOOLTIP_PROFILE_VIEWER_BLOCK=Block this user TOOLTIP_PROFILE_VIEWER_UPDATE=Check for updated profile +### Tooltip for chat MuLink panel +TOOLTIP_MULINK_PANEL=Link created by {0} +TOOLTIP_MULINK_PANEL_DOWNLOAD=Download file +TOOLTIP_MULINK_PANEL_VIEW=View collection ## Test string TEST_PLURALIZABLE_STRING={count, plural, one {You have {count} item.} other {You have {count} items.}} diff --git a/gui/griffon-app/resources/copy.png b/gui/griffon-app/resources/copy.png new file mode 100644 index 0000000000000000000000000000000000000000..47b6c5a36d5dc0c1f5458eb72d8bc81e6187a5fa GIT binary patch literal 1147 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|rlm%Bruq6Z zXaU(A46KYo49p-UK*+!-#lQ+?Gcb5DO2gSfjD`$MKyg7Jj%v?jV1cU10n#Ag0mMMv z5W2j)TrV>(yEr+qAXP8FC>XQ2>tmIipR1RclAn~SSCLx)(#2p?VFhI7rj{fsROII56h?X&sHg; zq@=(~UmxV1a$}H3^bIX7E%gnI^o@*kfhu&1EAvVcD|GXUl_7?}%yCIAPACWTTHEh_1oE zC^HopIA9HiQ1!@S=;|Y|S%54E)nKC!3Q(i~hQuCN6c~MWTtL6Tl7byq$=}BTz=Y}Q z>Eak-A=o;3wI8dYfW!23JtiR`8OOwT;teVX1!VY~H%Qbmp0$r@RC~x@z@c)#ft|hO z`|CM*>G|c636nN|eojH*jY7d#y9*X28 zO0PSx(LduP>%B^Cqq28~Z_g;bwzQdAx@y_mEMrTH>ABXC4e1pPsus+j&-mZH?H7KJ zb5G;ydk3}79F|+tu!*D3Ty{woTh$R=4gIZNNBcLHfBkKBqO!MZvVL)UkK8Q5X5X^@ ziBWHl#3$!PZk_yj`Ri$yw=HH4*F68w{I~m6jR!41EcYzhl$-C``SI52`x*&BIq40u zlYNYz8)pBV=EB%KJ7C=%uQwKF#TFkB)8vgH8V*?q0EvQAywVOzpp~KSBA;)78&qol`;+0BTxq A^#A|> literal 0 HcmV?d00001 diff --git a/gui/src/main/groovy/com/muwire/gui/chat/MuLinkPanel.groovy b/gui/src/main/groovy/com/muwire/gui/chat/MuLinkPanel.groovy index 098af2f5..6e2d0a9c 100644 --- a/gui/src/main/groovy/com/muwire/gui/chat/MuLinkPanel.groovy +++ b/gui/src/main/groovy/com/muwire/gui/chat/MuLinkPanel.groovy @@ -1,10 +1,13 @@ package com.muwire.gui.chat +import com.muwire.gui.CopyPasteSupport import com.muwire.gui.UISettings import com.muwire.gui.mulinks.CollectionMuLink import com.muwire.gui.mulinks.FileMuLink import com.muwire.gui.mulinks.MuLink +import static com.muwire.gui.Translator.trans + import javax.swing.BorderFactory import javax.swing.Icon import javax.swing.ImageIcon @@ -18,9 +21,10 @@ import java.util.function.Consumer class MuLinkPanel extends JPanel { - private static final Icon DOWN_ICON + private static final Icon DOWN_ICON, COPY_ICON static { DOWN_ICON = new ImageIcon(MuLinkPanel.class.getClassLoader().getResource("down_arrow.png")) + COPY_ICON = new ImageIcon(MuLinkPanel.class.getClassLoader().getResource("copy.png")) } private final UISettings settings @@ -32,21 +36,37 @@ class MuLinkPanel extends JPanel { this.linkConsumer = linkConsumer setLayout(new BorderLayout()) + + JPanel buttonPanel = new JPanel() + add(buttonPanel, BorderLayout.EAST) + + JButton downloadButton = new JButton() + downloadButton.setIcon(DOWN_ICON) + downloadButton.addActionListener({linkConsumer.accept(link)}) + buttonPanel.add(downloadButton) + + JButton copyButton = new JButton() + copyButton.setIcon(COPY_ICON) + copyButton.addActionListener({ CopyPasteSupport.copyToClipboard(link.toLink())}) + copyButton.setToolTipText(trans("COPY_LINK_TO_CLIPBOARD")) + buttonPanel.add(copyButton) + def label = null - if (link.getLinkType() == MuLink.LinkType.FILE) - label = new FileLinkLabel((FileMuLink)link, settings, false) - else if (link.getLinkType() == MuLink.LinkType.COLLECTION) - label = new CollectionLinkLabel((CollectionMuLink)link, settings, false) + if (link.getLinkType() == MuLink.LinkType.FILE) { + label = new FileLinkLabel((FileMuLink) link, settings, false) + downloadButton.setToolTipText(trans("TOOLTIP_MULINK_PANEL_DOWNLOAD")) + } else if (link.getLinkType() == MuLink.LinkType.COLLECTION) { + label = new CollectionLinkLabel((CollectionMuLink) link, settings, false) + downloadButton.setToolTipText(trans("TOOLTIP_MULINK_PANEL_VIEW")) + } + label.setToolTipText(trans("TOOLTIP_MULINK_PANEL", link.getHost().getHumanReadableName())) add(label, BorderLayout.CENTER) - JButton button = new JButton() - button.setIcon(DOWN_ICON) - button.addActionListener({linkConsumer.accept(link)}) - add(button, BorderLayout.EAST) + def labelDim = label.getMaximumSize() double preferredY = labelDim.getHeight() - double preferredX = labelDim.getWidth() + DOWN_ICON.getIconWidth() + double preferredX = labelDim.getWidth() + DOWN_ICON.getIconWidth() + COPY_ICON.getIconWidth() Border border = BorderFactory.createEtchedBorder() setBorder(border) @@ -56,7 +76,7 @@ class MuLinkPanel extends JPanel { preferredY += insets.top preferredY += insets.bottom - preferredX += 20 + preferredX += 40 setMaximumSize([(int)preferredX, (int)preferredY] as Dimension) float alignmentY = 0.5f + (settings.fontSize * 1f / preferredY) / 2