← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11115: PDF Form SaveAs button hide for now.

 

------------------------------------------------------------
revno: 11115
committer: James Chang <jamesbchang@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-30 17:42:28 +0700
message:
  PDF Form SaveAs button hide for now.
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java	2013-05-29 04:29:41 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/DefaultPdfDataEntryFormService.java	2013-05-30 10:42:28 +0000
@@ -35,6 +35,7 @@
 import com.lowagie.text.Paragraph;
 import com.lowagie.text.Phrase;
 import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.BaseFont;
 import com.lowagie.text.pdf.CMYKColor;
 import com.lowagie.text.pdf.PdfAnnotation;
 import com.lowagie.text.pdf.PdfAppearance;
@@ -171,10 +172,11 @@
 
             document.add( mainTable );
 
-            document.add( Chunk.NEWLINE );
-            document.add( Chunk.NEWLINE );
+            // Hide the 'Save As' button for now.
+            //document.add( Chunk.NEWLINE );
+            //document.add( Chunk.NEWLINE );
 
-            insertSaveAsButton( document, writer, PdfDataEntryFormUtil.LABELCODE_BUTTON_SAVEAS );
+            //insertSaveAsButton( document, writer, PdfDataEntryFormUtil.LABELCODE_BUTTON_SAVEAS );
         }
     }
 
@@ -400,18 +402,19 @@
         table.setWidths( cellWidths );
 
         // Create Header
-        table.addCell( new PdfPCell( new Phrase( "Date" ) ) );
+        addCell_Text( table, "Date", Element.ALIGN_CENTER );
 
         // Add Program Data Elements Columns
         for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
         {
             DataElement dataElement = programStageDataElement.getDataElement();
 
-            table.addCell( new PdfPCell( new Phrase( dataElement.getDisplayFormName() ) ) );
+            addCell_Text( table, dataElement.getDisplayFormName(), Element.ALIGN_CENTER );
         }
 
-        table.addCell( new PdfPCell( new Phrase( TEXT_BLANK ) ) );
+        addCell_Text( table, TEXT_BLANK, Element.ALIGN_CENTER );
 
+        
         // ADD A HIDDEN INFO FOR ProgramStageID
         // Print rows, having the data elements repeating on each column.
 
@@ -593,7 +596,7 @@
 
         cell.setPhrase( new Phrase( text, font ) );
 
-        table.addCell( cell );
+        table.addCell( cell ); // TODO: change this with cellEvent?
     }
 
     private void addCell_WithTextField( PdfPTable table, Rectangle rect, PdfWriter writer, String strfldName )
@@ -630,8 +633,8 @@
         nameField.setText( value );
 
         nameField.setAlignment( Element.ALIGN_RIGHT );
-        nameField.setFontSize( PdfDataEntryFormUtil.UNITSIZE_DEFAULT );
-
+        nameField.setFont( pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_BODY ).getBaseFont() );
+        
         PdfPCell cell = PdfDataEntryFormUtil.getPdfPCell( PdfDataEntryFormUtil.CELL_MIN_HEIGHT_DEFAULT,
             PdfDataEntryFormUtil.CELL_COLUMN_TYPE_ENTRYFIELD );
         cell.setCellEvent( new PdfFieldCell( nameField.getTextField(), (int) (rect.getWidth()), fieldCellType, writer ) );

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java	2013-05-25 11:38:41 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java	2013-05-30 10:42:28 +0000
@@ -51,39 +51,54 @@
 import java.util.Map.Entry;
 import java.util.Set;
 
