Plex 2E

  • 1.  How to add Jpanel components to a Plex panel

    Posted Oct 07, 2014 03:02 AM

    The code below opens a PDF document in a Jpanel. I have managed to create it as a source code object and calling it opens up a new Jpanel window.

     

    Is there a way to add this to a plex panel so that I can add additional functionality using plex, for example data fields.

     

    I would assume I would need to modify the code around the JFrame() part to reference a Plex Panel or Control on a plex panel?

     

     

    import org.icepdf.ri.common.SwingController;
    import org.icepdf.ri.common.SwingViewBuilder;
    import org.icepdf.ri.util.PropertiesManager;

    import javax.swing.*;
    import java.util.ResourceBundle;

    {
            // Get a file from the command line to open
            String filePath = "C:/PDFLocal/Gen/Bld/CA Plex 71.pdf";

            // build a component controller
            SwingController controller = new SwingController();
            controller.setIsEmbeddedComponent(true);

            PropertiesManager properties = new PropertiesManager(
                    System.getProperties(),
                    ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));

            properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.75");

            SwingViewBuilder factory = new SwingViewBuilder(controller, properties);

            // add interactive mouse link annotation support via callback
            controller.getDocumentViewController().setAnnotationCallback(
                    new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

            JPanel viewerComponentPanel = factory.buildViewerPanel();
            JFrame applicationFrame = new JFrame();
          

            applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            applicationFrame.getContentPane().add(viewerComponentPanel);
            // Now that the GUI is all in place, we can try openning a PDF
            controller.openDocument(filePath);
            // show the component
            applicationFrame.pack();
            applicationFrame.setVisible(true);
        }



  • 2.  Re: How to add Jpanel components to a Plex panel

    Posted Oct 08, 2014 11:50 AM

    Anybody able to offer help to Gavin?

    Gavin Beangstrom wrote:

     

    The code below opens a PDF document in a Jpanel. I have managed to create it as a source code object and calling it opens up a new Jpanel window.

     

    Is there a way to add this to a plex panel so that I can add additional functionality using plex, for example data fields.

     

    I would assume I would need to modify the code around the JFrame() part to reference a Plex Panel or Control on a plex panel?

     

     

    import org.icepdf.ri.common.SwingController;
    import org.icepdf.ri.common.SwingViewBuilder;
    import org.icepdf.ri.util.PropertiesManager;

    import javax.swing.*;
    import java.util.ResourceBundle;

    {
            // Get a file from the command line to open
            String filePath = "C:/PDFLocal/Gen/Bld/CA Plex 71.pdf";

            // build a component controller
            SwingController controller = new SwingController();
            controller.setIsEmbeddedComponent(true);

            PropertiesManager properties = new PropertiesManager(
                    System.getProperties(),
                    ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));

            properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.75");

            SwingViewBuilder factory = new SwingViewBuilder(controller, properties);

            // add interactive mouse link annotation support via callback
            controller.getDocumentViewController().setAnnotationCallback(
                    new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

            JPanel viewerComponentPanel = factory.buildViewerPanel();
            JFrame applicationFrame = new JFrame();
         

            applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            applicationFrame.getContentPane().add(viewerComponentPanel);
            // Now that the GUI is all in place, we can try openning a PDF
            controller.openDocument(filePath);
            // show the component
            applicationFrame.pack();
            applicationFrame.setVisible(true);
        }



  • 3.  Re: How to add Jpanel components to a Plex panel

    Posted Oct 09, 2014 05:40 AM

    As an alternative, does any one have details on creating a PDF viewer contained in Plex Java panel. I have just used ICE PDF as I managed to call it from plex, but not in a plex panel.



  • 4.  Re: How to add Jpanel components to a Plex panel
    Best Answer

    Posted Nov 07, 2014 10:17 AM

    After spending some time on everything J, JFrame, JPanel, JText, JButton, etc and a bit more time understanding the ObUserAPI.getComponentFromName and inspecting a number of components I have solved this, so here is how to add components (non Java Bean) at run time to a plex panel.

     

    My problem was to take a PDF viewer, in this case icePDF and embed it in plex. You can do similar things as well like adding Buttons, Fieilds, Labels, etc as well.

     

    1) On a plex panel create a new region, and change the region Type to "Site". It turns out that this then implemented as a JPanel.

    2) Set the Control Name property of the region to a value, eg "PDFView"

    3) Create a source code object with a parameter of  "ActiveXControl"

    4) in the source code  insert the following code.

     

    import java.awt.* ;
    import java.awt.event.*;
    import javax.swing.*;

    import org.icepdf.ri.common.SwingController;
    import org.icepdf.ri.common.SwingViewBuilder;
    import org.icepdf.ri.util.PropertiesManager;

    String filePath = "C:/PDFDocs/Sample.pdf";

    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    //ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
          new org.icepdf.ri.common.MyAnnotationCallback(
                 controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    //JFrame window = new JFrame("Using the Viewer Component");
    JPanel window = (JPanel) ObUserAPI.getComponentFromName(getFunction(), new ObCharFld("*Current"), &(1:).toString());
    window.add(viewerComponentPanel, BorderLayout.CENTER);


    // Open a PDF document to view
    controller.openDocument(filePath);


    4) The important lines are those marked in bold

     

    5) In the initialisation of your function, call the source Code object passing on the control name parameter, eg PDFView

     

    You now have a PDF Viewer integrated to a Plex Panel



  • 5.  Re: How to add Jpanel components to a Plex panel

    Posted Nov 08, 2014 01:21 AM

    You make me want to start playing with java client again.

     

    You deserve this:

    RareLego.png



  • 6.  Re: How to add Jpanel components to a Plex panel

    Posted Nov 08, 2014 05:04 AM

    Thanks George, so do you have a Mr Gold you willing to give me?