/* * Created on Sep 24, 2008 * */ package jPDFNotesSamples.customStamps; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.StringTokenizer; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.LookAndFeel; import javax.swing.UIManager; 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.pdfNotes.AnnotToolbar; import com.qoppa.pdfNotes.MutableDocument; import com.qoppa.pdfNotes.PDFNotesBean; import com.qoppa.pdfNotes.settings.FreeTextTool; public class SimpleFrame extends JFrame implements ActionListener { private static double DPI_SCALING_MULTIPLIER = 0.0; private JPanel jPanel = null; private PDFNotesBean m_NotesBean = null; private final static String FREETEXT_CORRECT = "FreeTextCorrect"; private final static String STAMP_CORRECT = "StampCorrect"; private final static String RED_CIRCLE = "RedCircle"; public static void main (String [] args) { SimpleFrame sf = new SimpleFrame(); sf.setVisible(true); } /** * This method initializes * */ public SimpleFrame() { super(); initialize(); } /** * This method initializes this * */ private void initialize() { this.setBounds(new Rectangle(0, 0, (int)(800 * getDPIScalingMultiplier()), (int)(600 * getDPIScalingMultiplier()))); 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 MyNotesBean(); // Create custom buttons JButton ftCorrect = new JButton ("FT"); ftCorrect.setActionCommand(FREETEXT_CORRECT); ftCorrect.addActionListener(this); m_NotesBean.getAnnotToolbar().add (ftCorrect); JButton rsCorrect = new JButton ("RS"); rsCorrect.setActionCommand(STAMP_CORRECT); rsCorrect.addActionListener(this); m_NotesBean.getAnnotToolbar().add (rsCorrect); m_NotesBean.getAnnotToolbar().getJmAddStamps().addSeparator(); try { // Create a menu item with a preview of the rubber stamp JMenuItem menuItem = AnnotToolbar.createStampMenuItem("Correct", Color.blue); menuItem.setActionCommand(STAMP_CORRECT); menuItem.addActionListener(this); // Add a menu item to the toolbar m_NotesBean.getAnnotToolbar().getJmAddStamps().add(menuItem); } catch (PDFException ex) { ex.printStackTrace(); } // Red Circle JButton jbRedCircle = new JButton ("RC"); jbRedCircle.setActionCommand(RED_CIRCLE); jbRedCircle.addActionListener(this); m_NotesBean.getAnnotToolbar().add (jbRedCircle); } return m_NotesBean; } public void actionPerformed(ActionEvent e) { MutableDocument doc = m_NotesBean.getMutableDocument(); if(doc != null) { IAnnotationFactory factory = doc.getAnnotationFactory(); if (e.getActionCommand() == FREETEXT_CORRECT) { FreeTextTool.setShowPropDialog(false); FreeText correctAnnot = factory.createFreeText("Correct"); m_NotesBean.startEdit (correctAnnot, false, false); } else if (e.getActionCommand() == STAMP_CORRECT) { m_NotesBean.startEdit (factory.createRubberStamp ("Correct", Color.blue), false, false); } else if (e.getActionCommand() == RED_CIRCLE) { Circle redCircle = factory.createCircle(null); redCircle.setColor(Color.red); redCircle.setInternalColor(Color.blue); m_NotesBean.startEdit(redCircle, false, false); } } } /** * This method allows high DPI monitor support * */ public static double getDPIScalingMultiplier() { if (DPI_SCALING_MULTIPLIER == 0) { String version = System.getProperty("java.version"); StringTokenizer st = new StringTokenizer(version, "."); if (Integer.valueOf(st.nextToken()).intValue() > 8) { DPI_SCALING_MULTIPLIER = 1; } else { try { String osName = System.getProperty("os.name").toLowerCase(); LookAndFeel current = UIManager.getLookAndFeel(); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); DPI_SCALING_MULTIPLIER = Math.max(1, osName.indexOf("mac") != -1 ? 1 : new JLabel().getFont().getSize() / (osName.indexOf("windows") != -1 ? 11.0 : 15.0)); UIManager.setLookAndFeel(current); } catch (Exception e) { DPI_SCALING_MULTIPLIER = 1; } } } return DPI_SCALING_MULTIPLIER; } } // @jve:decl-index=0:visual-constraint="10,10"