41 |
import java.awt.Color; |
import java.awt.Color; |
42 |
import java.awt.FontMetrics; |
import java.awt.FontMetrics; |
43 |
import java.awt.Graphics; |
import java.awt.Graphics; |
44 |
|
import java.awt.Rectangle; |
45 |
import java.awt.Shape; |
import java.awt.Shape; |
46 |
|
|
47 |
import javax.swing.JPasswordField; |
import javax.swing.JPasswordField; |
212 |
/** |
/** |
213 |
* Provides a mapping from the document model coordinate space to the |
* Provides a mapping from the document model coordinate space to the |
214 |
* coordinate space of the view mapped to it. |
* coordinate space of the view mapped to it. |
215 |
* |
* |
216 |
|
* This method is overridden to provide a correct mapping with respect to the |
217 |
|
* echo char and not to the real content. |
218 |
|
* |
219 |
* @param pos - the position to convert >= 0 |
* @param pos - the position to convert >= 0 |
220 |
* @param a - the allocated region to render into |
* @param a - the allocated region to render into |
221 |
* @param b - typesafe enumeration to indicate bias to a position in the model. |
* @param b - typesafe enumeration to indicate bias to a position in the model. |
226 |
public Shape modelToView(int pos, Shape a, Position.Bias b) |
public Shape modelToView(int pos, Shape a, Position.Bias b) |
227 |
throws BadLocationException |
throws BadLocationException |
228 |
{ |
{ |
229 |
return super.modelToView(pos, a, b); |
Shape newAlloc = adjustAllocation(a); |
230 |
|
|
231 |
|
// Ensure metrics are up-to-date. |
232 |
|
updateMetrics(); |
233 |
|
|
234 |
|
// Get rectangle of the line containing position. |
235 |
|
int lineIndex = getElement().getElementIndex(pos); |
236 |
|
Rectangle rect = lineToRect(newAlloc, lineIndex); |
237 |
|
|
238 |
|
// Get the rectangle for position. |
239 |
|
Element line = getElement().getElement(lineIndex); |
240 |
|
int lineStart = line.getStartOffset(); |
241 |
|
Segment segment = getLineBuffer(); |
242 |
|
segment.array = new char[pos - lineStart]; |
243 |
|
char echoChar = getEchoChar(); |
244 |
|
for (int i = 0; i < segment.array.length; ++i) |
245 |
|
segment.array[i] = echoChar; |
246 |
|
segment.offset = 0; |
247 |
|
segment.count = segment.array.length; |
248 |
|
|
249 |
|
int xoffset = Utilities.getTabbedTextWidth(segment, metrics, rect.x, |
250 |
|
this, lineStart); |
251 |
|
|
252 |
|
// Calc the real rectangle. |
253 |
|
rect.x += xoffset; |
254 |
|
rect.width = 1; |
255 |
|
rect.height = metrics.getHeight(); |
256 |
|
|
257 |
|
return rect; |
258 |
} |
} |
259 |
|
|
260 |
/** |
/** |
271 |
*/ |
*/ |
272 |
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) |
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) |
273 |
{ |
{ |
274 |
|
// FIXME: This only provides a view->model mapping for the real text |
275 |
|
// content and does not respect the echo char. |
276 |
return super.viewToModel(fx, fy, a, bias); |
return super.viewToModel(fx, fy, a, bias); |
277 |
} |
} |
278 |
} |
} |