示例#1
0
 private void openPDFFile(String file) throws Exception {
   if (document != null) {
     document.close();
     documentPanel.removeAll();
   }
   InputStream input = null;
   File f = new File(file);
   input = new FileInputStream(f);
   document = parseDocument(input);
   pages = document.getDocumentCatalog().getAllPages();
   numberOfPages = pages.size();
   // AH* Sidantal till GUI:
   sumPan.Sidantal.setText("" + 1 + " Av " + numberOfPages);
   sumPan.sidnrantal = numberOfPages;
   currentFilename = f.getAbsolutePath(); // AH* Borttagen i senare version.
   currentPage = 0;
   updateTitle();
   showPage(0);
 }
示例#2
0
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  private void initComponents() {
    SkrivUt(4, "initComponents");
    menuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    openMenuItem = new javax.swing.JMenuItem();
    exitMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    contentsMenuItem = new javax.swing.JMenuItem();
    aboutMenuItem = new javax.swing.JMenuItem();
    printMenuItem = new javax.swing.JMenuItem();
    viewMenu = new javax.swing.JMenu();
    nextPageItem = new javax.swing.JMenuItem();
    previousPageItem = new javax.swing.JMenuItem();

    if (EasyReader) {
      SkrivUt(4, "EasyReader True, sumPan.");
      sumPan = new SummarizerPanelPDF(this, false); // AH* tillagd.
    } else {
      SkrivUt(4, "EasyReader False, sumPan.");
      sumPan = new SummarizerPanelPDF(this, true); // AH* tillagd.
    }
    sumPan.setSize(100, 30); // AH* tillagd.

    setTitle("PDFBox - PDF Reader");
    addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent evt) {
            exitApplication();
          }
        });

    JScrollPane documentScroller = new JScrollPane();
    documentScroller.setViewportView(documentPanel);

    getContentPane().add(sumPan, java.awt.BorderLayout.NORTH); // AH* SumPan.
    getContentPane().add(documentScroller, java.awt.BorderLayout.CENTER);
    getContentPane().add(bottomStatusPanel, java.awt.BorderLayout.SOUTH);

    fileMenu.setText("Arkiv");
    openMenuItem.setText("Öppna");
    openMenuItem.setToolTipText("Öppna PDF fil");
    openMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            openMenuItemActionPerformed(evt);
          }
        });

    fileMenu.add(openMenuItem);

    printMenuItem.setText("Skriv Ut");
    printMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            try {
              if (document != null) {
                document.print();
              }
            } catch (PrinterException e) {
              e.printStackTrace();
            }
          }
        });
    fileMenu.add(printMenuItem);

    exitMenuItem.setText("Avsluta");
    exitMenuItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitApplication();
          }
        });

    fileMenu.add(exitMenuItem);

    menuBar.add(fileMenu);

    helpMenu.setText("Hjälp");
    contentsMenuItem.setText("Innehåll");
    helpMenu.add(contentsMenuItem);

    aboutMenuItem.setText("Om...");
    helpMenu.add(aboutMenuItem);

    viewMenu.setText("Visa");
    nextPageItem.setText("Nästa sida");
    nextPageItem.setAccelerator(KeyStroke.getKeyStroke('+'));
    nextPageItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            nextPage();
          }
        });
    viewMenu.add(nextPageItem);

    previousPageItem.setText("Föregående sida");
    previousPageItem.setAccelerator(KeyStroke.getKeyStroke('-'));
    previousPageItem.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            previousPage();
          }
        });
    viewMenu.add(previousPageItem);

    menuBar.add(viewMenu);

    menuBar.add(helpMenu); // AH* Avkommenterad.

    setJMenuBar(menuBar);

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 700) / 2, (screenSize.height - 600) / 2, 700, 600);
  }