Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Mar 19, 2021
2 parents a988cc4 + 459cbbf commit 5edf16a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/featurecat/lizzie/gui/CommentPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public void mouseClicked(MouseEvent e) {
Lizzie.frame.getFocus();
Lizzie.frame.checkRightClick(e);
}

@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
Lizzie.frame.editComment();
}
}
});
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder());
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,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();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,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
mainPanel.enableInputMethods(false);

Input input = new Input();

mainPanel.addMouseListener(input);
Expand Down Expand Up @@ -1179,6 +1184,8 @@ public void onDoubleClicked(int x, int y) {
Lizzie.board.goToMoveNumberBeyondBranch(moveNumber);
}
}
} else if (Lizzie.config.showComment && commentRect.contains(x, y)) {
editComment();
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,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);
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/featurecat/lizzie/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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;
Expand All @@ -24,6 +28,8 @@
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.json.JSONObject;
Expand Down Expand Up @@ -210,6 +216,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();
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,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"));
Expand Down

0 comments on commit 5edf16a

Please sign in to comment.