krysalis-jplugin/src/java/org/krysalis/swingx PrintUtils.java,1.1,1.2

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-jplugin/src/java/org/krysalis/swingx
In directory sc8-pr-cvs1:/tmp/cvs-serv2913/java/org/krysalis/swingx

Modified Files:
	PrintUtils.java 
Log Message:
Print Utils :-)

Index: PrintUtils.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-jplugin/src/java/org/krysalis/swingx/PrintUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PrintUtils.java	2 Oct 2003 15:29:25 -0000	1.1
--- PrintUtils.java	24 Oct 2003 09:42:07 -0000	1.2
***************
*** 16,27 ****
  import java.awt.print.PrinterJob;
  
  import javax.swing.RepaintManager;
  
  /**
   * @author barozzink 2-ott-2003
!  **/
  public class PrintUtils {
  
!     public static void print(Printable p) throws PrinterException {
          PrinterJob printJob = PrinterJob.getPrinterJob();
          printJob.setPrintable(p);
--- 16,40 ----
  import java.awt.print.PrinterJob;
  
+ import javax.swing.JScrollPane;
  import javax.swing.RepaintManager;
  
  /**
   * @author barozzink 2-ott-2003
!  */
  public class PrintUtils {
  
!     public static void print(Object o) throws PrinterException {
!         Printable p;
! 
!         if (o instanceof Printable) {
!             p = (Printable)o;
!         }
!         else if (o instanceof Component) {
!             p = new PrintableComponent((Component)o);
!         }
!         else {
!             throw new PrinterException("The object is not printable");
!         }
! 
          PrinterJob printJob = PrinterJob.getPrinterJob();
          printJob.setPrintable(p);
***************
*** 29,66 ****
              printJob.print();
          }
!       }
!       
      public static void print(Component component) throws PrinterException {
!       print(new PrintUtils.PrintableComponent(component));
      }
!     
      public static void disableDoubleBuffering(Component c) {
!       RepaintManager.currentManager(c).setDoubleBufferingEnabled(false);
      }
  
      public static void enableDoubleBuffering(Component c) {
!       RepaintManager.currentManager(c).setDoubleBufferingEnabled(true);
      }
!       
      protected static class PrintableComponent implements Printable {
  
!           protected Component componentToBePrinted = null;
!           
!           protected PrintableComponent(Component componentToBePrinted) {
!               this.componentToBePrinted = componentToBePrinted;
!           }
!           
!           public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
              if (pageIndex > 0) {
!               return(NO_SUCH_PAGE);
!             } else {
!               Graphics2D g2 = (Graphics2D)g;
!               g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
!               disableDoubleBuffering(componentToBePrinted);
!               componentToBePrinted.paint(g2);
!               enableDoubleBuffering(componentToBePrinted);
!               return(PAGE_EXISTS);
              }
!           }
!       }
!     }
\ No newline at end of file
--- 42,87 ----
              printJob.print();
          }
!     }
! 
      public static void print(Component component) throws PrinterException {
!         print(new PrintUtils.PrintableComponent(component));
      }
! 
      public static void disableDoubleBuffering(Component c) {
!         RepaintManager.currentManager(c).setDoubleBufferingEnabled(false);
      }
  
      public static void enableDoubleBuffering(Component c) {
!         RepaintManager.currentManager(c).setDoubleBufferingEnabled(true);
      }
! 
      protected static class PrintableComponent implements Printable {
  
!         protected Component componentToBePrinted = null;
! 
!         protected PrintableComponent(Component componentToBePrinted) {
!             if (componentToBePrinted instanceof JScrollPane) {
!                 this.componentToBePrinted =
!                     ((JScrollPane)componentToBePrinted).getComponent(0);
! 
!             }
!             this.componentToBePrinted = componentToBePrinted;
!         }
! 
!         public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
              if (pageIndex > 0) {
!                 return (NO_SUCH_PAGE);
              }
!             else {
!                 Graphics2D g2 = (Graphics2D)g;
!                 g2.translate(
!                     pageFormat.getImageableX(),
!                     pageFormat.getImageableY());
!                 disableDoubleBuffering(componentToBePrinted);
!                 componentToBePrinted.paint(g2);
!                 enableDoubleBuffering(componentToBePrinted);
!                 return (PAGE_EXISTS);
!             }
!         }
!     }
! }
\ No newline at end of file




-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.