1 7 package com.sun.java.swing.plaf.motif; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 12 import javax.swing.*; 13 import javax.swing.text.*; 14 import javax.swing.plaf.*; 15 16 30 public class MotifTextUI { 31 32 38 public static Caret createCaret() { 39 return new MotifCaret(); 40 } 41 42 52 public static class MotifCaret extends DefaultCaret implements UIResource { 53 54 63 public void focusGained(FocusEvent e) { 64 super.focusGained(e); 65 getComponent().repaint(); 66 } 67 68 76 public void focusLost(FocusEvent e) { 77 super.focusLost(e); 78 getComponent().repaint(); 79 } 80 81 89 protected void damage(Rectangle r) { 90 if (r != null) { 91 x = r.x - IBeamOverhang - 1; 92 y = r.y; 93 width = r.width + (2 * IBeamOverhang) + 3; 94 height = r.height; 95 repaint(); 96 } 97 } 98 99 109 public void paint(Graphics g) { 110 if(isVisible()) { 111 try { 112 JTextComponent c = getComponent(); 113 Color fg = c.hasFocus() ? c.getCaretColor() : 114 c.getDisabledTextColor(); 115 TextUI mapper = c.getUI(); 116 int dot = getDot(); 117 Rectangle r = mapper.modelToView(c, dot); 118 int x0 = r.x - IBeamOverhang; 119 int x1 = r.x + IBeamOverhang; 120 int y0 = r.y + 1; 121 int y1 = r.y + r.height - 2; 122 g.setColor(fg); 123 g.drawLine(r.x, y0, r.x, y1); 124 g.drawLine(x0, y0, x1, y0); 125 g.drawLine(x0, y1, x1, y1); 126 } catch (BadLocationException e) { 127 } 130 } 131 } 132 133 static final int IBeamOverhang = 2; 134 } 135 136 139 static final JTextComponent.KeyBinding[] defaultBindings = { 140 new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 141 InputEvent.CTRL_MASK), 142 DefaultEditorKit.copyAction), 143 new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 144 InputEvent.SHIFT_MASK), 145 DefaultEditorKit.pasteAction), 146 new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 147 InputEvent.SHIFT_MASK), 148 DefaultEditorKit.cutAction), 149 new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 150 InputEvent.SHIFT_MASK), 151 DefaultEditorKit.selectionBackwardAction), 152 new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 153 InputEvent.SHIFT_MASK), 154 DefaultEditorKit.selectionForwardAction), 155 }; 156 157 158 } 159 | Popular Tags |