本文整理匯總了Java中javax.swing.text.Utilities.drawTabbedText方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.drawTabbedText方法的具體用法?Java Utilities.drawTabbedText怎麽用?Java Utilities.drawTabbedText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.Utilities
的用法示例。
在下文中一共展示了Utilities.drawTabbedText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNPE
import javax.swing.text.Utilities; //導入方法依賴的package包/類
private static void testNPE() {
Graphics g = null;
try {
String test = "\ttest\ttest2";
BufferedImage buffImage = new BufferedImage(
100, 100, BufferedImage.TYPE_INT_RGB);
g = buffImage.createGraphics();
Segment segment = new Segment(test.toCharArray(), 0, test.length());
Utilities.drawTabbedText(segment, 0, 0, g, null, 0);
} finally {
if (g != null) {
g.dispose();
}
}
}
示例2: paintPlainLine
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected void paintPlainLine(Graphics gfx, int line, Font defaultFont,
Color defaultColor, int x, int y)
{
paintHighlight(gfx,line,y);
textArea.getLineText(line,currentLine);
gfx.setFont(defaultFont);
gfx.setColor(defaultColor);
y += fm.getHeight();
x = Utilities.drawTabbedText(currentLine,x,y,gfx,this,0);
if(eolMarkers)
{
gfx.setColor(eolMarkerColor);
gfx.drawString(".",x,y);
}
}
示例3: drawTabbedText
import javax.swing.text.Utilities; //導入方法依賴的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;
}
示例4: drawText
import javax.swing.text.Utilities; //導入方法依賴的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;
}
示例5: drawText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
private int drawText(Graphics g,
int x, int y,
int startOffset, int endOffset,
boolean error,
boolean selected,
DocElement docElem) throws BadLocationException {
Segment s = EventQueue.isDispatchThread() ? SEGMENT : new Segment();
s.array = docElem.getChars();
s.offset = startOffset - docElem.offset;
s.count = endOffset - startOffset;
g.setColor(getColor(error, selected));
return Utilities.drawTabbedText(s, x, y, g, this, startOffset);
}
示例6: paintSyntaxLine
import javax.swing.text.Utilities; //導入方法依賴的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;
}
示例7: paintPlainLine
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected void paintPlainLine(Graphics gfx, int line, Font defaultFont, Color defaultColor, int x, int y) {
paintHighlight(gfx, line, y);
textArea.getLineText(line, currentLine);
gfx.setFont(defaultFont);
gfx.setColor(defaultColor);
y += fm.getHeight();
x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0);
if (eolMarkers) {
gfx.setColor(eolMarkerColor);
gfx.drawString(".", x, y);
}
}
示例8: drawColoredText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
private int drawColoredText(Graphics g, int x, int y, TabExpander ex, Document doc,
int p0, int p1, Element elem) throws BadLocationException {
final Segment s = new Segment();
doc.getText(p0, p1 - p0, s);
g.setColor(getColor(elem));
final Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
return Utilities.drawTabbedText(s, x, y, g, ex, p0);
}
示例9: paintSyntaxLine
import javax.swing.text.Utilities; //導入方法依賴的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();
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;
tokens = tokens.next;
}
return x;
}
示例10: paintSyntaxLine
import javax.swing.text.Utilities; //導入方法依賴的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;
}
示例11: drawUnselectedText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int drawUnselectedText(Graphics g, int x, int y,int p0, int p1) throws BadLocationException
{
int stLine = p0;// findStartOfLine(p0, getDocument());
int enLine = p1;// findEndOfLine(p1-1, getDocument());
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
// x+= getLeftInset();
// System.out.println("p0 = "+p0+", p1 = "+p1+", st = "+stLine+",
// enLine = "+enLine+".");
try
{
g.setColor(Color.green);
Document doc = getDocument();
// Segment segment = getLineBuffer();
// System.out.println(doc.getText(p0, p1-p0));
// String s = doc.getText(p0, p1-p0);
String s = doc.getText(stLine, enLine-stLine);
// System.out.println("------");
// System.out.println("highlighting unselected string = \n"+s);
// System.out.println("------");
Style[] styles = highlight(s, (p0-stLine), (p1-p0));
int currStart = 0;
int currEnd = 0;
Color last = null;
String fname = handler.getPrismEditorFontFast().getName();
int fsize = handler.getPrismEditorFontFast().getSize();
for(int curr = 0; curr < styles.length; curr++)
{
Style c = styles[curr];
g.setColor(c.c);
g.setFont(new Font(fname, c.style, fsize));
Segment segm = new Segment();// getLineBuffer();
doc.getText(p0+curr, 1, segm);
x = Utilities.drawTabbedText(segm, x, y, g, this, p0+curr);
}
g.setColor(Color.black);
g.setFont(new Font(fname, Font.PLAIN, fsize));
}
catch(BadLocationException ex)
{
ex.printStackTrace();
}
return x;
}
示例12: drawSelectedText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int drawSelectedText(Graphics g, int x, int y,int p0, int p1) throws BadLocationException
{
int stLine = p0;// findStartOfLine(p0, getDocument());
int enLine = p1;// findEndOfLine(p1-1, getDocument());
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
// x+= getLeftInset();
// System.out.println("p0 = "+p0+", p1 = "+p1+", st = "+stLine+",
// enLine = "+enLine+".");
try
{
g.setColor(Color.green);
Document doc = getDocument();
// Segment segment = getLineBuffer();
// String s = doc.getText(p0, p1-p0);
// System.out.println(doc.getText(p0, p1-p0));
String s = doc.getText(stLine, enLine-stLine);
// System.out.println("------");
// System.out.println("highlighting selected string = \n"+s);
// System.out.println("------");
Style[] styles = highlight(s, (p0-stLine), (p1-p0));
int currStart = 0;
int currEnd = 0;
Color last = null;
String fname = handler.getPrismEditorFontFast().getName();
int fsize = handler.getPrismEditorFontFast().getSize();
for(int curr = 0; curr < styles.length; curr++)
{
Style c = styles[curr];
g.setColor(c.c);
g.setFont(new Font(fname, c.style, fsize));
Segment segm = new Segment();// getLineBuffer();
doc.getText(p0+curr, 1, segm);
x = Utilities.drawTabbedText(segm, x, y, g, this, p0+curr);
}
g.setColor(Color.black);
g.setFont(new Font(fname, Font.PLAIN, fsize));
}
catch(BadLocationException ex)
{
ex.printStackTrace();
}
return x;
}
示例13: drawUnselectedText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException
{
int stLine = findStartOfLine(p0, getDocument());
int enLine = findEndOfLine(p1, getDocument());
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
try
{
g.setColor(Color.green);
Document doc = getDocument();
Segment segment = getLineBuffer();
//String s = doc.getText(p0, p1-p0);
String s = doc.getText(stLine, enLine-stLine);
userinterface.model.Style[] styles = highlight(s, (p0-stLine), (p1-p0));
int currStart = 0;
int currEnd = 0;
Color last = null;
String fname = handler.getPepaEditorFontFast().getName();
int fsize = handler.getPepaEditorFontFast().getSize();
for(int curr = 0; curr < styles.length; curr++)
{
userinterface.model.Style c = styles[curr];
g.setColor(c.c);
g.setFont(new Font(fname, c.style, fsize));
Segment segm = getLineBuffer();
doc.getText(p0+curr, 1, segm);
x = Utilities.drawTabbedText(segm, x, y, g, this, p0+curr);
}
g.setColor(Color.black);
g.setFont(new Font(fname, Font.PLAIN, fsize));
}
catch(BadLocationException ex)
{
//System.out.println("ex = "+ex);
//ex.printStackTrace();
}
return x;
}
示例14: drawSelectedText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException
{
int stLine = findStartOfLine(p0, getDocument());
int enLine = findEndOfLine(p1, getDocument());
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
try
{
g.setColor(Color.green);
Document doc = getDocument();
Segment segment = getLineBuffer();
//String s = doc.getText(p0, p1-p0);
String s = doc.getText(stLine, enLine-stLine);
userinterface.model.Style[] styles = highlight(s, (p0-stLine), (p1-p0));
int currStart = 0;
int currEnd = 0;
Color last = null;
String fname = handler.getPepaEditorFontFast().getName();
int fsize = handler.getPepaEditorFontFast().getSize();
for(int curr = 0; curr < styles.length; curr++)
{
userinterface.model.Style c = styles[curr];
g.setColor(c.c);
g.setFont(new Font(fname, c.style, fsize));
Segment segm = getLineBuffer();
doc.getText(p0+curr, 1, segm);
x = Utilities.drawTabbedText(segm, x, y, g, this, p0+curr);
}
g.setColor(Color.black);
g.setFont(new Font(fname, Font.PLAIN, fsize));
}
catch(BadLocationException ex)
{
//System.out.println("ex = "+ex);
//ex.printStackTrace();
}
return x;
}
示例15: drawUnselectedText
import javax.swing.text.Utilities; //導入方法依賴的package包/類
@Override
protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) throws BadLocationException {
addRenderingHints(graphics);
Document doc = getDocument();
String text = doc.getText(p0, p1 - p0);
Segment segment = getLineBuffer();
SortedMap<Integer, Integer> searchStartMap = new TreeMap<Integer, Integer>();
SortedMap<Integer, Integer> startMap = new TreeMap<Integer, Integer>();
SortedMap<Integer, Color> colorMap = new TreeMap<Integer, Color>();
processText(text, patternColors, searchStartMap, startMap, colorMap);
int i = 0;
// Colour the parts
for (Map.Entry<Integer, Integer> entry : startMap.entrySet()) {
int start = entry.getKey();
int end = entry.getValue();
if (i < start) {
graphics.setColor(Color.black);
doc.getText(p0 + i, start - i, segment);
x = Utilities.drawTabbedText(segment, x, y, graphics, this, i);
}
graphics.setColor(colorMap.get(start));
i = end;
doc.getText(p0 + start, i - start, segment);
drawHighlightedWord(searchStartMap, segment, start, x, y, graphics);
x = Utilities.drawTabbedText(segment, x, y, graphics, this, start);
}
// Paint possible remaining text black
if (i < text.length()) {
graphics.setColor(Color.black);
doc.getText(p0 + i, text.length() - i, segment);
x = Utilities.drawTabbedText(segment, x, y, graphics, this, i);
}
return x;
}