final public void actionPerformed(ActionEvent objPactionEvent) { final Object objLsourceObject = objPactionEvent.getSource(); if (this.objGportraitPrintIconRadioJButton.isSameAs(objLsourceObject)) { this.objGprintJDialog.getAttributes().add(OrientationRequested.PORTRAIT); } else if (this.objGlandscapePrintIconRadioJButton.isSameAs(objLsourceObject)) { this.objGprintJDialog.getAttributes().add(OrientationRequested.LANDSCAPE); } else if (this.objGreversePortraitPrintIconRadioJButton.isSameAs(objLsourceObject)) { this.objGprintJDialog.getAttributes().add(OrientationRequested.REVERSE_PORTRAIT); } else if (this.objGreverseLandscapePrintIconRadioJButton.isSameAs(objLsourceObject)) { this.objGprintJDialog.getAttributes().add(OrientationRequested.REVERSE_LANDSCAPE); } // orientation affects display of margins. if (this.objGprintMarginsSubJPanel != null) { this.objGprintMarginsSubJPanel.setValues(); } }
@Override public void actionPerformed(ActionEvent e) { try { if (selectedDriver == null) return; PrintService ps = (PrintService)printers.getSelectedItem(); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new Copies(1)); attr.add((Media)ps.getDefaultAttributeValue(Media.class)); // set to default paper from printer attr.add(OrientationRequested.LANDSCAPE); SimpleDoc doc = new SimpleDoc(activeLabel, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); ps.createPrintJob().print(doc, attr); } catch (PrintException ex) { log.log(Level.SEVERE, "\bBarcode print failed: " + ex.getMessage(), ex); } }
public OrientationRequested assignOrientation(final String orientation) { OrientationRequested answer; if (orientation == null) { // default to portrait answer = OrientationRequested.PORTRAIT; } else if (orientation.equalsIgnoreCase("portrait")) { answer = OrientationRequested.PORTRAIT; } else if (orientation.equalsIgnoreCase("landscape")) { answer = OrientationRequested.LANDSCAPE; } else if (orientation.equalsIgnoreCase("reverse-portrait")) { answer = OrientationRequested.REVERSE_PORTRAIT; } else if (orientation.equalsIgnoreCase("reverse-landscape")) { answer = OrientationRequested.REVERSE_LANDSCAPE; } else { answer = OrientationRequested.PORTRAIT; } return answer; }
@Test public void printToMiddleTray() throws Exception { PrinterEndpoint endpoint = new PrinterEndpoint(); PrinterConfiguration configuration = new PrinterConfiguration(); configuration.setHostname("localhost"); configuration.setPort(631); configuration.setPrintername("DefaultPrinter"); configuration.setMediaSizeName(MediaSizeName.ISO_A4); configuration.setInternalSides(Sides.ONE_SIDED); configuration.setInternalOrientation(OrientationRequested.PORTRAIT); configuration.setMediaTray("middle"); PrinterProducer producer = new PrinterProducer(endpoint, configuration); producer.start(); PrinterOperations printerOperations = producer.getPrinterOperations(); PrintRequestAttributeSet attributeSet = printerOperations.getPrintRequestAttributeSet(); Attribute attribute = attributeSet.get(javax.print.attribute.standard.Media.class); assertNotNull(attribute); assertTrue(attribute instanceof MediaTray); MediaTray mediaTray = (MediaTray) attribute; assertEquals("middle", mediaTray.toString()); }
@Test public void printsWithLandscapeOrientation() throws Exception { PrinterEndpoint endpoint = new PrinterEndpoint(); PrinterConfiguration configuration = new PrinterConfiguration(); configuration.setHostname("localhost"); configuration.setPort(631); configuration.setPrintername("DefaultPrinter"); configuration.setMediaSizeName(MediaSizeName.ISO_A4); configuration.setInternalSides(Sides.ONE_SIDED); configuration.setInternalOrientation(OrientationRequested.REVERSE_LANDSCAPE); configuration.setMediaTray("middle"); configuration.setSendToPrinter(false); PrinterProducer producer = new PrinterProducer(endpoint, configuration); producer.start(); PrinterOperations printerOperations = producer.getPrinterOperations(); PrintRequestAttributeSet attributeSet = printerOperations.getPrintRequestAttributeSet(); Attribute attribute = attributeSet.get(OrientationRequested.class); assertNotNull(attribute); assertEquals("reverse-landscape", attribute.toString()); }
/** * Return Print Request Attributes * @return PrintRequestAttributeSet */ public PrintRequestAttributeSet getPrintRequestAttributeSet() { PrintRequestAttributeSet pratts = new HashPrintRequestAttributeSet(); // media-printable-area = (25.4,25.4)->(165.1,228.6)mm - class javax.print.attribute.standard.MediaPrintableArea pratts.add(getMediaPrintableArea()); // orientation-requested = landscape - class javax.print.attribute.standard.OrientationRequested if (isLandscape()) pratts.add(OrientationRequested.LANDSCAPE); else pratts.add(OrientationRequested.PORTRAIT); // media = na-legal //Commented Lines By AA Goodwill: Custom Paper Support //pratts.add(getMediaSizeName()); //End Of AA Goodwill return pratts; }
/** * Print (async) * @param printerName optional printer name * @param jobName optional printer job name * @param pageable pageable * @param copies number of copies * @param withDialog if true, shows printer dialog */ static public void print (Pageable pageable, String printerName, String jobName, int copies, boolean withDialog) { if (pageable == null) return; String name = "Adempiere_"; if (jobName != null) name += jobName; // PrinterJob job = CPrinter.getPrinterJob(printerName); job.setJobName (name); job.setPageable (pageable); // Attributes HashPrintRequestAttributeSet prats = new HashPrintRequestAttributeSet(); prats.add(new Copies(copies)); // Set Orientation if (pageable.getPageFormat(0).getOrientation() == PageFormat.PORTRAIT) prats.add(OrientationRequested.PORTRAIT); else prats.add(OrientationRequested.LANDSCAPE); prats.add(new JobName(name, Language.getLoginLanguage().getLocale())); prats.add(getJobPriority(pageable.getNumberOfPages(), copies, withDialog)); // print (job, prats, withDialog, false); }
private void printInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printInfoButtonActionPerformed // TODO add your handling code here: PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat preformat = pjob.defaultPage(); preformat.setOrientation(PageFormat.PORTRAIT); PageFormat postformat = pjob.pageDialog(preformat); //If user does not hit cancel then print. if (preformat != postformat) { //Set print component pjob.setPrintable(new Printer(bottomPanel), postformat); if (pjob.printDialog()) { try { PrintRequestAttributeSet set = new HashPrintRequestAttributeSet(); set.add(OrientationRequested.PORTRAIT); //pjob.print(); table.print(JTable.PrintMode.FIT_WIDTH, header, null, false, set, false); } catch (PrinterException ex) { Logger.getLogger(EditProjectParticipants.class.getName()).log(Level.SEVERE, null, ex); } } } }
public void setAttribute(final Attribute attr) { final Class<? extends Attribute> category = attr.getCategory(); if (OrientationRequested.class.equals(category)) { setOrientation((OrientationRequested) attr); } else if (MediaSize.class.equals(category)) { setPaper((MediaSize) attr); } else if (Media.class.equals(category)) { setPaper((MediaSizeName) attr); } else if (Paper.class.equals(category)) { setPaper((Paper) attr); } else if (Copies.class.equals(category)) { setCopies((Copies) attr); } else if (PrintQuality.class.equals(category)) { setPrintQuality((PrintQuality) attr); } else if (Sides.class.equals(category)) { setSides((Sides) attr); } else if (SheetCollate.class.equals(category)) { setCollate((SheetCollate) attr); } else if (PrinterResolution.class.equals(category)) { setPrinterResolution((PrinterResolution) attr); } else if (Chromaticity.class.equals(category)) { setChromaticity((Chromaticity) attr); } }
private void enableOrient(OrientationRequested[] list) { portraitBtn.setEnabled(false); landscapeBtn.setEnabled(false); rvportraitBtn.setEnabled(false); rvlandscapeBtn.setEnabled(false); if (list != null) { for (int i = 0; i < list.length; i++) { if (list[i].equals(OrientationRequested.LANDSCAPE)) { landscapeBtn.setEnabled(true); } else if (list[i].equals(OrientationRequested.PORTRAIT)) { portraitBtn.setEnabled(true); } else if (list[i].equals(OrientationRequested.REVERSE_LANDSCAPE)) { rvlandscapeBtn.setEnabled(true); } else if (list[i].equals(OrientationRequested.REVERSE_PORTRAIT)) { rvportraitBtn.setEnabled(true); } } } }
private void createOrientationCombo(PrintRequestAttributeSet set) { OrientationRequested[] orientations = (OrientationRequested[]) mService.getSupportedAttributeValues(OrientationRequested.class, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); if (orientations != null && orientations.length > 0) { HashSet<OrientationRequested> possible = new HashSet<>(); for (OrientationRequested one : orientations) { possible.add(one); } ArrayList<PageOrientation> choices = new ArrayList<>(); for (PageOrientation orientation : PageOrientation.values()) { if (possible.contains(orientation.getOrientationRequested())) { choices.add(orientation); } } mOrientation = new JComboBox<>(choices.toArray(new PageOrientation[0])); mOrientation.setSelectedItem(PrintUtilities.getPageOrientation(mService, set)); UIUtilities.setOnlySize(mOrientation, mOrientation.getPreferredSize()); LinkedLabel label = new LinkedLabel(ORIENTATION, mOrientation); add(label, new PrecisionLayoutData().setEndHorizontalAlignment()); add(mOrientation); } else { mOrientation = null; } }
@Test public void printsWithLandscapeOrientation() throws Exception { PrinterEndpoint endpoint = new PrinterEndpoint(); PrinterConfiguration configuration = new PrinterConfiguration(); configuration.setHostname("localhost"); configuration.setPort(631); configuration.setPrintername("DefaultPrinter"); configuration.setMediaSizeName(MediaSizeName.ISO_A4); configuration.setInternalSides(Sides.ONE_SIDED); configuration.setInternalOrientation(OrientationRequested.REVERSE_LANDSCAPE); configuration.setMediaTray("middle"); configuration.setSendToPrinter(false); PrinterProducer producer = new PrinterProducer(endpoint, configuration); producer.start(); PrinterOperations printerOperations = producer.getPrinterOperations(); PrintRequestAttributeSet attributeSet = printerOperations.getPrintRequestAttributeSet(); Attribute attribute = attributeSet.get(OrientationRequested.class); Assert.assertNotNull(attribute); Assert.assertEquals("reverse-landscape", attribute.toString()); }
public static void printComponent(Component c) { // Get a list of all printers that can handle Printable objects. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); // Set some define printing attributes PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet(); //printAttributes.add(OrientationRequested.LANDSCAPE); // landscape mode printAttributes.add(OrientationRequested.PORTRAIT); // PORTRAIT mode printAttributes.add(Chromaticity.MONOCHROME); // print in mono printAttributes.add(javax.print.attribute.standard.PrintQuality.HIGH); // highest resolution // Display a dialog that allows the user to select one of the // available printers and to edit the default attributes PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes); // If the user canceled, don't do anything if(service==null) { return; } // Now call a method defined below to finish the printing printToService(c, service, printAttributes); }
public void printWorksheetLevel() { PrinterJob print = PrinterJob.getPrinterJob(); PrintRequestAttributeSet set = new HashPrintRequestAttributeSet(); set.add(OrientationRequested.LANDSCAPE); print.setPrintable(oscilloscope); if(print.printDialog(set)) try { print.print(); } catch(PrinterException e) {} }
public void printableJob(Printable printable, PrintRequestAttributeSet attributes) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); PageFormat pf = new PageFormat(); if (mediaSize != null) { Paper p = new Paper(); p.setSize(mediaSize.getX(MediaSize.INCH)*72.0, mediaSize.getY(MediaSize.INCH)*72.0); p.setImageableArea(72.0, 72.0, p.getWidth()-144.0, p.getHeight()-144.0); pf.setPaper(p); } if (orient == OrientationRequested.REVERSE_LANDSCAPE) { pf.setOrientation(PageFormat.REVERSE_LANDSCAPE); } else if (orient == OrientationRequested.LANDSCAPE) { pf.setOrientation(PageFormat.LANDSCAPE); } job.setPrintable(printable, pf); job.print(attributes); notifyEvent(PrintJobEvent.JOB_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; } }
private boolean isPSDocAttr(Class category) { if (category == OrientationRequested.class || category == Copies.class) { return true; } else { return false; } }
public void printableJob(Printable printable) throws PrintException { try { synchronized(this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new PSPrinterJob(); } } job.setPrintService(getPrintService()); job.setCopies(copies); job.setJobName(jobName); PageFormat pf = new PageFormat(); if (mediaSize != null) { Paper p = new Paper(); p.setSize(mediaSize.getX(MediaSize.INCH)*72.0, mediaSize.getY(MediaSize.INCH)*72.0); p.setImageableArea(72.0, 72.0, p.getWidth()-144.0, p.getHeight()-144.0); pf.setPaper(p); } if (orient == OrientationRequested.REVERSE_LANDSCAPE) { pf.setOrientation(PageFormat.REVERSE_LANDSCAPE); } else if (orient == OrientationRequested.LANDSCAPE) { pf.setOrientation(PageFormat.LANDSCAPE); } job.setPrintable(printable, pf); job.print(reqAttrSet); notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE); return; } catch (PrinterException pe) { notifyEvent(PrintJobEvent.JOB_FAILED); throw new PrintException(pe); } finally { printReturned = true; notifyEvent(PrintJobEvent.NO_MORE_EVENTS); } }
private boolean isPSDocAttr(Class<?> category) { if (category == OrientationRequested.class || category == Copies.class) { return true; } else { return false; } }
public static final void main( String[] parameters ) { PrinterJob printjob = PrinterJob.getPrinterJob(); printjob.setJobName( "Test Print Job" ); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add( OrientationRequested.LANDSCAPE ); try { printjob.setPrintable( new Painter() ); printjob.print( attributes ); } catch( PrinterException exception ) { exception.printStackTrace(); } }
private void getPageAttributes() { OrientationRequested orientation = (OrientationRequested) attributes.get( OrientationRequested.LANDSCAPE.getCategory() ); if( orientation == null) return; if( orientation.equals(OrientationRequested.PORTRAIT) ) pageFormat.setOrientation(PageFormat.PORTRAIT); else if( orientation.equals(OrientationRequested.LANDSCAPE) ) pageFormat.setOrientation(PageFormat.LANDSCAPE); else if( orientation.equals(OrientationRequested.REVERSE_LANDSCAPE) ) pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE); }
/** * Constructs an array from a set of -supported attributes. * @param set set to process * @return The constructed array. * * @see #getAssociatedAttribute() */ public static OrientationRequested[] getAssociatedAttributeArray(Set<Attribute> set) { OrientationRequested[] result = new OrientationRequested[set.size()]; int j = 0; for (Attribute tmp : set) { result[j] = ((OrientationRequestedSupported) tmp).getAssociatedAttribute(); j++; } return result; }
/** * Writes an attribute in EnumSyntax into the stream. * @param attribute the attribute * @throws IOException if thrown by the stream */ private void write(EnumSyntax attribute) throws IOException { // in JPS API enum syntax is used for enums, keyword and boolean types String name = ((Attribute) attribute).getName(); // the enum value types if (attribute instanceof Finishings || attribute instanceof OrientationRequested || attribute instanceof PrintQuality) { out.writeByte(IppValueTag.ENUM); out.writeShort(name.length()); out.write(name.getBytes()); out.writeShort(4); // length, enum is 4 bytes out.writeInt(attribute.getValue()); } // the boolean value type else if (attribute instanceof Fidelity) { out.writeByte(IppValueTag.BOOLEAN); out.writeShort(name.length()); out.write(name.getBytes()); out.writeShort(1); // length, boolean is 1 bytes out.writeByte(attribute.getValue() == 0 ? 0x00 : 0x01); } // the keyword value types else { String keyword = attribute.toString(); out.writeByte(IppValueTag.KEYWORD); out.writeShort(name.length()); out.write(name.getBytes()); out.writeShort(keyword.length()); out.write(keyword.getBytes()); } }