@Test public void testPutGetList() { final List<Person> inserted = genPersonList(10000); Paper.book().write("persons", inserted); List<Person> persons = Paper.book().read("persons"); assertThat(persons).isEqualTo(inserted); }
public synchronized void printThisInvoice(JTable tbl) { this.tblprint = tbl; // this.totrecords = totrec; PrinterJob pj = PrinterJob.getPrinterJob(); PageFormat pf = new PageFormat(); Paper paper = new Paper(); paper.setSize(WIDTH, HEIGHT); paper.setImageableArea(0, 0, WIDTH, HEIGHT); pf.setPaper(paper); pj.setPrintable(this, pf); // if (pj.printDialog()) { try { System.out.println("Starting........"); pj.print(); System.out.println("Done!......"); } catch (Exception e) { System.out.println("Error: Print Error: " + e); e.printStackTrace(); } // } }
/** * Returns the y coordinate of the upper left point of the imageable area of the <code>Paper * </code> object associated with this <code>PageFormat</code>. This method takes into account the * orientation of the page. * * @return the y coordinate of the upper left point of the imageable area of the <code>Paper * </code> object associated with this <code>PageFormat</code>. */ public double getImageableY() { double y; switch (getOrientation()) { case LANDSCAPE: y = mPaper.getImageableX(); break; case PORTRAIT: y = mPaper.getImageableY(); break; case REVERSE_LANDSCAPE: y = mPaper.getWidth() - (mPaper.getImageableX() + mPaper.getImageableWidth()); break; default: /* This should never happen since it signifies that the * PageFormat is in an invalid orientation. */ throw new InternalError("unrecognized orientation"); } return y; }
@Test public void testPutMap() { final Map<Integer, Person> inserted = genPersonMap(10000); Paper.book().write("persons", inserted); final Map<Integer, Person> personMap = Paper.book().read("persons"); assertThat(personMap).isEqualTo(inserted); }
@Test public void testPutPOJO() { final Person person = genPerson(1); Paper.book().write("profile", person); final Person savedPerson = Paper.book().read("profile"); assertThat(savedPerson).isEqualTo(person); assertThat(savedPerson).isNotSameAs(person); }
public void testManyToOneGenerics() throws Exception { Paper white = new Paper(); white.setName("WhiteA4"); PaperType type = new PaperType(); type.setName("A4"); SomeGuy me = new SomeGuy(); white.setType(type); white.setOwner(me); Price price = new Price(); price.setAmount(new Double(1)); price.setCurrency("Euro"); white.setValue(price); Session s = openSession(); Transaction tx = s.beginTransaction(); s.persist(type); s.persist(price); s.persist(me); s.persist(white); tx.commit(); // s.close(); s = openSession(); tx = s.beginTransaction(); white = (Paper) s.get(Paper.class, white.getId()); s.delete(white.getType()); s.delete(white.getOwner()); s.delete(white.getValue()); s.delete(white); tx.commit(); // s.close(); }
/** * Returns the width, in 1/72nds of an inch, of the imageable area of the page. This method takes * into account the orientation of the page. * * @return the width of the page. */ public double getImageableWidth() { double width; if (getOrientation() == PORTRAIT) { width = mPaper.getImageableWidth(); } else { width = mPaper.getImageableHeight(); } return width; }
/** * Return the height, in 1/72nds of an inch, of the imageable area of the page. This method takes * into account the orientation of the page. * * @return the height of the page. */ public double getImageableHeight() { double height; if (getOrientation() == PORTRAIT) { height = mPaper.getImageableHeight(); } else { height = mPaper.getImageableWidth(); } return height; }
public void printableJob(Printable printable) throws PrintException { try { synchronized (this) { if (job != null) { // shouldn't happen throw new PrintException("already printing"); } else { job = new sun.awt.windows.WPrinterJob(); } } PrintService svc = getPrintService(); job.setPrintService(svc); if (copies == 0) { Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class); copies = c.getValue(); } if (mediaName == null) { Object media = svc.getDefaultAttributeValue(Media.class); if (media instanceof MediaSizeName) { mediaName = (MediaSizeName) media; mediaSize = MediaSize.getMediaSizeForName(mediaName); } } if (orient == null) { orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class); } 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); } }
/** * Returns the height, in 1/72nds of an inch, of the page. This method takes into account the * orientation of the page when determining the height. * * @return the height of the page. */ public double getHeight() { double height; int orientation = getOrientation(); if (orientation == PORTRAIT) { height = mPaper.getHeight(); } else { height = mPaper.getWidth(); } return height; }
/** * Returns the width, in 1/72nds of an inch, of the page. This method takes into account the * orientation of the page when determining the width. * * @return the width of the page. */ public double getWidth() { double width; int orientation = getOrientation(); if (orientation == PORTRAIT) { width = mPaper.getWidth(); } else { width = mPaper.getHeight(); } return width; }
public void setPaperSize(PaperSize s) { paper.setSize(s.PaperWidth, s.PaperHeight); paper.setImageableArea(s.ImageableX, s.ImageableY, s.ImageableWidth, s.ImageableHeight); if (s == A4) { for (PrintMech pm : Mechs) { pm.setA4(); } } else if (s == Letter) { for (PrintMech pm : Mechs) { pm.setLetter(); } } }
/** * Makes a copy of this <code>PageFormat</code> with the same contents as this <code>PageFormat * </code>. * * @return a copy of this <code>PageFormat</code>. */ public Object clone() { PageFormat newPage; try { newPage = (PageFormat) super.clone(); newPage.mPaper = (Paper) mPaper.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); newPage = null; // should never happen. } return newPage; }
/** * Returns a transformation matrix that translates user space rendering to the requested * orientation of the page. The values are placed into the array as * { m00, m10, m01, m11, m02, m12} in the form required by the * {@link AffineTransform} constructor. * * @return the matrix used to translate user space rendering to the orientation of the page. * @see java.awt.geom.AffineTransform */ public double[] getMatrix() { double[] matrix = new double[6]; switch (mOrientation) { case LANDSCAPE: matrix[0] = 0; matrix[1] = -1; matrix[2] = 1; matrix[3] = 0; matrix[4] = 0; matrix[5] = mPaper.getHeight(); break; case PORTRAIT: matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; break; case REVERSE_LANDSCAPE: matrix[0] = 0; matrix[1] = 1; matrix[2] = -1; matrix[3] = 0; matrix[4] = mPaper.getWidth(); matrix[5] = 0; break; default: throw new IllegalArgumentException(); } return matrix; }
// {{{ getPageFormat() method public static PageFormat getPageFormat() { // convert from PrintRequestAttributeSet to the pageFormat PrinterJob prnJob = getPrintJob(" "); PageFormat pf = prnJob.defaultPage(); Paper pap = pf.getPaper(); MediaSizeName media = (MediaSizeName) format.get(Media.class); MediaSize ms = MediaSize.getMediaSizeForName(media); MediaPrintableArea mediaarea = (MediaPrintableArea) format.get(MediaPrintableArea.class); if (mediaarea != null) pap.setImageableArea( (mediaarea.getX(MediaPrintableArea.INCH) * 72), (mediaarea.getY(MediaPrintableArea.INCH) * 72), (mediaarea.getWidth(MediaPrintableArea.INCH) * 72), (mediaarea.getHeight(MediaPrintableArea.INCH) * 72)); if (ms != null) pap.setSize((ms.getX(MediaSize.INCH) * 72), (ms.getY(MediaSize.INCH) * 72)); pf.setPaper(pap); OrientationRequested orientation = (OrientationRequested) format.get(OrientationRequested.class); if (orientation != null) { if (orientation.getValue() == OrientationRequested.LANDSCAPE.getValue()) { pf.setOrientation(PageFormat.LANDSCAPE); } else if (orientation.getValue() == OrientationRequested.REVERSE_LANDSCAPE.getValue()) { pf.setOrientation(PageFormat.REVERSE_LANDSCAPE); } else if (orientation.getValue() == OrientationRequested.PORTRAIT.getValue()) { pf.setOrientation(PageFormat.PORTRAIT); } else if (orientation.getValue() == OrientationRequested.REVERSE_PORTRAIT.getValue()) { // doesnt exist?? // pf.setOrientation(PageFormat.REVERSE_PORTRAIT); // then just do the next best thing pf.setOrientation(PageFormat.PORTRAIT); } } return pf; } // }}}
/** * Sets the <code>Paper</code> object for this <code>PageFormat</code>. * * @param paper the <code>Paper</code> object to which to set the <code>Paper</code> object for * this <code>PageFormat</code>. * @exception NullPointerException a null paper instance was passed as a parameter. * @see #getPaper */ public void setPaper(Paper paper) { mPaper = (Paper) paper.clone(); }
/** * Returns a copy of the {@link Paper} object associated with this <code>PageFormat</code>. * Changes made to the <code>Paper</code> object returned from this method do not affect the * <code>Paper</code> object of this <code>PageFormat</code>. To update the <code>Paper</code> * object of this <code>PageFormat</code>, create a new <code>Paper</code> object and set it into * this <code>PageFormat</code> by using the {@link #setPaper(Paper)} method. * * @return a copy of the <code>Paper</code> object associated with this <code>PageFormat</code>. * @see #setPaper */ public Paper getPaper() { return (Paper) mPaper.clone(); }
public void setPrintArea( double printAreaTop, double printAreaLeft, double printAreaWidth, double printAreaHeight) { super.setImageableArea( printAreaTop * k, printAreaLeft * k, printAreaWidth * k, printAreaHeight * k); }
private Object testReadWriteWithoutClassCheck(Object originObj) { Paper.book().write("obj", originObj); Object readObj = Paper.book().read("obj"); assertThat(readObj).isEqualTo(originObj); return readObj; }
@Before public void setUp() throws Exception { Paper.init(getTargetContext()); Paper.book().destroy(); }
@Test public void testPutEmptyList() throws Exception { final List<Person> inserted = genPersonList(0); Paper.book().write("persons", inserted); assertThat(Paper.book().<List>read("persons")).isEmpty(); }