431 |
*/ |
*/ |
432 |
public int getBoundedPosition(GlyphView v, int p0, float x, float len) |
public int getBoundedPosition(GlyphView v, int p0, float x, float len) |
433 |
{ |
{ |
434 |
// TODO: Implement this properly. |
TabExpander te = v.getTabExpander(); |
435 |
throw new AssertionError("Not yet implemented."); |
Segment txt = v.getText(p0, v.getEndOffset()); |
436 |
|
Font font = v.getFont(); |
437 |
|
FontMetrics fm = v.getContainer().getFontMetrics(font); |
438 |
|
int pos = Utilities.getTabbedTextOffset(txt, fm, (int) x, |
439 |
|
(int) (x + len), te, p0, false); |
440 |
|
return pos; |
441 |
} |
} |
442 |
|
|
443 |
/** |
/** |
451 |
* |
* |
452 |
* @return the model location that represents the specified view location |
* @return the model location that represents the specified view location |
453 |
*/ |
*/ |
454 |
public int viewToModel(GlyphView v, float x, float y, Shape a, Bias[] biasRet) |
public int viewToModel(GlyphView v, float x, float y, Shape a, |
455 |
|
Bias[] biasRet) |
456 |
{ |
{ |
457 |
// TODO: Implement this properly. |
Rectangle b = a.getBounds(); |
458 |
throw new AssertionError("Not yet implemented."); |
assert b.contains(x, y) : "The coordinates are expected to be within the " |
459 |
|
+ "view's bounds: x=" + x + ", y=" + y |
460 |
|
+ "a=" + a; |
461 |
|
int pos = getBoundedPosition(v, v.getStartOffset(), b.x, x - b.x); |
462 |
|
return pos; |
463 |
} |
} |
464 |
} |
} |
465 |
|
|
560 |
View parent = getParent(); |
View parent = getParent(); |
561 |
if (parent instanceof TabExpander) |
if (parent instanceof TabExpander) |
562 |
tabEx = (TabExpander) parent; |
tabEx = (TabExpander) parent; |
|
// TODO: Figure out how to determine the x parameter. |
|
563 |
span = painter.getSpan(this, getStartOffset(), getEndOffset(), |
span = painter.getSpan(this, getStartOffset(), getEndOffset(), |
564 |
tabEx, 0.F); |
tabEx, 0.F); |
565 |
} |
} |
620 |
*/ |
*/ |
621 |
public TabExpander getTabExpander() |
public TabExpander getTabExpander() |
622 |
{ |
{ |
|
// TODO: Figure out if this is correct. |
|
623 |
TabExpander te = null; |
TabExpander te = null; |
624 |
View parent = getParent(); |
View parent = getParent(); |
625 |
|
|
626 |
if (parent instanceof ParagraphView) |
if (parent instanceof TabExpander) |
627 |
te = (ParagraphView) parent; |
te = (TabExpander) parent; |
628 |
|
|
629 |
return te; |
return te; |
630 |
} |
} |
672 |
} |
} |
673 |
|
|
674 |
/** |
/** |
|
* Returns the starting offset in the document model of the portion |
|
|
* of text that this view is responsible for. |
|
|
* |
|
|
* @return the starting offset in the document model of the portion |
|
|
* of text that this view is responsible for |
|
|
*/ |
|
|
public int getBeginIndex() |
|
|
{ |
|
|
return getElement().getStartOffset(); |
|
|
} |
|
|
|
|
|
/** |
|
675 |
* Returns the start offset in the document model of the portion |
* Returns the start offset in the document model of the portion |
676 |
* of text that this view is responsible for. |
* of text that this view is responsible for. |
677 |
* |
* |
891 |
if (goodBreakLocation != BreakIterator.DONE) |
if (goodBreakLocation != BreakIterator.DONE) |
892 |
breakLocation = goodBreakLocation; |
breakLocation = goodBreakLocation; |
893 |
|
|
894 |
GlyphView brokenView = (GlyphView) clone(); |
View brokenView = createFragment(p0, breakLocation); |
|
brokenView.startOffset = p0; |
|
|
brokenView.endOffset = breakLocation; |
|
895 |
return brokenView; |
return brokenView; |
896 |
} |
} |
897 |
|
|
898 |
|
/** |
899 |
|
* Determines how well the specified view location is suitable for inserting |
900 |
|
* a line break. If <code>axis</code> is <code>View.Y_AXIS</code>, then |
901 |
|
* this method forwards to the superclass, if <code>axis</code> is |
902 |
|
* <code>View.X_AXIS</code> then this method returns |
903 |
|
* {@link View#ExcellentBreakWeight} if there is a suitable break location |
904 |
|
* (usually whitespace) within the specified view span, or |
905 |
|
* {@link View#GoodBreakWeight} if not. |
906 |
|
* |
907 |
|
* @param axis the axis along which the break weight is requested |
908 |
|
* @param pos the starting view location |
909 |
|
* @param len the length of the span at which the view should be broken |
910 |
|
* |
911 |
|
* @return the break weight |
912 |
|
*/ |
913 |
public int getBreakWeight(int axis, float pos, float len) |
public int getBreakWeight(int axis, float pos, float len) |
914 |
{ |
{ |
915 |
// FIXME: Implement me. |
int weight; |
916 |
throw new AssertionError("Not yet implemented."); |
if (axis == Y_AXIS) |
917 |
|
weight = super.getBreakWeight(axis, pos, len); |
918 |
|
else |
919 |
|
{ |
920 |
|
// Determine the model locations at pos and pos + len. |
921 |
|
int spanX = (int) getPreferredSpan(X_AXIS); |
922 |
|
int spanY = (int) getPreferredSpan(Y_AXIS); |
923 |
|
Rectangle dummyAlloc = new Rectangle(0, 0, spanX, spanY); |
924 |
|
Position.Bias[] biasRet = new Position.Bias[1]; |
925 |
|
int offset1 = viewToModel(pos, spanY / 2, dummyAlloc, biasRet); |
926 |
|
int offset2 = viewToModel(pos, spanY / 2, dummyAlloc, biasRet); |
927 |
|
Segment txt = getText(offset1, offset2); |
928 |
|
BreakIterator lineBreaker = BreakIterator.getLineInstance(); |
929 |
|
lineBreaker.setText(txt); |
930 |
|
int breakLoc = lineBreaker.previous(); |
931 |
|
if (breakLoc == offset1) |
932 |
|
weight = View.BadBreakWeight; |
933 |
|
else if(breakLoc == BreakIterator.DONE) |
934 |
|
weight = View.GoodBreakWeight; |
935 |
|
else |
936 |
|
weight = View.ExcellentBreakWeight; |
937 |
|
} |
938 |
|
return weight; |
939 |
} |
} |
940 |
|
|
941 |
|
/** |
942 |
|
* Receives notification that some text attributes have changed within the |
943 |
|
* text fragment that this view is responsible for. This calls |
944 |
|
* {@link View#preferenceChanged(View, boolean, boolean)} on the parent for |
945 |
|
* both width and height. |
946 |
|
* |
947 |
|
* @param e the document event describing the change; not used here |
948 |
|
* @param a the view allocation on screen; not used here |
949 |
|
* @param vf the view factory; not used here |
950 |
|
*/ |
951 |
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf) |
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf) |
952 |
{ |
{ |
953 |
// FIXME: Implement me. |
getParent().preferenceChanged(this, true, true); |
|
throw new AssertionError("Not yet implemented."); |
|
954 |
} |
} |
955 |
|
|
956 |
|
/** |
957 |
|
* Receives notification that some text has been inserted within the |
958 |
|
* text fragment that this view is responsible for. This calls |
959 |
|
* {@link View#preferenceChanged(View, boolean, boolean)} on the parent for |
960 |
|
* width. |
961 |
|
* |
962 |
|
* @param e the document event describing the change; not used here |
963 |
|
* @param a the view allocation on screen; not used here |
964 |
|
* @param vf the view factory; not used here |
965 |
|
*/ |
966 |
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory vf) |
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory vf) |
967 |
{ |
{ |
968 |
// FIXME: Implement me. |
getParent().preferenceChanged(this, true, false); |
|
throw new AssertionError("Not yet implemented."); |
|
969 |
} |
} |
970 |
|
|
971 |
|
/** |
972 |
|
* Receives notification that some text has been removed within the |
973 |
|
* text fragment that this view is responsible for. This calls |
974 |
|
* {@link View#preferenceChanged(View, boolean, boolean)} on the parent for |
975 |
|
* width. |
976 |
|
* |
977 |
|
* @param e the document event describing the change; not used here |
978 |
|
* @param a the view allocation on screen; not used here |
979 |
|
* @param vf the view factory; not used here |
980 |
|
*/ |
981 |
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf) |
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf) |
982 |
{ |
{ |
983 |
// FIXME: Implement me. |
getParent().preferenceChanged(this, true, false); |
|
throw new AssertionError("Not yet implemented."); |
|
984 |
} |
} |
985 |
|
|
986 |
|
/** |
987 |
|
* Creates a fragment view of this view that starts at <code>p0</code> and |
988 |
|
* ends at <code>p1</code>. |
989 |
|
* |
990 |
|
* @param p0 the start location for the fragment view |
991 |
|
* @param p1 the end location for the fragment view |
992 |
|
* |
993 |
|
* @return the fragment view |
994 |
|
*/ |
995 |
public View createFragment(int p0, int p1) |
public View createFragment(int p0, int p1) |
996 |
{ |
{ |
997 |
// FIXME: Implement me. |
GlyphView fragment = (GlyphView) clone(); |
998 |
throw new AssertionError("Not yet implemented."); |
fragment.startOffset = p0; |
999 |
|
fragment.endOffset = p1; |
1000 |
|
return fragment; |
1001 |
} |
} |
1002 |
|
|
1003 |
/** |
/** |