From 00014ca96f93d0d2c1f1acd67521c4956380a4ed Mon Sep 17 00:00:00 2001 From: MUEDSA <7676275+muedsa@users.noreply.github.com> Date: Wed, 21 Dec 2022 09:59:34 +0800 Subject: [PATCH] update: tool window editor disable --- .../intellij/textReader/ui/ReaderWindow.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/muedsa/intellij/textReader/ui/ReaderWindow.java b/src/main/java/com/muedsa/intellij/textReader/ui/ReaderWindow.java index 0396229..aec74ed 100644 --- a/src/main/java/com/muedsa/intellij/textReader/ui/ReaderWindow.java +++ b/src/main/java/com/muedsa/intellij/textReader/ui/ReaderWindow.java @@ -32,10 +32,7 @@ import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import java.awt.*; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; +import java.awt.event.*; import java.io.IOException; import java.util.Objects; import java.util.Vector; @@ -113,6 +110,47 @@ public ReaderWindow(Project project) { } private void createUIComponents(){ + //编辑器 禁止编辑 显示光标 WASD键改为方向键 + textContent.setEditable(false); + textContent.setCursor(new Cursor(Cursor.TEXT_CURSOR)); + textContent.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + JTextPane textPane = (JTextPane) e.getComponent(); + textPane.getCaret().setVisible(true); + } + + @Override + public void focusLost(FocusEvent e) { + JTextPane textPane = (JTextPane) e.getComponent(); + textPane.getCaret().setVisible(false); + } + }); + + textContent.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + switch (e.getKeyChar()){ + case 'w': + e.setKeyCode(KeyEvent.VK_UP); + e.setKeyChar('\uFFFF'); + break; + case 'a': + e.setKeyCode(KeyEvent.VK_LEFT); + e.setKeyChar('\uFFFF'); + break; + case 's': + e.setKeyCode(KeyEvent.VK_DOWN); + e.setKeyChar('\uFFFF'); + break; + case 'd': + e.setKeyCode(KeyEvent.VK_RIGHT); + e.setKeyChar('\uFFFF'); + break; + } + } + }); + //字体 String[] fontFamilyNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel<>(fontFamilyNames);