[Dev] Re: Problems with toolbar

Frank Cohen fcohen at pushtotest.com
Wed Mar 7 07:47:10 PST 2007


jbase has a few other methods to work with the toolbar. You need to  
changes these too. Specifically, add a new global private variable:

     private JPanel pttpanel = null;

and then modify the setToolbar(), frameToggleToolbar(), and addToolbar 
() methods as below.

-Frank


     public void setToolbar()
     {
         if (showToolbar && ToolBar.isToolBarEnabled()) {
             // We want a toolbar.
             ToolBar tb = currentEditor.getMode().getToolBar(this);
             if (tb != toolbar) {
                 if (toolbar != null) {
                     this.jpanel.remove(pttpanel);
                     pttpanel = null;
                     toolbar = null;
                 }
                 if (tb != null) {

                     System.out.println("Adding PushToTest panel 1");
                     pttpanel = new JPanel();
                     pttpanel.setLayout(new java.awt.BorderLayout());
                     pttpanel.add( tb, "Center");

                     JPanel pttpanel2 = new JPanel();
                     JButton pttbutton = new JButton();
                     pttbutton.setText("PushToTest");
                     pttpanel2.add( pttbutton );
                     pttpanel.add( pttpanel2, "North" );

                     toolbar = tb;
                     this.jpanel.add(pttpanel, "North");


                     toolbar.repaint();
                 }
                 this.jpanel.validate();
             }
         } else {
             // We don't want a toolbar.
             if (toolbar != null) {
                 jpanel.remove(pttpanel);
                 toolbar=null;
                 pttpanel= null;
                 jpanel.validate();
             }
         }
     }

     public void frameToggleToolbar()
     {
         showToolbar = !showToolbar;
         if (toolbar != null) {
             if (!showToolbar) {
                 jpanel.remove(pttpanel);
                 pttpanel = null;
                 toolbar = null;
                 jpanel.validate();
             }
         } else {
             if (showToolbar && ToolBar.isToolBarEnabled()) {
                 ToolBar tb = currentEditor.getMode().getToolBar(this);
                 if (tb != null) {

                     System.out.println("Adding PushToTest panel 1");
                     pttpanel = new JPanel();
                     pttpanel.setLayout(new java.awt.BorderLayout());
                     pttpanel.add( tb, "Center");

                     JPanel pttpanel2 = new JPanel();
                     JButton pttbutton = new JButton();
                     pttbutton.setText("PushToTest");
                     pttpanel2.add( pttbutton );
                     pttpanel.add( pttpanel2, "North" );

                     toolbar = tb;
                     this.jpanel.add(pttpanel, "North");


                     toolbar.repaint();
                     jpanel.validate();
                 }
             }
         }
         // Save new state.
         Editor.getSessionProperties().setShowToolbar(this,  
showToolbar);
     }

     private ToolBar defaultToolBar;

     public ToolBar getDefaultToolBar()
     {
         if (defaultToolBar == null)
             defaultToolBar = new DefaultToolBar(this);

         return defaultToolBar;
     }

     public void addToolbar(ToolBar tb)
     {
         Debug.assertTrue(toolbar == null);
         if (tb != null) {

             System.out.println("Adding PushToTest panel 1");
             pttpanel = new JPanel();
             pttpanel.setLayout(new java.awt.BorderLayout());
             pttpanel.add( tb, "Center");

             JPanel pttpanel2 = new JPanel();
             JButton pttbutton = new JButton();
             pttbutton.setText("PushToTest");
             pttpanel2.add( pttbutton );
             pttpanel.add( pttpanel2, "North" );

             toolbar = tb;
             this.jpanel.add(pttpanel, "North");

             toolbar.repaint();
         }
         // Make sure toolbar doesn't steal focus.
         Runnable r = new Runnable() {
             public void run()
             {
                 JComponent c = getFocusedComponent();
                 if (c != null)
                     c.requestFocus();
             }
         };
         SwingUtilities.invokeLater(r);
     }




On Mar 7, 2007, at 6:41 AM, William Martínez Pomares wrote:

> Hi Frank.
> The solution worked great at first, but it seems the J Editor  
> repaints its tool bar depending on the type of file you are  
> displaying. Thus, when we replace that one with our composed panel,  
> the new bar is drawn below, and on top the Jpanel. When we pass the  
> mouse over the buttons they get weirdly  repainted (see image).
>
> Could it be a problem of J Editor expecting only one tool bar? Can  
> we hook in to a J Editor event that paints the tool bar to custom  
> paint ours?
>
> Thanks.
>
> William.
>
>  -----Original Message-----
> From:   Luis Carlos Lara López
> Sent:   Tuesday, March 06, 2007 6:24 PM
> To:     William Martínez Pomares
> Subject:        Problems with toolbar
>
> It seems It seems you example don’t work completely correct in TM
>
> When you change between files, the toolbar appear, but it’s non  
> functional, it seems that the first toolbar don’t disappear and  
> replace the new
>
>
>
> and sometime the tool bar disappear
>
>
>
> Please confirm the problem. Maybe the problem is in our source
>
> Thank
> LC
>
>



--
Frank Cohen, PushToTest, http://www.PushToTest.com, phone 408 374 7426
TestMaker: The open-source SOA test automation tool





More information about the Dev mailing list