@@ -0,0 +1,1983 @@
+package edu.drexel.tm.cs338.textacular;%0A%0Aimport java.awt.Color;%0Aimport java.awt.Dimension;%0Aimport java.awt.Graphics;%0Aimport java.awt.Image;%0Aimport java.awt.Toolkit;%0Aimport java.awt.geom.Rectangle2D;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.RandomAccessFile;%0Aimport java.nio.ByteBuffer;%0Aimport java.nio.channels.FileChannel;%0A%0Aimport javax.swing.ImageIcon;%0Aimport javax.swing.JLabel;%0Aimport javax.swing.JPanel;%0Aimport javax.swing.JScrollPane;%0A%0Aimport com.sun.pdfview.PDFFile;%0Aimport com.sun.pdfview.PDFPage;%0A%0Apublic class PreviewPanel extends JPanel %7B%0A%09private Image image;%0A%09%0A%09private ImageIcon icon;%0A%09%0A%09private JLabel label;%0A%09%0A%09public PreviewPanel() %7B%0A%09%09setBackground(Color.RED);%0A%09%09setPreferredSize(new Dimension(300, 600));%0A%09%09%0A%09%09icon = new ImageIcon();%0A%09%09%0A%09%09label = new JLabel();%0A%09%09label.setVerticalAlignment(JLabel.TOP);%0A%09%09add(new JScrollPane(label));%0A%09%7D%0A%09%0A%09public void refresh() %7B%0A%09%09if (loadPdf()) %7B%0A%09%09%09icon.setImage(image);%0A%09%09%09label.setIcon(icon);%0A%09%09%09repaint();%0A%09%09%09revalidate();%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected boolean loadPdf() %7B%0A%09%09String filename = %22res/output/output.pdf%22;%0A%09%09File f = new File(filename);%0A%09%09if (f.exists() && !f.isDirectory()) %7B%0A%09%09%09try %7B%0A%09%09%09%09RandomAccessFile raf = new RandomAccessFile(f, %22r%22);%0A%09%09%09%09FileChannel fc = raf.getChannel();%0A%09%09%09%09ByteBuffer buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());%0A%09%09%09%09PDFFile pdfFile = new PDFFile(buf);%0A%09%09%09%09%0A%09%09%09%09int nPages = pdfFile.getNumPages();%0A%09%09%09%09System.out.println(nPages);%0A%09%09%09%09PDFPage page = pdfFile.getPage(1);%0A%09%09%09%09Rectangle2D r2d = page.getBBox();%0A%09%09%09%09%0A%09%09%09%09double w = r2d.getWidth();%0A%09%09%09%09double h = r2d.getHeight();%0A%09%09%09%09w /= 72.0;%0A%09%09%09%09h /= 72.0;%0A%09%09%09%09int res = Toolkit.getDefaultToolkit().getScreenResolution();%0A%09%09%09%09w *= res;%0A%09%09%09%09h *= res;%0A%09%09%09%09%0A%09%09%09%09image = page.getImage((int) w, (int) h, r2d, null, true, true);%0A%09%09%09%09%0A%09%09%09%09return true;%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09System.out.printf(%22%25s does not exist.%22, f.getAbsolutePath());%0A%09%09%7D%0A%09%09%0A%09%09return false;%0A%09%7D%0A%7D%0A

Add preview panel