Merge remote-tracking branch 'origin/GP-1428-dragonmacher-comment-dialog-enter-press--SQUASHED'

This commit is contained in:
Ryan Kurtz
2021-10-25 15:05:17 -04:00
2 changed files with 66 additions and 55 deletions
@@ -92,16 +92,7 @@
</OL> </OL>
</BLOCKQUOTE> </BLOCKQUOTE>
<BLOCKQUOTE>
<IMG src="../../shared/note.png" alt=""> <FONT size="4">If the <I><A name=
"Comments_Option"></A>Enter accepts comment</I> checkbox is selected, you can simply press
the <B>Enter</B> key to set the comment and close the dialog. When the checkbox is not
selected, the <B>Enter</B> key simply adds a new line to the current comment for a multiple
line comment.<BR>
</FONT>
</BLOCKQUOTE><BR>
<TABLE width="100%"> <TABLE width="100%">
<TBODY> <TBODY>
<TR> <TR>
@@ -110,6 +101,30 @@
</TBODY> </TBODY>
</TABLE> </TABLE>
<BLOCKQUOTE>
<P>
This dialog has the following keyboard shortcut behavior:
</P>
<UL>
<LI>
When the <I>Enter accepts comment</I> checkbox is not selected, pressing <B>Enter</B>
simply adds newlines to the text; when the checkbox is selected, pressing <B>Enter</B>
will close the dialog and accept the current text without adding a newline.
</LI>
<LI>
Pressing <B>Shift-Enter</B> will always insert a newline into the text
</LI>
<LI>
Pressing <B>Control-Enter</B> will always close the dialog, accepting the current text
</LI>
</UL>
</BLOCKQUOTE>
<BR>
<H2><A name="Delete_Comments"></A><B>Deleting Comments</B></H2> <H2><A name="Delete_Comments"></A><B>Deleting Comments</B></H2>
<BLOCKQUOTE> <BLOCKQUOTE>
@@ -20,7 +20,8 @@ import java.awt.event.*;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document; import javax.swing.text.Document;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
@@ -63,19 +64,13 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen
private boolean enterMode = false; private boolean enterMode = false;
private JCheckBox enterBox = new GCheckBox("Enter accepts comment", enterMode); private JCheckBox enterBox = new GCheckBox("Enter accepts comment", enterMode);
{ {
enterBox.addChangeListener(new ChangeListener() { enterBox.addChangeListener(e -> {
@Override enterMode = enterBox.isSelected();
public void stateChanged(ChangeEvent e) { plugin.updateOptions();
enterMode = enterBox.isSelected();
plugin.updateOptions();
}
}); });
} }
private JPopupMenu popup = new JPopupMenu(); private JPopupMenu popup = new JPopupMenu();
/**
* Constructor
*/
CommentsDialog(CommentsPlugin plugin) { CommentsDialog(CommentsPlugin plugin) {
super("Set Comments"); super("Set Comments");
setHelpLocation(new HelpLocation(plugin.getName(), "Comments")); setHelpLocation(new HelpLocation(plugin.getName(), "Comments"));
@@ -269,16 +264,13 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen
Arrays.sort(annotations); Arrays.sort(annotations);
GComboBox<AnnotationAdapterWrapper> annotationsComboBox = new GComboBox<>(annotations); GComboBox<AnnotationAdapterWrapper> annotationsComboBox = new GComboBox<>(annotations);
JButton addAnnotationButton = new JButton("Add Annotation"); JButton addAnnotationButton = new JButton("Add Annotation");
addAnnotationButton.addActionListener(new ActionListener() { addAnnotationButton.addActionListener(e -> {
@Override JTextArea currentTextArea = getSelectedTextArea();
public void actionPerformed(ActionEvent e) { AnnotationAdapterWrapper aaw =
JTextArea currentTextArea = getSelectedTextArea(); (AnnotationAdapterWrapper) annotationsComboBox.getSelectedItem();
AnnotationAdapterWrapper aaw = currentTextArea.insert(aaw.getPrototypeString(),
(AnnotationAdapterWrapper) annotationsComboBox.getSelectedItem(); currentTextArea.getCaretPosition());
currentTextArea.insert(aaw.getPrototypeString(), currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1);
currentTextArea.getCaretPosition());
currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1);
}
}); });
JPanel annoPanel = new JPanel(); JPanel annoPanel = new JPanel();
annoPanel.add(addAnnotationButton); annoPanel.add(addAnnotationButton);
@@ -360,30 +352,22 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen
tab.addTab(" Plate Comment ", new JScrollPane(plateField)); tab.addTab(" Plate Comment ", new JScrollPane(plateField));
tab.addTab(" Repeatable Comment ", new JScrollPane(repeatableField)); tab.addTab(" Repeatable Comment ", new JScrollPane(repeatableField));
tab.addChangeListener(new ChangeListener() { tab.addChangeListener(ev -> chooseFocus());
@Override
public void stateChanged(ChangeEvent ev) {
chooseFocus();
}
});
ActionListener addAnnotationAction = new ActionListener() { ActionListener addAnnotationAction = e -> {
@Override JTextArea currentTextArea = getSelectedTextArea();
public void actionPerformed(ActionEvent e) { for (AnnotationAdapterWrapper annotation : annotations) {
JTextArea currentTextArea = getSelectedTextArea(); if (annotation.toString().equals(e.getActionCommand())) {
for (int i = 0; i < annotations.length; i++) { currentTextArea.insert(annotation.getPrototypeString(),
if (annotations[i].toString().equals(e.getActionCommand())) { currentTextArea.getCaretPosition());
currentTextArea.insert(annotations[i].getPrototypeString(), currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1);
currentTextArea.getCaretPosition());
currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1);
}
} }
} }
}; };
JMenu insertMenu = new JMenu("Insert"); JMenu insertMenu = new JMenu("Insert");
for (int i = 0; i < annotations.length; i++) { for (AnnotationAdapterWrapper annotation : annotations) {
JMenuItem menuItem = new JMenuItem(annotations[i].toString()); JMenuItem menuItem = new JMenuItem(annotation.toString());
menuItem.addActionListener(addAnnotationAction); menuItem.addActionListener(addAnnotationAction);
insertMenu.add(menuItem); insertMenu.add(menuItem);
} }
@@ -466,14 +450,26 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
JTextArea textArea = (JTextArea) e.getSource(); JTextArea textArea = (JTextArea) e.getSource();
if (e.getKeyCode() != KeyEvent.VK_ENTER) {
return;
}
if (e.getKeyCode() == KeyEvent.VK_ENTER) { int modifiers = e.getModifiersEx();
if (e.isShiftDown() && enterMode) { if ((modifiers & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
textArea.append("\n"); textArea.replaceSelection("\n");
} e.consume();
else if (e.isShiftDown() != enterMode) { return;
okCallback(); }
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
okCallback(); // Control-Enter allows closes the dialog
e.consume();
return;
}
if (enterMode) {
e.consume();
okCallback();
} }
} }