changeset in /hg/icedtea6: 2008-04-14 Joshua Sumali <jsumali at r...

Joshua Sumali jsumali at redhat.com
Mon Apr 14 11:10:26 PDT 2008


changeset 43f18ddc7c1c in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=43f18ddc7c1c
description:
	2008-04-14  Joshua Sumali  <jsumali at redhat.com>

	        * rt/net/sourceforge/jnlp/services/XFileContents.java: Add support for
	        JNLPRandomAccessFile.
	        * rt/net/sourceforge/jnlp/services/XServiceManagerStub.java: Add
	        PrintService and JNLPRandomAccessFile services.
	        * rt/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java: New file.
	        * rt/net/sourceforge/jnlp/services/XPrintService.java: Likewise.

diffstat:

5 files changed, 345 insertions(+), 2 deletions(-)
ChangeLog                                                   |    9 
rt/net/sourceforge/jnlp/services/XFileContents.java         |    3 
rt/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java |  208 +++++++++++
rt/net/sourceforge/jnlp/services/XPrintService.java         |  123 ++++++
rt/net/sourceforge/jnlp/services/XServiceManagerStub.java   |    4 

diffs (396 lines):

diff -r c106e5ac6bf3 -r 43f18ddc7c1c ChangeLog
--- a/ChangeLog	Mon Apr 14 11:08:37 2008 -0400
+++ b/ChangeLog	Mon Apr 14 14:09:53 2008 -0400
@@ -1,3 +1,12 @@ 2008-04-14  Lillian Angel  <langel at redha
+2008-04-14  Joshua Sumali  <jsumali at redhat.com>
+
+	* rt/net/sourceforge/jnlp/services/XFileContents.java: Add support for
+	JNLPRandomAccessFile.
+	* rt/net/sourceforge/jnlp/services/XServiceManagerStub.java: Add
+	PrintService and JNLPRandomAccessFile services.
+	* rt/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java: New file.
+	* rt/net/sourceforge/jnlp/services/XPrintService.java: Likewise.
+
 2008-04-14  Lillian Angel  <langel at redhat.com>
 
 	* Makefile.in: Regenerated.
diff -r c106e5ac6bf3 -r 43f18ddc7c1c rt/net/sourceforge/jnlp/services/XFileContents.java
--- a/rt/net/sourceforge/jnlp/services/XFileContents.java	Mon Apr 14 11:08:37 2008 -0400
+++ b/rt/net/sourceforge/jnlp/services/XFileContents.java	Mon Apr 14 14:09:53 2008 -0400
@@ -24,6 +24,7 @@ import javax.jnlp.*;
 import javax.jnlp.*;
 
 import net.sourceforge.jnlp.*;
