Java Code Examples for javax.print.attribute.PrintRequestAttributeSet#containsKey()

The following examples show how to use javax.print.attribute.PrintRequestAttributeSet#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Java14PrintUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This tests, whether the given attribute set defines the same page properties as the given JFreeReport object.
 * <p/>
 * While showing the print dialog, the user has the chance to alter the page format of the print job. When that
 * happens, we have to repaginate the whole report, which may render the users page range input invalid. In that case,
 * we will have to redisplay the dialog.
 *
 * @param attributes
 * @param report
 * @return
 */
public static int isValidConfiguration( final PrintRequestAttributeSet attributes, final MasterReport report ) {
  final PrintRequestAttributeSet reportAttributes = copyConfiguration( null, report );
  // now, compare that minimal set with the given attribute collection.

  final Attribute[] printAttribs = reportAttributes.toArray();
  boolean invalidConfig = false;
  for ( int i = 0; i < printAttribs.length; i++ ) {
    final Attribute attrib = printAttribs[i];
    if ( attributes.containsValue( attrib ) == false ) {
      invalidConfig = true;
      break;
    }
  }

  if ( invalidConfig == false ) {
    return CONFIGURATION_VALID;
  }
  if ( attributes.containsKey( PageRanges.class ) ) {
    return CONFIGURATION_SHOW_DIALOG;
  }
  return CONFIGURATION_REPAGINATE;
}
 
Example 2
Source File: JRPrintServiceExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setOrientation(JasperPrint jPrint,PrintRequestAttributeSet printRequestAttributeSet)
{
	if (!printRequestAttributeSet.containsKey(MediaPrintableArea.class))
	{
		int printableWidth;
		int printableHeight;
		switch (jPrint.getOrientationValue())
		{
			case LANDSCAPE:
				printableWidth = jPrint.getPageHeight();
				printableHeight = jPrint.getPageWidth();
				break;
			default:
				printableWidth = jPrint.getPageWidth();
				printableHeight = jPrint.getPageHeight();
				break;
		}
		
		printRequestAttributeSet.add(
			new MediaPrintableArea(
				0f, 
				0f, 
				printableWidth / 72f,
				printableHeight / 72f,
				MediaPrintableArea.INCH
				)
			);
	}

	if (!printRequestAttributeSet.containsKey(OrientationRequested.class))
	{
		OrientationRequested orientation;
		switch (jPrint.getOrientationValue())
		{
			case LANDSCAPE:
				orientation = OrientationRequested.LANDSCAPE;
				break;
			default:
				orientation = OrientationRequested.PORTRAIT;
				break;
		}
		printRequestAttributeSet.add(orientation);
	}
	
}