You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by "Schwartz, Cynthia L" <cy...@intel.com> on 2013/03/07 18:08:18 UTC

why does this paint twice?

I am writing a custom control and want to understand why this is painting twice. Complete code below.

Thanks,
Cynthia

public class PaintTest extends Application.Adapter {
    private Window window = null;
    private Waveform waveform = null;

    @Override
    public void startup(Display display, Map<String, String> properties) {
        window = new Window();
                waveform = new Waveform();
                window.setContent(waveform);
        window.setMaximized(true);
        window.open(display);
    }

    @Override
    public boolean shutdown(boolean optional) {
        if (window != null) {
            window.close();
        }

        return false;
    }

    public static void main(String[] args) {
        DesktopApplicationContext.main(PaintTest.class, args);
    }

}

package painttest;

import java.awt.Graphics2D;
import org.apache.pivot.wtk.Panel;

public class Waveform extends Panel
{
       @Override
        public void paint(Graphics2D graphics)
    {
                System.out.println("Painting");
}
}



Re: why does this paint twice?

Posted by Greg Brown <gk...@verizon.net>.
Yes - all components ultimately need to implement paint() in one way or another.

On Mar 7, 2013, at 1:03 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:

> That code = Code that overrides the paint method.  Is that the best way to paint a custom widget in Pivot?  It seems as if it would be, going to Java2D directly, but I just wanted to make sure since I am still learning of Pivot's capabilities and power.
> 
> Thanks,
> Cynthia 
> 
> -----Original Message-----
> From: Greg Brown [mailto:gk_brown@verizon.net] 
> Sent: Thursday, March 07, 2013 9:59 AM
> To: user@pivot.apache.org
> Subject: Re: why does this paint twice?
> 
> What code?
> 
> On Mar 7, 2013, at 12:30 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:
> 
>> Is that code the best (fastest, most efficient...)  way to accomplish the painting of a custom control in Pivot?
>> 
>> Thanks
>> Cynthia
>> 
>> -----Original Message-----
>> From: Greg Brown [mailto:gk_brown@verizon.net]
>> Sent: Thursday, March 07, 2013 9:22 AM
>> To: user@pivot.apache.org
>> Subject: Re: why does this paint twice?
>> 
>> paint() is called any time any region of the screen needs to be updated. This update could be triggered by the application or it could be triggered by the OS (for example, if an overlapping window is moved). 
>> 
>> The graphics context passed to paint() will be clipped to the bounds of the update region, but you should generally optimize your component's drawing code so it only draws that part that needs to be repainted.
>> 
>> On Mar 7, 2013, at 12:08 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:
>> 
>>> I am writing a custom control and want to understand why this is painting twice. Complete code below.
>>> 
>>> Thanks,
>>> Cynthia
>>> 
>>> public class PaintTest extends Application.Adapter {
>>>   private Window window = null;
>>>   private Waveform waveform = null;
>>> 
>>>   @Override
>>>   public void startup(Display display, Map<String, String> properties) {
>>>       window = new Window();
>>>               waveform = new Waveform();
>>>               window.setContent(waveform);
>>>       window.setMaximized(true);
>>>       window.open(display);
>>>   }
>>> 
>>>   @Override
>>>   public boolean shutdown(boolean optional) {
>>>       if (window != null) {
>>>           window.close();
>>>       }
>>> 
>>>       return false;
>>>   }
>>> 
>>>   public static void main(String[] args) {
>>>       DesktopApplicationContext.main(PaintTest.class, args);
>>>   }
>>> 
>>> }
>>> 
>>> package painttest;
>>> 
>>> import java.awt.Graphics2D;
>>> import org.apache.pivot.wtk.Panel;
>>> 
>>> public class Waveform extends Panel
>>> {
>>>      @Override
>>>       public void paint(Graphics2D graphics)
>>>   {
>>>               System.out.println("Painting"); } }
>>> 
>>> 
>> 
> 


RE: why does this paint twice?

Posted by "Schwartz, Cynthia L" <cy...@intel.com>.
That code = Code that overrides the paint method.  Is that the best way to paint a custom widget in Pivot?  It seems as if it would be, going to Java2D directly, but I just wanted to make sure since I am still learning of Pivot's capabilities and power.

Thanks,
Cynthia 

-----Original Message-----
From: Greg Brown [mailto:gk_brown@verizon.net] 
Sent: Thursday, March 07, 2013 9:59 AM
To: user@pivot.apache.org
Subject: Re: why does this paint twice?

What code?

On Mar 7, 2013, at 12:30 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:

> Is that code the best (fastest, most efficient...)  way to accomplish the painting of a custom control in Pivot?
> 
> Thanks
> Cynthia
> 
> -----Original Message-----
> From: Greg Brown [mailto:gk_brown@verizon.net]
> Sent: Thursday, March 07, 2013 9:22 AM
> To: user@pivot.apache.org
> Subject: Re: why does this paint twice?
> 
> paint() is called any time any region of the screen needs to be updated. This update could be triggered by the application or it could be triggered by the OS (for example, if an overlapping window is moved). 
> 
> The graphics context passed to paint() will be clipped to the bounds of the update region, but you should generally optimize your component's drawing code so it only draws that part that needs to be repainted.
> 
> On Mar 7, 2013, at 12:08 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:
> 
>> I am writing a custom control and want to understand why this is painting twice. Complete code below.
>> 
>> Thanks,
>> Cynthia
>> 
>> public class PaintTest extends Application.Adapter {
>>    private Window window = null;
>>    private Waveform waveform = null;
>> 
>>    @Override
>>    public void startup(Display display, Map<String, String> properties) {
>>        window = new Window();
>>                waveform = new Waveform();
>>                window.setContent(waveform);
>>        window.setMaximized(true);
>>        window.open(display);
>>    }
>> 
>>    @Override
>>    public boolean shutdown(boolean optional) {
>>        if (window != null) {
>>            window.close();
>>        }
>> 
>>        return false;
>>    }
>> 
>>    public static void main(String[] args) {
>>        DesktopApplicationContext.main(PaintTest.class, args);
>>    }
>> 
>> }
>> 
>> package painttest;
>> 
>> import java.awt.Graphics2D;
>> import org.apache.pivot.wtk.Panel;
>> 
>> public class Waveform extends Panel
>> {
>>       @Override
>>        public void paint(Graphics2D graphics)
>>    {
>>                System.out.println("Painting"); } }
>> 
>> 
> 


Re: why does this paint twice?

Posted by Greg Brown <gk...@verizon.net>.
What code?

On Mar 7, 2013, at 12:30 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:

> Is that code the best (fastest, most efficient...)  way to accomplish the painting of a custom control in Pivot?
> 
> Thanks
> Cynthia
> 
> -----Original Message-----
> From: Greg Brown [mailto:gk_brown@verizon.net] 
> Sent: Thursday, March 07, 2013 9:22 AM
> To: user@pivot.apache.org
> Subject: Re: why does this paint twice?
> 
> paint() is called any time any region of the screen needs to be updated. This update could be triggered by the application or it could be triggered by the OS (for example, if an overlapping window is moved). 
> 
> The graphics context passed to paint() will be clipped to the bounds of the update region, but you should generally optimize your component's drawing code so it only draws that part that needs to be repainted.
> 
> On Mar 7, 2013, at 12:08 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:
> 
>> I am writing a custom control and want to understand why this is painting twice. Complete code below.
>> 
>> Thanks,
>> Cynthia
>> 
>> public class PaintTest extends Application.Adapter {
>>    private Window window = null;
>>    private Waveform waveform = null;
>> 
>>    @Override
>>    public void startup(Display display, Map<String, String> properties) {
>>        window = new Window();
>>                waveform = new Waveform();
>>                window.setContent(waveform);
>>        window.setMaximized(true);
>>        window.open(display);
>>    }
>> 
>>    @Override
>>    public boolean shutdown(boolean optional) {
>>        if (window != null) {
>>            window.close();
>>        }
>> 
>>        return false;
>>    }
>> 
>>    public static void main(String[] args) {
>>        DesktopApplicationContext.main(PaintTest.class, args);
>>    }
>> 
>> }
>> 
>> package painttest;
>> 
>> import java.awt.Graphics2D;
>> import org.apache.pivot.wtk.Panel;
>> 
>> public class Waveform extends Panel
>> {
>>       @Override
>>        public void paint(Graphics2D graphics)
>>    {
>>                System.out.println("Painting");
>> }
>> }
>> 
>> 
> 


