• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Blocking screensaver and sleep mode

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I'm doing a just-for-fun personal project and i am facing a small problem.
My application consists of a world-map background and a "panel" foreground. Basically the program fetches news from different sites, identifies where the news refer to and shows the main image of the news and headline with a pointer pointing to the country it refers to. For example: regarding the turmoil in Greece, i would get the main image+headline in a small box and then an arrow pointing to Greece in the background map.

I found 2 problems:

1)The images+headlines are place in a panel with a JLabel + a second JPanel with a bufferedImage. I want that panel to "slide" on the x axis from width to 0. I managed to do it by rewriting paintComponent(Graphics g). Is there an easier/less mistake prone way of handling this?

2)This application will be running on my laptop, which i only use very sporadically at work to make fast direct queries to the server. The problem is that after some time the laptop goes into screensaver/sleep mode. I do not want to remove the screensaver or sleep mode permanently (i often forget the laptop at work...). Is there a way to block the screensaver/sleep from firing while the application is active?

Thanks a lot for the help

Daniel M.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Marti wrote:1)The images+headlines are place in a panel with a JLabel + a second JPanel with a bufferedImage. I want that panel to "slide" on the x axis from width to 0. I managed to do it by rewriting paintComponent(Graphics g). Is there an easier/less mistake prone way of handling this?


Using a JScrollPane with hidden scroll bars is an option. Wrap the component in a JScrollPane with ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER and ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER. Then use getHorizontalScrollBar().setValue(...) to scroll from code.

2)This application will be running on my laptop, which i only use very sporadically at work to make fast direct queries to the server. The problem is that after some time the laptop goes into screensaver/sleep mode. I do not want to remove the screensaver or sleep mode permanently (i often forget the laptop at work...). Is there a way to block the screensaver/sleep from firing while the application is active?


A hack is to use java.awt.PointerInfo and java.awt.Robot to move the mouse a bit:
Call this using a javax.swing.Timer and your mouse will move one pixel and back regularly. That can be annoying when you're actually using your mouse, so perhaps you can build in a check to only do this if the mouse hasn't moved since the last time.
 
Daniel Marti
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. I have code to stop the application at a certain keystroke combo, so i can stop the automated mouse movement from there.
While the JScrollPane idea is quite ingenious, I'm afraid it won't work the way i want, because when the info panel first appears, it only appears partially (coming from the side), like in a slide show. I can combine your idea with my way of solving it, and draw the image in a growing rectangle each time i move the JScrollPane scroller. I'll check what happens and report back
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you can use the result of g.getClipBounds() to find out which part needs to be painted; you can skip the rest.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Call this using a javax.swing.Timer and your mouse will move one pixel and back regularly. That can be annoying when you're actually using your mouse, so perhaps you can build in a check to only do this if the mouse hasn't moved since the last time.



Rob Camick's Application Inactivity can be useful for that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic