50 |
import java.awt.datatransfer.Transferable; |
import java.awt.datatransfer.Transferable; |
51 |
import java.awt.datatransfer.UnsupportedFlavorException; |
import java.awt.datatransfer.UnsupportedFlavorException; |
52 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
53 |
import java.awt.event.InputMethodListener; |
import java.awt.event.InputMethodListener; |
54 |
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
55 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
72 |
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
73 |
import javax.swing.Scrollable; |
import javax.swing.Scrollable; |
74 |
import javax.swing.SwingConstants; |
import javax.swing.SwingConstants; |
|
import javax.swing.Timer; |
|
75 |
import javax.swing.TransferHandler; |
import javax.swing.TransferHandler; |
76 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
77 |
import javax.swing.event.CaretEvent; |
import javax.swing.event.CaretEvent; |
302 |
} |
} |
303 |
|
|
304 |
/** |
/** |
|
* The timer that lets the caret blink. |
|
|
*/ |
|
|
private class CaretBlinkTimer extends Timer implements ActionListener |
|
|
{ |
|
|
/** |
|
|
* Creates a new CaretBlinkTimer object with a default delay of 1 second. |
|
|
*/ |
|
|
public CaretBlinkTimer() |
|
|
{ |
|
|
super(1000, null); |
|
|
addActionListener(this); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Lets the caret blink. |
|
|
*/ |
|
|
public void actionPerformed(ActionEvent ev) |
|
|
{ |
|
|
Caret c = caret; |
|
|
if (c != null) |
|
|
c.setVisible(!c.isVisible()); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Updates the blink delay according to the current caret. |
|
|
*/ |
|
|
public void update() |
|
|
{ |
|
|
stop(); |
|
|
Caret c = caret; |
|
|
if (c != null) |
|
|
{ |
|
|
setDelay(c.getBlinkRate()); |
|
|
if (editable) |
|
|
start(); |
|
|
else |
|
|
c.setVisible(false); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
305 |
* According to <a |
* According to <a |
306 |
* href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">this |
* href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">this |
307 |
* report</a>, a pair of private classes wraps a {@link |
* report</a>, a pair of private classes wraps a {@link |
657 |
private char focusAccelerator = '\0'; |
private char focusAccelerator = '\0'; |
658 |
private NavigationFilter navigationFilter; |
private NavigationFilter navigationFilter; |
659 |
|
|
|
private CaretBlinkTimer caretBlinkTimer; |
|
|
|
|
660 |
/** |
/** |
661 |
* Get a Keymap from the global keymap table, by name. |
* Get a Keymap from the global keymap table, by name. |
662 |
* |
* |
914 |
creatingKeymap = true; |
creatingKeymap = true; |
915 |
} |
} |
916 |
|
|
|
caretBlinkTimer = new CaretBlinkTimer(); |
|
|
|
|
917 |
setFocusable(true); |
setFocusable(true); |
918 |
setEditable(true); |
setEditable(true); |
919 |
enableEvents(AWTEvent.KEY_EVENT_MASK); |
enableEvents(AWTEvent.KEY_EVENT_MASK); |
1152 |
if (editable == newValue) |
if (editable == newValue) |
1153 |
return; |
return; |
1154 |
|
|
|
if (newValue == true) |
|
|
caretBlinkTimer.start(); |
|
|
else |
|
|
{ |
|
|
caretBlinkTimer.stop(); |
|
|
caret.setVisible(false); |
|
|
} |
|
|
|
|
1155 |
boolean oldValue = editable; |
boolean oldValue = editable; |
1156 |
editable = newValue; |
editable = newValue; |
1157 |
firePropertyChange("editable", oldValue, newValue); |
firePropertyChange("editable", oldValue, newValue); |
1180 |
Caret oldCaret = caret; |
Caret oldCaret = caret; |
1181 |
caret = newCaret; |
caret = newCaret; |
1182 |
|
|
|
caretBlinkTimer.update(); |
|
|
|
|
1183 |
if (caret != null) |
if (caret != null) |
1184 |
caret.install(this); |
caret.install(this); |
1185 |
|
|