2016-07-07 80 views
0

我正在使用它們的項目中升級庫(從3.x版本到6.0.0),並且我不知道在哪裏得到這3個缺失變量。他們曾經在舊版本中受到保護。現在他們是私人的。我在哪裏可以找到globalOffsetX,globalOffsetY和放大課程擴展新的JRGraphics2DExporter?

我的舊代碼:

import java.awt.Rectangle; 
import java.awt.RenderingHints; 
import java.awt.Shape; 
import java.awt.geom.AffineTransform; 
import net.sf.jasperreports.engine.JRException; 
import net.sf.jasperreports.engine.JRPrintPage; 
import net.sf.jasperreports.engine.export.JRGraphics2DExporter; 

public class SRptGraphics2DExporter extends JRGraphics2DExporter { 

    Double rotationAngle = 0.0; 

    public SRptGraphics2DExporter() throws JRException { 
     super(); 
     this.setParameter(SRptGraphics2DExporterParameter.ROTATION_ANGLE, new Double(0.0)); 
    } 

    @Override 
    public void exportReportToGraphics2D() throws JRException { 
     boolean printPageBorders = (Boolean) parameters.get(SRptGraphics2DExporterParameter.PRINT_PAGE_BORDERS); 
     rotationAngle = (Double) parameters.get(SRptGraphics2DExporterParameter.ROTATION_ANGLE); 
     grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
     grx.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 
     grx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 

     AffineTransform atrans = new AffineTransform(); 
     atrans.translate(globalOffsetX, globalOffsetY); 
     atrans.rotate(rotationAngle); 
     atrans.scale(zoom, zoom); 

     AffineTransform sa = grx.getTransform(); 
     grx.transform(atrans); 

     java.util.List pages = jasperPrint.getPages(); 
     if (pages != null) { 
      Shape oldClipShape = grx.getClip(); 
      grx.clip(new Rectangle(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight())); 

      try { 
       JRPrintPage page = (JRPrintPage) pages.get(startPageIndex); 
       exportPage(page); 
       if (printPageBorders) { 
        grx.drawRect(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); 
       } 
      } finally { 
       grx.setClip(oldClipShape); 
       grx.setTransform(sa); 
      } 
     } 
    } 
} 
+0

發現它在受保護的JR(約3.xx的版本) –

+0

的舊的源代碼 - (變焦不可在這個版本中)http://grepcode.com/file/repo1.maven.org/maven2/net.sf.jasperreports/jasperreports/5.0.4/net/sf/jasperreports/engine/JRAbstractExporter.java#JRAbstractExporter.0gl​​obalOffsetX –

+0

我試圖用新的庫來編譯這個代碼......它與舊的一起工作,並與新的一個netbeans告訴我,符號無法找到 - 我應該發送整個班? –

回答

0

我終於找到繼承功能getCurrentItemConfiguration();,在那裏我找到了這些功能: getCurrentItemConfiguration().getZoomRatio();getCurrentItemConfiguration().getOffsetX()getCurrentItemConfiguration().getOffsetY()

所以我改變了源代碼(有一些其他的變化,由於其他不兼容):

@Override 
public void exportReportToGraphics2D(Graphics2D grx) throws JRException { 

    Shape oldClipShape = grx.getClip(); 
    boolean printPageBorders = (Boolean) parameters.get(SRptGraphics2DExporterParameter.PRINT_PAGE_BORDERS); 
    grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
    //grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); 
    grx.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 
    grx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 

    rotationAngle = (Double) parameters.get(SRptGraphics2DExporterParameter.ROTATION_ANGLE); 

    setCurrentExporterInputItem(exporterInput.getItems().get(0)); 

    ReportExportConfiguration configuration = getCurrentItemConfiguration(); 
    AffineTransform sa = grx.getTransform(); 

    float zoom = 1f; 

    Float zoomRatio = getCurrentItemConfiguration().getZoomRatio(); 
    if (zoomRatio != null) { 
     zoom = zoomRatio.floatValue(); 
     if (zoom <= 0) { 
      throw new JRRuntimeException(
        EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, 
        new Object[]{zoom} 
      ); 
     } 
    } 

    AffineTransform atrans = new AffineTransform(); 
    atrans.translate(
      configuration.getOffsetX() == null ? 0 : configuration.getOffsetX(), 
      configuration.getOffsetY() == null ? 0 : configuration.getOffsetY() 
    ); 
    atrans.rotate(rotationAngle); 

    atrans.scale(zoom, zoom); 

    grx.transform(atrans); 

    List<JRPrintPage> pages = jasperPrint.getPages(); 
    if (pages != null) { 
     PageRange pageRange = getPageRange(); 
     int startPageIndex = (pageRange == null || pageRange.getStartPageIndex() == null) ? 0 : pageRange.getStartPageIndex(); 

     PrintPageFormat pageFormat = jasperPrint.getPageFormat(startPageIndex); 

     grx.clip(new Rectangle(0, 0, pageFormat.getPageWidth(), pageFormat.getPageHeight())); 
     atrans = grx.getTransform(); 
     try {     
      AffineTransform ertrans = new AffineTransform(); 
      ertrans.translate(
        configuration.getOffsetX() == null ? 0 : -configuration.getOffsetX(), 
        configuration.getOffsetY() == null ? 0 : -configuration.getOffsetY() 
      ); 
      grx.transform(ertrans); 

      exportPage(grx, startPageIndex); 

      grx.setTransform(atrans); 

      if (printPageBorders) { 
       grx.drawRect(1, 1, pageFormat.getPageWidth() -1, pageFormat.getPageHeight()-1); 
      } 


     } finally { 

      grx.setTransform(sa); 
      grx.setClip(oldClipShape); 

     } 
    } 
} 
相關問題