140 if ((pos >= p0) && (pos <= p1)) {
141 // determine range to the left of the position
142 text = v.getText(p0, pos);
143 int[] justificationData = getJustificationData(v);
144 int width = Utilities.getTabbedTextWidth(v, text, metrics, alloc.x, expander, p0,
145 justificationData);
146 SegmentCache.releaseSharedSegment(text);
147 return new Rectangle(alloc.x + width, alloc.y, 0, metrics.getHeight());
148 }
149 throw new BadLocationException("modelToView - can't convert", p1);
150 }
151
152 /**
153 * Provides a mapping from the view coordinate space to the logical
154 * coordinate space of the model.
155 *
156 * @param v the view containing the view coordinates
157 * @param x the X coordinate
158 * @param y the Y coordinate
159 * @param a the allocated region to render into
160 * @param biasReturn always returns <code>Position.Bias.Forward</code>
161 * as the zero-th element of this array
162 * @return the location within the model that best represents the
163 * given point in the view
164 * @see View#viewToModel
165 */
166 public int viewToModel(GlyphView v, float x, float y, Shape a,
167 Position.Bias[] biasReturn) {
168
169 sync(v);
170 Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
171 int p0 = v.getStartOffset();
172 int p1 = v.getEndOffset();
173 TabExpander expander = v.getTabExpander();
174 Segment text = v.getText(p0, p1);
175 int[] justificationData = getJustificationData(v);
176 int offs = Utilities.getTabbedTextOffset(v, text, metrics,
177 alloc.x, (int) x, expander, p0,
178 justificationData);
179 SegmentCache.releaseSharedSegment(text);
180 int retValue = p0 + offs;
|
140 if ((pos >= p0) && (pos <= p1)) {
141 // determine range to the left of the position
142 text = v.getText(p0, pos);
143 int[] justificationData = getJustificationData(v);
144 int width = Utilities.getTabbedTextWidth(v, text, metrics, alloc.x, expander, p0,
145 justificationData);
146 SegmentCache.releaseSharedSegment(text);
147 return new Rectangle(alloc.x + width, alloc.y, 0, metrics.getHeight());
148 }
149 throw new BadLocationException("modelToView - can't convert", p1);
150 }
151
152 /**
153 * Provides a mapping from the view coordinate space to the logical
154 * coordinate space of the model.
155 *
156 * @param v the view containing the view coordinates
157 * @param x the X coordinate
158 * @param y the Y coordinate
159 * @param a the allocated region to render into
160 * @param biasReturn always returns {@code Position.Bias.Forward}
161 * as the zero-th element of this array
162 * @return the location within the model that best represents the
163 * given point in the view
164 * @see View#viewToModel
165 */
166 public int viewToModel(GlyphView v, float x, float y, Shape a,
167 Position.Bias[] biasReturn) {
168
169 sync(v);
170 Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
171 int p0 = v.getStartOffset();
172 int p1 = v.getEndOffset();
173 TabExpander expander = v.getTabExpander();
174 Segment text = v.getText(p0, p1);
175 int[] justificationData = getJustificationData(v);
176 int offs = Utilities.getTabbedTextOffset(v, text, metrics,
177 alloc.x, (int) x, expander, p0,
178 justificationData);
179 SegmentCache.releaseSharedSegment(text);
180 int retValue = p0 + offs;
|