jEdit Community - Resources for users of the jEdit Text Editor
indicate progress, status bar
Submitted by takeshin on Thursday, 31 July, 2008 - 17:36
I wrote a macro which takes a long time to execute.
(while loop operating on texarea text). While the macro works, jEdit is frozen, and user may think it hanged.
How to notify user that everything is ok?
How to set statusbar message?

How to indicate progress of the macro?
It would be nice to have message box saying: macro in progress… [cancel]

How to use observers in macros?

--
regards,
takeshin
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Hmm.
by elberry on Fri, 01/08/2008 - 07:03
Well, to start, you won't be able to show your users anything when jEdit is frozen, since you've essentially locked the UI thread.

First, you should wrap your long running macro in a runnable and either spawn a separate thread to run it in, or use it as a swing worker.

Take a look at the SwingUtilities class:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)

Now you should be able to run your macro without jEdit freezing.

As for updating the status, take a look at the View object:
http://jedit.org/api/org/gjt/sp/jedit/View.html

There's a getStatus method, which returns the status bar, where you can set the message.

Hope that helps.

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
???
by Robert Schwenn on Fri, 01/08/2008 - 19:37
Hi, I already tried to use the status bar to show macro progress in the way to set a message like "x lines processed now". The message can be set by "view.getStatus().setMessageAndClear(String)". And I used it in a macro construction like this:

void testStatusmessage() {
  void run() {
    for (i = 1; i < textArea.getLineCount(); i++) {
      // do something here ..
      view.getStatus().setMessageAndClear("process line: " + String.valueOf(i));
    }
  }
  
  // Do the work when jEdit is ready to do it (essential for startup script)
  // When using as startup script, it's run BEFORE a file (given at command line) is loaded!
  VFSManager.runInAWTThread(this);
}

testStatusmessage();

The construction isn't my development. And the only thing I understand is, that the run() method would be started at a matching time Eye-wink. That's needed because I use it at startup script sometimes.

My real macro takes a lot of time for each line to process. But the whole time the status bar doesn't change. Only after the macro has finished it's work, the status bar shows the last message. Can You see a way to change this?

Robert

 
It could be that it's just ha
by elberry on Sat, 02/08/2008 - 05:06
It could be that it's just happening so quick you don't see anything but the last message. It could also be because you're running it in the AWT thread which also controls the painting of components.

Try running it in a separate thread.
void testStatusmessage() {
   // create a new thread.
   new Thread(new Runnable() {
      public void run() {
         for (i = 1; i < textArea.getLineCount(); i++) {
            view.getStatus().setMessageAndClear("process line: " + String.valueOf(i));
            // this is busy work, intended to be some long running process.
            for(count = 0; count < 100000; count++) {
               int time = count + 1;
            }
         }
      }
      // start the new thread.
   }).start();
}

testStatusmessage();
I tested this out and I had complete access to jEdit and the status bar updated about once per second.

Hope that helps.

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
perfect!
by Robert Schwenn on Sat, 02/08/2008 - 14:15
Eric, it works like a charme!

Thanks.
Robert
User login
Browse archives
« November 2024  
MoTuWeThFrSaSu
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300