tooltips and option to copy chat links to clipboard

dbus-notify
Zlatin Balevsky 2022-08-07 15:42:08 +01:00
parent fdf4fdeaf4
commit 6d56c19583
No known key found for this signature in database
GPG Key ID: A72832072D525E41
3 changed files with 35 additions and 11 deletions

View File

@ -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.}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -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