-
 public class PdfDataEntryFormUtil
 {
     public static final int DATATYPE_DATASET = 0;
+
     public static final int DATATYPE_PROGRAMSTAGE = 1;
 
     public static final float UNITSIZE_DEFAULT = 10;
 
     // Label Names
-    
+
     public static final String LABELCODE_TEXTFIELD = "TXFD_";
+
     public static final String LABELCODE_BUTTON = "BTNFD_";
+
     public static final String LABELCODE_ORGID = LABELCODE_TEXTFIELD + "OrgID";
+
     public static final String LABELCODE_PERIODID = LABELCODE_TEXTFIELD + "PeriodID";
+
     public static final String LABELCODE_BUTTON_SAVEAS = LABELCODE_BUTTON + "SaveAs";
+
     public static final String LABELCODE_DATADATETEXTFIELD = "TXFDDT_";
+
     public static final String LABELCODE_DATAENTRYTEXTFIELD = "TXFDDV_";
+
     public static final String LABELCODE_PROGRAMSTAGEIDTEXTBOX = "TXPSTGID_";
 
     // Cell Related
 
-    public final static float CELL_MIN_HEIGHT_DEFAULT = 13;
+    public final static float CELL_MIN_HEIGHT_DEFAULT = 14;
+
     public final static float CONTENT_HEIGHT_DEFAULT = 11;
+
     public final static int CELL_COLUMN_TYPE_LABEL = 0;
+
     public final static int CELL_COLUMN_TYPE_ENTRYFIELD = 1;
 
+    public final static int CELL_COLUMN_TYPE_HEADER = 2;
+
     private static final String DATAVALUE_IMPORT_STOREBY = "admin";
+
     private static final String DATAVALUE_IMPORT_COMMENT = "Imported by PDF Data Entry Form";
+
     private static final String DATAVALUE_IMPORT_TIMESTAMP_DATEFORMAT = "yyyy-MM-dd";
+
     private static final String FOOTERTEXT_DEFAULT = "PDF Template generated from DHIS %s on %s";
+
     private static final String DATEFORMAT_FOOTER_DEFAULT = "MMMM dd, yyyy";
 
-
     // -------------------------------------------------------------------------
     // METHODS
     // -------------------------------------------------------------------------
@@ -110,8 +125,8 @@
     {
         if ( typeId == PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE )
         {
-            return new Rectangle( PageSize.A4.getLeft(),
-                PageSize.A4.getBottom(), PageSize.A4.getTop(), PageSize.A4.getRight() );
+            return new Rectangle( PageSize.A4.getLeft(), PageSize.A4.getBottom(), PageSize.A4.getTop(),
+                PageSize.A4.getRight() );
         }
         else
         {
@@ -129,16 +144,28 @@
         PdfPCell cell = new PdfPCell();
         cell.setMinimumHeight( minHeight );
         cell.setBorder( Rectangle.NO_BORDER );
+        cell.setPadding( 1f );
 
-        if ( cellContentType == CELL_COLUMN_TYPE_LABEL )
+        switch ( cellContentType )
         {
+        case CELL_COLUMN_TYPE_ENTRYFIELD:
+            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
+            cell.setVerticalAlignment( Element.ALIGN_MIDDLE );
+
+            break;
+
+        case CELL_COLUMN_TYPE_HEADER:
+            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
+            cell.setVerticalAlignment( Element.ALIGN_MIDDLE );
+
+            break;
+
+        case CELL_COLUMN_TYPE_LABEL:
             cell.setHorizontalAlignment( Element.ALIGN_RIGHT );
             cell.setVerticalAlignment( Element.ALIGN_TOP );
-        }
-        else if ( cellContentType == CELL_COLUMN_TYPE_ENTRYFIELD )
-        {
-            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
-            cell.setVerticalAlignment( Element.ALIGN_MIDDLE );
+
+        default:
+            break;
         }
 
         return cell;
@@ -161,8 +188,6 @@
 
             if ( form != null )
             {
-                // TODO: MOVE THESE STATIC NAME VALUES TO inside of service
-                // class or PDFForm Class <-- should be in PDFForm Class.
                 String strOrgUID = form.getField( PdfDataEntryFormUtil.LABELCODE_ORGID );
                 String strPeriodID = form.getField( PdfDataEntryFormUtil.LABELCODE_PERIODID );
 

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java	2013-05-25 11:38:41 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfFieldCell.java	2013-05-30 10:42:28 +0000
@@ -49,12 +49,21 @@
     implements PdfPCellEvent
 {
     public final static int TYPE_DEFAULT = 0;
+
     public final static int TYPE_BUTTON = 1;
+
     public final static int TYPE_TEXT_ORGUNIT = 2;
+
     public final static int TYPE_TEXT_NUMBER = 3;
+
     public final static int TYPE_CHECKBOX = 4;
+
     public final static int TYPE_RADIOBUTTON = 5;
+
+    public final static int TPYE_LABEL = 6;
+
     private final static float RADIOBUTTON_WIDTH = 10.0f;
+
     private final static float RADIOBUTTON_TEXTOFFSET = 3.0f;
 
     private PdfFormField parent;
@@ -117,119 +126,126 @@
         this.width = width;
     }
 
-    public void cellLayout( PdfPCell cell, Rectangle rect, PdfContentByte[] canvas )
+    public void cellLayout( PdfPCell cell, Rectangle rect, PdfContentByte[] canvases )
     {
         try
         {
 
-            PdfContentByte cb = null;
-
-            if ( type == TYPE_RADIOBUTTON )
-            {
-                cb = canvas[PdfPTable.TEXTCANVAS];
-            }
-            else
-            {
-                cb = canvas[PdfPTable.LINECANVAS];
-            }
+            PdfContentByte canvasText = canvases[PdfPTable.TEXTCANVAS];
+            // PdfContentByte canvasLine = canvases[PdfPTable.LINECANVAS];
+            //
+            // float margin = 2;
+            //
+            // float x1 = rect.getLeft() + margin;
+            // float x2 = rect.getRight() - margin;
+            // float y1 = rect.getTop() - margin;
+            // float y2 = rect.getBottom() + margin;
+            //
+            // canvasLine.rectangle( x1, y1, x2 - x1, y2 - y1 );
 
             switch ( type )
             {
-                case TYPE_RADIOBUTTON:
-
-                    if ( parent != null )
-                    {
-                        float leftLoc = rect.getLeft();
-                        float rightLoc = rect.getLeft() + RADIOBUTTON_WIDTH;
-
-                        try
-                        {
-                            String text;
-                            String value;
-
-                            for ( int i = 0; i < texts.length; i++ )
-                            {
-
-                                text = texts[i];
-                                value = values[i];
-
-                                Rectangle radioRec = new Rectangle( leftLoc, rect.getBottom(), rightLoc, rect.getTop() );
-
-                                RadioCheckField rf = new RadioCheckField( writer, radioRec, "RDBtn_" + text, value );
-
-                                if ( value == checkValue )
-                                    rf.setChecked( true );
-
-                                rf.setBorderColor( GrayColor.GRAYBLACK );
-                                rf.setBackgroundColor( GrayColor.GRAYWHITE );
-                                rf.setCheckType( RadioCheckField.TYPE_CIRCLE );
-
-                                parent.addKid( rf.getRadioField() );
-
-                                leftLoc = rightLoc;
-                                rightLoc += width;
-
-                                ColumnText.showTextAligned( cb, Element.ALIGN_LEFT, new Phrase( text ), leftLoc
-                                    + RADIOBUTTON_TEXTOFFSET, (radioRec.getBottom() + radioRec.getTop()) / 2, 0 );
-
-                                leftLoc = rightLoc;
-                                rightLoc += RADIOBUTTON_WIDTH;
-                            }
-                        }
-                        catch ( Exception ex )
-                        {
-                            throw new RuntimeException( ex.getMessage() );
-                        }
-
-                        writer.addAnnotation( parent );
-                    }
-
-                    break;
-
-                case TYPE_BUTTON:
-                    // Add the push button
-                    PushbuttonField button = new PushbuttonField( writer, rect, name );
-                    button.setBackgroundColor( new GrayColor( 0.75f ) );
-                    button.setBorderColor( GrayColor.GRAYBLACK );
-                    button.setBorderWidth( 1 );
-                    button.setBorderStyle( PdfBorderDictionary.STYLE_BEVELED );
-                    button.setTextColor( GrayColor.GRAYBLACK );
-                    button.setFontSize( PdfDataEntryFormUtil.UNITSIZE_DEFAULT );
-                    button.setText( text );
-                    button.setLayout( PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT );
-                    button.setScaleIcon( PushbuttonField.SCALE_ICON_ALWAYS );
-                    button.setProportionalIcon( true );
-                    button.setIconHorizontalAdjustment( 0 );
-
-                    formField = button.getField();
-                    formField.setAction( PdfAction.javaScript( jsAction, writer ) );
-
-                    break;
-
-                case TYPE_CHECKBOX:
-
-                    // Start from the middle of the cell width.
-                    float startingPoint = rect.getLeft() + ((rect.getWidth() + width) / 2.0f);
-
-                    formField.setWidget(
-                        new Rectangle( startingPoint, rect.getBottom(), startingPoint + width, rect.getTop() ),
-                        PdfAnnotation.HIGHLIGHT_NONE );
-
-                    break;
-
-                case TYPE_TEXT_ORGUNIT:
-                    formField.setAdditionalActions( PdfName.BL, PdfAction.javaScript(
-                        "if(event.value == '') app.alert('Warning! Please Enter The Org ID.');", writer ) );
-
-                case TYPE_TEXT_NUMBER:
-
-                default:
-
-                    formField.setWidget(
-                        new Rectangle( rect.getLeft(), rect.getBottom(), rect.getLeft() + width, rect.getTop() ),
-                        PdfAnnotation.HIGHLIGHT_NONE );
-
-                    break;
+            case TYPE_RADIOBUTTON:
+
+                if ( parent != null )
+                {
+                    float leftLoc = rect.getLeft();
+                    float rightLoc = rect.getLeft() + RADIOBUTTON_WIDTH;
+
+                    try
+                    {
+                        String text;
+                        String value;
+
+                        for ( int i = 0; i < texts.length; i++ )
+                        {
+
+                            text = texts[i];
+                            value = values[i];
+
+                            Rectangle radioRec = new Rectangle( leftLoc, rect.getBottom(), rightLoc, rect.getTop() );
+
+                            RadioCheckField rf = new RadioCheckField( writer, radioRec, "RDBtn_" + text, value );
+
+                            if ( value == checkValue )
+                                rf.setChecked( true );
+
+                            rf.setBorderColor( GrayColor.GRAYBLACK );
+                            rf.setBackgroundColor( GrayColor.GRAYWHITE );
+                            rf.setCheckType( RadioCheckField.TYPE_CIRCLE );
+
+                            parent.addKid( rf.getRadioField() );
+
+                            leftLoc = rightLoc;
+                            rightLoc += width;
+
+                            ColumnText.showTextAligned( canvasText, Element.ALIGN_LEFT, new Phrase( text ), leftLoc
+                                + RADIOBUTTON_TEXTOFFSET, (radioRec.getBottom() + radioRec.getTop()) / 2, 0 );
+
+                            leftLoc = rightLoc;
+                            rightLoc += RADIOBUTTON_WIDTH;
+                        }
+                    }
+                    catch ( Exception ex )
+                    {
+                        throw new RuntimeException( ex.getMessage() );
+                    }
+
+                    writer.addAnnotation( parent );
+                }
+
+                break;
+
+            case TYPE_BUTTON:
+                // Add the push button
+                PushbuttonField button = new PushbuttonField( writer, rect, name );
+                button.setBackgroundColor( new GrayColor( 0.75f ) );
+                button.setBorderColor( GrayColor.GRAYBLACK );
+                button.setBorderWidth( 1 );
+                button.setBorderStyle( PdfBorderDictionary.STYLE_BEVELED );
+                button.setTextColor( GrayColor.GRAYBLACK );
+                button.setFontSize( PdfDataEntryFormUtil.UNITSIZE_DEFAULT );
+                button.setText( text );
+                button.setLayout( PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT );
+                button.setScaleIcon( PushbuttonField.SCALE_ICON_ALWAYS );
+                button.setProportionalIcon( true );
+                button.setIconHorizontalAdjustment( 0 );
+
+                formField = button.getField();
+                formField.setAction( PdfAction.javaScript( jsAction, writer ) );
+
+                break;
+
+            case TYPE_CHECKBOX:
+
+                // Start from the middle of the cell width.
+                float startingPoint = rect.getLeft() + ((rect.getWidth() + width) / 2.0f);
+
+                formField.setWidget(
+                    new Rectangle( startingPoint, rect.getBottom(), startingPoint + width, rect.getTop() ),
+                    PdfAnnotation.HIGHLIGHT_NONE );
+
+                break;
+
+            case TYPE_TEXT_ORGUNIT:
+                formField.setAdditionalActions( PdfName.BL, PdfAction.javaScript(
+                    "if(event.value == '') app.alert('Warning! Please Enter The Org ID.');", writer ) );
+
+            case TYPE_TEXT_NUMBER:
+
+            default:
+
+                // Add -1, +1 to create cellpadding effect - spacing between
+                // rows/cells
+                // formField.setWidget(
+                // new Rectangle( rect.getLeft() + 1, rect.getBottom() + 1,
+                // rect.getLeft() + width - 1, rect.getTop() - 1 ),
+                // PdfAnnotation.HIGHLIGHT_NONE );
+                formField.setWidget(
+                    new Rectangle( rect.getLeft(), rect.getBottom(), rect.getLeft() + width, rect.getTop() ),
+                    PdfAnnotation.HIGHLIGHT_NONE );
+
+                break;
 
             }