本文整理汇总了Java中javax.swing.text.TabExpander类的典型用法代码示例。如果您正苦于以下问题:Java TabExpander类的具体用法?Java TabExpander怎么用?Java TabExpander使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TabExpander类属于javax.swing.text包,在下文中一共展示了TabExpander类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPositionAbove
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given
* view location in the row above. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
*
* @param c the editor
* @param offs the offset in the document >= 0
* @param x the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static int getPositionAbove(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView)e;
Token token = tov.getTokenListForPhysicalLineAbove(offs);
if (token==null) {
return -1;
}
else if (token.getType()==Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be >0 ??
return c.getLineStartOffset(line-1);
}
else {
return token.getListOffset(c, e, c.getMargin().left, x);
}
}
示例2: getPositionBelow
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given
* view location in the row below. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
*
* @param c the editor
* @param offs the offset in the document >= 0
* @param x the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static int getPositionBelow(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView)e;
Token token = tov.getTokenListForPhysicalLineBelow(offs);
if (token==null) {
return -1;
}
else if (token.getType()==Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be > c.getLineCount()-1 ??
// return c.getLineStartOffset(line+1);
FoldManager fm = c.getFoldManager();
line = fm.getVisibleLineBelow(line);
return c.getLineStartOffset(line);
}
else {
return token.getListOffset(c, e, c.getMargin().left, x);
}
}
示例3: getPositionAbove
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given
* view location in the row above. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
*
* @param c the editor
* @param offs the offset in the document >= 0
* @param x the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static final int getPositionAbove(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView)e;
Token token = tov.getTokenListForPhysicalLineAbove(offs);
if (token==null)
return -1;
// A line containing only Token.NULL is an empty line.
else if (token.getType()==Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be >0 ??
return c.getLineStartOffset(line-1);
}
else {
return token.getListOffset(c, e, c.getMargin().left, x);
}
}
示例4: getPositionBelow
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given
* view location in the row below. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
*
* @param c the editor
* @param offs the offset in the document >= 0
* @param x the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static final int getPositionBelow(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView)e;
Token token = tov.getTokenListForPhysicalLineBelow(offs);
if (token==null)
return -1;
// A line containing only Token.NULL is an empty line.
else if (token.getType()==Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be > c.getLineCount()-1 ??
// return c.getLineStartOffset(line+1);
FoldManager fm = c.getFoldManager();
line = fm.getVisibleLineBelow(line);
return c.getLineStartOffset(line);
}
else {
return token.getListOffset(c, e, c.getMargin().left, x);
}
}
示例5: getPositionAbove
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given view location in the row above. The component
* given must have a size to compute the result. If the component doesn't have a size a value of -1 will be
* returned.
*
* @param c
* the editor
* @param offs
* the offset in the document >= 0
* @param x
* the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
* @exception BadLocationException
* if the offset is out of range
*/
public static final int getPositionAbove(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView) e;
Token token = tov.getTokenListForPhysicalLineAbove(offs);
if (token == null)
return -1;
// A line containing only Token.NULL is an empty line.
else if (token.type == Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be >0 ??
return c.getLineStartOffset(line - 1);
}
else {
return token.getListOffset(c, e, 0, x);
}
}
示例6: getPositionBelow
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given view location in the row below. The component
* given must have a size to compute the result. If the component doesn't have a size a value of -1 will be
* returned.
*
* @param c
* the editor
* @param offs
* the offset in the document >= 0
* @param x
* the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
* @exception BadLocationException
* if the offset is out of range
*/
public static final int getPositionBelow(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView) e;
Token token = tov.getTokenListForPhysicalLineBelow(offs);
if (token == null)
return -1;
// A line containing only Token.NULL is an empty line.
else if (token.type == Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be > c.getLineCount()-1 ??
return c.getLineStartOffset(line + 1);
}
else {
return token.getListOffset(c, e, 0, x);
}
}
示例7: drawText
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Draw text. This can directly call the Utilities.drawTabbedText.
* Sub-classes can override this method to provide any other decorations.
* @param segment - the source of the text
* @param x - the X origin >= 0
* @param y - the Y origin >= 0
* @param graphics - the graphics context
* @param e - how to expand the tabs. If this value is null, tabs will be
* expanded as a space character.
* @param startOffset - starting offset of the text in the document >= 0
* @return
*/
public int drawText(Segment segment, int x, int y,
Graphics graphics, TabExpander e, int startOffset) {
graphics.setFont(graphics.getFont().deriveFont(getFontStyle()));
FontMetrics fontMetrics = graphics.getFontMetrics();
int a = fontMetrics.getAscent();
int h = a + fontMetrics.getDescent();
//JPEXS: UniTools for multi fonts
int w = UniTools.getTabbedTextWidth(graphics,segment,0, e, startOffset);
int rX = x - 1;
int rY = y - a;
int rW = w + 2;
int rH = h;
if ((getFontStyle() & 0x10) != 0) {
graphics.setColor(Color.decode("#EEEEEE"));
graphics.fillRect(rX, rY, rW, rH);
}
graphics.setColor(getColor());
//JPEXS: UniTools for multi fonts
x = UniTools.drawTabbedText(segment, x, y, graphics, e, startOffset);
if ((getFontStyle() & 0x8) != 0) {
graphics.setColor(Color.RED);
graphics.drawRect(rX, rY, rW, rH);
}
return x;
}
示例8: getTabbedTextOffset
import javax.swing.text.TabExpander; //导入依赖的package包/类
public static int getTabbedTextOffset(Segment segment, FontMetrics metrics, int tabBase,int x,TabExpander e, int startOffset){
List<Segment> segments=new ArrayList<Segment>();
List<Boolean> unis=new ArrayList<Boolean>();
Font origFont=metrics.getFont();
getSegments(origFont, segment, segments, unis);
Graphics g=new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getGraphics();
Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());
int ofs=0;
int totalto = 0;
for(int i=0;i<segments.size();i++){
Segment seg=segments.get(i);
FontMetrics fm=unis.get(i)?g.getFontMetrics(uniFont):metrics;
int to = Utilities.getTabbedTextOffset(seg, fm, tabBase+ofs,x, e, startOffset);
totalto += to;
ofs+=fm.stringWidth(seg.toString());
if(to<seg.length()){
break;
}
}
return totalto;
}
示例9: drawTabbedText
import javax.swing.text.TabExpander; //导入依赖的package包/类
public static int drawTabbedText(Segment segment, int x, int y, Graphics g, TabExpander e, int startOffset){
List<Segment> segments=new ArrayList<Segment>();
List<Boolean> unis=new ArrayList<Boolean>();
getSegments(g.getFont(), segment, segments, unis);
Font origFont=g.getFont();
Font uniFont = defaultUniFont.deriveFont(origFont.getStyle(),origFont.getSize2D());
int ret=x;
int pos=0;
for(int i=0;i<segments.size();i++){
Segment seg=segments.get(i);
if(unis.get(i)){
g.setFont(uniFont);
}else{
g.setFont(origFont);
}
ret = Utilities.drawTabbedText(seg, ret, y, g, e, startOffset+pos);
pos += seg.length();
}
g.setFont(origFont);
return ret;
}
示例10: getBreakLocation
import javax.swing.text.TabExpander; //导入依赖的package包/类
public static final int getBreakLocation(final Segment s,
final FontMetrics fm,
final int start,
final int end,
final TabExpander t,
final int pos) {
int offset = s.offset;
int index = TextUtils.getTabbedTextOffset(s, fm, start, end, t, pos,
false);
int fullIndex = offset + index;
BreakIterator bi = BreakIterator.getWordInstance();
bi.setText(s);
if (bi.last() <= fullIndex) {
return bi.last() - offset;
}
if (bi.isBoundary(fullIndex)) {
return Character.isWhitespace(s.array[fullIndex])
? index + 1 : index;
}
int prev = bi.preceding(fullIndex);
if (prev == bi.first()) {
return index;
}
return prev - offset;
}
示例11: drawText
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Draw text. This can directly call the Utilities.drawTabbedText.
* Sub-classes can override this method to provide any other decorations.
*
* @param segment - the source of the text
* @param x - the X origin >= 0
* @param y - the Y origin >= 0
* @param graphics - the graphics context
* @param e - how to expand the tabs. If this value is null, tabs will be
* expanded as a space character.
* @param startOffset - starting offset of the text in the document >= 0
* @return
*/
public int drawText(Segment segment, int x, int y,
Graphics graphics, TabExpander e, int startOffset) {
graphics.setFont(graphics.getFont().deriveFont(getFontStyle()));
FontMetrics fontMetrics = graphics.getFontMetrics();
int a = fontMetrics.getAscent();
int h = a + fontMetrics.getDescent();
int w = Utilities.getTabbedTextWidth(segment, fontMetrics, 0, e, startOffset);
int rX = x - 1;
int rY = y - a;
int rW = w + 2;
int rH = h;
if ((getFontStyle() & 0x10) != 0) {
graphics.setColor(Color.decode("#EEEEEE"));
graphics.fillRect(rX, rY, rW, rH);
}
graphics.setColor(getColor());
x = Utilities.drawTabbedText(segment, x, y, graphics, e, startOffset);
if ((getFontStyle() & 0x8) != 0) {
graphics.setColor(Color.RED);
graphics.drawRect(rX, rY, rW, rH);
}
return x;
}
示例12: getPositionAbove
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given
* view location in the row above. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
*
* @param c the editor
* @param offs the offset in the document >= 0
* @param x the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static final int getPositionAbove(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView)e;
Token token = tov.getTokenListForPhysicalLineAbove(offs);
if (token==null)
return -1;
// A line containing only Token.NULL is an empty line.
else if (token.type==Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be >0 ??
return c.getLineStartOffset(line-1);
}
else {
return token.getListOffset(c, e, 0, x);
}
}
示例13: getPositionBelow
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Determines the position in the model that is closest to the given
* view location in the row below. The component given must have a
* size to compute the result. If the component doesn't have a size
* a value of -1 will be returned.
*
* @param c the editor
* @param offs the offset in the document >= 0
* @param x the X coordinate >= 0
* @return the position >= 0 if the request can be computed, otherwise
* a value of -1 will be returned.
* @exception BadLocationException if the offset is out of range
*/
public static final int getPositionBelow(RSyntaxTextArea c, int offs,
float x, TabExpander e) throws BadLocationException {
TokenOrientedView tov = (TokenOrientedView)e;
Token token = tov.getTokenListForPhysicalLineBelow(offs);
if (token==null)
return -1;
// A line containing only Token.NULL is an empty line.
else if (token.type==Token.NULL) {
int line = c.getLineOfOffset(offs); // Sure to be > c.getLineCount()-1 ??
// return c.getLineStartOffset(line+1);
FoldManager fm = c.getFoldManager();
line = fm.getVisibleLineBelow(line);
return c.getLineStartOffset(line);
}
else {
return token.getListOffset(c, e, 0, x);
}
}
示例14: getTabbedSpan
import javax.swing.text.TabExpander; //导入依赖的package包/类
@Override
public float getTabbedSpan(float x, TabExpander e) {
int offset = getStartOffset();
int endOffset = offset + getLength();
float tabX = e.nextTabStop(x, offset++);
firstTabWidth = tabX - x;
while (offset < endOffset) {
tabX = e.nextTabStop(tabX, offset++);
}
width = tabX - x;
return width;
}
示例15: paintSyntaxLine
import javax.swing.text.TabExpander; //导入依赖的package包/类
/**
* Paints the specified line onto the graphics context. Note that this method munges the offset
* and count values of the segment.
*
* @param line
* The line segment
* @param tokens
* The token list for the line
* @param styles
* The syntax style list
* @param expander
* The tab expander used to determine tab stops. May be null
* @param gfx
* The graphics context
* @param x
* The x co-ordinate
* @param y
* The y co-ordinate
* @return The x co-ordinate, plus the width of the painted string
*/
public static int paintSyntaxLine(Segment line, Token tokens, SyntaxStyle[] styles, TabExpander expander, Graphics gfx,
int x, int y) {
Font defaultFont = gfx.getFont();
Color defaultColor = gfx.getColor();
int offset = 0;
for (;;) {
byte id = tokens.id;
if (id == Token.END) {
break;
}
int length = tokens.length;
if (id == Token.NULL) {
if (!defaultColor.equals(gfx.getColor())) {
gfx.setColor(defaultColor);
}
if (!defaultFont.equals(gfx.getFont())) {
gfx.setFont(defaultFont);
}
} else {
styles[id].setGraphicsFlags(gfx, defaultFont);
}
line.count = length;
x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0);
line.offset += length;
offset += length;
tokens = tokens.next;
}
return x;
}