Hichem-elAbassi / j4me

Automatically exported from code.google.com/p/j4me
0 stars 0 forks source link

MenuOption paintComponent #58

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. append a menuoption with a string that has 2 lines

What is the expected output? What do you see instead?
The components shouldn't overlap. I see the components overlapping

What version of the product are you using? On what operating system?

Please provide any additional information below.

This version allows for images to be next to the text in a menuoption.

protected void paintComponent (Graphics g, Theme theme, int width, int 
height, boolean selected)
    {
        // Paint the background for the menu item.
         if ( selected ) 
         { 
                 int backgroundColor = theme.getHighlightColor(); 
                 g.setColor( backgroundColor ); 
                 g.fillRect( 0, 0, width, height ); 
         } 

        // Calculate the dimensions of the text and submenu arrow.

        if ( hasimage )
        {int[] submenuDimensions = newpic.getPreferredSize(theme, 
width, height);
            // Get the dimensions of the arrow.
            int imageheight = submenuDimensions[1];

            if ( imageheight % 2 == 0 )
            {
                // The arrow height must odd to make a 
good looking triangle.
                imageheight--;
            }

            int imageWidth = submenuDimensions[0];
            int imageX =HORIZONTAL_MARGIN; //width - 
HORIZONTAL_MARGIN - arrowWidth;
            int imageY = (height - imageheight) / 2;
            newpic.paintComponent(g, theme, imageWidth, imageheight, 
selected);
            // Set the color of the arrow.
            //int arrowColor = selected ?
            //      theme.getMenuFontColor() :
            //      theme.getFontColor();
            //g.setColor( arrowColor );

            // Draw the arrow as a triangle.
            //g.fillTriangle(
            //      arrowX, arrowY,
            //      arrowX, arrowY + arrowHeight,
                //  arrowX + arrowWidth, arrowY + 
arrowHeight / 2 + 1 );

        int textWidth = width - 3 * HORIZONTAL_MARGIN - 
submenuDimensions[0];    - > problem occurs with subtraction of  
submenuDimensions[0]

        int[] textDimensions = getPreferredTextSize( theme, 
textWidth, height );
        int textHeight = textDimensions[1];
        int textTop = (height - textHeight) / 2;
        int textLeft = HORIZONTAL_MARGIN + submenuDimensions
[0]; //HORIZONTAL_MARGIN;

        // Paint the menu text.
        paintText( g, theme, textLeft, textTop, textWidth, 
textHeight, selected );
}
        else
        {
        int textWidth = width - 3 * HORIZONTAL_MARGIN ;

        int[] textDimensions = getPreferredTextSize( theme, 
textWidth, height );
        int textHeight = textDimensions[1];
        int textTop = (height - textHeight) / 2;
        int textLeft = HORIZONTAL_MARGIN ; //HORIZONTAL_MARGIN;

        // Paint the menu text.
        paintText( g, theme, textLeft, textTop, textWidth, 
textHeight, selected );
        }
    }

Original issue reported on code.google.com by juliocas...@gmail.com on 26 Jan 2010 at 6:45

GoogleCodeExporter commented 9 years ago
The modified function for pictures doesn't work in all cases. I'm guessing that 
the 
text overlapping happens with every component.

Original comment by juliocas...@gmail.com on 26 Jan 2010 at 9:16

GoogleCodeExporter commented 9 years ago
Never mind. I needed to adjust getPreferredComponentSize for the image addition.

Original comment by juliocas...@gmail.com on 27 Jan 2010 at 7:16

GoogleCodeExporter commented 9 years ago
Please close this issue.

Original comment by juliocas...@gmail.com on 30 Jan 2010 at 8:22