JInternalFrame and JPanel

Pavan Sara <[email protected]> Tue, 25 Jan 2005 09:05:10 +0100
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Hi,
I have a couple of situations which gave me some problems and, even if 
now they work correctly,
I'd like to know if my implementation is right.

1) I have a JDesktopPane instance and I want to add some JInternalFrame 
objects: the content of each
JInternalFrame is in a xml file.
The xml file is of this kind:

/<?xml version="1.0" encoding="UTF-8"?>
<internalframe id="reportMain_if" size="800,500" title="Generation 
input"  resizable="true" closable="true" visible="true">
...
</internalframe>/

My Java code is:
/
public class pmMain extends WindowAdapter implements ActionListener {
  private static final String DESCRIPTOR = "xml/pmMain.xml";
  private SwingEngine swix;

  public JMenuItem mi_exit, mi_save;
  public JPanel pnl_North;
  public JDesktopPane main_desktopane;
  //
  // For every Actions, there needs to be a
  // public AbstractAction member variables with an anonymous inner 
class instantiation
  //

  /* attribute Action="newAction" in pmMain.xml* */
  public Action newAction = new AbstractAction() {

      public void actionPerformed(ActionEvent e) {
         try {
        ReportMain reportForm = new ReportMain();
            main_desktopane.add(reportForm.getInternalFrame(), 
javax.swing.JLayeredPane.DRAG_LAYER);
            main_desktopane.repaint();
         }
     catch (Exception exception)
     {
            System.err.println( exception.getMessage() );
          }
     }
  };/


where the function reportForm.getInternalFrame() return the 
JInternalFrame reportMain_if.

2) I have a JInternalFrame instance with a JSplitPane object.
On one hand it contains a JTree object and, according to the leaf 
selected, on the other side a different
JPanel is loaded. Each JPanel is descripted by a xml file.

The xml file for each JPanel is:
/<?xml version="1.0" encoding="UTF-8"?>
<panel id= "customInd_p" border="TitledBorder(Building Custom Report" 
layout="BorderLayout">
</panel>/

The java code:

/public class ReportMain {
  public JInternalFrame reportMain_if;
  public JTree advancedRep_tree;
  public JPanel advanced_p;
  private SwingEngine swix;
  private static final String DESCRIPTOR = "xml/reportMain.xml";
 
  public ReportMain() throws Exception {
    swix = new SwingEngine( this );
    swix.render( ReportMain.DESCRIPTOR );
    initComponents();
  }
  private void initComponents()
  {
    //Where the tree is initialized:
    advancedRep_tree.getSelectionModel().setSelectionMode
            (TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Listen for when the selection changes.
    advancedRep_tree.addTreeSelectionListener(new 
MyTreeSelectionListener());
    advancedRep_tree.setRootVisible(false);
  }
 
  public JInternalFrame getInternalFrame()
  {
      return reportMain_if;
  }
 
      /** <code>Action</code> GenerateAction handles the 
<em>combobox</em> */
    public Action generateAction = new AbstractAction()
    {
      public void actionPerformed(ActionEvent e)
      {
         try
         {
        ReportGenerate generateForm = new ReportGenerate();
            
reportMain_if.getDesktopPane().add(generateForm.getInternalFrame(), 
javax.swing.JLayeredPane.DRAG_LAYER);
         }
     catch (Exception exception)
     {
            System.err.println( exception.getMessage() );
         }
      }
    };
   
   /** <code>Action</code> GenerateAction handles the <em>combobox</em> */
    public Action scheduleAction = new AbstractAction()
    {
      public void actionPerformed(ActionEvent e)
      {
         try
         {
        ReportSchedule scheduleForm = new ReportSchedule();
            
reportMain_if.getDesktopPane().add(scheduleForm.getInternalFrame(), 
javax.swing.JLayeredPane.DRAG_LAYER);
         }
     catch (Exception exception)
     {
            System.err.println( exception.getMessage() );
         }
      }
    };
   
    //**********************************************************************
    // Inner Classes
    //**********************************************************************
    class MyTreeSelectionListener implements TreeSelectionListener {
      public void valueChanged(TreeSelectionEvent e)
      {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                       (e.getPath().getLastPathComponent());

        if (node == null) return;
        if (node.isLeaf())
        {
            String text = node.toString();
            if (text.equals("Measure Counters"))
            {
               try
              {
                 CustomIndicator customIndForm = new CustomIndicator();
                 advanced_p.add(customIndForm.getPanel());
                 reportMain_if.repaint();
              }
              catch (Exception exception)
             {
                System.err.println( exception.getMessage() );
              }
            }
            else {...}
        }
      }
    }
}/

    * advanced_p is a JPanel, contained in the xml file which describes
      the JInternalFrame.
    * customIndForm.getPanel() return customInd_p, the JPanel descripted
      in the xml file I quoted above.

Thank you very much,
S.

_______________________________________________
Forum mailing list
[email protected]
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com