5 Replies Latest reply: Nov 11, 2008 8:45 AM by 843851 RSS

    Seting a HLook

    843851
      Hi,
      ¿Someone using HLook for seting the appearence of a component in an separate way from the funcionality?

      I try to asign an HLook to a HTextButton but something goes wrong because after seting this the component is not painted.

      Here is the code:
      in a HContainer constructor:

           
                      lookBtn=new HTextLookCantata();
                HTextButton.setDefaultLook(lookBtn);
                      ...
                btnExit=new HTextButton();
                btnExit.setTextContent("SALIR", HState.NORMAL_STATE);
                btnExit.setLocation(pxB1, pyB1);
                btnExit.setActionCommand("EXIT");
                      this.add(btnExit);
      the class that implements HTextButtonLook
      public class HTextLookCantata extends HTextLook {
           private final int w=150;
           private final int h=30;
           private final int arcW=10;
           private final int arcH=10;
           private DVBColor bc=new DVBColor( DVBColor.blue);
           private final DVBColor fc=new DVBColor( DVBColor.cyan);
           
           public HTextLookCantata(){
                super();
           }
           public boolean isOpaque(){
                return true;
           }
           public void showLook(Graphics g,HVisible visible,int state){
                super.showLook(g,visible, state);
                      g.setColor(bc);
                g.fillRoundRect(0, 0, w,h,,arcW,arcH);
                
                g.setColor(fc);
                g.drawString("hello",5,20);
                
           }
      
      }
      ¿what is missing? ¿Do I have to call to showLook function?

      thanks in advance,
      Aitor Peña

      Edited by: apenz on Nov 3, 2008 4:46 AM

      Edited by: apenz on Nov 3, 2008 4:47 AM
        • 1. Re: Seting a HLook
          843851
          Looking at the extended HLook class i guess you have not overridden the function
          public void widgetChanged(HVisible vis, HChangeData[] changes)..Try using this in the Look class where you can just call vis.repaint(); .i.e
          public class HTextLookCantata extends HTextLook
          {
          ////other functions...
           public void widgetChanged(HVisible vis, HChangeData[] changes)
           {
              vis.repaint(); 
           }
          }
          Hope this helps.
          Pallavi.
          • 2. Re: Seting a HLook
            843851
            thanks I´ve tryed this but buttons are still not being painted, nor getting any error so I don´t know what is missing.
            ¿Could be the my STB which doesn´t support HLook because of its MHP version?

            thanks
            greetings

            Edited by: apenz on Nov 4, 2008 12:31 AM
            • 3. Re: Seting a HLook
              843851
              Try setting the size of your button.That should help.
              i.e
              ....
              btnExit.setTextContent("SALIR", HState.NORMAL_STATE);
              btnExit.setLocation(200,200);
              btnExit.setSize(200,200);
              btnExit.setActionCommand("EXIT");
              ....
              • 4. Re: Seting a HLook
                843851
                Thanks Pallavi_N, I thougth that the size of the button could been set in the HLook class. So my code now is this
                In the class that extends HContainer, Constructor:
                          lookBtn=new HTextLookCantata();
                                ...
                          btnExit=new HTextButton();
                          btnExit.setTextContent("EXIT", HState.NORMAL_STATE);
                          try {
                               btnExit.setLook(lookBtn);
                          } catch (HInvalidLookException ile) {
                               // TODO Auto-generated catch block
                               System.out.println("Main::Constructor:InvalidLookException:"+ile.getMessage());
                
                          }
                          btnExit.setLocation(pxBtnExit, pyBtnExit);
                          btnExit.setSize(wBtnExit, hBtnExit);
                          btnExit.setActionCommand("EXIT");
                          btnExit.setBackgroundMode(HVisible.BACKGROUND_FILL);
                          btnExit.setBackground(backColorBtnExit);
                          btnExit.setForeground(foreColorBtnExit);
                In HTextLookCantata which extends (HTextLook) implemetation:
                     private final int arcW=20;
                     private final int arcH=20;
                     private DVBColor backColor=new DVBColor(DVBColor.blue);
                     private final DVBColor foreColor=new DVBColor(DVBColor.cyan);
                     
                     public HTextLookCantata(){
                          super();
                     }
                     public boolean isOpaque(){
                          return true;
                     }
                     public void showLook(Graphics g,HVisible visible,int state){
                          int w,h;
                     
                          w=visible.getSize().width;
                          h=visible.getSize().height;
                                g.setColor(visible.getBackground());
                
                          g.drawRoundRect(0, 0, w-arcW,h-arcH,arcW,arcH);
                
                          g.setColor(visible.getForeground());
                
                          g.setFont(new Font("default",Font.PLAIN,20));
                          g.drawString(visible.getTextContent(HState.NORMAL_STATE),2,2);
                          
                     }
                     
                     public void widgetChanged(HVisible vis,HChangeData changes[]){
                          vis.repaint();
                     }
                When I run I notice that the buttons are not painted properly they look blurry. And when I comment the lines where the HLook is set, this lines buttons are painted in normal way.

                It seems like the decoder doesn´t understand the style settings made in HLook class.

                greetings,
                AItor

                Edited by: apenz on Nov 6, 2008 1:59 AM

                Edited by: apenz on Nov 6, 2008 3:09 AM

                Edited by: apenz on Nov 6, 2008 3:10 AM

                Edited by: apenz on Nov 6, 2008 7:21 AM
                • 5. Re: Seting a HLook
                  843851
                  Hi,

                  Finally it works, thanks for the help, the only problem now is that I don´t see the transparencies properly, but maybe I will start another thread.
                  Bellow I post my code so that somebody could find it helpfull.
                            btnSalir=new HTextButton();
                            btnSalir.setTextContent("SALIR", HState.NORMAL_STATE);
                            btnSalir.setLocation(pxBtnSalir, pyBtnSalir);
                            btnSalir.setSize(wBtnSalir, hBtnSalir);
                            btnSalir.setActionCommand("EXIT");
                            btnSalir.setBackgroundMode(HVisible.BACKGROUND_FILL);
                            btnSalir.setBackground(backColorBtnSalir);
                            btnSalir.setForeground(foreColorBtnSalir);
                            try {
                                 btnSalir.setLook(lookBtn);
                            } catch (HInvalidLookException ile) {
                                 // TODO Auto-generated catch block
                                 System.out.println("Principal::Constructor:InvalidLookException:"+ile.getMessage());
                                 //e1.printStackTrace();
                            }
                       
                            HFlatEffectMatte m;
                            float data[]=new float[3];
                            data[0]=0.2f;
                            data[1]=0.4f;
                            data[2]=0.8f;
                            
                            m=new HFlatEffectMatte(data);
                            m.setDelay(1000);
                            
                            try {
                                 btnSalir.setMatte(m);
                            } catch (HMatteException hme) {
                                 // TODO Auto-generated catch block
                                 System.out.println("Principal::Constructor:"+hme.getMessage());
                            }
                            m.start();
                       public void showLook(Graphics g,HVisible visible,int state){
                            int width,height,w,h;
                            int buttonWidth,buttonHeight;
                  
                            width=visible.getSize().width;
                            height=visible.getSize().height;
                            buttonWidth=width-2*buttonBorder;
                            buttonHeight=height-2*buttonBorder;
                  
                  
                            switch(state){
                                 case HState.NORMAL_STATE:
                                      
                                      backColor=new DVBColor(200,50,50,100);
                                      foreColor=new DVBColor(50,200,50,100);
                                      borderColor=new DVBColor(200,50,50,100);
                                      break;
                                 case HState.FOCUSED_STATE:
                                      backColor=new DVBColor(255,50,50,100);
                                      foreColor=new DVBColor(50,220,50,100);
                                      borderColor=new DVBColor(255,255,255,100);
                                      break;
                                      
                            }
                            g.setColor(borderColor);
                            g.fillRoundRect(0, 0, width, height,arcWidth,arcHeight);
                            
                           g.setColor(backColor);
                  
                           g.fillRoundRect(buttonBorder, buttonBorder, buttonWidth, buttonHeight,arcWidth,arcHeight);
                  
                            g.setColor(foreColor);
                            g.setFont(new Font("default",Font.PLAIN,20));
                           fm = g.getFontMetrics();
                           w = fm.stringWidth(visible.getTextContent(HState.NORMAL_STATE));
                           h=fm.getAscent();
                           g.drawString(visible.getTextContent(HState.NORMAL_STATE), (buttonWidth - w) / 2, (buttonHeight+h)/2);//height*9/10-7);
                           System.out.println("Principal::Button With:"+buttonWidth+"Position:"+((buttonWidth - w) / 2)+"\nButton Height:"+buttonHeight+"Position:"+((buttonHeight-h)/2));
                       }
                  greetings