mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
8 changed files with 90 additions and 166 deletions
@ -0,0 +1,63 @@ |
|||||||
|
/* |
||||||
|
* MIT License |
||||||
|
* |
||||||
|
* Copyright (c) 2020 Jannis Weis |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
* of this software and associated documentation files (the "Software"), to deal |
||||||
|
* in the Software without restriction, including without limitation the rights |
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
* copies of the Software, and to permit persons to whom the Software is |
||||||
|
* furnished to do so, subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
* SOFTWARE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
package com.github.weisj.darklaf.ui.text.action; |
||||||
|
|
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.KeyEvent; |
||||||
|
|
||||||
|
import javax.swing.text.Caret; |
||||||
|
import javax.swing.text.DefaultEditorKit; |
||||||
|
import javax.swing.text.JTextComponent; |
||||||
|
|
||||||
|
import com.github.weisj.darklaf.ui.text.DarkCaret; |
||||||
|
|
||||||
|
public class DarkKeyTypedAction extends DefaultEditorKit.DefaultKeyTypedAction { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void actionPerformed(final ActionEvent e) { |
||||||
|
JTextComponent target = getTextComponent(e); |
||||||
|
if ((target != null) && (e != null)) { |
||||||
|
if ((!target.isEditable()) || (!target.isEnabled())) { |
||||||
|
return; |
||||||
|
} |
||||||
|
String content = e.getActionCommand(); |
||||||
|
Caret c = target.getCaret(); |
||||||
|
if (c instanceof DarkCaret) { |
||||||
|
boolean isDelete = !content.isEmpty(); |
||||||
|
if (isDelete) { |
||||||
|
char key = content.charAt(0); |
||||||
|
isDelete = key == KeyEvent.VK_DELETE || key == KeyEvent.VK_BACK_SPACE; |
||||||
|
} |
||||||
|
if (((DarkCaret) c).isInsertMode()) { |
||||||
|
((DarkCaret) c).setExpandMode(!isDelete); |
||||||
|
} |
||||||
|
super.actionPerformed(e); |
||||||
|
((DarkCaret) c).setExpandMode(false); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
super.actionPerformed(e); |
||||||
|
} |
||||||
|
} |
@ -1,76 +0,0 @@ |
|||||||
/* |
|
||||||
* MIT License |
|
||||||
* |
|
||||||
* Copyright (c) 2020 Jannis Weis |
|
||||||
* |
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||||
* of this software and associated documentation files (the "Software"), to deal |
|
||||||
* in the Software without restriction, including without limitation the rights |
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||||
* copies of the Software, and to permit persons to whom the Software is |
|
||||||
* furnished to do so, subject to the following conditions: |
|
||||||
* |
|
||||||
* The above copyright notice and this permission notice shall be included in all |
|
||||||
* copies or substantial portions of the Software. |
|
||||||
* |
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
||||||
* SOFTWARE. |
|
||||||
* |
|
||||||
*/ |
|
||||||
package com.github.weisj.darklaf.ui.text.action; |
|
||||||
|
|
||||||
import java.awt.event.ActionEvent; |
|
||||||
|
|
||||||
import javax.swing.*; |
|
||||||
import javax.swing.text.*; |
|
||||||
|
|
||||||
public class DeleteNextCharAction extends DarkTextAction { |
|
||||||
|
|
||||||
public DeleteNextCharAction() { |
|
||||||
super(DefaultEditorKit.deleteNextCharAction); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void actionPerformed(final ActionEvent e) { |
|
||||||
JTextComponent target = getTextComponent(e); |
|
||||||
setupDeleteMode(target, true); |
|
||||||
boolean beep = true; |
|
||||||
if ((target != null) && (target.isEditable())) { |
|
||||||
try { |
|
||||||
Document doc = target.getDocument(); |
|
||||||
Caret caret = target.getCaret(); |
|
||||||
int dot = caret.getDot(); |
|
||||||
int mark = caret.getMark(); |
|
||||||
if (dot != mark) { |
|
||||||
doc.remove(Math.min(dot, mark), Math.abs(dot - mark)); |
|
||||||
beep = false; |
|
||||||
} else if (dot < doc.getLength()) { |
|
||||||
int delChars = 1; |
|
||||||
|
|
||||||
if (dot < doc.getLength() - 1) { |
|
||||||
String dotChars = doc.getText(dot, 2); |
|
||||||
char c0 = dotChars.charAt(0); |
|
||||||
char c1 = dotChars.charAt(1); |
|
||||||
|
|
||||||
if (c0 >= '\uD800' && c0 <= '\uDBFF' && |
|
||||||
c1 >= '\uDC00' && c1 <= '\uDFFF') { |
|
||||||
delChars = 2; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
doc.remove(dot, delChars); |
|
||||||
beep = false; |
|
||||||
} |
|
||||||
} catch (BadLocationException ignored) {} |
|
||||||
} |
|
||||||
if (beep) { |
|
||||||
UIManager.getLookAndFeel().provideErrorFeedback(target); |
|
||||||
} |
|
||||||
setupDeleteMode(target, false); |
|
||||||
} |
|
||||||
} |
|
@ -1,76 +0,0 @@ |
|||||||
/* |
|
||||||
* MIT License |
|
||||||
* |
|
||||||
* Copyright (c) 2020 Jannis Weis |
|
||||||
* |
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||||
* of this software and associated documentation files (the "Software"), to deal |
|
||||||
* in the Software without restriction, including without limitation the rights |
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||||
* copies of the Software, and to permit persons to whom the Software is |
|
||||||
* furnished to do so, subject to the following conditions: |
|
||||||
* |
|
||||||
* The above copyright notice and this permission notice shall be included in all |
|
||||||
* copies or substantial portions of the Software. |
|
||||||
* |
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
||||||
* SOFTWARE. |
|
||||||
* |
|
||||||
*/ |
|
||||||
package com.github.weisj.darklaf.ui.text.action; |
|
||||||
|
|
||||||
import java.awt.event.ActionEvent; |
|
||||||
|
|
||||||
import javax.swing.*; |
|
||||||
import javax.swing.text.*; |
|
||||||
|
|
||||||
public class DeletePreviousCharAction extends DarkTextAction { |
|
||||||
|
|
||||||
public DeletePreviousCharAction() { |
|
||||||
super(DefaultEditorKit.deletePrevCharAction); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void actionPerformed(final ActionEvent e) { |
|
||||||
JTextComponent target = getTextComponent(e); |
|
||||||
setupDeleteMode(target, true); |
|
||||||
boolean beep = true; |
|
||||||
if ((target != null) && (target.isEditable())) { |
|
||||||
try { |
|
||||||
Document doc = target.getDocument(); |
|
||||||
Caret caret = target.getCaret(); |
|
||||||
int dot = caret.getDot(); |
|
||||||
int mark = caret.getMark(); |
|
||||||
if (dot != mark) { |
|
||||||
doc.remove(Math.min(dot, mark), Math.abs(dot - mark)); |
|
||||||
beep = false; |
|
||||||
} else if (dot > 0) { |
|
||||||
int delChars = 1; |
|
||||||
|
|
||||||
if (dot > 1) { |
|
||||||
String dotChars = doc.getText(dot - 2, 2); |
|
||||||
char c0 = dotChars.charAt(0); |
|
||||||
char c1 = dotChars.charAt(1); |
|
||||||
|
|
||||||
if (c0 >= '\uD800' && c0 <= '\uDBFF' && |
|
||||||
c1 >= '\uDC00' && c1 <= '\uDFFF') { |
|
||||||
delChars = 2; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
doc.remove(dot - delChars, delChars); |
|
||||||
beep = false; |
|
||||||
} |
|
||||||
} catch (BadLocationException ignored) {} |
|
||||||
} |
|
||||||
if (beep) { |
|
||||||
UIManager.getLookAndFeel().provideErrorFeedback(target); |
|
||||||
} |
|
||||||
setupDeleteMode(target, false); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue