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/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/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index 434828245..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); @@ -1186,6 +1191,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/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); diff --git a/src/main/java/featurecat/lizzie/gui/MainFrame.java b/src/main/java/featurecat/lizzie/gui/MainFrame.java index d3074ef09..69c91ea12 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; @@ -23,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; @@ -155,6 +161,37 @@ 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; + 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(); 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"));