1010 **/
1111package com .ldiamond .sqgraph ;
1212
13+ import java .awt .Color ;
1314import java .awt .image .BufferedImage ;
1415import java .io .FileOutputStream ;
1516import java .io .IOException ;
2122import com .google .common .collect .HashBasedTable ;
2223import com .lowagie .text .Document ;
2324import com .lowagie .text .Element ;
25+ import com .lowagie .text .Font ;
2426import com .lowagie .text .Image ;
2527import com .lowagie .text .Paragraph ;
2628import com .lowagie .text .Phrase ;
@@ -79,7 +81,109 @@ public static void closePDF() {
7981 document .close ();
8082 }
8183
82- /*
84+ public static void addTextDashboard (final HashBasedTable <String , String , Double > dashboardData , final Config config ) {
85+ try {
86+ document .add (new Phrase ("" )); // spacer
87+
88+ List <Integer > colWidths = new ArrayList <>();
89+ PdfPTable table = new PdfPTable (config .getMetrics ().length + 1 );
90+ table .setHorizontalAlignment (table .ALIGN_LEFT );
91+ table .setWidthPercentage (95 );
92+ table .setSpacingBefore (2 );
93+ table .setSpacingAfter (2 );
94+ Phrase pphrase = new Phrase ("Project" );
95+ Font pfont = pphrase .getFont ();
96+ pfont .setSize (20 );
97+ PdfPCell cell = new PdfPCell (pphrase );
98+ cell .setHorizontalAlignment (Element .ALIGN_CENTER );
99+ cell .setBackgroundColor (Color .LIGHT_GRAY );
100+ cell .setPaddingBottom (cell .getPaddingBottom () + 3 );
101+ table .addCell (cell );
102+ colWidths .add (2 );
103+ int col = 1 ;
104+ for (SQMetrics m : config .getMetrics ()) {
105+ Phrase phrase = new Phrase (m .getTitle ());
106+ Font font = phrase .getFont ();
107+ font .setSize (20 );
108+ cell = new PdfPCell (phrase );
109+ cell .setHorizontalAlignment (Element .ALIGN_CENTER );
110+ cell .setBackgroundColor (Color .LIGHT_GRAY );
111+ table .addCell (cell );
112+ colWidths .add (getWidthOfString (m .getTitle ()));
113+ col ++;
114+ }
115+ for (Application a : config .getApplications ()) {
116+ col = 0 ;
117+ Phrase tphrase = new Phrase (a .getTitle ());
118+ Font tfont = tphrase .getFont ();
119+ tfont .setSize (20 );
120+ cell = new PdfPCell (tphrase );
121+ cell .setPaddingLeft (cell .getPaddingLeft () + 2 );
122+ cell .setHorizontalAlignment (Element .ALIGN_LEFT );
123+ cell .setVerticalAlignment (Element .ALIGN_CENTER );
124+ cell .setPaddingBottom (cell .getPaddingBottom () + 3 );
125+ setMax (colWidths , col , a .getTitle (), 0 );
126+ table .addCell (cell );
127+ for (SQMetrics m : config .getMetrics ()) {
128+ String text = SqgraphApplication .standardDecimalFormatter .format (dashboardData .get (m .getTitle (), a .getTitle ()));
129+ Phrase phrase = new Phrase (text );
130+ Font font = phrase .getFont ();
131+ font .setSize (20 );
132+ cell = new PdfPCell (phrase );
133+ cell .setHorizontalAlignment (Element .ALIGN_RIGHT );
134+ cell .setVerticalAlignment (Element .ALIGN_CENTER );
135+ cell .setPaddingLeft (cell .getPaddingLeft () + 2 );
136+ cell .setPaddingRight (cell .getPaddingRight () + 5 );
137+ SQMetrics metric = config .getMetrics ()[col ];
138+ String greenString = metric .getGreen ();
139+ String yellowString = metric .getYellow ();
140+ if ((greenString != null ) && (yellowString != null )) {
141+ double green = Double .parseDouble (greenString );
142+ double yellow = Double .parseDouble (yellowString );
143+ boolean greenHigher = true ;
144+ if (yellow > green ) greenHigher = false ;
145+ double cellValue = Double .parseDouble (text );
146+ if (greenHigher ) {
147+ if (cellValue > green ) {
148+ cell .setBackgroundColor (Color .GREEN );
149+ } else {
150+ if (cellValue > yellow ) {
151+ cell .setBackgroundColor (Color .YELLOW );
152+ } else {
153+ cell .setBackgroundColor (Color .PINK );
154+ }
155+ }
156+ } else {
157+ if (cellValue < green ) {
158+ cell .setBackgroundColor (Color .GREEN );
159+ } else {
160+ if (cellValue < yellow ) {
161+ cell .setBackgroundColor (Color .YELLOW );
162+ } else {
163+ cell .setBackgroundColor (Color .PINK );
164+ }
165+ }
166+ }
167+ }
168+ table .addCell (cell );
169+ col ++;
170+ setMax (colWidths , col , text , 4 );
171+ }
172+ }
173+
174+ int [] w = new int [colWidths .size ()];
175+ int colWidthsSize = colWidths .size ();
176+ for (int loop = 0 ; loop < colWidthsSize ; loop ++) {
177+ w [loop ] = colWidths .get (loop );
178+ }
179+
180+ table .setWidths (w );
181+ document .add (table );
182+ } catch (Exception e ) {
183+ e .printStackTrace ();
184+ }
185+ }
186+
83187 private static int getWidthOfString (final String s ) {
84188 int width = 2 ;
85189
@@ -106,67 +210,4 @@ private static void setMax (List<Integer> widths, int col, String s, int plus) {
106210 widths .set (col , width );
107211 }
108212 }
109-
110- public static void addTextDashboard(final HashBasedTable<String, String, Double> dashboardData, final Config config) {
111- document.add(new Phrase ("")); // spacer
112- // Phrase p = new Phrase ("blah");
113- // Font f = p.getFont();
114- // System.out.println ("Font " + f.getFamilyname() + " size " + f.getSize());
115-
116- List<Integer> colWidths = new ArrayList<>();
117-
118- PdfPTable table = new PdfPTable(config.getMetrics().length + 1);
119- table.setWidthPercentage(100);
120- table.setSpacingBefore(1);
121- table.setSpacingAfter(2);
122- PdfPCell cell = new PdfPCell(new Phrase ("Text"));
123- table.addCell(cell);
124- colWidths.add (2);
125- int col = 1;
126- for (SQMetrics m : config.getMetrics()) {
127- cell = new PdfPCell(new Phrase (m.getTitle()));
128-
129- cell.setHorizontalAlignment(Element.ALIGN_CENTER);
130- table.addCell(cell);
131- colWidths.add(getWidthOfString (m.getTitle()));
132- col++;
133- }
134- for (Application a : config.getApplications()) {
135- col = 0;
136- cell = new PdfPCell(new Phrase (a.getTitle()));
137- cell.setHorizontalAlignment(Element.ALIGN_LEFT);
138- cell.setVerticalAlignment(Element.ALIGN_CENTER);
139- setMax(colWidths, col, a.getTitle(), 0);
140- table.addCell(cell);
141- for (SQMetrics m : config.getMetrics()) {
142- col++;
143- String text = SqgraphApplication.standardDecimalFormatter.format (dashboardData.get(m.getTitle(),a.getTitle()));
144- cell = new PdfPCell(new Phrase (text));
145- cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
146- cell.setVerticalAlignment(Element.ALIGN_CENTER);
147- cell.setPaddingLeft(cell.getPaddingLeft() + 2);
148- cell.setPaddingRight(cell.getPaddingRight() + 2);
149- table.addCell(cell);
150- setMax(colWidths, col, text, 4);
151- }
152- }
153-
154- int [] w = new int [colWidths.size()];
155- int sum = 0;
156- int colWidthsSize = colWidths.size();
157- for (int loop = 0; loop < colWidthsSize; loop++) {
158- // System.out.println ("width " + loop + " = " + colWidths.get(loop));
159- w [loop] = colWidths.get(loop);
160- sum += w [loop];
161- }
162- System.out.println ("Sum = " + sum);
163-
164-
165-
166- table.setWidths(w);
167-
168- document.add (table);
169- }
170-
171- /* */
172213}
0 commit comments