📄 printmessagethread.java
字号:
} else { line = text.substring( 0, endi ); text = text.substring( endi + skip ); } if ( line.length() == 0 ) { newLine(); continue; } int off = line.length() - 1; for ( ; line.length() > 0 ; ) { int sW = this.plainFM.stringWidth( line ); if ( sW < lineW ) { if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "BODY DRAW1: Sw=" + sW + " line[" + (line==null?"(null)":""+line.length()) +"] '" + (line==null?"(null)":line)+"'" ); } this.pg.drawString( line, this.xPosition, this.yPosition ); if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "BODY DRAW1: DONE." ); } newLine(); break; } for ( ; ; ) { int si = line.lastIndexOf( " ", off ); int ti = line.lastIndexOf( "\t", off ); int idx = ( si > ti ? si : ti ); if ( idx == -1 ) idx = line.length() - 1; off = idx - 1; String sub = line.substring( 0, idx ); sW = this.plainFM.stringWidth( sub ); if ( sW < lineW ) { if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "BODY DRAW2: line[" +(sub==null?"(null)":""+sub.length()) +"] '" + (sub==null?"(null)":sub)+"'" ); } this.pg.drawString( sub, this.xPosition, this.yPosition ); newLine(); line = line.substring( idx + 1 ); off = line.length() - 1; break; } } } } } private void newLine() { if ( Package.DEBUG && Package.isTraceable( "PrintMessageThread" ) ) { System.out.println( "PrintMessageThread.newLine()" ); } this.yPosition += this.lineHeight; this.xPosition = this.xMargin; if ( this.yPosition > this.pageSz.height ) { this.yPosition = this.yMargin + this.lineHeight; Font saveF = this.pg.getFont(); this.pg.dispose(); this.pg = job.getGraphics(); this.pg.setFont( saveF ); } } private String printTextArea( String text, int xOrigin, int yOrigin, int width, int height, int lineH ) { if ( Package.DEBUG && Package.isTraceable( "PrintMessageThread" ) ) { System.out.println( "PrintMessageThread.printTextArea(s,i,i,i,i,i): " + "X-" + xOrigin + ",Y-" + yOrigin + ",W-" + width + ", H-" + height + ",LH-" + lineH ); } String line; this.yPosition = yOrigin; this.xPosition = xOrigin; for ( ; text.length() > 0 ; ) { int endi; int skip = 1; int ni = text.indexOf( "\n" ); int ri = text.indexOf( "\r" ); if ( ri != -1 && ni == (ri + 1) ) { // CR/NL endi = ri; skip = 2; } else if ( ri == -1 && ni == -1 ) { endi = -1; } else if ( ri == -1 ) { endi = ni; } else if ( ni == -1 ) { endi = ri; } else { endi = ( ri < ni ? ri : ni ); } if ( endi == -1 ) { line = text; text = ""; } else { line = text.substring( 0, endi ); text = text.substring( endi + skip ); } if ( line.length() == 0 ) { if ( ((this.yPosition + lineH) - yOrigin) > height ) return text; if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "BLANK LINE!!" ); } this.yPosition += lineH; this.xPosition = xOrigin; continue; } int off = line.length() - 1; for ( ; line.length() > 0 ; ) { int sW = this.plainFM.stringWidth( line ); if ( ((this.xPosition - xOrigin) + sW) < width ) { if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "DRAWSTRING1( '" +line+ "'\n" + "X=" +this.xPosition+ ", Y=" +this.yPosition+ " sW=" +sW ); } this.pg.drawString( line, this.xPosition, this.yPosition ); if ( ((this.yPosition + lineH) - yOrigin) > height ) return text; if ( text.length() > 0 ) { this.yPosition += lineH; this.xPosition = xOrigin; } break; } for ( ; ; ) { int si = line.lastIndexOf( " ", off ); int ti = line.lastIndexOf( "\t", off ); int idx = ( si > ti ? si : ti ); if ( idx == -1 ) idx = line.length() - 1; off = idx - 1; String sub = line.substring( 0, idx ); sW = this.plainFM.stringWidth( sub ); if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "OFF_2 '" +off+ " SW=" + sW ); } if ( (this.xPosition + sW) < (xOrigin + width) ) { if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "DRAWSTRING2( '" +sub+ "'\n" + "X=" +this.xPosition+ ", Y=" +this.yPosition+ " sW=" +sW ); } this.pg.drawString( sub, this.xPosition, this.yPosition ); line = line.substring( idx + 1 ); if ( ((this.yPosition + lineH) - yOrigin) > height ) return ( line + "\n" + text ); this.yPosition += lineH; this.xPosition = xOrigin; off = line.length() - 1; break; } } } } return null; } private void printHeaderLine( String title, Address[] adds ) { if ( Package.DEBUG && Package.isTraceable( "PrintMessageThread" ) ) { System.out.println( "PrintMessageThread.printHeaderLine(s,a[])" ); } int subMargin = this.xMargin; this.lineHeight = this.plainFM.getHeight(); this.pg.setFont( this.titleF ); pg.drawString( title, this.xPosition, this.yPosition ); this.xPosition += titleFM.stringWidth( title ) + 6; subMargin = this.xPosition; for ( int i = 0 ; adds != null && i < adds.length ; ++i ) { StringBuffer sbuf = new StringBuffer(); sbuf.append( adds[i].toString() ); if ( i < (adds.length - 1) ) sbuf.append( ", " ); String s = sbuf.toString(); int sWidth = this.plainFM.stringWidth( s ); if ( (this.xPosition + sWidth) > (this.pageSz.width - this.xMargin) ) { this.xPosition = subMargin; this.yPosition += this.lineHeight; if ( this.yPosition > (this.pageSz.height - this.yMargin) ) { this.yPosition = this.yMargin; this.pg.dispose(); this.pg = job.getGraphics(); } } this.pg.setFont( this.plainF ); this.pg.drawString( s, this.xPosition, this.yPosition ); this.xPosition += sWidth; } } private void printHeaderLine( String title, String line ) { if ( Package.DEBUG && Package.isTraceable( "PrintMessageThread" ) ) { System.out.println( "PrintMessageThread.printHeaderLine(s,s)" ); } StringBuffer sbuf = new StringBuffer(); this.pg.setFont( this.titleF ); pg.drawString( title, this.xPosition, this.yPosition ); this.xPosition += this.titleFM.stringWidth( title ) + 6; this.pg.setFont( this.plainF ); if ( Package.DEBUG && Debug_ > 0 ) { System.out.println( "PAGE SZ: W " + this.pageSz.width + " H " + this.pageSz.height + " XM " + this.xMargin + " YM " + this.yMargin ); } printTextArea( line, this.xPosition, this.yPosition, ( ( this.pageSz.width - this.xMargin ) - this.xPosition ), ( ( this.pageSz.height - this.yMargin ) - this.yPosition ), this.plainFM.getHeight() );// pg.drawString( line, this.xPosition, this.yPosition );// this.xPosition += this.plainFM.stringWidth( line ); } private StringBuffer getMessageText( StringBuffer buf, Part part ) { if ( Package.DEBUG && Package.isTraceable( "PrintMessageThread" ) ) { System.out.println( "PrintMessageThread.getMessageText(sb,p)" ); } try { Object content = MessageUtilities.getPartContent( part ); if ( content == null ) { } else if ( content instanceof Multipart ) { Multipart mPart = (Multipart) content; int partCount = mPart.getCount(); for ( int i = 0 ; i < partCount ; i++ ) { getMessageText( buf, mPart.getBodyPart(i) ); buf.append( "\n" ); } } else if ( content instanceof Image ) { buf.append( "<<<Image: " ); buf.append( MessageUtilities.getFileName( part ) ); buf.append( ">>>" ); buf.append( "\n" ); } else if ( content instanceof String ) { buf.append( (String)content ); } else { buf.append( "<<<Attachment: " ); buf.append( MessageUtilities.getFileName( part ) ); buf.append( ">>>" ); buf.append( "\n" ); } } catch ( Exception ex ) { ex.printStackTrace(); } return buf; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -