Skip to content

Commit

Permalink
copy message to clipboard #2143
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Nov 9, 2023
1 parent b0d8574 commit a8ba59d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,15 @@ You should also get your employer (if you work as a programmer) or school,
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.apache.log4j.Logger;
Expand All @@ -699,6 +703,8 @@ You should also get your employer (if you work as a programmer) or school,
public class CalloutPanelComponent extends javax.swing.JPanel {

private static final Logger log = Logger.getLogger(CalloutPanelComponent.class.getName());
private static final ImageIcon ICON_COPY=new javax.swing.ImageIcon(CalloutPanelComponent.class.getResource("/icons16/material/baseline_content_copy_lightgrey_48dp.png"));
private static final ImageIcon ICON_DELETE=new javax.swing.ImageIcon(CalloutPanelComponent.class.getResource("/icons16/material/baseline_delete_lightgrey_48dp.png"));

private static int READ = 10;
private static int UNREAD = 20;
Expand All @@ -708,7 +714,9 @@ public class CalloutPanelComponent extends javax.swing.JPanel {
private int indicatorY = 10;
private int indicatorSize = 15;
private int deleteX=1000;
private int deleteY=20;
private int deleteY=10;
private int copyX=1000;
private int copyY=10;
private Font defaultFont = null;
private Font defaultFontBold = null;
private Font miniFont = null;
Expand Down Expand Up @@ -776,12 +784,18 @@ public void mouseClicked(MouseEvent e) {
return;

}
if (e.getX() >= (deleteX-15) && e.getX() <= deleteX + 20
&& e.getY() >= (deleteY-15) && e.getY() <= deleteY + 20) {
if (e.getX() >= (deleteX) && e.getX() <= deleteX + 20
&& e.getY() >= (deleteY) && e.getY() <= deleteY + 20) {
deleteMessage(message.getId());

}
if (e.getX() >= (copyX) && e.getX() <= copyX + 20
&& e.getY() >= (copyY) && e.getY() <= copyY + 20) {
copyMessageToClipboard();
}
}


});

addMouseMotionListener(new MouseAdapter() {
Expand All @@ -793,15 +807,27 @@ public void mouseMoved(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
return;
}
if (e.getX() >= (deleteX-15) && e.getX() <= deleteX + 20
&& e.getY() >= (deleteY-15) && e.getY() <= deleteY + 20) {
if (e.getX() >= (deleteX) && e.getX() <= deleteX + 20
&& e.getY() >= (deleteY) && e.getY() <= deleteY + 20) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
return;
}
if (e.getX() >= (copyX) && e.getX() <= copyX + 20
&& e.getY() >= (copyY) && e.getY() <= copyY + 20) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
return;
}
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
});
}

private void copyMessageToClipboard() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(this.message.getContent());
clipboard.setContents(strSel, null);
}

private void updateTooltip() {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -911,7 +937,7 @@ protected void paintComponent(Graphics g) {

// Calculate wrapped text
FontMetrics metrics = g2d.getFontMetrics();
int messageWidth = width - 90; // Adjusted for padding
int messageWidth = width - 130; // Adjusted for padding
//int yOffset = height / 2;
int yOffset = 10 + metrics.getHeight();
int lineSpacing = metrics.getHeight();
Expand Down Expand Up @@ -969,10 +995,16 @@ protected void paintComponent(Graphics g) {
}

// delete button
this.deleteX=width-60;
g2d.setFont(miniFont.deriveFont(defaultFont.getStyle() | java.awt.Font.BOLD));
g2d.setColor(DefaultColorTheme.COLOR_LIGHT_GREY);
g2d.drawString("x", this.deleteX,this.deleteY); // Timestamp position
this.deleteX=width-70;
// g2d.setFont(miniFont.deriveFont(defaultFont.getStyle() | java.awt.Font.BOLD));
// g2d.setColor(DefaultColorTheme.COLOR_LIGHT_GREY);
// g2d.drawString("x", this.deleteX,this.deleteY); // Timestamp position

// delete icon
ICON_DELETE.paintIcon(this, g2d, this.deleteX, this.deleteY);
// copy icon
this.copyX=this.deleteX-20;
ICON_COPY.paintIcon(this, g2d, this.copyX, this.copyY);

this.setPreferredSize(new Dimension(width, yOffset + lineSpacing));
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a8ba59d

Please sign in to comment.