From b0263e29c85898440294c1aefa4c1258ced851c6 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Tue, 9 Mar 2021 22:09:32 +0900 Subject: [PATCH 1/4] Copy comment to clipboard by Ctrl-Shift-C for #806 --- src/main/java/featurecat/lizzie/gui/Input.java | 4 +++- .../java/featurecat/lizzie/gui/MainFrame.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/featurecat/lizzie/gui/Input.java b/src/main/java/featurecat/lizzie/gui/Input.java index bd5298a41..21a3291ee 100644 --- a/src/main/java/featurecat/lizzie/gui/Input.java +++ b/src/main/java/featurecat/lizzie/gui/Input.java @@ -391,7 +391,9 @@ public void keyPressed(KeyEvent e) { break; case VK_C: - if (controlIsPressed(e)) { + if (controlIsPressed(e) && e.isShiftDown()) { + Lizzie.frame.copyCommentToClipboard(); + } else if (controlIsPressed(e)) { Lizzie.frame.copySgf(); } else { Lizzie.config.toggleCoordinates(); diff --git a/src/main/java/featurecat/lizzie/gui/MainFrame.java b/src/main/java/featurecat/lizzie/gui/MainFrame.java index d3074ef09..5c138aa44 100644 --- a/src/main/java/featurecat/lizzie/gui/MainFrame.java +++ b/src/main/java/featurecat/lizzie/gui/MainFrame.java @@ -12,6 +12,10 @@ import java.awt.FontFormatException; import java.awt.HeadlessException; import java.awt.LayoutManager; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.io.File; @@ -155,6 +159,18 @@ public void addSuggestionAsBranch() {} public abstract void pasteSgf(); + public void copyCommentToClipboard() { + String comment = Lizzie.board.getHistory().getData().comment; + if (comment.isEmpty()) return; + try { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable transferableString = new StringSelection(comment); + clipboard.setContents(transferableString, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void setPlayers(String whitePlayer, String blackPlayer) { playerTitle = String.format("(%s [W] vs %s [B])", whitePlayer, blackPlayer); updateTitle(); From 145e18d7b58cdacccbbaa851a42076603d035d4f Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Tue, 9 Mar 2021 22:09:32 +0900 Subject: [PATCH 2/4] Edit comment by double-click on comment area for #806 --- .../featurecat/lizzie/gui/CommentPane.java | 7 +++++++ .../featurecat/lizzie/gui/LizzieFrame.java | 2 ++ .../java/featurecat/lizzie/gui/MainFrame.java | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/main/java/featurecat/lizzie/gui/CommentPane.java b/src/main/java/featurecat/lizzie/gui/CommentPane.java index b3a42bb28..15c13eb13 100644 --- a/src/main/java/featurecat/lizzie/gui/CommentPane.java +++ b/src/main/java/featurecat/lizzie/gui/CommentPane.java @@ -76,6 +76,13 @@ public CommentPane(LizzieMain owner) { public void mouseClicked(MouseEvent e) { Lizzie.frame.getFocus(); } + + @Override + public void mousePressed(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + Lizzie.frame.editComment(); + } + } }); scrollPane = new JScrollPane(); scrollPane.setBorder(BorderFactory.createEmptyBorder()); diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index 434828245..db535c23f 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -1186,6 +1186,8 @@ public void onDoubleClicked(int x, int y) { Lizzie.board.goToMoveNumberBeyondBranch(moveNumber); } } + } else if (Lizzie.config.showComment && commentRect.contains(x, y)) { + editComment(); } } diff --git a/src/main/java/featurecat/lizzie/gui/MainFrame.java b/src/main/java/featurecat/lizzie/gui/MainFrame.java index 5c138aa44..69c91ea12 100644 --- a/src/main/java/featurecat/lizzie/gui/MainFrame.java +++ b/src/main/java/featurecat/lizzie/gui/MainFrame.java @@ -27,6 +27,8 @@ import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.filechooser.FileNameExtensionFilter; import org.json.JSONObject; @@ -159,6 +161,25 @@ public void addSuggestionAsBranch() {} public abstract void pasteSgf(); + public void editComment() { + String oldComment = Lizzie.board.getHistory().getData().comment; + // https://stackoverflow.com/questions/7765478/how-to-add-text-area-on-joptionpane + // https://stackoverflow.com/a/55678093 + JTextArea textArea = new JTextArea(oldComment); + textArea.setColumns(40); + textArea.setRows(20); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + textArea.setSize(textArea.getPreferredSize().width, textArea.getPreferredSize().height); + int ret = + JOptionPane.showConfirmDialog( + null, new JScrollPane(textArea), "Comment", JOptionPane.OK_CANCEL_OPTION); + if (ret == JOptionPane.OK_OPTION) { + Lizzie.board.getHistory().getData().comment = textArea.getText(); + refresh(); + } + } + public void copyCommentToClipboard() { String comment = Lizzie.board.getHistory().getData().comment; if (comment.isEmpty()) return; From 9b53d938ad536090ffb0871cfdd589ed0b473b11 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Tue, 9 Mar 2021 22:09:32 +0900 Subject: [PATCH 3/4] Add "Edit/Copy comment" into Game menu --- src/main/java/featurecat/lizzie/gui/Menu.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/featurecat/lizzie/gui/Menu.java b/src/main/java/featurecat/lizzie/gui/Menu.java index 7985e9f88..8c3e5225b 100644 --- a/src/main/java/featurecat/lizzie/gui/Menu.java +++ b/src/main/java/featurecat/lizzie/gui/Menu.java @@ -1162,6 +1162,29 @@ public void actionPerformed(ActionEvent e) { } }); gameMenu.add(pass); + + gameMenu.addSeparator(); + + final JMenuItem editComment = new JMenuItem("Edit comment"); + editComment.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Lizzie.frame.editComment(); + } + }); + gameMenu.add(editComment); + + final JMenuItem copyComment = new JMenuItem("Copy comment(Ctrl+Shift+C)"); + copyComment.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Lizzie.frame.copyCommentToClipboard(); + } + }); + gameMenu.add(copyComment); + gameMenu.addSeparator(); final JMenuItem clearBoard = new JMenuItem(resourceBundle.getString("Menu.game.clearBoard")); From 459cbbf0a93bd44f689a6a64d26c1b6b6c4f4aa7 Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Wed, 17 Mar 2021 20:54:10 +0900 Subject: [PATCH 4/4] Avoid IME issue after "Edit comment" in #880 --- src/main/java/featurecat/lizzie/gui/LizzieFrame.java | 5 +++++ src/main/java/featurecat/lizzie/gui/LizzieMain.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index db535c23f..94292dba1 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -221,6 +221,11 @@ protected void paintComponent(Graphics g) { createBufferStrategy(2); bs = getBufferStrategy(); + // avoid IME issue + // https://github.com/featurecat/lizzie/pull/880#issuecomment-800804632 + // https://github.com/yzyray/lizzie_adv/commit/e5e8be01b4e072615250e4c4cc8462938b7c0332 + mainPanel.enableInputMethods(false); + Input input = new Input(); mainPanel.addMouseListener(input); diff --git a/src/main/java/featurecat/lizzie/gui/LizzieMain.java b/src/main/java/featurecat/lizzie/gui/LizzieMain.java index 5c03a9e44..e620cdbd5 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieMain.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieMain.java @@ -230,6 +230,11 @@ protected void paintComponent(Graphics g) { setVisible(true); + // avoid IME issue + // https://github.com/featurecat/lizzie/pull/880#issuecomment-800804632 + // https://github.com/yzyray/lizzie_adv/commit/e5e8be01b4e072615250e4c4cc8462938b7c0332 + enableInputMethods(false); + input = new Input(); // addMouseListener(input); addKeyListener(input);