You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/10/09 07:33:21 UTC

svn commit: r454289 [10/22] - in /incubator/harmony/enhanced/classlib/trunk/modules/H-1609: ./ modules/ modules/applet/ modules/applet/src/ modules/applet/src/main/ modules/applet/src/main/java/ modules/applet/src/main/java/java/ modules/applet/src/mai...

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/javax/print/event/PrintServiceAttributeListener.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/javax/print/event/PrintServiceAttributeListener.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/javax/print/event/PrintServiceAttributeListener.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/javax/print/event/PrintServiceAttributeListener.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,26 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.3 $ 
+ */ 
+
+package javax.print.event;
+
+public interface PrintServiceAttributeListener {
+
+    public void attributeUpdate(PrintServiceAttributeEvent event);
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/javax/print/event/PrintServiceAttributeListener.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSDocPrintJob.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSDocPrintJob.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSDocPrintJob.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSDocPrintJob.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,405 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.2 $ 
+ */ 
+package org.apache.harmony.x.print;
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+import java.awt.image.ImageObserver;
+import java.awt.print.PageFormat;
+import java.awt.print.Pageable;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.util.ArrayList;
+import javax.print.Doc;
+import javax.print.DocFlavor;
+import javax.print.DocPrintJob;
+import javax.print.PrintException;
+import javax.print.PrintService;
+import javax.print.StreamPrintService;
+import javax.print.attribute.HashPrintJobAttributeSet;
+import javax.print.attribute.PrintJobAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.standard.MediaSize;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.OrientationRequested;
+import javax.print.event.PrintJobAttributeListener;
+import javax.print.event.PrintJobListener;
+
+/*
+ * Image2PSDocPrintJob
+  */
+public class All2PSDocPrintJob implements DocPrintJob {
+    private PrintService begetPrintService;
+    private HashPrintJobAttributeSet printJobAttributeSet;
+    private ArrayList printJobListeners;
+    private ArrayList printJobAttributeListeners; 
+    private boolean action = false;
+    private PrintStream outstream;
+    /*
+    private PrinterJob printerJob;
+    private MediaSize mediaSize;
+    */
+    private String jobName;
+    private int copies;
+        
+    private final static int BANK_MAX_BYTES = 32768;
+   
+    /*
+     * static method to read images 
+     */
+    public static Image readImage(InputStream source) 
+                                            throws PrintException {
+        ArrayList banks = new ArrayList();
+        ArrayList bankLengths = new ArrayList();
+        Image image = null;  
+        Toolkit toolkit;
+                
+        int bytesRead = 0;
+        int nBanks = 0;
+        int totalSize = 0;
+        byte[] byteImage;               
+        byte[] buffer; 
+                        
+        try {
+            do {             
+                buffer = new byte[BANK_MAX_BYTES];        
+                bytesRead = source.read(buffer);
+                if (bytesRead > 0) {
+                    banks.add(buffer);
+                    bankLengths.add(new Integer(bytesRead));
+                    totalSize += bytesRead;
+                }              
+            } while (bytesRead >= 0);
+            source.close();
+            nBanks = banks.size();
+            byteImage = new byte[totalSize];
+            int k=0;
+            for (int i = 0; i < nBanks; i++) {
+                buffer = (byte[])banks.get(i);
+                int bufferLength = ((Integer)bankLengths.get(i)).intValue();
+                for (int j = 0; j < bufferLength; j++) {
+                    byteImage[k++] = buffer[j];
+                }
+            }                
+        } catch (IOException ioe) {
+            throw new PrintException("Can't read print data.");
+        }
+        
+        toolkit = Toolkit.getDefaultToolkit();
+
+        image = toolkit.createImage(byteImage);
+        while (!toolkit.prepareImage(image, -1, -1, null) &&
+               (toolkit.checkImage(image, -1, -1, null) &
+                       (ImageObserver.ERROR | ImageObserver.ABORT)) == 0) {
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException ie) {
+                // Interrupted by user.
+                return (BufferedImage) null;
+            }
+        }
+        if (!toolkit.prepareImage(image, -1, -1, null)) {
+            throw new PrintException("Error while loading image (possibly, " +
+                    "image format is not supported).");
+        }
+        BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
+                image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
+        Graphics graphics = bufferedImage.getGraphics();
+        graphics.drawImage(image, 0, 0, null);
+        return bufferedImage;
+    }
+    
+    protected All2PSDocPrintJob(StreamPrintService printService) {
+        super();
+        begetPrintService = printService;
+        printJobListeners = new ArrayList();
+        printJobAttributeListeners = new ArrayList();
+        printJobAttributeSet = new HashPrintJobAttributeSet();
+        jobName = "PS printing";
+        copies = 1;
+        outstream = new PrintStream(printService.getOutputStream());
+    }
+
+    /* 
+     * Determines the PrintService object 
+     * to which this print job object is bound.
+     * It's  private field begetPrintService;
+     */
+    public PrintService getPrintService() {   
+        return begetPrintService;
+    }
+
+    /* 
+     *   Returns the print job attributes. 
+     */
+    public PrintJobAttributeSet getAttributes() {        
+        return printJobAttributeSet;
+    }
+
+    /*
+     * Registers a listener for event occurring during this print job. 
+     */
+    public void addPrintJobListener(PrintJobListener listener) {
+        if (listener != null){
+            if (! printJobListeners.contains(listener)){
+                printJobListeners.add(listener);
+            }
+        }
+    }
+    
+    /*
+     * Registers a listener for changes in the specified attributes
+     */
+    public void addPrintJobAttributeListener(
+            PrintJobAttributeListener listener,
+            PrintJobAttributeSet attributes) {
+        
+            if (listener != null){
+                printJobAttributeListeners.add(listener);
+            }
+            printJobAttributeSet.addAll(attributes);
+    }      
+    
+    
+    public void removePrintJobAttributeListener(
+            PrintJobAttributeListener listener) {
+            printJobAttributeListeners.remove(listener);
+    }
+
+  
+    public void removePrintJobListener(PrintJobListener listener) {
+        printJobListeners.remove(listener);
+    }
+    
+  
+    public void print(Doc doc, PrintRequestAttributeSet attributes)
+            throws PrintException {
+        
+        Object data;
+        DocFlavor docflavor;
+        String docflavorClassName;
+        Image image = null;
+        int x = 0;
+        int y = 0;
+        int width;
+        int height;
+        int iWidth;
+        int iHeight;        
+        int newWidth;
+        int newHeight;
+        float scaleX;
+        float scaleY; 
+        
+        synchronized (this) {
+            if (action) {
+                throw new PrintException("printing is in action");
+            }
+            action = true;
+        }
+
+        try { // for finally block. To make action false.
+
+            docflavor = doc.getDocFlavor();
+            try {
+                data = doc.getPrintData();
+            } catch (IOException ioexception) {
+                throw new PrintException("no data for print: "
+                        + ioexception.toString());
+            }            
+            if (docflavor == null) {
+                throw new PrintException("flavor is null");
+            }
+            if (!begetPrintService.isDocFlavorSupported(docflavor)) {
+                throw new PrintException("invalid flavor :"
+                        + docflavor.toString());
+            }
+
+            docflavorClassName = docflavor.getRepresentationClassName();
+
+            if (docflavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
+                docflavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
+                docflavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
+                docflavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
+                docflavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
+                docflavor.equals(DocFlavor.BYTE_ARRAY.PNG)) {                
+                try {
+                    image = readImage(doc.getStreamForBytes());
+                } catch (IOException ioe) {
+                    throw new PrintException(ioe);
+                }
+            } else if (docflavor.equals(DocFlavor.URL.GIF) ||
+                       docflavor.equals(DocFlavor.URL.JPEG) ||
+                       docflavor.equals(DocFlavor.URL.PNG)) {
+                URL url = (URL) data;
+                try {
+                    image = readImage(url.openStream());
+                } catch (IOException ioe) {
+                    throw new PrintException(ioe);
+                }
+            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)){
+                Printable printable = (Printable)data;
+                print(printable, null);
+            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
+                Pageable pageable = (Pageable)data;
+                print(null, pageable);
+            } else {
+                throw new PrintException("Wrong DocFlavor class: "
+                        + docflavorClassName);
+            }
+
+            if (image != null) {
+                MediaSize size = null;
+                if (attributes != null) {
+                    if (attributes.containsKey(MediaSize.class)) {
+                        size = (MediaSize) attributes.get(MediaSize.class);
+                    } else if (attributes.containsKey(MediaSizeName.class)) {
+                        MediaSizeName name = (MediaSizeName) attributes
+                                .get(MediaSizeName.class);
+                        size = MediaSize.getMediaSizeForName(name);
+                    } else {
+                        size = MediaSize
+                                .getMediaSizeForName(MediaSizeName.ISO_A4);
+                    }
+                } else {
+                    size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4);
+                }
+                width = (int) (size.getX(MediaSize.INCH) * 72.0);
+                height =(int) (size.getY(MediaSize.INCH) * 72.0);
+                if (attributes != null) {
+                    if (attributes.containsValue(
+                            OrientationRequested.LANDSCAPE)) {
+                        int temp = width;
+                        width = height;
+                        height = temp;
+                    }
+                }
+                iWidth = image.getWidth(null);
+                iHeight = image.getHeight(null);
+                x = (width - iWidth) / 2;
+                y = (height - iHeight) / 2;
+
+                Graphics2D2PS graphics = new Graphics2D2PS(outstream, height);
+                graphics.startPage(1);
+                if (x < 0 || y < 0) {
+                    scaleX = (float) image.getWidth(null) / (float) width;
+                    scaleY = (float) image.getHeight(null) / (float) height;
+                    newWidth = width;
+                    newHeight = height;
+                    
+                    if (scaleX > scaleY) {
+                        newWidth = (int) ((float) iWidth / scaleX);
+                        newHeight = (int) ((float) iHeight / scaleX);
+                        x = 0;
+                        y = (height - newHeight) / 2;
+                    } else {
+                        newWidth = (int) ((float) iWidth / scaleY);
+                        newHeight = (int) ((float) iHeight / scaleY);
+                        y = 0;
+                        x = (width - newWidth) / 2;
+                    }
+                    graphics.drawImage(image, x, y, newWidth, newHeight, null);
+                } else {
+                    graphics.drawImage(image, x, y, null);
+                }
+                graphics.endOfPage(1);
+                graphics.finish();
+            }
+
+        } finally {
+            synchronized (this) {
+                action = false;
+            }
+        }
+    }
+
+    private void print(Printable psPrintable, Pageable psDocument)
+            throws PrintException {
+        PageFormat format = null;
+        Graphics2D2PS converter = null;
+        
+        if (psPrintable == null && psDocument == null)  {
+            return;
+        }
+        
+        if (psDocument == null){
+            converter = new Graphics2D2PS(outstream);
+            format = null;            
+        } else {
+            double height = psDocument.getPageFormat(0).getHeight();        
+            converter = new Graphics2D2PS(outstream, height);               
+        }
+        
+        Graphics2D2PS fake = new Graphics2D2PS(new PrintStream(
+                new OutputStream() {
+                    public void write(int b) {
+                        // Do nothing.
+                    }
+                }));
+        
+        int iPage = 0;
+        int result = -1;
+        int pages = -1;
+        if (psDocument != null) {
+            pages = psDocument.getNumberOfPages();
+        }
+        do {
+            try {
+                Printable page = null;
+                PageFormat pageFormat = null;
+                result = -1;
+                if (psPrintable != null) {
+                    page = psPrintable;
+                    pageFormat = format;
+                    result = psPrintable.print(fake, format, iPage);
+                } else {
+                    if (pages != Pageable.UNKNOWN_NUMBER_OF_PAGES &&
+                        iPage >= pages) {
+                        break;
+                    }
+                    page = psDocument.getPrintable(iPage);
+                    pageFormat = psDocument.getPageFormat(iPage);
+                    if (page != null) {
+                        result = page.print(fake, pageFormat, iPage);
+                    } else {
+                        throw new PrinterException("No printable for page " +
+                                iPage + " in given document.");
+                    }
+                }
+                if (result == Printable.PAGE_EXISTS) {
+                    converter.startPage(iPage + 1);
+                    result = page.print(converter, pageFormat, iPage);
+                    converter.endOfPage(iPage + 1);
+                }
+            } catch (PrinterException pe) {
+                converter.finish();
+                throw new PrintException(pe.getMessage());
+            }
+            iPage++;            
+        } while (result == Printable.PAGE_EXISTS);
+        converter.finish();
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSDocPrintJob.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSStreamPrintService.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSStreamPrintService.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSStreamPrintService.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSStreamPrintService.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,192 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print;
+
+import java.io.OutputStream;
+import javax.print.DocFlavor;
+import javax.print.DocPrintJob;
+import javax.print.ServiceUIFactory;
+import javax.print.StreamPrintService;
+import javax.print.StreamPrintServiceFactory;
+import javax.print.attribute.Attribute;
+import javax.print.attribute.AttributeSet;
+import javax.print.attribute.PrintServiceAttribute;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.attribute.standard.ColorSupported;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.Media;
+import javax.print.attribute.standard.MediaPrintableArea;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.Sides;
+import javax.print.event.PrintServiceAttributeListener;
+
+/*
+ * Image2PSStreamPrintService
+ */
+public class All2PSStreamPrintService extends StreamPrintService {
+ 
+    private static final String outputFormat = "application/postscript";
+    private static final MediaSizeName mediaSizes[] = {
+            MediaSizeName.ISO_A3,
+            MediaSizeName.ISO_A4,
+            MediaSizeName.ISO_A5};
+
+    private static final Class supportedAttributeCategories[] = {
+            ColorSupported.class,
+            Copies.class, 
+            JobName.class, 
+            Media.class, 
+            MediaPrintableArea.class,  
+            Sides.class};
+
+    private static final DocFlavor supportedDocFlavors[] = {
+            DocFlavor.SERVICE_FORMATTED.PRINTABLE,
+            DocFlavor.SERVICE_FORMATTED.PAGEABLE,
+            DocFlavor.BYTE_ARRAY.GIF, 
+            DocFlavor.INPUT_STREAM.GIF, 
+            DocFlavor.URL.GIF,
+            DocFlavor.BYTE_ARRAY.JPEG, 
+            DocFlavor.INPUT_STREAM.JPEG, 
+            DocFlavor.URL.JPEG,
+            DocFlavor.BYTE_ARRAY.PNG, 
+            DocFlavor.INPUT_STREAM.PNG, 
+            DocFlavor.URL.PNG};
+                        
+    public All2PSStreamPrintService(OutputStream outputstream,
+            StreamPrintServiceFactory factory) {
+        super(outputstream);
+        if (factory == null) {
+            throw new NullPointerException("factory is null");
+        }   
+    }
+
+     public String getOutputFormat() {
+        return outputFormat;
+    }
+
+    public Class[] getSupportedAttributeCategories() {
+        Class copy_supportedAttrCats[] 
+                     = new Class[supportedAttributeCategories.length];
+        for (int i = 0; i < supportedAttributeCategories.length; i++) {
+            copy_supportedAttrCats[i] = supportedAttributeCategories[i];
+        }
+        return copy_supportedAttrCats;
+    }
+
+    public boolean isAttributeCategorySupported(Class category) {
+        if (category == null) {
+            throw new NullPointerException("Argument category is null");
+        }
+        if (!(javax.print.attribute.Attribute.class).isAssignableFrom(category)) {
+            throw new IllegalArgumentException(category.toString()
+                    + " is not an Attribute");
+        }
+
+        for (int i = 0; i < supportedAttributeCategories.length; i++) {
+            if (category.equals(supportedAttributeCategories[i]))
+                return true;
+        }
+        return false;
+    }
+                    
+        
+    public String getName() {
+        return "Convert source to Postscript language";
+    }
+
+    public DocFlavor[] getSupportedDocFlavors() {
+        DocFlavor copy_supportedDocFlavors[] 
+                       = new DocFlavor[supportedDocFlavors.length];
+        for (int i = 0; i < supportedDocFlavors.length; i++) {
+            copy_supportedDocFlavors[i] = supportedDocFlavors[i];
+        }
+        return copy_supportedDocFlavors;
+    }
+        
+    public boolean isDocFlavorSupported(DocFlavor flavor) {
+        if (flavor == null) {
+            throw new NullPointerException("Argument flavor is null");
+        }    
+            
+        for(int i = 0; i < supportedDocFlavors.length; i++){
+            if(flavor.equals(supportedDocFlavors[i]))
+                return true; 
+            } 
+        return false;
+    }
+
+    public DocPrintJob createPrintJob() {        
+        return new All2PSDocPrintJob(this);
+    }
+
+    public int hashCode() {
+        return getName().hashCode();
+    }
+
+    public boolean equals(Object obj) {
+        return obj == this || (obj instanceof All2PSStreamPrintService)
+            && ((All2PSStreamPrintService) obj).getName().equals(getName());
+    }    
+
+    public ServiceUIFactory getServiceUIFactory() {
+        return null;
+    }
+    /* methods below this line must be completed */
+
+    public PrintServiceAttributeSet getAttributes() {
+        return null;
+    }
+
+    public void addPrintServiceAttributeListener(
+            PrintServiceAttributeListener arg0) {
+    }
+
+    public void removePrintServiceAttributeListener(
+            PrintServiceAttributeListener arg0) {
+    }
+
+    public Object getDefaultAttributeValue(Class arg0) {
+        return null;
+    }
+
+    public PrintServiceAttribute getAttribute(Class arg0) {
+        return null;
+    }
+
+    public boolean isAttributeValueSupported(Attribute arg0, DocFlavor arg1,
+            AttributeSet arg2) {
+        return false;
+    }
+
+    public AttributeSet getUnsupportedAttributes(DocFlavor arg0,
+            AttributeSet arg1) {
+        return arg1;
+    }
+
+    public Object getSupportedAttributeValues(Class arg0, DocFlavor arg1,
+            AttributeSet arg2) {
+        return null;
+    }
+        
+}
+
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/All2PSStreamPrintService.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintJob.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintJob.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintJob.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintJob.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,234 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+import javax.print.Doc;
+import javax.print.DocFlavor;
+import javax.print.DocPrintJob;
+import javax.print.PrintException;
+import javax.print.PrintService;
+import javax.print.SimpleDoc;
+import javax.print.StreamPrintService;
+import javax.print.StreamPrintServiceFactory;
+import javax.print.attribute.AttributeSetUtilities;
+import javax.print.attribute.HashPrintJobAttributeSet;
+import javax.print.attribute.PrintJobAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.event.PrintJobAttributeListener;
+import javax.print.event.PrintJobListener;
+
+public class DefaultPrintJob implements DocPrintJob {
+    DefaultPrintService printService;
+    PrintClient printClient;
+    PrintJobAttributeSet printJobAS;
+    boolean busyFlag;
+
+    public DefaultPrintJob(DefaultPrintService printservice) {
+        if (printservice == null) {
+            throw new NullPointerException("Argument is null");
+        }
+        this.printService = printservice;
+        this.printClient = printService.getPrintClient();
+        printJobAS = new HashPrintJobAttributeSet();
+        busyFlag = false;
+    }
+
+    public PrintService getPrintService() {
+        return printService;
+    }
+
+    public PrintJobAttributeSet getAttributes() {
+        return AttributeSetUtilities.unmodifiableView(printJobAS);
+    }
+
+    //=======================================================================//
+    public void print(Doc userDoc, PrintRequestAttributeSet printRequestAS)
+            throws PrintException {
+
+        synchronized (this) {
+            if (busyFlag) {
+                throw new PrintException(
+                        "Already printed. Need to create new DocPrintJob.");
+            }
+            busyFlag = true;
+        }
+        
+        DocFlavor userDocDF = userDoc.getDocFlavor();
+
+        /*
+         * Checking if doc.DocFlavor is supported by the current
+         * PrintService
+         */
+        if (!printService.isDocFlavorSupported(userDocDF)) {
+            throw new PrintException("Doc flavor \'" + userDocDF
+                    + "\' is not supported");
+        }
+
+        /*
+         * Checking if doc.DocFlavor is supported directly by osClent. If it
+         * is not: - get StereamPrintServiceFactory for doc.DocFlavor -
+         * instantiate StreamPrintService - get PrintJob from it - run this
+         * PrintJob in separate thread
+         */
+        printClient = printService.getPrintClient();
+        if (printService.isDocFlavorSupportedByClient(userDocDF)) {
+            printClient.print(userDoc, printRequestAS);
+        } else {
+            try {
+                Doc clientDoc = userDoc;
+                PipedOutputStream spsOutStream = new PipedOutputStream();
+                PipedInputStream clientInputStream = new PipedInputStream(
+                        spsOutStream);
+
+                DocFlavor newFlavor = null;
+                StreamPrintServiceFactory spsf = null;
+                DocFlavor clientFlavors[] = printClient
+                        .getSupportedDocFlavors();
+
+                for (int i = 0; i < clientFlavors.length; i++) {
+                    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
+                            .lookupStreamPrintServiceFactories(userDocDF,
+                                    clientFlavors[i].getMimeType());
+                    if (factories.length > 0
+                            && Class.forName(
+                                    clientFlavors[i]
+                                            .getRepresentationClassName())
+                                    .isInstance(clientInputStream)) {
+                        spsf = factories[0];
+                        newFlavor = clientFlavors[i];
+                        break;
+                    }
+                }
+
+                if (spsf != null) {
+                    StreamPrintService sps = spsf.getPrintService(spsOutStream);
+
+                    /*
+                     * Constructing new Doc object for client: - connecting
+                     * InputStream of client with OutputStream of
+                     * StreamPrintSrevice - constructing DocFlavor for
+                     * StreamPrintSrevice output - creating new SimpleDoc
+                     * for client
+                     */
+                    clientDoc = new SimpleDoc(clientInputStream, newFlavor,
+                            userDoc.getAttributes());
+
+                    PrintJobThread printThread = new PrintJobThread(this,
+                            userDoc, printRequestAS, sps);
+                    printThread.start();
+                    printClient.print(clientDoc, printRequestAS);
+
+                    if (printThread.exceptionOccured()) {
+                        throw new PrintException(printThread
+                                .getPrintException());
+                    }
+                } else {
+                    throw new PrintException("Doc flavor "
+                            + userDocDF.getRepresentationClassName()
+                            + " is not supported");
+                }
+            } catch (ClassNotFoundException e) {
+                throw new PrintException(e);
+            } catch (IOException e) {
+                throw new PrintException(e);
+            } catch (PrintException e) {
+                throw e;
+            }
+        }
+    }
+
+    //=======================================================================//
+    public void addPrintJobAttributeListener(
+            PrintJobAttributeListener listener, PrintJobAttributeSet attributes) {
+        synchronized (this) {
+            // TODO - add print job attribute listener
+        }
+    }
+
+    public void addPrintJobListener(PrintJobListener listener) {
+        synchronized (this) {
+            // TODO - add print job listener
+        }
+    }
+
+    public void removePrintJobAttributeListener(
+            PrintJobAttributeListener listener) {
+        synchronized (this) {
+            // TODO - remove print job attribute listener
+        }
+    }
+
+    public void removePrintJobListener(PrintJobListener listener) {
+        synchronized (this) {
+            // TODO - remove print job listener
+        }
+    }
+
+    class PrintJobThread extends Thread {
+        DefaultPrintJob printJob;
+        Doc printDoc;
+        PrintRequestAttributeSet printAttributeSet;
+        Exception exception;
+        boolean exceptionisnotnull;
+        StreamPrintService streamservice;
+
+        /**
+         * job - parent DefaultPrintJob doc - doc to print attributeset -
+         * attributes set spsDocPrintJob - stream print service's print job
+         */
+        PrintJobThread(DefaultPrintJob job, Doc doc,
+                PrintRequestAttributeSet attributeset, StreamPrintService sps) {
+            this.printJob = job;
+            this.printDoc = doc;
+            this.printAttributeSet = attributeset;
+            this.streamservice = sps;
+            this.exception = null;
+            this.exceptionisnotnull = false;
+        }
+
+        public void run() {
+            try {
+                DocPrintJob spsDocPrintJob = streamservice.createPrintJob();
+                spsDocPrintJob.print(printDoc, printAttributeSet);
+            } catch (Exception e) {
+                exception = e;
+                exceptionisnotnull = true;
+                try {
+                    streamservice.getOutputStream().close();
+                } catch (IOException ioe) {
+                    // ignoring
+                }
+            }
+        }
+
+        boolean exceptionOccured() {
+            return exceptionisnotnull;
+        }
+
+        Exception getPrintException() {
+            return exception;
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintJob.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintService.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintService.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintService.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintService.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,393 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.print.DocFlavor;
+import javax.print.DocPrintJob;
+import javax.print.PrintService;
+import javax.print.ServiceUIFactory;
+import javax.print.StreamPrintService;
+import javax.print.StreamPrintServiceFactory;
+import javax.print.attribute.Attribute;
+import javax.print.attribute.AttributeSet;
+import javax.print.attribute.AttributeSetUtilities;
+import javax.print.attribute.HashAttributeSet;
+import javax.print.attribute.PrintServiceAttribute;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.event.PrintServiceAttributeListener;
+
+public class DefaultPrintService implements PrintService {
+
+    //= Fields ===============================================================//
+
+    private PrintClient client = null;
+    private EventNotifier notifier = null;
+    private String serviceName = null;
+
+    //= Constructors =========================================================//
+
+    public DefaultPrintService(String servicename, PrintClient printclient) {
+        if (printclient == null || servicename == null) {
+            throw new NullPointerException("Argument is null");
+        }
+
+        this.client = printclient;
+        this.serviceName = servicename;
+        notifier = EventNotifier.getNotifier();
+    }
+
+    //= Basic methods ======================================================//
+
+    PrintClient getPrintClient() {
+        return client;
+    }
+
+    public String getName() {
+        return serviceName;
+    }
+
+    public boolean equals(Object obj) {
+        if (obj instanceof DefaultPrintService) {
+            DefaultPrintService service = (DefaultPrintService) obj;
+            if (service.getName().equals(serviceName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        return serviceName.hashCode();
+    }
+
+    public String toString() {
+        return "Printer : " + serviceName;
+    }
+
+    //= Print service attributes ===========================================//
+
+    public PrintServiceAttribute getAttribute(Class category) {
+        if (!PrintServiceAttribute.class.isAssignableFrom(category)) {
+            throw new IllegalArgumentException();
+        }
+        PrintServiceAttributeSet attributes = getAttributes();
+        if (attributes.containsKey(category)) {
+            PrintServiceAttribute attribute = (PrintServiceAttribute) attributes
+                    .get(category);
+            return attribute;
+        }
+        return null;
+    }
+
+    public PrintServiceAttributeSet getAttributes() {
+        return AttributeSetUtilities.unmodifiableView(client.getAttributes());
+    }
+
+    //= Print request attributes =============================================//
+
+    public Class[] getSupportedAttributeCategories() {
+        return client.getSupportedAttributeCategories();
+    }
+
+    public boolean isAttributeCategorySupported(Class category) {
+        if (category == null) {
+            throw new NullPointerException("Argument 'category' is null");
+        }
+        if (!(Attribute.class.isAssignableFrom(category))) {
+            throw new IllegalArgumentException(
+                    "Argument 'category' must implement interface Attribute");
+        }
+
+        Class[] categories = getSupportedAttributeCategories();
+        for (int i = 0; i < categories.length; i++) {
+            if (categories[i].equals(category)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
+            AttributeSet attributes) {
+        if (attributes == null) {
+            return null;
+        }
+        if (flavor != null && !isDocFlavorSupported(flavor)) {
+            throw new IllegalArgumentException("Flavor " + flavor.getMimeType()
+                    + " is not supported by print service");
+        }
+        
+        Attribute[] attrs = attributes.toArray();
+        HashAttributeSet unsupported = new HashAttributeSet();
+        for (int i = 0; i < attrs.length; i++) {
+            if (!isAttributeValueSupported(attrs[i], flavor, attributes)) {
+                unsupported.add(attrs[i]);
+            }
+        }
+        if (unsupported.size() > 0) {
+            return unsupported;
+        }
+        return null;
+    }
+
+    public Object getDefaultAttributeValue(Class category) {
+        if (category == null) {
+            throw new NullPointerException("Argument 'category' is null");
+        }
+        if (!(Attribute.class.isAssignableFrom(category))) {
+            throw new IllegalArgumentException(
+                    "Argument 'category' must implement interface Attribute");
+        }
+
+        return client.getDefaultAttributeValue(category);
+    }
+
+    public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
+            AttributeSet attributes) {
+        if (category == null) {
+            throw new NullPointerException("Argument is null");
+        }
+        if (!(Attribute.class.isAssignableFrom(category))) {
+            throw new IllegalArgumentException(
+                    "Argument must implement interface Attribute");
+        }
+        if (flavor == null) {
+            return client.getSupportedAttributeValues(category, flavor,
+                    attributes);
+        }
+
+        DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
+        if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
+            return client.getSupportedAttributeValues(category, flavor,
+                    attributes);
+        }
+        /*
+         * Searching stream print service factories, which
+         * able to convert print data to flavor supported by
+         * PrintClient (both user and internal). And then,
+         * return supported attributes by created stream print
+         * service
+         */
+        for (int i = 0; i < clientFlavors.length; i++) {
+            StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
+                    .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
+                            .getMimeType());
+            for (int j = 0; j < factories.length; j++) {
+                StreamPrintService sps = factories[j]
+                        .getPrintService(new ByteArrayOutputStream());
+                if (sps != null) {
+                    try {
+                        sps.getOutputStream().close();
+                    } catch (IOException e) {
+                        // just ignore
+                    }
+                    sps.dispose();
+                    //return sps.getSupportedAttributeValues(category,
+                    //        flavor, attributes);
+                    return client.getSupportedAttributeValues(category,
+                            clientFlavors[i], attributes);
+                }
+            }
+        }
+
+        throw new IllegalArgumentException("DocFlavor '" + flavor
+                + "' is not supported by the print service");
+    }
+
+    public boolean isAttributeValueSupported(Attribute attrval,
+            DocFlavor flavor, AttributeSet attributes) {
+        if (attrval == null) {
+            throw new NullPointerException("Argument is null");
+        }
+
+        if (flavor == null) {
+            return client
+                    .isAttributeValueSupported(attrval, flavor, attributes);
+        }
+
+        DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
+        if (isDocFlavorSupportedByClient(flavor, clientFlavors)) {
+            return client
+                    .isAttributeValueSupported(attrval, flavor, attributes);
+        }
+
+        /*
+         * Searching stream print service factories, which
+         * able to convert print data to flavor supported by
+         * PrintClient (both user and internal). And then,
+         * return supported attributes by created stream print
+         * service
+         */
+        for (int i = 0; i < clientFlavors.length; i++) {
+            StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
+                    .lookupStreamPrintServiceFactories(flavor, clientFlavors[i]
+                            .getMimeType());
+            for (int j = 0; j < factories.length; j++) {
+                StreamPrintService sps = factories[j]
+                        .getPrintService(new ByteArrayOutputStream());
+                if (sps != null) {
+                    try {
+                        sps.getOutputStream().close();
+                    } catch (IOException e) {
+                        // just ignore
+                    }
+                    sps.dispose();
+                    //return sps.isAttributeValueSupported(attrval, flavor, attributes);
+                    return client.isAttributeValueSupported(attrval,
+                            clientFlavors[i], attributes);
+                }
+            }
+        }
+
+        throw new IllegalArgumentException("DocFlavor '" + flavor
+                + "' is not supported by the print service");
+
+    }
+
+    //= Listeners ============================================================//
+
+    public void addPrintServiceAttributeListener(
+            PrintServiceAttributeListener listener) {
+        notifier.addListener(this, listener);
+    }
+
+    public void removePrintServiceAttributeListener(
+            PrintServiceAttributeListener listener) {
+        notifier.removeListener(this, listener);
+    }
+
+    //= DocFlavors ===========================================================//
+
+    /*
+     * Returns two categories of DocFlavors:
+     *  1) DocFlavors supported by PrintClient
+     *  2) DocFlavors that can be converted by StreamPrintServices to 
+     *     PrintClient's DocFlavors
+     * 
+     *  If there is a DocFlavor that supported by PrintClient and by
+     *  StreamPrintService, the method returns PrintClient's one only. 
+     */
+
+    public DocFlavor[] getSupportedDocFlavors() {
+        DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
+        ArrayList flavors = new ArrayList();
+
+        /*
+         * Putting all PrintClient's supported flavors (except
+         * internal flavors) into list of flavors supported by
+         * this print service.
+         */
+        for (int i = 0; i < clientFlavors.length; i++) {
+            if (!isInternalDocFlavor(clientFlavors[i])) {
+                flavors.add(clientFlavors[i]);
+            }
+        }
+
+        /*
+         * Searching stream print service factories, which
+         * able to convert print data to flavor supported by
+         * PrintClient (both user and internal). And then,
+         * gathering all flavors supported by those factories
+         * and putting them into list of flavors supported
+         * by this print service.
+         */
+        for (int i = 0; i < clientFlavors.length; i++) {
+            StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
+                    .lookupStreamPrintServiceFactories(null, clientFlavors[i]
+                            .getMimeType());
+            for (int j = 0; j < factories.length; j++) {
+                DocFlavor[] factoryFlavors = factories[j]
+                        .getSupportedDocFlavors();
+                for (int k = 0; k < factoryFlavors.length; k++) {
+                    if (!flavors.contains(factoryFlavors[k])) {
+                        flavors.add(factoryFlavors[k]);
+                    }
+                }
+            }
+        }
+        return (DocFlavor[]) flavors.toArray(new DocFlavor[0]);
+    }
+
+    public boolean isDocFlavorSupported(DocFlavor flavor) {
+        if (flavor == null) {
+            throw new NullPointerException("DocFlavor flavor is null");
+        }
+
+        DocFlavor[] flavors = getSupportedDocFlavors();
+        for (int i = 0; i < flavors.length; i++) {
+            if (flavors[i].equals(flavor)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /*
+     * Checks, whether specified falvor is internal or not.
+     */
+    private boolean isInternalDocFlavor(DocFlavor flavor) {
+        if (flavor.getMimeType().toLowerCase().indexOf("internal") != -1) {
+            return true;
+        }
+        return false;
+    }
+
+    /*
+     * Checks, whether specified falvor is supported by
+     * PrintClient or not.
+     */
+    boolean isDocFlavorSupportedByClient(DocFlavor flavor) {
+        DocFlavor clientFlavors[] = client.getSupportedDocFlavors();
+        for (int i = 0; i < clientFlavors.length; i++) {
+            if (clientFlavors[i].equals(flavor)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    boolean isDocFlavorSupportedByClient(DocFlavor flavor,
+            DocFlavor[] clientFlavors) {
+        for (int i = 0; i < clientFlavors.length; i++) {
+            if (clientFlavors[i].equals(flavor)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    //= Service user interface factory =======================================//
+
+    public ServiceUIFactory getServiceUIFactory() {
+        // We have not service user interface factory
+        return null;
+    }
+
+    //= DocPrintJob ==========================================================//
+
+    public DocPrintJob createPrintJob() {
+        return new DefaultPrintJob(this);
+    }
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/DefaultPrintService.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/EventNotifier.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/EventNotifier.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/EventNotifier.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/EventNotifier.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,174 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print;
+
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import javax.print.PrintService;
+import javax.print.attribute.Attribute;
+import javax.print.attribute.HashPrintServiceAttributeSet;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.event.PrintServiceAttributeEvent;
+import javax.print.event.PrintServiceAttributeListener;
+
+/*
+ * Unified class EventNotifier is used for notifying attribute
+ * listeners of print services about attribute events. There is
+ * only one instance of EventNotifier which can be used by any
+ * number print services. Generally, it is used by instances of
+ * DefaultPrintService class.
+ */
+public class EventNotifier extends Thread {
+
+    private static ArrayList services = new ArrayList();
+    private static HashMap listeners = new HashMap();
+    private static HashMap attributes = new HashMap();
+    private static EventNotifier notifier = new EventNotifier();
+    private boolean running = false;
+    
+    private EventNotifier() {
+        setPriority(Thread.NORM_PRIORITY);
+        setDaemon(true);
+    }
+
+    /*
+     * This method returns the only instance of this class.
+     */
+    public static EventNotifier getNotifier() {
+        return notifier;
+    }
+    
+    /*
+     * Adds pair service - listener to the map of listeners.
+     * Added listener is notified as soon as any attribute
+     * event occurs in service. 
+     */
+    public void addListener(PrintService service,
+            PrintServiceAttributeListener listener) {
+        if (service == null || listener == null) {
+            return;
+        }
+        
+        if (services.contains(service)) {
+            ArrayList serviceListeners = (ArrayList)listeners.get(service);
+            serviceListeners.add(listener);
+        } else {
+            services.add(service);
+            ArrayList serviceListeners = new ArrayList();
+            serviceListeners.add(listener);
+            listeners.put(service, serviceListeners);
+            PrintServiceAttributeSet serviceAttributes =
+                service.getAttributes();
+            attributes.put(service, serviceAttributes);
+        }
+
+        if (!running) {
+            start();
+        }
+    }
+
+    /*
+     * Removes pair service - listener from the map of listeners.
+     * Removed listener never receive notifications again, except
+     * it is not added again. 
+     */
+    public void removeListener(PrintService service,
+            PrintServiceAttributeListener listener) {
+        if (service == null || listener == null) {
+            return;
+        }
+        
+        if (services.contains(service)) {
+            ArrayList serviceListeners = (ArrayList)listeners.get(service);
+            serviceListeners.remove(listener);
+            if (serviceListeners.size() == 0) {
+                listeners.remove(service);
+                attributes.remove(service);
+                services.remove(service);
+            }
+        }
+
+        if (services.size() == 0) {
+            running = false;
+        }
+    }
+    
+    /*
+     * Stops event notifier. While event notifier is stopped,
+     * all added listeners do not receive any notifications.
+     */
+    public void Finish() {
+        running = false;
+    }
+    
+    /*
+     * Starts event notifier. Event notifier starts automatically
+     * when at least one listener added, and stops when all
+     * listeners removed.
+     */
+    public void run() {
+        try {
+            running = true;
+            while (running) {
+                Thread.sleep(1000);
+                
+                for (int i = 0; i < services.size(); i++) {
+                    PrintService service = (PrintService)services.get(i);
+                    PrintServiceAttributeSet lastSet =
+                        (PrintServiceAttributeSet)attributes.get(service);
+                    PrintServiceAttributeSet newSet = service.getAttributes();
+                    if (!lastSet.equals(newSet)) {
+                        PrintServiceAttributeSet updated =
+                            getUpdatedAttributeSet(lastSet, newSet);
+                        if (updated.size() > 0) {
+                            PrintServiceAttributeEvent event =
+                                new PrintServiceAttributeEvent(service,updated);
+                            ArrayList serviceListeners =
+                                (ArrayList)listeners.get(service);
+                            for (int j = 0; j < serviceListeners.size(); j++) {
+                                PrintServiceAttributeListener listener =
+                                    (PrintServiceAttributeListener)
+                                    serviceListeners.get(j);
+                                listener.attributeUpdate(event);
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (InterruptedException ie) {
+            // EventNotifier interrupted.
+            running = false;
+        }
+    }
+    
+    private PrintServiceAttributeSet getUpdatedAttributeSet(
+            PrintServiceAttributeSet oldSet, PrintServiceAttributeSet newSet) {
+        Attribute[] newAttributes = newSet.toArray();
+        PrintServiceAttributeSet updated = new HashPrintServiceAttributeSet();
+        for (int i = 0; i < newAttributes.length; i++) {
+            if (!oldSet.containsValue(newAttributes[i])) {
+                updated.add(newAttributes[i]);
+            }
+        }
+        return updated;
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/EventNotifier.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,787 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print;
+
+import java.awt.Color;
+import java.awt.Composite;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.RenderingHints.Key;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+import java.awt.image.BufferedImage;
+import java.awt.image.BufferedImageOp;
+import java.awt.image.ImageObserver;
+import java.awt.image.RenderedImage;
+import java.awt.image.renderable.RenderableImage;
+import java.io.PrintStream;
+import java.text.AttributedCharacterIterator;
+import java.text.CharacterIterator;
+import java.util.Date;
+import java.util.Map;
+
+/*
+ * Graphics2D2PS
+ *  
+ */
+public class Graphics2D2PS extends Graphics2D {
+    
+    private Color color;
+    private Color bgcolor;
+    private Color XORcolor; 
+    private Paint paint; 
+    private Font font;    
+    private PrintStream out_stream;
+    
+    static double const1 = 842; // 11.7"
+    static double yscale = 1;
+    
+    private static int convY (int y){      
+        return (int)(const1*yscale)- y ;        
+    }
+   
+    public void setY(int y){
+        const1 = (double)y;
+    }
+           
+    private static String threebytes2Hex (int b){
+        
+        char [] hex = {'0', '1', '2', '3', '4', '5', '6', '7',
+                       '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+        
+        char [] ret = new char[6];
+        
+            for (int i = 0; i < 6; i++){
+                ret[5-i] = hex[b & 0x0F];
+                b = b >> 4;
+        }
+        return new  String(ret);
+    }   
+            
+    public Graphics2D2PS(PrintStream stream, double height) {              
+        super();
+        if (stream == null) {
+            throw new IllegalArgumentException("stream is null");
+        }          
+        out_stream = stream;
+        font = new Font("Courier", Font.PLAIN, 12);
+        color = Color.BLACK;
+        bgcolor = Color.WHITE;
+        yscale = 1;
+        const1 = height;
+        out_stream.println("%!PS-Adobe");
+        out_stream.println("%%Title: Java printJob");
+        out_stream.println("%%Creator: Intel(tm) java printing ");
+        out_stream.println("%%CreationDate: " + new Date());
+        out_stream.println("%%EndComments"); 
+    }
+    
+    public Graphics2D2PS(PrintStream stream) {    
+        this(stream, 842D);   
+    }   
+
+    public void finish(){       
+        out_stream.println("%%EOF");   
+        out_stream.close();
+    }
+
+    public void startPage(int number){
+        out_stream.println("%%Page: " + number + " " + number);
+    }
+    
+    public void endOfPage(int number){
+        out_stream.println("showpage");
+        out_stream.println("%%EndPage: " + number + " " + number);
+    }
+         
+    /* drawImage-s */    
+    public boolean drawImage(Image image, int x, int y,
+            ImageObserver imageObserver) {
+        drawImage(image, x, convY(y));
+        return true;
+    }   
+  
+    public boolean drawImage(Image image, int x, int y, int width, int height,
+            ImageObserver imageObserver) {
+        float w;
+        float h;         
+        BufferedImage imageGIF = (BufferedImage) image;
+        w = (float)imageGIF.getWidth();
+        h = (float)imageGIF.getHeight();       
+        drawImage(image, x, convY(y), true, ((float)width)/w , ((float)height)/h);
+        return true;
+    }
+        
+    public boolean drawImage(Image image, int x, int y, Color bbgcolor,
+            ImageObserver imageObserver) {
+        int iw;
+        int ih;
+        Color cur_color;
+        
+        BufferedImage imageGIF = (BufferedImage) image;
+        cur_color = getColor();
+        setColor(bbgcolor);
+        
+        iw = imageGIF.getWidth();
+        ih = imageGIF.getHeight();               
+        fillRect(x, y, iw, ih);
+        setColor(cur_color);
+        
+        drawImage(image, x, convY(y));
+        return true;
+    }
+    
+    
+    public boolean drawImage(Image image, int x, int y, int width, int height,
+            Color bbgcolor, ImageObserver imageObserver) {
+        float w;
+        float h;
+        Color cur_color;
+
+        cur_color = getColor();
+        setColor(bbgcolor);        
+        fillRect(x, y, width, height);
+        setColor(cur_color);
+        
+        BufferedImage imageGIF = (BufferedImage) image;
+        w = (float)imageGIF.getWidth();
+        h = (float)imageGIF.getHeight();
+        
+        drawImage(image, x, convY(y), true, ((float)width)/w , ((float)height)/h);
+        return true;
+    }
+     
+    
+    public boolean drawImage(Image image, 
+            int dx1, int dy1, int dx2, int dy2,
+            int sx1, int sy1, int sx2, int sy2, 
+            ImageObserver imageObserver) {
+        
+        int sx;
+        int sy;
+        int width;
+        int height;
+        int dx;
+        int dy;
+        int d;
+        int comp;
+        BufferedImage newImage;
+        BufferedImage imageGIF;
+        
+        /* this method have to be improved to flip image 
+         * if dx2 < dx1 or dy2 <dy1
+         */     
+        if (dx2 < dx1) {
+            d = dx2;
+            dx2 = dx1;
+            dx1 = d;
+        }
+        if (dy2 < dy1) {
+            d = dy2;
+            dy2 = dy1;
+            dy1 = d;
+        }
+        dx = dx2 - dx1 + 1;
+        dy = dy2 - dy1 + 1;       
+        
+        imageGIF = (BufferedImage) image;
+        width = imageGIF.getWidth();
+        height = imageGIF.getHeight();       
+        if (dx2 > width || dy2 > height){
+            return false;
+        }
+        newImage = new BufferedImage(dx, dy, BufferedImage.TYPE_INT_ARGB);  
+        
+        sy = 0;
+        for (int iy = dy1; iy <= dy2; iy++) {
+            sx = 0;
+            for (int ix = dx1; ix <= dx2; ix++) {   
+                comp = imageGIF.getRGB(ix, iy);
+                newImage.setRGB(sx++, sy, comp);              
+            } 
+            sy++;                
+        }        
+        drawImage(newImage, sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1, null);
+        
+        return true;         
+    }
+    
+    public boolean drawImage(Image image, 
+            int dx1, int dy1, int dx2, int dy2,
+            int sx1, int sy1, int sx2, int sy2, 
+            Color bbgcolor, ImageObserver imageObserver) {
+        
+        Color cur_color;
+        cur_color = getColor();
+        setColor(bbgcolor);        
+        fillRect( sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1);
+        setColor(cur_color);
+        
+        return drawImage(image, 
+                dx1, dy1, dx2, dy2,
+                sx1, sy1, sx2, sy2, 
+                imageObserver); 
+        
+    }
+
+    /* method have to be implemented*/
+    public boolean drawImage(Image image, AffineTransform transform,
+            ImageObserver imageObserver) {
+        return true;        
+    }    
+    
+    /* method have to be implemented*/     
+    public void drawImage(BufferedImage image, BufferedImageOp arg1, 
+            int arg2, int arg3) {       
+    }
+    
+    
+    /*
+     * common private methods for drawImage methods.  
+     */    
+    private void drawImage(Image image, int x, int y) {
+         drawImage(image, x, y, false, 0f, 0f);     
+    }       
+
+    private void drawImage(Image image, int x, int y, boolean scale,
+            float sx, float sy) {
+        int line = 0;
+        int comp;
+        int imageHeight;
+        int imageWidth;
+        BufferedImage imageGIF;
+        
+        if (image != null) {
+            imageHeight = image.getHeight(null);
+            imageWidth = image.getWidth(null);           
+            imageGIF = (BufferedImage) image;          
+           
+            out_stream.println("");
+            out_stream.println(x + " " + y + " translate");  
+            if (scale){
+                out_stream.println(sx + " " + sy + " scale");               
+            }
+            out_stream.print(imageWidth + " ");
+            out_stream.println(imageHeight + " 8");
+            
+            out_stream.println(" [1 0 0 -1 0 1]");   
+            out_stream.println("{ currentfile");
+            
+            out_stream.println(" 32 string readhexstring pop");
+            out_stream.println("}");
+            out_stream.println("false 3"); 
+            out_stream.println("colorimage");             
+            
+            for (int iy = 0; iy < imageHeight; iy++) {
+                for (int ix = 0; ix < imageWidth; ix++) {   
+                    comp = imageGIF.getRGB(ix, iy);
+                    out_stream.print(threebytes2Hex(comp));                                         
+                    if (line++ == 30) {
+                        out_stream.println();
+                        line = 0;
+                    }                      
+                }
+                if (line != 0){
+                    line = 0;
+                    out_stream.println();
+                }
+            }
+              
+            if (scale){
+                out_stream.println(1/sx + " " + 1/sy + " scale");                   
+            }
+            out_stream.println((-x) + " " + (-y) + " translate");
+            out_stream.println("stroke");
+        }
+        return;
+    }
+   
+    
+    
+    public void drawString(String text, float x, float y) {
+        drawString(text, (int) x, (int) y);
+    }
+    
+    public void drawString(String text, int x, int y) {
+        Font cur_font = getFont(); 
+        y = convY(y);
+        out_stream.println("/" + cur_font.getName() + " findfont");
+        out_stream.println(cur_font.getSize() + " scalefont setfont");
+        out_stream.println("  " + x + " " + y + " moveto");
+        out_stream.println("(" + text + ") show");       
+        out_stream.println("stroke");
+    }  
+
+    public void drawString(AttributedCharacterIterator iterator, 
+                           float x, float y) {
+        drawString(iterator, (int) x, (int) y);
+    }
+    
+    public void drawString(AttributedCharacterIterator iterator, int x, int y) {
+
+        int i = 0;
+        int n = iterator.getEndIndex();
+        char [] cc = new char[n];
+        
+        for (char c = iterator.first(); c != CharacterIterator.DONE; 
+                c = iterator.next()) {
+            cc[i++] = c;
+        }
+        drawChars(cc, 0, n, x, y);        
+    }
+
+    
+    public void drawLine(int x1, int y1, int x2, int y2)  {
+        out_stream.println("newpath");  
+        out_stream.println("  " + x1 + " " + convY(y1) + " moveto");
+        out_stream.println("  " + x2 + " " + convY(y2) + " lineto");
+        out_stream.println("stroke");         
+    }
+    
+    
+    
+    public void drawOval(int x, int y, int width, int height) {    
+        drawArc(x, y, width, height, 0, 360, false);       
+    }
+
+    
+    public void fillOval(int x, int y, int width, int height) {
+        drawArc(x, y, width, height, 0, 360, true);
+    }
+
+    
+    public void drawArc(int x, int y, int width, int height, int startAngle,
+            int arcAngle) {          
+        drawArc(x, y, width, height, startAngle, arcAngle, false);  
+    }
+    
+    public void fillArc(int x, int y, int width, int height, 
+            int startAngle, int arcAngle) {      
+        drawArc(x, y, width, height, startAngle, arcAngle, true);      
+    }
+      
+    /*
+     * common private method for drawOval, fillOval, 
+     * drawArc and fillArc methods.  
+     */
+    private void drawArc(int x, int y, int width, int height, int startAngle,
+            int arcAngle, boolean fill) {   
+        
+        int cx = x + width /2;
+        int cy = convY(y + height /2);
+        y = convY(y);
+        
+        float scale1 = (float)width/(float)height;
+        float scale2 = (float)height/(float)width;       
+        
+        out_stream.println("newpath");
+        out_stream.println(scale1 + " 1 scale");
+        out_stream.print("  " + (cx * scale2));
+        out_stream.print(" " + cy + " " + height /2); 
+        out_stream.println(" " + startAngle + " " + arcAngle + " arc");
+        if (fill) {      
+            out_stream.print("  " + (cx * scale2));
+            out_stream.println(" " + cy + " lineto");                
+            out_stream.println("fill");       
+        }
+        out_stream.println(scale2 + " 1 scale");
+        out_stream.println("stroke");       
+    } 
+ 
+    public void drawRoundRect(int x, int y, int width, int height,
+            int arcWidth, int arcHeight) {
+        drawRoundRect(x, y, width, height, arcWidth, arcHeight, false);
+    }
+    
+    public void fillRoundRect(int x, int y, int width, int height,
+            int arcWidth, int arcHeight) {
+        drawRoundRect(x, y, width, height, arcWidth, arcHeight, true);
+    }
+    
+    /*
+     * common private method for drawRoundRect 
+     * and fillRoundRect methods.  
+     */        
+    private void drawRoundRect(int x, int y, int width, int height,
+            int arcWidth, int arcHeight, boolean fill) { 
+             
+        int x1 = x + arcWidth;
+        int x2 = x + width - arcWidth;
+       
+        int y1 = convY(y + arcHeight);
+        int y2 = convY(y + height - arcHeight);        
+        y = convY(y);   
+        
+        float scale1 = (float)arcWidth/(float)arcHeight;
+        float scale2 = (float)arcHeight/(float)arcWidth;  
+       
+        out_stream.println("newpath");
+        out_stream.println("  " + x + " " + y1 + " moveto");
+        out_stream.println(scale1 + " 1 scale");        
+        out_stream.print("  " + (x1 * scale2) + " " + y2 + " ");
+        out_stream.println(arcHeight + " 180 270 arc");
+        out_stream.print("  " + (x2 * scale2) + " " + y2 + " "); 
+        out_stream.println(arcHeight + " 270 0 arc");
+        out_stream.print("  " + (x2 * scale2) + " " + y1 + " ");
+        out_stream.println(arcHeight + " 0 90 arc");
+        out_stream.print("  " + (x1 * scale2) + " " + y1 + " ");
+        out_stream.println(arcHeight + " 90 180 arc");
+        out_stream.println(scale2 + " 1 scale");
+        if (fill) { 
+            out_stream.println("fill");       
+        }        
+        out_stream.println("stroke");        
+    }
+    
+    public void drawRect(int x, int y, int width, int height) {        
+        int x2 = x + width;
+        int y1 = convY(y);
+        int y2 = convY(y + height);        
+        int [] xPoints = {x, x2, x2, x};
+        int [] yPoints = {y1, y1, y2, y2};
+        drawPolyline (xPoints, yPoints, 4, true, false);
+    }
+
+    public void fillRect(int x, int y, int width, int height) {
+        int x2 = x + width;
+        int y1 = convY(y);
+        int y2 = convY(y + height);        
+        int [] xPoints = {x, x2, x2, x};
+        int [] yPoints = {y1, y1, y2, y2};
+        drawPolyline (xPoints, yPoints, 4, true, true);        
+    }       
+    
+    public void clearRect(int x, int y, int width, int height) {
+        Color savecolor = getColor();
+        setColor(bgcolor);      
+        fillRect(x, y, width, height);
+        setColor(savecolor);
+    }   
+    
+    public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
+        for (int i = 0; i < nPoints; i++) {
+            yPoints[i]=convY(yPoints[i]);
+        } 
+        drawPolyline (xPoints, yPoints, nPoints, true, false); 
+    }
+
+    
+    public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {          
+        for (int i = 0; i < nPoints; i++) {
+            yPoints[i]=convY(yPoints[i]);
+        }        
+        drawPolyline (xPoints, yPoints, nPoints, false, false);       
+    }
+
+    public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
+        for (int i = 0; i < nPoints; i++) {
+            yPoints[i]=convY(yPoints[i]);
+        } 
+        drawPolyline (xPoints, yPoints, nPoints, true, true);      
+    }
+    
+    /*
+     * common private method for drawPolyline, drawPolygon, drawRect,
+     * clearRect, fillPolyline, fillPolygon and  fillRect methods.  
+     */
+    private void drawPolyline(int[] xPoints, int[] yPoints, int nPoints,
+            boolean close, boolean fill) {
+
+        out_stream.println("newpath");
+        out_stream.print("  " + xPoints[0]); 
+        out_stream.println(" " + yPoints[0] + " moveto");
+        
+        for (int i = 1; i < nPoints; i++) {
+            out_stream.print("  " + xPoints[i]); 
+            out_stream.println(" " + yPoints[i] + " lineto");
+        }
+        if (close) {
+            out_stream.println("closepath");            
+        }
+        if (fill) {
+            out_stream.println("fill");
+        }
+        out_stream.println("stroke");
+    }      
+   
+    
+    public void draw(Shape shape) {
+        drawShape(shape, false);
+    }
+
+    public void fill(Shape shape) {
+        drawShape(shape, true);
+    }
+
+    private void drawShape(Shape shape, boolean fill) {
+        float[] coords = new float[6];
+        int i;
+        PathIterator  pathIterator;    
+        pathIterator = shape.getPathIterator((AffineTransform)null);
+        
+        out_stream.println("newpath 3");
+        i = 0;
+        int j=0;
+        
+        while (!pathIterator.isDone()){
+            i=pathIterator.currentSegment(coords);
+            switch (i) {
+                case PathIterator.SEG_MOVETO: {
+                    out_stream.print("  " + (int) coords[0] + " ");
+                    out_stream.println(convY((int) coords[1]) + " moveto");
+                    break;
+                }
+                case PathIterator.SEG_LINETO: {
+                    out_stream.println("  " + (int) coords[0] + " ");
+                    out_stream.println(convY((int) coords[1]) + " lineto");
+                    break;
+                }
+                case PathIterator.SEG_QUADTO: {
+                    //fake - need to improved
+                    out_stream.print("  " + (int) coords[0] + " ");
+                    out_stream.println(convY((int) coords[1]) + " lineto");                     
+                    out_stream.print("  " + (int) coords[2] + " ");
+                    out_stream.println(convY((int) coords[3]) + " lineto");
+                    break;  
+                }
+                case PathIterator.SEG_CUBICTO: {
+                    out_stream.print("  " + (int) coords[0] + " ");
+                    out_stream.print(convY((int) coords[1]));
+                    out_stream.print("  " + (int) coords[2] + " ");
+                    out_stream.print(convY((int) coords[3]));
+                    out_stream.print("  " + (int) coords[4] + " ");
+                    out_stream.print(convY((int) coords[5]));
+                    out_stream.println(" curveto");
+                    break;
+                }
+                case PathIterator.SEG_CLOSE: {
+                    out_stream.println("closepath");
+                    break;
+                } 
+            }
+            pathIterator.next();
+        }
+        
+        if (fill) {
+            out_stream.println("fill");
+        }
+        out_stream.println("stroke");
+    }      
+           
+    public Color getColor() { 
+        return color;
+    }
+
+    public void setColor(Color arg_color) {
+        color = arg_color;        
+        float[] rgb = color.getRGBColorComponents((float[])null);
+        out_stream.print("  " + rgb[0] + " " + rgb[1]);
+        out_stream.println(" " + rgb[2] + " setrgbcolor");  
+    }
+
+    public Color getBackground() {
+        return bgcolor;
+    }
+
+    public void setBackground(Color arg_color) {
+        bgcolor = arg_color;
+    }
+        
+    public void setXORMode(Color arg_color) {        
+        XORcolor = arg_color;
+    }
+
+    public Font getFont() {
+        return font;
+    }
+
+    public void setFont(Font arg_font) {
+        font=arg_font;
+    }
+
+    public FontMetrics getFontMetrics(Font arg_font) {
+        Font cur_font = getFont();
+        setFont(arg_font);
+        FontMetrics fontMetrics=getFontMetrics(); 
+        setFont(cur_font);
+        return fontMetrics;
+    }
+
+    public void translate(int x, int y) {
+          out_stream.println(x + " " + (-y) + " translate");
+    }
+
+    public void translate(double x, double y) {
+        translate((int)x, (int)y);
+    }
+    
+    public void rotate(double theta) {
+        rotate(theta, 0d, 0d);
+    }
+
+    public void rotate(double theta, double x, double y) {
+        double alfa; //angle in degrees 
+        int y0;
+        int x0;
+        alfa = - theta * 180/java.lang.Math.PI;
+        x0 =(int)x;
+        y0 = convY((int)y);
+        out_stream.println(x0 + " " + y0 + " translate");       
+        out_stream.println(alfa + " rotate");
+        out_stream.println((-x0) + " " + (-y0) + " translate");
+    }
+       
+    public void scale(double sx, double sy) {
+        out_stream.println(sx + " " + sy + " scale");
+        yscale = yscale/sy;
+    }
+
+    public Paint getPaint() {      
+        return  paint; 
+    }
+
+    public void setPaint(Paint arg0) {
+        paint = arg0;
+    }
+    
+    public void setClip(int x, int y, int width, int height) {
+        int x2 = x + width;
+        int y1 = convY(y);
+        int y2 = convY(y + height);
+        
+        out_stream.println("newpath");
+        out_stream.println("  " + x + " " + y1 + " moveto");
+        out_stream.println("  " + x2 + " " + y1 + " lineto");
+        out_stream.println("  " + x2 + " " + y2 + " lineto");
+        out_stream.println("  " + x + " " + y2 + " lineto");
+        out_stream.println("closepath clip");   
+    }      
+    
+    /* methods below this line must be implemented*/    
+    public Graphics create() {        
+        return null;
+    }
+
+    public Rectangle getClipBounds() {       
+        return null;
+    }
+
+    public Shape getClip() {
+        return null;
+    }
+
+    public void setClip(Shape arg0) {       
+    }
+
+    public void shear(double arg0, double arg1) {
+    }
+   
+    public Composite getComposite() {
+        return null;
+    }
+
+    public void setComposite(Composite arg0) {
+    }
+
+    public GraphicsConfiguration getDeviceConfiguration() {
+        return null;
+    }
+
+    public RenderingHints getRenderingHints() {
+        return null;
+    }
+
+    public void clip(Shape arg0) {
+    }
+  
+   
+    public Stroke getStroke() {
+        return null;
+    }
+
+    public void setStroke(Stroke arg0) {
+    }
+
+    public FontRenderContext getFontRenderContext() {
+        return null;
+    }
+
+    public void drawGlyphVector(GlyphVector arg0, float arg1, float arg2) {
+    }
+
+    public AffineTransform getTransform() {
+        return null;
+    }
+
+    public void setTransform(AffineTransform arg0) {
+    }
+
+    public void transform(AffineTransform arg0) {
+    }
+
+    public void addRenderingHints(Map hints) {
+    }
+
+    public void setRenderingHints(Map hints) {
+    }
+
+    public boolean hit(Rectangle arg0, Shape arg1, boolean arg2) {
+        return false;
+    }
+
+    public void drawRenderedImage(RenderedImage arg0, AffineTransform arg1) {
+    }
+
+    public void drawRenderableImage(RenderableImage arg0, 
+                                            AffineTransform arg1) {
+    }
+
+    public Object getRenderingHint(Key hintKey) {
+        return null;
+    }
+
+    public void setRenderingHint(RenderingHints.Key hintKey, 
+                                            Object hintValue) {
+    }
+
+    public void dispose() {      
+    }
+
+    public void setPaintMode() {        
+    }
+  
+    public void clipRect(int x, int y, int width, int height) {
+    }
+        
+    public void copyArea(int x, int y, int width, int height, int dx, int dy) {
+    }    
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java
------------------------------------------------------------------------------
    svn:executable = *