Change how placeholder text is displayed and hidden (#64)

* Change how placeholder text is displayed and hidden
- based on the IntelliJ Platform UI Guidelines https://jetbrains.design/intellij/controls/input_field/#placeholder
- remove focus event and listener

* Remove color styling on input box text
This commit is contained in:
Michael Best 2023-03-28 17:31:02 -06:00 committed by GitHub
parent 87dbc42040
commit e3c748b0fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,23 +3,19 @@ package ee.carlrobert.codegpt.toolwindow.components;
import static ee.carlrobert.codegpt.util.SwingUtils.addShiftEnterInputMap;
import static ee.carlrobert.codegpt.util.SwingUtils.createIconButton;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBTextArea;
import com.intellij.util.ui.JBUI;
import icons.Icons;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JButton;
import javax.swing.JScrollPane;
public class TextArea extends JBTextArea {
public TextArea(Runnable onSubmit, JScrollPane textAreaScrollPane) {
super("Ask me anything...");
setForeground(JBColor.GRAY);
super();
getEmptyText().setText("Ask me anything...");
setMargin(JBUI.insets(5));
addFocusListener(getFocusListener());
addSubmitButton(onSubmit, textAreaScrollPane);
addShiftEnterInputMap(this, onSubmit);
}
@ -36,22 +32,4 @@ public class TextArea extends JBTextArea {
button.addActionListener(submitButtonListener);
return button;
}
private FocusListener getFocusListener() {
return new FocusListener() {
public void focusGained(FocusEvent e) {
if (getText().equals("Ask me anything...")) {
setText("");
setForeground(JBColor.BLACK);
}
}
public void focusLost(FocusEvent e) {
if (getText().isEmpty()) {
setForeground(JBColor.GRAY);
setText("Ask me anything...");
}
}
};
}
}