} /* Close the message queues so that nobody is stuck * waiting for one. */ graphicsToBeDrawn.closeWhenEmpty(); graphicsDrawn.close(); } private class MessageQ { private String qid="noname"; private ArrayList queue = new ArrayList(); MessageQ(String id) { qid = id; } synchronized void closeWhenEmpty() { while (queue != null && queue.size() > 0) { try { wait(1000); } catch (InterruptedException e) { // do nothing. } } queue = null; notifyAll(); } synchronized void close() { queue = null; notifyAll(); } synchronized boolean append(Graphics2D g) { boolean queued = false; if (queue != null) { queue.add(g); queued = true; notify(); } return queued; } synchronized Graphics2D pop() { Graphics2D g = null; while (g == null && queue != null) { if (queue.size() > 0) { g = (Graphics2D) queue.remove(0); notify(); } else { try { wait(2000); } catch (InterruptedException e) { // do nothing. } } } return g; } synchronized boolean isClosed() { return queue == null; } } private static int[] getSize(MediaType mType) { int []dim = new int[2]; dim[0] = 612; dim[1] = 792; for (int i=0; i < SIZES.length; i++) { if (SIZES[i] == mType) { dim[0] = WIDTHS[i]; dim[1] = LENGTHS[i]; break; } } return dim; } public static MediaSizeName mapMedia(MediaType mType) { MediaSizeName media = null; // JAVAXSIZES.length and SIZES.length must be equal! // Attempt to recover by getting the smaller size. int length = Math.min(SIZES.length, JAVAXSIZES.length); for (int i=0; i < length; i++) { if (SIZES[i] == mType) { if ((JAVAXSIZES[i] != null) && MediaSize.getMediaSizeForName(JAVAXSIZES[i]) != null) { media = JAVAXSIZES[i]; break; } else { /* create Custom Media */ media = new CustomMediaSizeName(SIZES[i].toString()); float w = (float)Math.rint(WIDTHS[i] / 72.0); float h = (float)Math.rint(LENGTHS[i] / 72.0); if (w > 0.0 && h > 0.0) { // add new created MediaSize to our static map // so it will be found when we call findMedia new MediaSize(w, h, Size2DSyntax.INCH, media); } break; } } } return media; } public static MediaType unMapMedia(MediaSizeName mSize) { MediaType media = null; // JAVAXSIZES.length and SIZES.length must be equal! // Attempt to recover by getting the smaller size. int length = Math.min(SIZES.length, JAVAXSIZES.length); for (int i=0; i < length; i++) { if (JAVAXSIZES[i] == mSize) { if (SIZES[i] != null) { media = SIZES[i]; break; } } } return media; } private void translateInputProps() { if (props == null) { return; } String str; str = props.getProperty(DEST_PROP); if (str != null) { if (str.equals(PRINTER)) { jobAttributes.setDestination(DestinationType.PRINTER); } else if (str.equals(FILE)) { jobAttributes.setDestination(DestinationType.FILE); } } str = props.getProperty(PRINTER_PROP); if (str != null) { jobAttributes.setPrinter(str); } str = props.getProperty(FILENAME_PROP); if (str != null) { jobAttributes.setFileName(str); } str = props.getProperty(NUMCOPIES_PROP); if (str != null) { jobAttributes.setCopies(Integer.parseInt(str)); } this.options = props.getProperty(OPTIONS_PROP, ""); str = props.getProperty(ORIENT_PROP); if (str != null) { if (str.equals(PORTRAIT)) { pageAttributes.setOrientationRequested( OrientationRequestedType.PORTRAIT); } else if (str.equals(LANDSCAPE)) { pageAttributes.setOrientationRequested( OrientationRequestedType.LANDSCAPE); } } str = props.getProperty(PAPERSIZE_PROP); if (str != null) { if (str.equals(LETTER)) { pageAttributes.setMedia(SIZES[MediaType.LETTER.hashCode()]); } else if (str.equals(LEGAL)) { pageAttributes.setMedia(SIZES[MediaType.LEGAL.hashCode()]); } else if (str.equals(EXECUTIVE)) { pageAttributes.setMedia(SIZES[MediaType.EXECUTIVE.hashCode()]); } else if (str.equals(A4)) { pageAttributes.setMedia(SIZES[MediaType.A4.hashCode()]); } } } private void translateOutputProps() { if (props == null) { return; } String str; props.setProperty(DEST_PROP, (jobAttributes.getDestination() == DestinationType.PRINTER) ? PRINTER : FILE); str = jobAttributes.getPrinter(); if (str != null && !str.equals("")) { props.setProperty(PRINTER_PROP, str); } str = jobAttributes.getFileName(); if (str != null && !str.equals("")) { props.setProperty(FILENAME_PROP, str); } int copies = jobAttributes.getCopies(); if (copies > 0) { props.setProperty(NUMCOPIES_PROP, "" + copies); } str = this.options; if (str != null && !str.equals("")) { props.setProperty(OPTIONS_PROP, str); } props.setProperty(ORIENT_PROP, (pageAttributes.getOrientationRequested() == OrientationRequestedType.PORTRAIT) ? PORTRAIT : LANDSCAPE); MediaType media = SIZES[pageAttributes.getMedia().hashCode()]; if (media == MediaType.LETTER) { str = LETTER; } else if (media == MediaType.LEGAL) { str = LEGAL; } else if (media == MediaType.EXECUTIVE) { str = EXECUTIVE; } else if (media == MediaType.A4) { str = A4; } else { str = media.toString(); } props.setProperty(PAPERSIZE_PROP, str); } private void throwPrintToFile() { SecurityManager security = System.getSecurityManager(); FilePermission printToFilePermission = null; if (security != null) { if (printToFilePermission == null) { printToFilePermission = new FilePermission("<<ALL FILES>>", "read,write"); } security.checkPermission(printToFilePermission); } } }Lines 1001–1257 of 1257. Previous lines
} /* Close the message queues so that nobody is stuck * waiting for one. */ graphicsToBeDrawn.closeWhenEmpty(); graphicsDrawn.close(); } private class MessageQ { private String qid="noname"; private ArrayList queue = new ArrayList(); MessageQ(String id) { qid = id; } synchronized void closeWhenEmpty() { while (queue != null && queue.size() > 0) { try { wait(1000); } catch (InterruptedException e) { // do nothing. } } queue = null; notifyAll(); } synchronized void close() { queue = null; notifyAll(); } synchronized boolean append(Graphics2D g) { boolean queued = false; if (queue != null) { queue.add(g); queued = true; notify(); } return queued; } synchronized Graphics2D pop() { Graphics2D g = null; while (g == null && queue != null) { if (queue.size() > 0) { g = (Graphics2D) queue.remove(0); notify(); } else { try { wait(2000); } catch (InterruptedException e) { // do nothing. } } } return g; } synchronized boolean isClosed() { return queue == null; } } private static int[] getSize(MediaType mType) { int []dim = new int[2]; dim[0] = 612; dim[1] = 792; for (int i=0; i < SIZES.length; i++) { if (SIZES[i] == mType) { dim[0] = WIDTHS[i]; dim[1] = LENGTHS[i]; break; } } return dim; } public static MediaSizeName mapMedia(MediaType mType) { MediaSizeName media = null; // JAVAXSIZES.length and SIZES.length must be equal! // Attempt to recover by getting the smaller size. int length = Math.min(SIZES.length, JAVAXSIZES.length); for (int i=0; i < length; i++) { if (SIZES[i] == mType) { if ((JAVAXSIZES[i] != null) && MediaSize.getMediaSizeForName(JAVAXSIZES[i]) != null) { media = JAVAXSIZES[i]; break; } else { /* create Custom Media */ media = new CustomMediaSizeName(SIZES[i].toString()); float w = (float)Math.rint(WIDTHS[i] / 72.0); float h = (float)Math.rint(LENGTHS[i] / 72.0); if (w > 0.0 && h > 0.0) { // add new created MediaSize to our static map // so it will be found when we call findMedia new MediaSize(w, h, Size2DSyntax.INCH, media); } break; } } } return media; } public static MediaType unMapMedia(MediaSizeName mSize) { MediaType media = null; // JAVAXSIZES.length and SIZES.length must be equal! // Attempt to recover by getting the smaller size. int length = Math.min(SIZES.length, JAVAXSIZES.length); for (int i=0; i < length; i++) { if (JAVAXSIZES[i] == mSize) { if (SIZES[i] != null) { media = SIZES[i]; break; } } } return media; } private void translateInputProps() { if (props == null) { return; } String str; str = props.getProperty(DEST_PROP); if (str != null) { if (str.equals(PRINTER)) { jobAttributes.setDestination(DestinationType.PRINTER); } else if (str.equals(FILE)) { jobAttributes.setDestination(DestinationType.FILE); } } str = props.getProperty(PRINTER_PROP); if (str != null) { jobAttributes.setPrinter(str); } str = props.getProperty(FILENAME_PROP); if (str != null) { jobAttributes.setFileName(str); } str = props.getProperty(NUMCOPIES_PROP); if (str != null) { jobAttributes.setCopies(Integer.parseInt(str)); } this.options = props.getProperty(OPTIONS_PROP, ""); str = props.getProperty(ORIENT_PROP); if (str != null) { if (str.equals(PORTRAIT)) { pageAttributes.setOrientationRequested( OrientationRequestedType.PORTRAIT); } else if (str.equals(LANDSCAPE)) { pageAttributes.setOrientationRequested( OrientationRequestedType.LANDSCAPE); } } str = props.getProperty(PAPERSIZE_PROP); if (str != null) { if (str.equals(LETTER)) { pageAttributes.setMedia(SIZES[MediaType.LETTER.hashCode()]); } else if (str.equals(LEGAL)) { pageAttributes.setMedia(SIZES[MediaType.LEGAL.hashCode()]); } else if (str.equals(EXECUTIVE)) { pageAttributes.setMedia(SIZES[MediaType.EXECUTIVE.hashCode()]); } else if (str.equals(A4)) { pageAttributes.setMedia(SIZES[MediaType.A4.hashCode()]); } } } private void translateOutputProps() { if (props == null) { return; } String str; props.setProperty(DEST_PROP, (jobAttributes.getDestination() == DestinationType.PRINTER) ? PRINTER : FILE); str = jobAttributes.getPrinter(); if (str != null && !str.equals("")) { props.setProperty(PRINTER_PROP, str); } str = jobAttributes.getFileName(); if (str != null && !str.equals("")) { props.setProperty(FILENAME_PROP, str); } int copies = jobAttributes.getCopies(); if (copies > 0) { props.setProperty(NUMCOPIES_PROP, "" + copies); } str = this.options; if (str != null && !str.equals("")) { props.setProperty(OPTIONS_PROP, str); } props.setProperty(ORIENT_PROP, (pageAttributes.getOrientationRequested() == OrientationRequestedType.PORTRAIT) ? PORTRAIT : LANDSCAPE); MediaType media = SIZES[pageAttributes.getMedia().hashCode()]; if (media == MediaType.LETTER) { str = LETTER; } else if (media == MediaType.LEGAL) { str = LEGAL; } else if (media == MediaType.EXECUTIVE) { str = EXECUTIVE; } else if (media == MediaType.A4) { str = A4; } else { str = media.toString(); } props.setProperty(PAPERSIZE_PROP, str); } private void throwPrintToFile() { SecurityManager security = System.getSecurityManager(); FilePermission printToFilePermission = null; if (security != null) { if (printToFilePermission == null) { printToFilePermission = new FilePermission("<<ALL FILES>>", "read,write"); } security.checkPermission(printToFilePermission); } } }