+import net.sourceforge.jnlp.runtime.JNLPRuntime;
 
 /**
  * File contents.
@@ -105,7 +106,7 @@ class XFileContents implements FileConte
      * @throws IOException if an I/O exception occurs.
      */
     public JNLPRandomAccessFile getRandomAccessFile(String mode) throws IOException {
-        return null;
+        return new XJNLPRandomAccessFile(file, mode);
     }
 
     /**
diff -r c106e5ac6bf3 -r 43f18ddc7c1c rt/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java	Mon Apr 14 14:09:53 2008 -0400
@@ -0,0 +1,208 @@
+/* XJNLPRandomAccessFile.java
+   Copyright (C) 2008 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+package net.sourceforge.jnlp.services;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import javax.jnlp.JNLPRandomAccessFile;
+
+public class XJNLPRandomAccessFile implements JNLPRandomAccessFile {
+
+	private RandomAccessFile raf;
+	
+	public XJNLPRandomAccessFile(File file, String mode) {
+		try {
+			raf = new RandomAccessFile(file, mode);
+		} catch (FileNotFoundException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
+	public void close() throws IOException {
+		raf.close();
+	}
+
+	public long getFilePointer() throws IOException {
+		return raf.getFilePointer();
+	}
+
+	public long length() throws IOException {
+		return raf.length();
+	}
+
+	public int read() throws IOException {
+		return raf.read();
+	}
+
+	public int read(byte[] b, int off, int len) throws IOException {
+		return raf.read(b, off, len);
+	}
+
+	public int read(byte[] b) throws IOException {
+		return raf.read(b);
+	}
+
+	public boolean readBoolean() throws IOException {
+		return raf.readBoolean();
+	}
+
+	public byte readByte() throws IOException {
+		return raf.readByte();
+	}
+
+	public char readChar() throws IOException {
+		return raf.readChar();
+	}
+
+	public double readDouble() throws IOException {
+		return raf.readDouble();
+	}
+
+	public float readFloat() throws IOException {
+		return raf.readFloat();
+	}
+
+	public void readFully(byte[] b) throws IOException {
+		raf.readFully(b);
+	}
+
+	public void readFully(byte[] b, int off, int len) throws IOException {
+		raf.readFully(b, off, len);
+	}
+
+	public int readInt() throws IOException {
+		return raf.readInt();
+	}
+
+	public String readLine() throws IOException {
+		return raf.readLine();
+	}
+
+	public long readLong() throws IOException {
+		return raf.readLong();
+	}
+
+	public short readShort() throws IOException {
+		return raf.readShort();
+	}
+
+	public String readUTF() throws IOException {
+		return raf.readUTF();
+	}
+
+	public int readUnsignedByte() throws IOException {
+		return raf.readUnsignedByte();
+	}
+
+	public int readUnsignedShort() throws IOException {
+		return raf.readUnsignedShort();
+	}
+
+	public void seek(long pos) throws IOException {
+		raf.seek(pos);
+	}
+
+	public void setLength(long newLength) throws IOException {
+		raf.setLength(newLength);
+	}
+
+	public int skipBytes(int n) throws IOException {
+		return raf.skipBytes(n);
+	}
+
+	public void write(int b) throws IOException {
+		raf.write(b);
+
+	}
+
+	public void write(byte[] b) throws IOException {
+		raf.write(b);
+	}
+
+	public void write(byte[] b, int off, int len) throws IOException {
+		raf.write(b, off, len);
+	}
+
+	public void writeBoolean(boolean v) throws IOException {
+		raf.writeBoolean(v);
+	}
+
+	public void writeByte(int v) throws IOException {
+		raf.writeByte(v);
+	}
+
+	public void writeBytes(String s) throws IOException {
+		raf.writeBytes(s);
+	}
+
+	public void writeChar(int v) throws IOException {
+		raf.writeChar(v);
+	}
+
+	public void writeChars(String s) throws IOException {
+		raf.writeChars(s);
+	}
+
+	public void writeDouble(double v) throws IOException {
+		raf.writeDouble(v);
+	}
+
+	public void writeFloat(float v) throws IOException {
+		raf.writeFloat(v);
+	}
+
+	public void writeInt(int v) throws IOException {
+		raf.writeInt(v);
+	}
+
+	public void writeLong(long v) throws IOException {
+		raf.writeLong(v);
+	}
+
+	public void writeShort(int v) throws IOException {
+		raf.writeShort(v);
+	}
+
+	public void writeUTF(String str) throws IOException {
+		raf.writeUTF(str);
+	}
+
+}
diff -r c106e5ac6bf3 -r 43f18ddc7c1c rt/net/sourceforge/jnlp/services/XPrintService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rt/net/sourceforge/jnlp/services/XPrintService.java	Mon Apr 14 14:09:53 2008 -0400
@@ -0,0 +1,123 @@
+/* XPrintService.java
+   Copyright (C) 2008 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+package net.sourceforge.jnlp.services;
+
+import java.awt.print.PageFormat;
+import java.awt.print.Pageable;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+
+import javax.jnlp.*;
+import javax.swing.JOptionPane;
+
+import net.sourceforge.jnlp.runtime.JNLPRuntime;
+
+public class XPrintService implements PrintService {
+
+	// If pj is null, then we do not have a printer to use.
+	private PrinterJob pj;
+	
+	public XPrintService() {
+		pj = PrinterJob.getPrinterJob();
+	}
+	
+	public PageFormat getDefaultPage() {
+		if (pj != null)
+			return pj.defaultPage();
+		else {
+			showWarning();
+			return new PageFormat(); // might not have default settings.
+		}
+	}
+	
+	public PageFormat showPageFormatDialog(PageFormat page) {
+		if (pj != null)
+			return pj.pageDialog(page);
+		else {
+			showWarning();
+			return page;
+		}
+
+	}
+	
+	public boolean print(Pageable document) {
+		if (pj != null) {
+			pj.setPageable(document);
+			if (pj.printDialog()) {
+				try {
+					pj.print();
+					return true;
+				} catch(PrinterException pe) {
+					System.err.println("Could not print: " + pe);
+					return false;
+				}
+			}
+		} else 
+			showWarning();
+		
+		return false;
+	}
+	
+	public boolean print(Printable painter) {
+		if (pj != null) {
+			pj.setPrintable(painter);
+			if (pj.printDialog()) {
+				try {
+					pj.print();
+					return true;
+				} catch(PrinterException pe) {
+					System.err.println("Could not print: " + pe);
+					return false;
+				}
+				
+			}
+		} else
+			showWarning();
+		
+		return false;
+	}
+	
+	private void showWarning() {
+		JOptionPane.showMessageDialog(null, 
+				"Unable to find a default printer.", 
+				"Warning", 
+				JOptionPane.WARNING_MESSAGE);
+		System.err.println("Unable to print: Unable to find default printer.");
+	}
+}
diff -r c106e5ac6bf3 -r 43f18ddc7c1c rt/net/sourceforge/jnlp/services/XServiceManagerStub.java
--- a/rt/net/sourceforge/jnlp/services/XServiceManagerStub.java	Mon Apr 14 11:08:37 2008 -0400
+++ b/rt/net/sourceforge/jnlp/services/XServiceManagerStub.java	Mon Apr 14 14:09:53 2008 -0400
@@ -49,7 +49,8 @@ public class XServiceManagerStub impleme
         "javax.jnlp.PersistenceService",
         "javax.jnlp.FileOpenService",
         "javax.jnlp.FileSaveService",
-        "javax.jnlp.ClipboardService"
+        "javax.jnlp.ClipboardService",
+        "javax.jnlp.PrintService"
     };
 
     private static Object services[] = {
@@ -60,6 +61,7 @@ public class XServiceManagerStub impleme
         ServiceUtil.createPrivilegedProxy(FileOpenService.class, new XFileOpenService()),
         ServiceUtil.createPrivilegedProxy(FileSaveService.class, new XFileSaveService()),
         ServiceUtil.createPrivilegedProxy(ClipboardService.class, new XClipboardService()),
+        ServiceUtil.createPrivilegedProxy(PrintService.class, new XPrintService())
     };
 
 



More information about the distro-pkg-dev mailing list