下面列出了javax.swing.text.View#X_AXIS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int getBreakWeight(int axis, float pos, float len) {
// return GoodBreakWeight;
if (axis == View.X_AXIS) {
checkPainter();
int p0 = getStartOffset();
int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
if (p1 == p0) {
// can't even fit a single character
return View.BadBreakWeight;
}
try {
// if the view contains line break char return forced break
String text = getDocument().getText(p0, p1 - p0);
if (text.indexOf(WrapHTMLFactory.SEPARATOR) >= 0) {
return View.ForcedBreakWeight;
}
} catch (BadLocationException ex) {
// should never happen
}
}
return super.getBreakWeight(axis, pos, len);
}
public View breakView(int axis, int p0, float pos, float len) {
if (axis == View.X_AXIS) {
checkPainter();
int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
try {
// if the view contains line break char break the view
int index = getDocument().getText(p0, p1 - p0).indexOf(WrapHTMLFactory.SEPARATOR);
if (index >= 0) {
GlyphView v = (GlyphView)createFragment(p0, p0 + index + 1);
return v;
}
} catch (BadLocationException ex) {
// should never happen
}
}
return super.breakView(axis, p0, pos, len);
}
@Override
public float getPreferredSpan(int axis) {
// Although the width could be e.g. 1 return a default width of a character
// since if caret is blinking over the newline character and the caret
// is in overwrite mode then this will make the caret fully visible.
DocumentView documentView = getDocumentView();
if (axis == View.X_AXIS) {
return (documentView != null)
? (documentView.op.isNonPrintableCharactersVisible()
? documentView.op.getNewlineCharTextLayout().getAdvance()
: documentView.op.getDefaultCharWidth())
: 1; // Only return one if not connected to view hierarchy
} else {
return (documentView != null) ? documentView.op.getDefaultRowHeight() : 1;
}
}
/**
* Determines if a point falls before an allocated region.
*
* @param x
* the X coordinate >= 0
* @param y
* the Y coordinate >= 0
* @param innerAlloc
* the allocated region; this is the area inside of the insets
* @return true if the point lies before the region else false
*/
@Override
protected boolean isBefore(int x, int y, Rectangle innerAlloc)
{
// System.err.println("isBefore: " + innerAlloc + " my bounds " +
// box.getAbsoluteBounds());
// System.err.println("XY: " + x + " : " + y);
innerAlloc.setBounds(box.getAbsoluteBounds());
if (majorAxis == View.X_AXIS)
{
return (x < innerAlloc.x);
}
else
{
return (y < innerAlloc.y);
}
}
@Override
public float getMinimumSpan(int axis) {
switch (axis) {
case View.X_AXIS:
return 0;
case View.Y_AXIS:
return super.getMinimumSpan(axis);
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
@Override
public float getMinimumSpan(int axis)
{
switch (axis)
{
case View.X_AXIS:
return 0;
case View.Y_AXIS:
return super.getMinimumSpan(axis);
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
@Override
public float getMinimumSpan(int axis)
{
switch (axis)
{
case View.X_AXIS:
return 0;
case View.Y_AXIS:
return super.getMinimumSpan(axis);
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
@Override
public float getPreferredSpan(int axis) {
DocumentView docView = getDocumentView();
return (axis == View.X_AXIS)
? width // Return last width computed by getTabbedSpan()
: ((docView != null) ? docView.op.getDefaultRowHeight() : 0f);
}
public ViewLayoutState selectLayoutMajorAxis(int majorAxis) {
// assert ViewUtilities.isAxisValid(majorAxis);
if (majorAxis == View.X_AXIS) {
setStatusBits(X_MAJOR_AXIS_BIT);
} else { // y axis
clearStatusBits(X_MAJOR_AXIS_BIT);
}
return this;
}
public static String axisToString(int axis) {
switch (axis) {
case View.X_AXIS:
return "x"; // NOI18N
case View.Y_AXIS:
return "y"; // NOI18N
default:
return "<invalid-axis-value=" + axis + ">"; // NOI18N
}
}
/**
* Construct a composite box view over the given element.
*
* @param elem the element of the model to represent.
* @param majorAxis the axis to tile along. This can be
* either X_AXIS or Y_AXIS.
*/
public GapBoxView(Element elem, int majorAxis) {
super(elem);
if (majorAxis == View.X_AXIS) {
setStatusBits(X_MAJOR_AXIS_BIT);
} // by default there should be no bits set
}
@Override
public float getMinimumSpan( int axis )
{
switch ( axis )
{
case View.X_AXIS:
return 0;
case View.Y_AXIS:
return super.getMinimumSpan( axis );
default:
throw new IllegalArgumentException( "Invalid axis: " + axis );
}
}
public ViewLayoutState selectLayoutMajorAxis(int axis) {
// assert ViewUtilities.isAxisValid(axis);
if (axis == View.X_AXIS) {
setStatusBits(X_MAJOR_AXIS_BIT);
} else { // y axis
clearStatusBits(X_MAJOR_AXIS_BIT);
}
return this;
}
@Override
public float getPreferredSpan(int axis) {
return (axis == View.X_AXIS) ? width : height;
}
/**
* Determines the preferred span for this view along an
* axis.
*
* @param axis may be either X_AXIS or Y_AXIS
* @return the span the view would like to be rendered into;
* typically the view is told to render into the span
* that is returned, although there is no guarantee;
* the parent may choose to resize or break the view
*/
public float getPreferredSpan(int axis) {
sync();
// If the attributes specified a width/height, always use it!
if (axis == View.X_AXIS && (state & WIDTH_FLAG) == WIDTH_FLAG) {
getPreferredSpanFromAltView(axis);
return width + leftInset + rightInset;
}
if (axis == View.Y_AXIS && (state & HEIGHT_FLAG) == HEIGHT_FLAG) {
getPreferredSpanFromAltView(axis);
return height + topInset + bottomInset;
}
Image image = getImage();
if (image != null) {
switch (axis) {
case View.X_AXIS:
return width + leftInset + rightInset;
case View.Y_AXIS:
return height + topInset + bottomInset;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
else {
View view = getAltView();
float retValue = 0f;
if (view != null) {
retValue = view.getPreferredSpan(axis);
}
switch (axis) {
case View.X_AXIS:
return retValue + (float)(width + leftInset + rightInset);
case View.Y_AXIS:
return retValue + (float)(height + topInset + bottomInset);
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
}
protected final int getMajorAxis() {
return isXMajorAxis() ? View.X_AXIS : View.Y_AXIS;
}
protected final int getMajorAxis() {
return isXMajorAxis() ? View.X_AXIS : View.Y_AXIS;
}
/**
* Determines the preferred span for this view along an
* axis.
*
* @param axis may be either X_AXIS or Y_AXIS
* @return the span the view would like to be rendered into;
* typically the view is told to render into the span
* that is returned, although there is no guarantee;
* the parent may choose to resize or break the view
*/
public float getPreferredSpan(int axis) {
sync();
// If the attributes specified a width/height, always use it!
if (axis == View.X_AXIS && (state & WIDTH_FLAG) == WIDTH_FLAG) {
getPreferredSpanFromAltView(axis);
return width + leftInset + rightInset;
}
if (axis == View.Y_AXIS && (state & HEIGHT_FLAG) == HEIGHT_FLAG) {
getPreferredSpanFromAltView(axis);
return height + topInset + bottomInset;
}
Image image = getImage();
if (image != null) {
switch (axis) {
case View.X_AXIS:
return width + leftInset + rightInset;
case View.Y_AXIS:
return height + topInset + bottomInset;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
else {
View view = getAltView();
float retValue = 0f;
if (view != null) {
retValue = view.getPreferredSpan(axis);
}
switch (axis) {
case View.X_AXIS:
return retValue + (float)(width + leftInset + rightInset);
case View.Y_AXIS:
return retValue + (float)(height + topInset + bottomInset);
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
}
protected final int getLayoutStateMajorAxis() {
return (isStatusBitsNonZero(LAYOUT_STATE_X_MAJOR_AXIS_BIT))
? View.X_AXIS
: View.Y_AXIS;
}
/**
* Fetch the major axis (the axis the children
* are tiled along). This will have a value of
* either X_AXIS or Y_AXIS.
*/
public final int getMajorAxis() {
return isXMajorAxis() ? View.X_AXIS : View.Y_AXIS;
}