-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed /u/PisuCat's Windows error, started implementing inventory hints
- Loading branch information
1 parent
8e022cd
commit da4842c
Showing
4 changed files
with
77 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/com/eshimoniak/conlangstudio/ui/panels/editor/HintingTextArea.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.eshimoniak.conlangstudio.ui.panels.editor; | ||
|
||
import java.awt.Color; | ||
import java.awt.Font; | ||
import java.awt.Graphics; | ||
import java.awt.Toolkit; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.KeyEvent; | ||
|
||
import javax.swing.AbstractAction; | ||
import javax.swing.ActionMap; | ||
import javax.swing.InputMap; | ||
import javax.swing.JComponent; | ||
import javax.swing.JTextArea; | ||
import javax.swing.KeyStroke; | ||
import javax.swing.event.UndoableEditEvent; | ||
import javax.swing.event.UndoableEditListener; | ||
import javax.swing.text.Document; | ||
import javax.swing.undo.CannotUndoException; | ||
import javax.swing.undo.UndoManager; | ||
|
||
public class HintingTextArea extends JTextArea { | ||
private UndoManager undoManager; | ||
|
||
public HintingTextArea() { | ||
InputMap im = getInputMap(JComponent.WHEN_FOCUSED); | ||
ActionMap am = getActionMap(); | ||
|
||
undoManager = new UndoManager(); | ||
Document doc = getDocument(); | ||
doc.addUndoableEditListener(new UndoableEditListener() { | ||
@Override | ||
public void undoableEditHappened(UndoableEditEvent e) { | ||
undoManager.addEdit(e.getEdit()); | ||
} | ||
}); | ||
|
||
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 16)); | ||
|
||
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "Undo"); | ||
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "Redo"); | ||
|
||
am.put("Undo", new AbstractAction() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
if (undoManager.canUndo()) { | ||
undoManager.undo(); | ||
} | ||
} catch (CannotUndoException exp) { | ||
exp.printStackTrace(); | ||
} | ||
} | ||
}); | ||
am.put("Redo", new AbstractAction() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
if (undoManager.canRedo()) { | ||
undoManager.redo(); | ||
} | ||
} catch (CannotUndoException exp) { | ||
exp.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters