package jPDFNotesSamples.customAnnotTools; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JPanel; import com.qoppa.pdf.PDFException; import com.qoppa.pdf.annotations.Circle; import com.qoppa.pdf.annotations.FreeText; import com.qoppa.pdf.annotations.IAnnotationFactory; import com.qoppa.pdf.annotations.RubberStamp; import com.qoppa.pdfNotes.AnnotToolbar; import com.qoppa.pdfNotes.MutableDocument; import com.qoppa.pdfNotes.PDFNotesBean; import com.qoppa.pdfNotes.settings.FreeTextTool; /* This example shows how to add jPDFNotes to a Frame, * customize the Annotation Toolbar by adding 3 custom annotation tools to it * (FreeText or Text Box, Square, Rubber Stamp) * and then launch the frame */ public class SimpleFrameWithCustomTools extends JFrame implements ActionListener { private JPanel jPanel = null; private PDFNotesBean m_NotesBean = null; private final static String START_FREETEXT = "StartFreeText"; private final static String START_CIRCLE = "StartCircle"; private final static String START_RUBBERSTAMP = "StartRubberStamp"; public static void main (String [] args) { SimpleFrameWithCustomTools sf = new SimpleFrameWithCustomTools(); sf.setVisible(true); } /** * This method initializes * */ public SimpleFrameWithCustomTools() { super(); initialize(); } /** * This method initializes this * */ private void initialize() { this.setBounds(new Rectangle(0, 0, 960, 720)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(getJPanel()); this.setTitle("Qoppa Software - jPDFNotes Sample"); this.setLocationRelativeTo(null); } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel(); jPanel.setLayout(new BorderLayout()); jPanel.add(getNotesBean(), BorderLayout.CENTER); } return jPanel; } /** * This method initializes PDFViewerBean * * @return com.qoppa.pdfViewer.PDFViewerBean */ private PDFNotesBean getNotesBean() { if (m_NotesBean == null) { m_NotesBean = new PDFNotesBean(); // // Create custom buttons on the toolbar // that can start annotation tool // // button for Free Text Custom Tool JButton ftCorrect = new JButton ("Free Text"); ftCorrect.setForeground(Color.black); ftCorrect.setActionCommand(START_FREETEXT); ftCorrect.addActionListener(this); m_NotesBean.getAnnotToolbar().add(ftCorrect, 0); // button for Circle Custom Tool JButton jbRedCircle = new JButton ("Circle"); jbRedCircle.setForeground(Color.red); jbRedCircle.setActionCommand(START_CIRCLE); jbRedCircle.addActionListener(this); m_NotesBean.getAnnotToolbar().add (jbRedCircle, 1); // button for Rubber Stamp Custom Tool JButton rsCorrect = new JButton ("Stamp"); rsCorrect.setForeground(Color.blue); rsCorrect.setActionCommand(START_RUBBERSTAMP); rsCorrect.addActionListener(this); m_NotesBean.getAnnotToolbar().add (rsCorrect, 2); // // Add a new item to the existing rubber stamp menu // // add a separator to the stamp menu // to separate the new stamp from the existing ones m_NotesBean.getAnnotToolbar().getJmAddStamps().addSeparator(); try { // Create a menu item with a preview of the rubber stamp JMenuItem menuItem = AnnotToolbar.createStampMenuItem("My Stamp", Color.blue); menuItem.setActionCommand(START_RUBBERSTAMP); menuItem.addActionListener(this); // Add the menu item to the existing stamp menu on the toolbar m_NotesBean.getAnnotToolbar().getJmAddStamps().add(menuItem); } catch (PDFException ex) { ex.printStackTrace(); } } return m_NotesBean; } public void actionPerformed(ActionEvent e) { MutableDocument doc = m_NotesBean.getMutableDocument(); if(doc != null) { IAnnotationFactory factory = doc.getAnnotationFactory(); if (e.getActionCommand() == START_FREETEXT) { FreeTextTool.setShowPropDialog(false); FreeText correctAnnot = factory.createFreeText("My Text"); m_NotesBean.startEdit (correctAnnot, false, false); } else if (e.getActionCommand() == START_RUBBERSTAMP) { RubberStamp myStamp = factory.createRubberStamp ("My Stamp", Color.blue); myStamp.setRotation(45); m_NotesBean.startEdit (myStamp, false, false); } else if (e.getActionCommand() == START_CIRCLE) { Circle redCircle = factory.createCircle(null); redCircle.setColor(Color.red); redCircle.setInternalColor(Color.blue); m_NotesBean.startEdit(redCircle, false, false); } } } } // @jve:decl-index=0:visual-constraint="10,10"