Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6407296

REGRESSION: Inconsistent (custom) menubar performance between JDK releases

XMLWordPrintable

    • 2d
    • x86
    • solaris_2.5.1

      A DESCRIPTION OF THE REGRESSION :
      due to some limitation on menu events, i was forced to create my own version of MenuBar and friends. All this worked in JDK1.4.

      Then came along JDK1.5 . The menu bar is printed, but unfortunately the submenu's for each menu-item are just not displayed. This occures with both XToolkit, and MToolkit. As far as I can tell it has failed with all releases of JDK1.5.

      Then there is JDK1.6 . The submenu's are back. Works with both MToolkit, and XToolkit. Unfortunately the size of the sub-menu text boxes are not the same size than that of jdk1.4 . In jdk1.4, the sub-menu;s are almost squaresh looking. JDK1.6 the boxes are distinctly rectangular and thin. I would like to compare with jdk1.5, but that has never worked.

      So is this a reverse regression? ;-}

      REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
      1) run pgm
      2) click on "This" ( a "1" should appear)
      3) click on "is" ( a "2" should appear )
      4) click on "a" ( a "3" should appear )
      5) click on "test" ( a "4" should appear )


      ===========================================================
      /*
       * NewFrame.java
       *
       * Created on March 29, 2006, 6:26 AM
       */

      /**
       *
       * @author gat
       */

      import GBMENU.*;

      public class NewFrame extends java.awt.Frame {
          
          /** Creates new form NewFrame */
          public NewFrame() {
              initComponents();
              setSize(300,300);
          }
          
          /** This method is called from within the constructor to
           * initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is
           * always regenerated by the Form Editor.
           */
          // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
          private void initComponents() {
              canvas2 = new java.awt.Canvas();
              menuPanel = new java.awt.Panel();
              panel2 = new java.awt.Panel();
              canvas1 = new java.awt.Canvas();
              panel3 = new java.awt.Panel();
              button1 = new java.awt.Button();
              button2 = new java.awt.Button();

              addWindowListener(new java.awt.event.WindowAdapter() {
                  public void windowClosing(java.awt.event.WindowEvent evt) {
                      exitForm(evt);
                  }
              });

              addMenuBar( menuPanel );
              add(menuPanel, java.awt.BorderLayout.NORTH);

              panel2.add(canvas1);

              add(panel2, java.awt.BorderLayout.CENTER);

              button1.setLabel("button1");
              panel3.add(button1);

              button2.setLabel("button2");
              panel3.add(button2);

              add(panel3, java.awt.BorderLayout.SOUTH);

              pack();
          }
          // </editor-fold>
          
          void addMenuBar( java.awt.Panel panel ) {
                  GBMenu t;
                  GBMenuBar menuBar = new GBMenuBar();
                  menuBar.add(t = new GBMenu("This", true ));
                  t.add( new java.awt.MenuItem("1"));
                  menuBar.add(t = new GBMenu("is", true ));
                  t.add( new java.awt.MenuItem("2"));
                  menuBar.add(t = new GBMenu("a", true ));
                  t.add( new java.awt.MenuItem("3"));
                  menuBar.add(t = new GBMenu("test", true ));
                  t.add( new java.awt.MenuItem("4"));
                  panel.add( menuBar );
          }
          /** Exit the Application */
          private void exitForm(java.awt.event.WindowEvent evt) {
              System.exit(0);
          }
          
          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new NewFrame().setVisible(true);
                  }
              });
          }
          
          
          // Variables declaration - do not modify
          private java.awt.Button button1;
          private java.awt.Button button2;
          private java.awt.Canvas canvas1;
          private java.awt.Canvas canvas2;
          private java.awt.Panel menuPanel;
          private java.awt.Panel panel2;
          private java.awt.Panel panel3;
          // End of variables declaration
          
      }
      ===================================================================
      /*
       * GbMenuBar.java
       *
       * Created on May 3, 2004, 9:19 PM
       */

      /**
       *
       * @author gat
       */
      package GBMENU;

      import java.awt.Graphics;
      import java.awt.MenuItem;
      import java.awt.FontMetrics;
      import java.awt.Font;
      import java.awt.Color;
      import java.util.Vector;
      import java.awt.Dimension;
      import java.awt.Component;
      import java.awt.Window;
      import java.awt.Point;
      import java.awt.Frame;

      public class GBMenu extends java.awt.Component {
          
          String label;
          static Integer gbmenuCount;
          int height, width;
          Vector mi;
          Font font = new java.awt.Font("Monospaced", 0, 12);
          FontMetrics fontM = getFontMetrics( font );
          
          Window win;
          GBMenuSub gbMenuSub;
          
          public GBMenu( String label, boolean b ) {
              setName(this.label = label);
              setFont(font);
              mi = new Vector();
              addMouseListener(new java.awt.event.MouseAdapter() {
                  public void mouseClicked(java.awt.event.MouseEvent evt) {
                      GBMenuMouseClicked(evt);
                  }
              });
          }
          public void addNotify() {
              super.addNotify();
              composePopup();
          }

          public void add( MenuItem menuitem ) {
              mi.add( menuitem );
          }

          public Dimension getSize() {
              return new Dimension( width, height );
          }
          public void setSize( int width, int height ) {
              this.width = width;
              this.height = height;
              super.setSize( width, height );
          }
          
          public Dimension getPreferredSize() {
              //System.out.println("GBMenu.getPreferredSize(); wid="+width+",heigh="+height+", label="+label);
              return new Dimension( width, height );
          }
          public Dimension getMinimumSize() {
              return getPreferredSize();
          }
          public Dimension getmaximumSize() {
              return new Dimension( Short.MAX_VALUE, getPreferredSize().height);
          }
          public void repaint() {
              //System.out.println("GBMenu("+label+").repaint()");
              if ( gbMenuSub != null )
                  gbMenuSub.repaint();
              super.repaint();
          }
          
          public void paint( Graphics g ) {
              //System.out.println("GBMenu("+label+").paint()");
              int x, y;
              x = ( width - fontM.stringWidth( label ) ) / 2;
              y = ( height + fontM.getHeight() ) / 2 - fontM.getDescent();
              
                  g.setColor( Color.magenta );
                  g.fillRect( 0,0, getSize().width, getSize().height );
              
              g.setColor( Color.black );
              g.drawString( label, x, y );
          }
          
          private void GBMenuMouseClicked(java.awt.event.MouseEvent evt) {
              //System.out.println("GBMenuMouseClicked");

              drawPopup( true );
          }
          void composePopup() {
              Frame f = null;
              Component t = this;
              while ( ( t = t.getParent() ) != null ) {
                  if ( t instanceof Frame )
                      f = (Frame) t;
              }
              if ( f == null )
                  return;
              win = new Window( f );
              gbMenuSub = new GBMenuSub( win, mi, font, fontM);
          }
          void drawPopup( boolean b ) {
              
                  Point scrnLoc = this.getLocationOnScreen();
                  gbMenuSub.setLocation( scrnLoc.x, scrnLoc.y + getSize().height );
                  gbMenuSub.invalidate();
                  gbMenuSub.pack();
                  gbMenuSub.setVisible( true );
                  gbMenuSub.toFront();

          }
      }
      ====================================================================
      /*
       * GBMenuSub.java
       *
       * Created on May 7, 2004, 10:00 PM
       */

      /**
       *
       * @author gat
       */
      package GBMENU;

      import java.awt.*;
      import java.awt.event.*;
      import java.util.Vector;

      class GBMenuSub extends java.awt.Window {
          
          /** Creates a new instance of GBMenuSub */
          Vector mi;
          Font font = new java.awt.Font("Monospaced", 0, 12);
          FontMetrics fontM = getFontMetrics( font );
          
          GBMenuSub(Window f, Vector mi, Font font, FontMetrics fontM ) {
              super( f );
              this.mi = mi;
              GBMenuItem m;
              for ( int i = 0; i < mi.size(); i++ ) {
                  Object c = mi.get( i );
                  if ( c instanceof MenuItem ) {
                      add( m = new GBMenuItem( (MenuItem)c ) );
                      m.setFont( font );
                  }
              }
          }
       
          public void paint( Graphics g ) {
              //System.out.println("GBMenuSub.paint();");
              Dimension d = getSize();
              g.setColor( Color.blue );
              g.drawRect( 0, 0, d.width-1, d.height-1 );
              super.paint( g );
          }
          public Dimension getPreferedSize() {
              return new Dimension( 1, fontM.getHeight() * 3 / 2 ); // width is ignored
          }
          public Insets getInsets() {
              return new Insets( 1, 1, 1, 1 );
          }
      }
      ================================================================
      /*
       * GBMenuItem.java
       *
       * Created on May 5, 2004, 5:07 PM
       */

      /**
       *
       * @author gat
       */

      package GBMENU;

      import java.awt.MenuItem;
      import java.awt.Graphics;
      import java.awt.Dimension;
      import java.awt.FontMetrics;
      import java.awt.Color;

      public class GBMenuItem extends java.awt.Component {
          
          /** Creates a new instance of GBMenuItem */
          MenuItem menuitem;
          FontMetrics fontM = getFontMetrics( new java.awt.Font("Monospaced", 0, 12));
          int width, height;
          
          public GBMenuItem( MenuItem m) {
              this.menuitem = m;
          }

          public void setSize( int width, int height ) {
              super.setSize( this.width = width, this.height = height );
          }
          public String getLabel() {
              return menuitem.getLabel();
          }
          public Dimension getPreferredSize() {
              int maxHeight = (fontM.getHeight() * 3 / 2 );
              int maxWidth = 10;
              if ( getLabel() != null )
                  maxWidth = fontM.stringWidth( getLabel() ) + fontM.getMaxAdvance();
              return new Dimension ( maxWidth, maxHeight );
         }
         public Dimension getMinimumSize() {
             return getPreferredSize();
         }
         public Dimension getmaximumSize() {
             return new Dimension( Short.MAX_VALUE, getPreferredSize().height);
         }
          public void paint( Graphics g ) {
              //System.out.println("gbMenuItem("+menuitem.getLabel()+").paint()");
              Dimension d = this.getSize();
                  g.setColor( Color.magenta );
                  g.fillRect( 0, 0, d.width, d.height );
                  g.setColor( Color.black );
                  d.height--; d.width--;
                  g.drawLine( 0, 0, d.width, 0 );
                  g.setColor( Color.white );
                  g.drawLine( 0, d.height, d.width, d.height);
              
                  g.setColor( Color.black );

              int x, y;
              x = fontM.getMaxAdvance() / 2;
              y = ( d.height + fontM.getHeight() ) / 2 - fontM.getDescent();
              g.drawString( menuitem.getLabel(), x, y );
          }
      }
      ===============================================================
      /*
       * GbMenuBar.java
       *
       * Created on May 3, 2004, 9:19 PM
       */

      /**
       *
       * @author gat
       */

      package GBMENU;

      import java.awt.Graphics;
      import java.awt.MenuContainer;
      import java.awt.FontMetrics;
      import java.awt.Font;
      import java.awt.Rectangle;
      import java.awt.Color;
      import java.util.Vector;
      import java.awt.Insets;
      import java.awt.Dimension;
      import java.awt.FlowLayout;


      public class GBMenuBar extends java.awt.Container implements MenuContainer/*, GBMenuEscapeListener*/ {
          
          /** Creates a new instance of GbMenuBar */
          Vector menu;
          Font font = new Font("Monospaced", Font.PLAIN, 12);
          FontMetrics fontM;
          short barHeight;
          short barWidth;
          static short objectCount;
          //transient ActionListener actionListener;
          
          public GBMenuBar() {
              menu = new Vector();
              fontM = getFontMetrics( font );
              barHeight = ( short ) ((fontM.getHeight() * 3 ) / 2);
              setLayout( new FlowLayout(FlowLayout.LEFT,0,0) );
              setName("GBMenuBar"+(objectCount++));
          }

          public GBMenu add( GBMenu m ) {
              //System.out.println("GBMenuBar.add("+m+")" );
              menu.add( m );
              m.setSize( fontM.stringWidth( m.label+" " ), barHeight );
              m.setFont( font );
              super.add( m );
              return m;
          }

          public void paint( Graphics g ) {
              
              Rectangle r = this.getBounds();
              g.setColor( Color.yellow );
              g.fillRect( 1, 1, r.width-1, r.height-1 );
              g.setColor( Color.black );
              g.drawRect( 0, 0, r.width-1, r.height-1 );
              super.paint( g );
          }
         public Dimension getPreferredSize() {
              int width = 0;
              Dimension d;
              for (int j=0; j < menu.size(); j++) {
                  d = ((GBMenu)menu.get( j )).getPreferredSize();
                  width += d.width;
              }
              Insets i = getInsets();
              return new Dimension( width+i.right+i.left, barHeight +i.top+i.bottom );
          }
         public Insets getInsets() {
             return new Insets( 1+2,1+2,1+2,1+2 );
         }
      }
      ==============================================================

      RELEASE LAST WORKED:
      5.0 Update 1

      RELEASE TEST FAILS:
      mustang-beta

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect all the JDK's to perform similarily. With MToolkit, and Xtoolkit.

      this is a Linux box, with fedora 4.
      ACTUAL -
      JDK1.4 - sub-menu's painted, and square.
      JDK1.5 - no sub-menu's at all
      JDK1.6 - Sub-menu's painted, but thin rectangular boxes.

      OBSERVED APPLICATION IMPACT:
      I really dont know how to ans this. I thought this would have been fixed some time ago in JDK1.5 .

            Unassigned Unassigned
            ttzhang Tao Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: