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 00000000..47b6c5a3 Binary files /dev/null and b/gui/griffon-app/resources/copy.png differ 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