Menu

How to understand the PenTock

Rui Hu
2009-04-21
2013-05-28
  • Rui Hu

    Rui Hu - 2009-04-21

    Hi,

    Could you please explain the PenTock? Where should I use it? When will PenTockEvent be generated?

    Could you please give me a simple example?

    Rui

     
    • Nicolas Carranza

      Hi Rui,

      JPen has an internal event queue. The providers enqueue pen tablet events at its own rate (10ms on Linux and Windows) filling the event queue. Another thread (the jpen-Pen thread) does the event dispatching: takes all the events from the queue, dispatches them calling the appropriate penXXXEvent methods and finally calls the penTock. This thread is doing the event dispatching in a loop at a frequency given by jpen.Pen.getFrequency() (60 by default).

      An example of penTock usage is done by the JPen Demo (see http://jpen.wiki.sourceforge.net/demo\). Instead of refreshing the "Levels" text fields using PenListener.penLevelEvent (a wacom intuous 4 can cause 200 penLevelEvent calls per second on windows), it refreshes them using penTock which is called only 60 times per second by default (and you can set it to lower values with jpen.Pen.setFrequencyLater(int) if needed, the JPen Demo sets it to 40) saving processing time.

      cheers!
      Nicolas

       
    • Rui Hu

      Rui Hu - 2009-04-28

      Hi,

      Sorry, I can't completely understand what you said. Suppose my PenLevelEvent() method takes a relative long time to process a PLevelEvent, but there is no enough time since the next PLevelEvent would come shortly. What should I do to save time for processing?

      Should I call the PenTock() method? or should I set up the frequency?

      Rui

       
      • Nicolas Carranza

        First, you need to detect if you are really getting short of time and you can use penTock in such a case. If availableMillis is <= 0 (on penTock(long availableMillis)) then you know you are consuming more time on penXXXEvent methods than the available.

        > What should I do to save time for processing?

        It all depends on your use case. For example, if you are making an application that draws points on the screen, you can do the rendering on a single step per period on penTock instead of a multiple times per period on penLevelEvent.

        > Should I call the PenTock() method? or should I set up the frequency?

        penTock() is called for you... You can also set up the frequency to a lower value to get less penTocks per second (but you will still get all the penXXXEvent() calls... each period jpen calls penXXXEvent() methods many times (as much times as there are events on the queue) and then finally penTock() only one time).

        Cheers!

         
    • Rui Hu

      Rui Hu - 2009-04-28

      Hi,

      Could you also explain the function:
      Pen.setFirePenTockOnSwing(boolean firePenTockOnSwing);

      My program takes relative long time to process a PLevelEvent. Thus, if I move the stylus faster than a threshold,  instead of getting a continous line, I got a number of discret dots. And if I move the stylus slower than the threshold, my program could make sure it is a continous line. What should I do to avoid those dots happen? Could the providers or the dispatching thead send events at a lower rate?

      Thank you.

      Rui

       
      • Nicolas Carranza

        > Could you also explain the function: Pen.setFirePenTockOnSwing(boolean firePenTockOnSwing);

        This is for javax.swing users. If you setup Pen.setFirePenTockOnSwing(true) then penTock will always be called from the java event dispatcher thread (also known as the Swing thread).

        > My program takes relative long time to process a PLevelEvent....

        The providers always send all events to the even queue at the fastest rate possible. On a wacom intuos this rate is constant at 200 points per second on Windows (5ms period), on a wacom graphire is 100 pps... and so on, it depends on the hardware. Usually paint programs connect the dots using  lines or curves.

        Cheers again!