RE: why does this paint twice?

Posted by "Schwartz, Cynthia L" <cy...@intel.com>.
Is that code the best (fastest, most efficient...)  way to accomplish the painting of a custom control in Pivot?

Thanks
Cynthia

-----Original Message-----
From: Greg Brown [mailto:gk_brown@verizon.net] 
Sent: Thursday, March 07, 2013 9:22 AM
To: user@pivot.apache.org
Subject: Re: why does this paint twice?

paint() is called any time any region of the screen needs to be updated. This update could be triggered by the application or it could be triggered by the OS (for example, if an overlapping window is moved). 

The graphics context passed to paint() will be clipped to the bounds of the update region, but you should generally optimize your component's drawing code so it only draws that part that needs to be repainted.

On Mar 7, 2013, at 12:08 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:

> I am writing a custom control and want to understand why this is painting twice. Complete code below.
>  
> Thanks,
> Cynthia
>  
> public class PaintTest extends Application.Adapter {
>     private Window window = null;
>     private Waveform waveform = null;
>  
>     @Override
>     public void startup(Display display, Map<String, String> properties) {
>         window = new Window();
>                 waveform = new Waveform();
>                 window.setContent(waveform);
>         window.setMaximized(true);
>         window.open(display);
>     }
>  
>     @Override
>     public boolean shutdown(boolean optional) {
>         if (window != null) {
>             window.close();
>         }
>  
>         return false;
>     }
>  
>     public static void main(String[] args) {
>         DesktopApplicationContext.main(PaintTest.class, args);
>     }
>  
> }
>  
> package painttest;
>  
> import java.awt.Graphics2D;
> import org.apache.pivot.wtk.Panel;
>  
> public class Waveform extends Panel
> {
>        @Override
>         public void paint(Graphics2D graphics)
>     {
>                 System.out.println("Painting");
> }
> }
>  
>  


Re: why does this paint twice?

Posted by Greg Brown <gk...@verizon.net>.
paint() is called any time any region of the screen needs to be updated. This update could be triggered by the application or it could be triggered by the OS (for example, if an overlapping window is moved). 

The graphics context passed to paint() will be clipped to the bounds of the update region, but you should generally optimize your component's drawing code so it only draws that part that needs to be repainted.

On Mar 7, 2013, at 12:08 PM, "Schwartz, Cynthia L" <cy...@intel.com> wrote:

> I am writing a custom control and want to understand why this is painting twice. Complete code below.
>  
> Thanks,
> Cynthia
>  
> public class PaintTest extends Application.Adapter {
>     private Window window = null;
>     private Waveform waveform = null;
>  
>     @Override
>     public void startup(Display display, Map<String, String> properties) {
>         window = new Window();
>                 waveform = new Waveform();
>                 window.setContent(waveform);
>         window.setMaximized(true);
>         window.open(display);
>     }
>  
>     @Override
>     public boolean shutdown(boolean optional) {
>         if (window != null) {
>             window.close();
>         }
>  
>         return false;
>     }
>  
>     public static void main(String[] args) {
>         DesktopApplicationContext.main(PaintTest.class, args);
>     }
>  
> }
>  
> package painttest;
>  
> import java.awt.Graphics2D;
> import org.apache.pivot.wtk.Panel;
>  
> public class Waveform extends Panel
> {
>        @Override
>         public void paint(Graphics2D graphics)
>     {
>                 System.out.println("Painting");
> }
> }
>  
>