mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
add generic progress indicator to status bar
This commit is contained in:
95
extra/jheidi/progressWaiter.ajl
Normal file
95
extra/jheidi/progressWaiter.ajl
Normal file
@@ -0,0 +1,95 @@
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
|
||||
log.debug("task is long running!");
|
||||
|
||||
WindowContext context = argObj("windowContext");
|
||||
Worker worker = argObj("worker");
|
||||
|
||||
String message = arg("waitOperation");
|
||||
|
||||
Panel statusBar = context.get("/statusBar");
|
||||
JLabel text = statusBar.getProperty("text");
|
||||
ProgressBar pbar = statusBar.getProperty("pbar");
|
||||
Stack messages = statusBar.getProperty("messages");
|
||||
|
||||
|
||||
synchronized (this.getClass())
|
||||
{
|
||||
if ( text == null )
|
||||
{
|
||||
text = (JLabel)statusBar.getComponent(0);
|
||||
statusBar.setProperty("text", text);
|
||||
}
|
||||
|
||||
if ( messages == null )
|
||||
{
|
||||
messages = new Stack();
|
||||
statusBar.setProperty("messages", messages);
|
||||
}
|
||||
|
||||
if ( pbar == null )
|
||||
{
|
||||
pbar = new ProgressBar();
|
||||
pbar.setIndeterminate(true);
|
||||
pbar.setPreferredSize(new java.awt.Dimension(75, 10));
|
||||
pbar.setBorder(new BevelBorder(BevelBorder.LOWERED));
|
||||
statusBar.setProperty("pbar", pbar);
|
||||
}
|
||||
|
||||
messages.push(message);
|
||||
|
||||
text.setText("Waiting for " + (String)messages.pop());
|
||||
|
||||
try
|
||||
{
|
||||
statusBar.getComponent(1);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
statusBar.add(pbar, BorderLayout.EAST);
|
||||
}
|
||||
statusBar.updateUI();
|
||||
}
|
||||
|
||||
while (!worker.isDone()) {};
|
||||
|
||||
synchronized(this.getClass())
|
||||
{
|
||||
if ( messages.size() > 0)
|
||||
{
|
||||
text.setText("Waiting for " + (String) messages.pop());
|
||||
}
|
||||
else
|
||||
{
|
||||
text.setText("Ready");
|
||||
statusBar.remove(1);
|
||||
statusBar.updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user