1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 import java.beans.PropertyChangeEvent ; 13 import javax.swing.plaf.*; 14 import javax.swing.plaf.basic.BasicTextFieldUI ; 15 import javax.swing.text.*; 16 import javax.swing.*; 17 import javax.swing.plaf.UIResource ; 18 import sun.swing.DefaultLookup; 19 20 21 22 49 public class WindowsTextFieldUI extends BasicTextFieldUI 50 { 51 57 public static ComponentUI createUI(JComponent c) { 58 return new WindowsTextFieldUI(); 59 } 60 61 69 protected void paintBackground(Graphics g) { 70 super.paintBackground(g); 71 } 72 73 78 protected Caret createCaret() { 79 return new WindowsFieldCaret(); 80 } 81 82 86 static class WindowsFieldCaret extends DefaultCaret implements UIResource { 87 88 public WindowsFieldCaret() { 89 super(); 90 } 91 92 98 protected void adjustVisibility(Rectangle r) { 99 SwingUtilities.invokeLater(new SafeScroller(r)); 100 } 101 102 107 protected Highlighter.HighlightPainter getSelectionPainter() { 108 return WindowsTextUI.WindowsPainter; 109 } 110 111 112 private class SafeScroller implements Runnable { 113 SafeScroller(Rectangle r) { 114 this.r = r; 115 } 116 117 public void run() { 118 JTextField field = (JTextField) getComponent(); 119 if (field != null) { 120 TextUI ui = field.getUI(); 121 int dot = getDot(); 122 Position.Bias bias = Position.Bias.Forward; 124 Rectangle startRect = null; 125 try { 126 startRect = ui.modelToView(field, dot, bias); 127 } catch (BadLocationException ble) {} 128 BoundedRangeModel vis = field.getHorizontalVisibility(); 129 int x = r.x + vis.getValue(); 130 int quarterSpan = vis.getExtent() / 4; 131 if (x < vis.getValue()) { 132 vis.setValue(x - quarterSpan); 133 } else if (x > vis.getValue() + vis.getExtent()) { 134 vis.setValue(x - (3 * quarterSpan)); 135 } 136 if (startRect != null) { 141 try { 142 Rectangle endRect; 143 endRect = ui.modelToView(field, dot, bias); 144 if (endRect != null && !endRect.equals(startRect)){ 145 damage(endRect); 146 } 147 } catch (BadLocationException ble) {} 148 } 149 } 150 } 151 152 private Rectangle r; 153 } 154 } 155 156 } 157 158 | Popular Tags |