swing - Java JLayer : How to prevent delegeting events to underlying Component -


hi found jlayer function. want use wait lock. if activate layer underlying component receives events (key , mouse). how can catch event in layer , prevent delegating?

thank in advance

dbausnnd

i took example http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html "animating busy indicator" , overrided methods: processmouseevent , processmouseevent conditionally e.consume(), , of course

 jlayer.setlayereventmask(                     awtevent.mouse_event_mask |                             awtevent.mouse_motion_event_mask             );   class waitlayerui extends layerui<jpanel> implements actionlistener {         private boolean misrunning;         private boolean misfadingout;         private timer mtimer;          private int mangle;         private int mfadecount;         private int mfadelimit = 15;          @override         public void installui(jcomponent c) {             super.installui(c);             jlayer jlayer = (jlayer)c;             jlayer.setlayereventmask(                     awtevent.mouse_event_mask |                             awtevent.mouse_motion_event_mask             );         }          @override         public void uninstallui(jcomponent c) {             jlayer jlayer = (jlayer)c;             jlayer.setlayereventmask(0);             super.uninstallui(c);         }          @override         protected void processmouseevent(mouseevent e, jlayer l) {             system.out.println("mouse event");             if (misrunning)             {                 e.consume();             }         }          @override         protected void processmousemotionevent(mouseevent e, jlayer l) {             system.out.println("mouse motion event");             if (misrunning)             {                 e.consume();             }         }          @override         public void paint(graphics g, jcomponent c)         {             graphics2d g2 = (graphics2d)g.create();              try             {                 int w = c.getwidth();                 int h = c.getheight();                  // paint view.                 super.paint(g, c);                  if (!misrunning)                 {                     return;                 }                   float fade = (float)mfadecount / (float)mfadelimit;                  // gray out.                 composite urcomposite = g2.getcomposite();                 g2.setcomposite(alphacomposite.getinstance(                         alphacomposite.src_over, .5f * fade));                 g2.fillrect(0, 0, w, h);                 g2.setcomposite(urcomposite);                  // paint wait indicator.                 int s = math.min(w, h) / 10;                 int cx = w / 2;                 int cy = h / 2;                 g2.setrenderinghint(renderinghints.key_antialiasing,                         renderinghints.value_antialias_on);                 g2.setstroke(                         new basicstroke(s / 4, basicstroke.cap_round, basicstroke.join_round));                 g2.setpaint(color.white);                 g2.rotate(math.pi * mangle / 180, cx, cy);                 (int = 0; < 12; i++)                 {                     float scale = (11.0f - (float)i) / 11.0f;                     g2.drawline(cx + s, cy, cx + s * 2, cy);                     g2.rotate(-math.pi / 6, cx, cy);                     g2.setcomposite(alphacomposite.getinstance(                             alphacomposite.src_over, scale * fade));                 }             }             catch (exception ex) {                 misrunning = false;             }                         {                 g2.dispose();             }         }          public void actionperformed(actionevent e)         {             if (misrunning)             {                 firepropertychange("tick", 0, 1);                 mangle += 3;                 if (mangle >= 360)                 {                     mangle = 0;                 }                 if (misfadingout)                 {                     if (--mfadecount == 0)                     {                         misrunning = false;                         mtimer.stop();                     }                 }                 else if (mfadecount < mfadelimit)                 {                     mfadecount++;                 }             }         }          public void start()         {             if (misrunning)             {                 return;             }              // run thread animation.             misrunning = true;             misfadingout = false;             mfadecount = 0;             int fps = 24;             int tick = 1000 / fps;             mtimer = new timer(tick, this);             mtimer.start();         }          public void stop()         {             misfadingout = true;         }          @override         public void applypropertychange(propertychangeevent pce, jlayer l)         {             if ("tick".equals(pce.getpropertyname()))             {                 l.repaint();             }         } } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -