1 19 20 package org.netbeans.editor.view.spi; 21 22 import java.awt.Container ; 23 import java.awt.Graphics ; 24 import java.awt.Point ; 25 import java.awt.Shape ; 26 import javax.swing.text.BadLocationException ; 27 import javax.swing.text.Caret ; 28 import javax.swing.text.JTextComponent ; 29 import javax.swing.text.Position ; 30 import javax.swing.text.Segment ; 31 import javax.swing.text.TabExpander ; 32 import javax.swing.text.View ; 33 34 56 57 public abstract class ViewRenderingContext { 58 59 63 public static synchronized ViewRenderingContext obtainContext(View v) { 64 return null; 66 } 67 68 public abstract float getSpan(View v, int p0, int p1, TabExpander e, float x); 69 70 public abstract float getHeight(View v); 71 72 public abstract float getAscent(View v); 73 74 public abstract float getDescent(View v); 75 76 79 public abstract void paint(View v, Graphics g, Shape a, int p0, int p1); 80 81 94 public abstract Shape modelToView(View v, 95 int pos, Position.Bias bias, 96 Shape a) throws BadLocationException ; 97 98 110 public abstract int viewToModel(View v, 111 float x, float y, Shape a, 112 Position.Bias [] biasReturn); 113 114 133 public abstract int getBoundedPosition(View v, int p0, float x, float len); 134 135 154 public int getNextVisualPositionFrom(View v, int pos, Position.Bias b, Shape a, 155 int direction, 156 Position.Bias [] biasRet) 157 throws BadLocationException { 158 159 int startOffset = v.getStartOffset(); 160 int endOffset = v.getEndOffset(); 161 Segment text; 162 163 switch (direction) { 164 case View.NORTH: 165 case View.SOUTH: 166 if (pos != -1) { 167 return -1; 171 } 172 Container container = v.getContainer(); 173 174 if (container instanceof JTextComponent ) { 175 Caret c = ((JTextComponent )container).getCaret(); 176 Point magicPoint; 177 magicPoint = (c != null) ? c.getMagicCaretPosition() :null; 178 179 if (magicPoint == null) { 180 biasRet[0] = Position.Bias.Forward; 181 return startOffset; 182 } 183 int value = v.viewToModel(magicPoint.x, 0f, a, biasRet); 184 return value; 185 } 186 break; 187 case View.EAST: 188 if(startOffset == v.getDocument().getLength()) { 189 if(pos == -1) { 190 biasRet[0] = Position.Bias.Forward; 191 return startOffset; 192 } 193 return -1; 196 } 197 if(pos == -1) { 198 biasRet[0] = Position.Bias.Forward; 199 return startOffset; 200 } 201 if(pos == endOffset) { 202 return -1; 203 } 204 if(++pos == endOffset) { 205 return -1; 208 } 209 else { 210 biasRet[0] = Position.Bias.Forward; 211 } 212 return pos; 213 case View.WEST: 214 if(startOffset == v.getDocument().getLength()) { 215 if(pos == -1) { 216 biasRet[0] = Position.Bias.Forward; 217 return startOffset; 218 } 219 return -1; 222 } 223 if(pos == -1) { 224 biasRet[0] = Position.Bias.Forward; 227 return endOffset - 1; 228 } 229 if(pos == startOffset) { 230 return -1; 231 } 232 biasRet[0] = Position.Bias.Forward; 233 return (pos - 1); 234 default: 235 throw new IllegalArgumentException ("Bad direction: " + direction); } 237 return pos; 238 239 } 240 241 } 242 | Popular Tags |