From 81c774fcf40341bd2b8cce93b5d408801fc3e90a Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 26 Jul 2017 14:48:43 -0700 Subject: [PATCH] Add copy pasting to history. --- src/org/nwapw/abacus/window/Window.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/org/nwapw/abacus/window/Window.java b/src/org/nwapw/abacus/window/Window.java index 62ab4ad..cfbcd8f 100644 --- a/src/org/nwapw/abacus/window/Window.java +++ b/src/org/nwapw/abacus/window/Window.java @@ -6,6 +6,9 @@ import org.nwapw.abacus.tree.TreeNode; import javax.swing.*; import java.awt.*; +import java.awt.datatransfer.StringSelection; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; /** * The main UI window for the calculator. @@ -177,5 +180,17 @@ public class Window extends JFrame { lastOutputArea.setText(lastOutput); inputField.setText(lastOutput); }); + historyTable.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + Point clickPoint = e.getPoint(); + if(e.getClickCount() == 2){ + int row = historyTable.rowAtPoint(clickPoint); + int column = historyTable.columnAtPoint(clickPoint); + String toCopy = historyTable.getValueAt(row, column).toString(); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(toCopy), null); + } + } + }); } }