1
1
/*
2
- * Copyright 2017 The kSAR Project. All rights reserved.
2
+ * Copyright 2018 The kSAR Project. All rights reserved.
3
3
* See the LICENSE file in the project root for more information.
4
4
*/
5
5
6
6
package net .atomique .ksar .export ;
7
7
8
+ import static com .itextpdf .text .FontFactory .COURIER ;
9
+ import static com .itextpdf .text .FontFactory .getFont ;
10
+
8
11
import com .itextpdf .awt .PdfGraphics2D ;
9
12
import com .itextpdf .text .BaseColor ;
10
13
import com .itextpdf .text .Document ;
11
14
import com .itextpdf .text .DocumentException ;
12
15
import com .itextpdf .text .ExceptionConverter ;
13
- import com .itextpdf .text .FontFactory ;
14
16
import com .itextpdf .text .PageSize ;
15
17
import com .itextpdf .text .pdf .BaseFont ;
16
18
import com .itextpdf .text .pdf .PdfContentByte ;
19
21
import com .itextpdf .text .pdf .PdfPageEventHelper ;
20
22
import com .itextpdf .text .pdf .PdfTemplate ;
21
23
import com .itextpdf .text .pdf .PdfWriter ;
24
+
22
25
import net .atomique .ksar .Config ;
23
26
import net .atomique .ksar .VersionNumber ;
24
27
import net .atomique .ksar .graph .Graph ;
27
30
import net .atomique .ksar .ui .ParentNodeInfo ;
28
31
import net .atomique .ksar .ui .SortedTreeNode ;
29
32
import net .atomique .ksar .ui .TreeNodeInfo ;
30
- import org . jfree . chart . ChartRenderingInfo ;
33
+
31
34
import org .jfree .chart .JFreeChart ;
35
+
32
36
import org .slf4j .Logger ;
33
37
import org .slf4j .LoggerFactory ;
34
38
35
39
import java .awt .Graphics2D ;
36
40
import java .awt .geom .Rectangle2D ;
37
41
import java .awt .geom .Rectangle2D .Double ;
42
+
38
43
import java .io .FileNotFoundException ;
39
44
import java .io .FileOutputStream ;
40
45
import java .io .IOException ;
@@ -46,7 +51,7 @@ public class FilePDF extends PdfPageEventHelper implements Runnable {
46
51
47
52
private static final Logger log = LoggerFactory .getLogger (FilePDF .class );
48
53
49
- public FilePDF (String filename , kSar hissar ) {
54
+ private FilePDF (String filename , kSar hissar ) {
50
55
pdffilename = filename ;
51
56
mysar = hissar ;
52
57
}
@@ -80,7 +85,7 @@ public void run() {
80
85
break ;
81
86
}
82
87
83
- float pdfheight = document .getPageSize ().getHeight ();
88
+ pdfheight = document .getPageSize ().getHeight ();
84
89
pdfwidth = document .getPageSize ().getWidth ();
85
90
pageheight = pdfheight - (2 * pdfmargins );
86
91
pagewidth = pdfwidth - (2 * pdfmargins );
@@ -95,8 +100,8 @@ public void run() {
95
100
96
101
// document parameter before open
97
102
document .addTitle ("kSar Grapher" );
98
- //document.addSubject("Sar output of " + mysar.hostName);
99
- //document.addKeywords("http ://ksar.atomique.net/ ");
103
+ //document.addSubject("SAR Statistics of " + mysar.hostName);
104
+ //document.addKeywords("https ://github.com/vlsi/ksar ");
100
105
//document.addKeywords(mysar.hostName);
101
106
//document.addKeywords(mysar.myOS.sarStartDate);
102
107
//document.addKeywords(mysar.myOS.sarEndDate);
@@ -108,7 +113,7 @@ public void run() {
108
113
pdfcb = writer .getDirectContent ();
109
114
PdfOutline root = pdfcb .getRootOutline ();
110
115
111
- IndexPage (writer , document );
116
+ IndexPage (document );
112
117
113
118
export_treenode (mysar .graphtree , root );
114
119
@@ -121,8 +126,7 @@ public void run() {
121
126
122
127
}
123
128
124
-
125
- public void export_treenode (SortedTreeNode node , PdfOutline root ) {
129
+ private void export_treenode (SortedTreeNode node , PdfOutline root ) {
126
130
int num = node .getChildCount ();
127
131
if (num > 0 ) {
128
132
Object obj1 = node .getUserObject ();
@@ -143,7 +147,7 @@ public void export_treenode(SortedTreeNode node, PdfOutline root) {
143
147
TreeNodeInfo tmpnode = (TreeNodeInfo ) obj1 ;
144
148
Graph nodeobj = tmpnode .getNode_object ();
145
149
if (nodeobj .isPrintSelected ()) {
146
- root = new PdfOutline (root , new PdfDestination (PdfDestination .FIT ), nodeobj .getTitle ());
150
+ new PdfOutline (root , new PdfDestination (PdfDestination .FIT ), nodeobj .getTitle ());
147
151
update_ui ();
148
152
addchart (writer , nodeobj );
149
153
document .newPage ();
@@ -163,49 +167,68 @@ private void update_ui() {
163
167
164
168
public void onEndPage (PdfWriter writer , Document document ) {
165
169
try {
166
- String text = "Page " + writer .getPageNumber () + "/" + total_pages ;
170
+
171
+ int pageNumber = writer .getPageNumber ();
172
+ String text = "Page " + pageNumber + "/" + total_pages ;
173
+ String hostName = mysar .myparser .gethostName ();
174
+ String date = mysar .myparser .getDate ();
167
175
168
176
pdfcb .beginText ();
169
177
pdfcb .setFontAndSize (bf , 10 );
170
178
pdfcb .setColorFill (new BaseColor (0x00 , 0x00 , 0x00 ));
171
- pdfcb .showTextAligned (PdfContentByte .ALIGN_RIGHT , text , ((pdfwidth - pdfmargins ) - 10 ),
172
- 10 + pdfmargins , 0 );
179
+
180
+ if ( pageNumber > 1 ) {
181
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_LEFT , hostName , pdfmargins , pdfheight - pdfmargins , 0 );
182
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_RIGHT , date , pdfwidth - pdfmargins , pdfheight - pdfmargins , 0 );
183
+ }
184
+
185
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_RIGHT , text ,pdfwidth - pdfmargins ,pdfmargins - 5 ,0 );
173
186
pdfcb .endText ();
174
187
} catch (Exception e ) {
175
188
throw new ExceptionConverter (e );
176
189
}
177
190
}
178
191
179
- public int addchart (PdfWriter writer , Graph graph ) {
192
+ private void addchart (PdfWriter writer , Graph graph ) {
180
193
JFreeChart chart =
181
194
graph .getgraph (mysar .myparser .getStartOfGraph (), mysar .myparser .getEndOfGraph ());
182
195
PdfTemplate pdftpl = pdfcb .createTemplate (pagewidth , pageheight );
183
196
Graphics2D g2d = new PdfGraphics2D (pdftpl , pagewidth , pageheight );
184
197
Double r2d = new Rectangle2D .Double (0 , 0 , pagewidth , pageheight );
185
- chart .draw (g2d , r2d , chartinfo );
198
+ chart .draw (g2d , r2d );
186
199
g2d .dispose ();
187
200
pdfcb .addTemplate (pdftpl , pdfmargins , pdfmargins );
188
201
try {
189
202
writer .releaseTemplate (pdftpl );
190
203
} catch (IOException ioe ) {
191
204
log .error ("Unable to write to : {}" , pdffilename );
192
205
}
193
- return 0 ;
194
206
}
195
207
196
- public void IndexPage (PdfWriter writer , Document document ) {
208
+ private void IndexPage (Document document ) {
197
209
try {
210
+ float pdfCenter = ((pdfwidth - pdfmargins ) / 2 );
211
+
212
+ String title = "SAR Statistics" ;
213
+ String t_date = "on " + mysar .myparser .getDate ();
214
+ String hostName = "for " + mysar .myparser .gethostName ();
215
+ String osType = mysar .myparser .getOstype ();
216
+ String graphStart = mysar .myparser .getStartOfGraph ().toString ();
217
+ String graphEnd = mysar .myparser .getEndOfGraph ().toString ();
198
218
199
- String title = "Statistics" ;
200
- String t_date = "On " + mysar .myparser .getDate ();
201
219
pdfcb .beginText ();
202
- pdfcb .setFontAndSize (bf , 48 );
220
+ pdfcb .setFontAndSize (bf , 40 );
203
221
pdfcb .setColorFill (new BaseColor (0x00 , 0x00 , 0x00 ));
204
- pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , title , ((pdfwidth - pdfmargins ) / 2 ), 500 ,
205
- 0 );
206
- pdfcb .setFontAndSize (bf , 36 );
207
- pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , t_date , ((pdfwidth - pdfmargins ) / 2 ), 300 ,
208
- 0 );
222
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , title , pdfCenter , 500 , 0 );
223
+
224
+ pdfcb .setFontAndSize (bf , 32 );
225
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , hostName + " (" + osType + ")" , pdfCenter , 400 ,0 );
226
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , t_date , pdfCenter , 300 ,0 );
227
+
228
+ pdfcb .setFontAndSize (bf , 20 );
229
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , graphStart , pdfCenter , 200 ,0 );
230
+ pdfcb .showTextAligned (PdfContentByte .ALIGN_CENTER , graphEnd , pdfCenter , 150 ,0 );
231
+
209
232
pdfcb .endText ();
210
233
document .newPage ();
211
234
@@ -216,17 +239,17 @@ public void IndexPage(PdfWriter writer, Document document) {
216
239
217
240
private int progress_info = 0 ;
218
241
private float pdfwidth ;
242
+ private float pdfheight ;
219
243
private int pdfmargins = 10 ;
220
244
private float pageheight ;
221
245
private float pagewidth ;
222
246
private int total_pages = 1 ; // page 1 (index)
223
- private String pdffilename = null ;
247
+ private String pdffilename ;
224
248
private Document document = null ;
225
249
private PdfWriter writer = null ;
226
250
private PdfContentByte pdfcb ;
227
- private kSar mysar = null ;
228
- private BaseFont bf = FontFactory . getFont (FontFactory . COURIER ).getCalculatedBaseFont (false );
251
+ private kSar mysar ;
252
+ private BaseFont bf = getFont (COURIER ).getCalculatedBaseFont (false );
229
253
private JProgressBar progress_bar = null ;
230
254
private JDialog dialog = null ;
231
- private ChartRenderingInfo chartinfo = null ;
232
255
}
0 commit comments