Board index » jbuilder » Jdialog in JBuilder

Jdialog in JBuilder


2003-06-27 05:40:31 PM
jbuilder15
I am making a plugin for Jbuilder, where I pop up a Jdialog as a status window(non modal), and dispose it when the process is over, the problem is that JDialog doesnot paint its components, basically it's just a JLabel, but if I make JDialog as modal it shows, but I need to close it to go ahead, I just need a self closing JDialog. I tried using a separate thread and then interrupting it, to Dispose the dialog, but nothing is working. It shows the Thread as being active but won't interrupt it. StatusDialog is a simple status dialog box..
Here is the code..
statusMsg = "Trying to do something...";
statusDialog = new StatusDialog(Browser.getActiveBrowser(), "Process Progress", false, statusMsg);
Thread.currentThread().yield();
Browser.getActiveBrowser().setCursor(hourglassCursor);
//
// Do some processing
//
statusDialog.dispose();
Any idea?? What am I doing wrong here??
 
 

Re:Jdialog in JBuilder

I coded a progress bar awhile ago, and used it as follows:
// Create the dialog and display it. NOTE:
displayProgressDialog() starts the dialog running in its own thread
iProgressDialog = new ProgressDialog( lProgressLength );
iProgressDialog.displayProgressDialog();
// Do some work
for (...) {
// Do some work
// Increment the displayed progress
iProgressDialog.setProgress( ++iProgress );
// Do more work
}
// Close the progress dialog
iProgressDialog.closeProgressDialog();
The ProgressDialog class extends JDialog and implements Runnable. Its run()
method simply calls this.show() to display it, and its closeProgressDialog()
method calls this.hide() to close it.
Now I don't know if this is the best implementation, but it seems to have
worked. :-)
cjb
"Ashima Singh" < XXXX@XXXXX.COM >wrote in message
Quote

I am making a plugin for Jbuilder, where I pop up a Jdialog as a status
window(non modal), and dispose it when the process is over, the problem is
that JDialog doesnot paint its components, basically it's just a JLabel, but
if I make JDialog as modal it shows, but I need to close it to go ahead, I
just need a self closing JDialog. I tried using a separate thread and then
interrupting it, to Dispose the dialog, but nothing is working. It shows the
Thread as being active but won't interrupt it. StatusDialog is a simple
status dialog box..
Quote

Here is the code..

statusMsg = "Trying to do something...";
statusDialog = new StatusDialog(Browser.getActiveBrowser(), "Process
Progress", false, statusMsg);
Thread.currentThread().yield();
Browser.getActiveBrowser().setCursor(hourglassCursor);
//
// Do some processing
//
statusDialog.dispose();
Any idea?? What am I doing wrong here??
 

Re:Jdialog in JBuilder

java.sun.com/docs/books/tutorial/uiswing/overview/threads.html
"Ashima Singh" < XXXX@XXXXX.COM >wrote in message
Quote

I am making a plugin for Jbuilder, where I pop up a Jdialog as a
status window(non modal), and dispose it when the process is over, the
problem is that JDialog doesnot paint its components, basically it's
just a JLabel, but if I make JDialog as modal it shows, but I need to
close it to go ahead, I just need a self closing JDialog. I tried using
a separate thread and then interrupting it, to Dispose the dialog, but
nothing is working. It shows the Thread as being active but won't
interrupt it. StatusDialog is a simple status dialog box..
Quote

Here is the code..

statusMsg = "Trying to do something...";
statusDialog = new StatusDialog(Browser.getActiveBrowser(), "Process
Progress", false, statusMsg);
Thread.currentThread().yield();
Browser.getActiveBrowser().setCursor(hourglassCursor);
//
// Do some processing
//
statusDialog.dispose();
Any idea?? What am I doing wrong here??
 

{smallsort}

Re:Jdialog in JBuilder

On 6/27/2003 at 5:40:31 AM, Ashima Singh wrote:
Quote
I am making a plugin for Jbuilder, where I pop up a Jdialog as a
status window(non modal), and dispose it when the process is over,
the problem is that JDialog doesnot paint its components, basically
it's just a JLabel, but if I make JDialog as modal it shows, but I
need to close it to go ahead, I just need a self closing JDialog. I
tried using a separate thread and then interrupting it, to Dispose
the dialog, but nothing is working. It shows the Thread as being
active but won't interrupt it. StatusDialog is a simple status dialog
box..

Here is the code..

statusMsg = "Trying to do something...";
statusDialog = new StatusDialog(Browser.getActiveBrowser(),
"Process Progress", false, statusMsg);
Thread.currentThread().yield();
Browser.getActiveBrowser().setCursor(hourglassCursor); //
// Do some processing
//
statusDialog.dispose();
Any idea?? What am I doing wrong here??
I presume this code is run in response to some event such as the action
event generated by a button press. If that is true, it is running in
the event dispatch thread, which is where the painting occurs. Since
you do not return from the event until your processing is complete, no
painting will occur until that happens.
You need to perform the processing in a separate thread. There is some
good material on this in the Java Tutorial, available on the Sun web
site.
When you use a modal dialog, I would not expect that you would see any
painting problem right away. When you display a modal dialog, it
suspends the current thread, but it also creates a new event dispatcher
to handle the events while the thread is suspended. So while the modal
dialog is displayed, the painting would occur.
However, once you close the model dialog, the new event dispatcher is
eliminated, the main event dispatch thread would resume and the code
that does your processing would then begin. While the processing is
occurring, painting would not occur, but you might not have noticed
that because your dialog is not showing. But if you drag another
window in front of the main window, it will not repaint.
--
Regards,
John McGrath [TeamB]
 

Re:Jdialog in JBuilder

Some time ago I also twiddelt around with this in my JavadocWiazard (JDW)
implementation. I too used a sort of status/processing dialog which had to
run beside other threads at the same time and which should have the ability
to be dismissed on user demands or automatically when another thread process
finished.
Note that most Swing stuff is not thread safe and that it is sometimes
difficult to yield the desired behaviour. As you also recognized it's
sometimes tricky to interrupt running threads correctly and to dismiss a
seperate running jdialog.
You should experiment (do tryouts) with the threads you invoked and if
possible kill the dialog and it's thread from another main thread. - You may
also take a look at Sun's "worker thread" implementation, which can be handy
in here. - I've first used a jdialog in the following way (the diaog is
created, controlled and dismissed/killed from another thread):
public class DialogThread extends Thread {
public DialogThread() {
aDialog = new JDialog();
aDialog.setTitle("Javadoc Wizard");
aDialog.setSize(300, 50);
statusLabel = new JLabel("Generating javadocs...");
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed (ActionEvent e) {
cancelButton_actionPerformed(e);
}
});
aDialog.getContentPane().add(statusLabel, BorderLayout.WEST);
aDialog.getContentPane().add(cancelButton, BorderLayout.EAST);
Point position = new Point(0, 0);
position.x =
(aDialog.getContentPane().getToolkit().getScreenSize().width -
aDialog.getSize().width) / 2;
position.y =
(aDialog.getContentPane().getToolkit().getScreenSize().height -
aDialog.getSize().height) / 2;
aDialog.setLocation(position);
aDialog.setResizable(false);
}
/**
* An overwriten run method for the dialog thread
*/
public void run()
{
try
{
aDialog.show();
Thread.sleep(3000);
processDialogFinish ();
}
catch(InterruptedException iexception) { }
}
/**
* Cancel Button action event of processDialogFinish()
* @param e The action event
*/
void cancelButton_actionPerformed (ActionEvent e) {
processDialogFinish();
}
/**
* Should remove the process dialog
*/
public void processDialogFinish ()
{
aDialog.hide();
aDialog.dispose();
}
private JDialog aDialog;
private JButton cancelButton;
private JLabel statusLabel;
}
*** Another alternative would be the following: ***
public class ProcessDialog extends DefaultDialog {
private JavadocController jcontrol;
JPanel jpane = new JPanel();
JButton cancelButton = new JButton();
JLabel statusLabel1 = new JLabel();;
JLabel statusLabel2 = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
static ImageIcon stop =
new ImageIcon(ProcessDialog.class.getResource("images/stopn.gif"));
static ImageIcon stopp =
new ImageIcon(ProcessDialog.class.getResource("images/stopp.gif"));
static ImageIcon stopd =
new ImageIcon(ProcessDialog.class.getResource("images/stopd.gif"));
static ImageIcon stopr =
new ImageIcon(ProcessDialog.class.getResource("images/stopr.gif"));
public ProcessDialog() {
super(null, "", false);
}
public ProcessDialog(Component owner, String title, boolean modal,
JavadocController jc) {
super(owner, title, modal);
jcontrol = jc;
jpane.setLayout(borderLayout1);
statusLabel1.setText("Javadoc processing... ");
cancelButton.setToolTipText("Press this button to stop the active
Javadoc process");
cancelButton.setBorder(null);
cancelButton.setBorderPainted(false);
cancelButton.setFocusPainted(false);
cancelButton.setContentAreaFilled(false);
cancelButton.setIcon(stop);
cancelButton.setPressedIcon(stopp);
cancelButton.setRolloverIcon(stopr);
cancelButton.setDisabledIcon(stopd);
cancelButton.setMargin(new Insets(0,0,0,0));
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed (ActionEvent e) {
cancelButton_actionPerformed(e);
}
});
jpane.add(statusLabel1, borderLayout1.WEST);
jpane.add(cancelButton, borderLayout1.EAST);
this.getContentPane().add(jpane);
WindowListener windowListener = new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
dispose();
}
};
this.addWindowListener(windowListener);
this.pack();
setAutoCenter(true);
}
protected JRootPane createRootPane() {
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
setVisible(false);
}
};
JRootPane rootPane = new JRootPane();
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.registerKeyboardAction(actionListener, stroke,
JComponent.WHEN_IN_FOCUSED_WINDOW);
return rootPane;
}
/**
* The cancel button action event calls processDialogFinish().
* @param e The action event
*/
void cancelButton_actionPerformed (ActionEvent e) {
processDialogInterrupted();
}
/**
* Remove or finish the process dialog.
*/
public void processDialogInterrupted()
{
jcontrol.stopDisplayOutput();
jcontrol.stopProcess();
dispose();
}
/**
* Remove or finish the process dialog.
*/
public void processDialogFinished()
{
dispose();
}
}
And then from another thread you would create, controll and destroy the
normal above shown dialog implementation:
/**
* Performs the wizards dialog process call.
*
* Invokes a process dialog as a separate thread, so that the Wizard
* can be dismissed. The dialog should appear only for ~3 seconds,
* so the JB IDE isn't blocked for other tasks.
*/
protected synchronized void dialogHandling() {
pd = new ProcessDialog(Browser.getActiveBrowser(), "Javadoc Wizard",
false, this);
Browser.getActiveBrowser().repaint();
pd.repaint();
pd.show();
}
/**
* Remove or finish the process dialog.
*/
public void processDialogFinished()
{
pd.processDialogFinished();
pd = null; // clean up for GC
if (procExitStatus == 0)
MESSAGES.setIcon(null);
else
MESSAGES.setIcon(jdw.stopicon);
Browser.getActiveBrowser().repaint();
}
Don't know if this is helpful for you (?), at least I hope a little bit.
-vkyr
"Ashima Singh" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote

I am making a plugin for Jbuilder, where I pop up a Jdialog as a status
window(non modal), and dispose it when the process is over, the problem is
that JDialog doesnot paint its components, basically it's just a JLabel, but
if I make JDialog as modal it shows, but I need to close it to go ahead, I
just need a self closing JDialog. I tried using a separate thread and then
interrupting it, to Dispose the dialog, but nothing is working. It shows the
Thread as being active but won't interrupt it. StatusDialog is a simple
status dialog box..
Quote

Here is the code..

statusMsg = "Trying to do something...";
statusDialog = new StatusDialog(Browser.getActiveBrowser(), "Process
Progress", false, statusMsg);
Thread.currentThread().yield();
Browser.getActiveBrowser().setCursor(hourglassCursor);
//
// Do some processing
//
statusDialog.dispose();
Any idea?? What am I doing wrong here??
 

Re:Jdialog in JBuilder

Valentino Kyriakides wrote:
Quote
Some time ago I also twiddelt around with this in my JavadocWiazard (JDW)
implementation. I too used a sort of status/processing dialog which had to
run beside other threads at the same time and which should have the ability
to be dismissed on user demands or automatically when another thread process
finished.

Note that most Swing stuff is not thread safe and that it is sometimes
difficult to yield the desired behaviour. As you also recognized it's
sometimes tricky to interrupt running threads correctly and to dismiss a
seperate running jdialog.

You should experiment (do tryouts) with the threads you invoked and if
possible kill the dialog and it's thread from another main thread. - You may
also take a look at Sun's "worker thread" implementation, which can be handy
in here. - I've first used a jdialog in the following way (the diaog is
created, controlled and dismissed/killed from another thread):

public class DialogThread extends Thread {

public DialogThread() {
aDialog = new JDialog();
aDialog.setTitle("Javadoc Wizard");
aDialog.setSize(300, 50);

statusLabel = new JLabel("Generating javadocs...");
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed (ActionEvent e) {
cancelButton_actionPerformed(e);
}
});

aDialog.getContentPane().add(statusLabel, BorderLayout.WEST);
aDialog.getContentPane().add(cancelButton, BorderLayout.EAST);
Point position = new Point(0, 0);
position.x =
(aDialog.getContentPane().getToolkit().getScreenSize().width -
aDialog.getSize().width) / 2;
position.y =
(aDialog.getContentPane().getToolkit().getScreenSize().height -
aDialog.getSize().height) / 2;
aDialog.setLocation(position);
aDialog.setResizable(false);
}

/**
* An overwriten run method for the dialog thread
*/
public void run()
{
try
{
aDialog.show();
Thread.sleep(3000);
processDialogFinish ();
}
catch(InterruptedException iexception) { }
}

/**
* Cancel Button action event of processDialogFinish()
* @param e The action event
*/
void cancelButton_actionPerformed (ActionEvent e) {
processDialogFinish();
}

/**
* Should remove the process dialog
*/
public void processDialogFinish ()
{
aDialog.hide();
aDialog.dispose();
}

private JDialog aDialog;
private JButton cancelButton;
private JLabel statusLabel;
}

*** Another alternative would be the following: ***

public class ProcessDialog extends DefaultDialog {

private JavadocController jcontrol;
JPanel jpane = new JPanel();
JButton cancelButton = new JButton();
JLabel statusLabel1 = new JLabel();;
JLabel statusLabel2 = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
static ImageIcon stop =
new ImageIcon(ProcessDialog.class.getResource("images/stopn.gif"));
static ImageIcon stopp =
new ImageIcon(ProcessDialog.class.getResource("images/stopp.gif"));
static ImageIcon stopd =
new ImageIcon(ProcessDialog.class.getResource("images/stopd.gif"));
static ImageIcon stopr =
new ImageIcon(ProcessDialog.class.getResource("images/stopr.gif"));

public ProcessDialog() {
super(null, "", false);
}
public ProcessDialog(Component owner, String title, boolean modal,
JavadocController jc) {
super(owner, title, modal);
jcontrol = jc;
jpane.setLayout(borderLayout1);
statusLabel1.setText("Javadoc processing... ");
cancelButton.setToolTipText("Press this button to stop the active
Javadoc process");
cancelButton.setBorder(null);
cancelButton.setBorderPainted(false);
cancelButton.setFocusPainted(false);
cancelButton.setContentAreaFilled(false);
cancelButton.setIcon(stop);
cancelButton.setPressedIcon(stopp);
cancelButton.setRolloverIcon(stopr);
cancelButton.setDisabledIcon(stopd);
cancelButton.setMargin(new Insets(0,0,0,0));
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed (ActionEvent e) {
cancelButton_actionPerformed(e);
}
});

jpane.add(statusLabel1, borderLayout1.WEST);
jpane.add(cancelButton, borderLayout1.EAST);

this.getContentPane().add(jpane);
WindowListener windowListener = new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
dispose();
}
};
this.addWindowListener(windowListener);
this.pack();
setAutoCenter(true);
}

protected JRootPane createRootPane() {
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
setVisible(false);
}
};
JRootPane rootPane = new JRootPane();
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.registerKeyboardAction(actionListener, stroke,
JComponent.WHEN_IN_FOCUSED_WINDOW);
return rootPane;
}

/**
* The cancel button action event calls processDialogFinish().
* @param e The action event
*/
void cancelButton_actionPerformed (ActionEvent e) {
processDialogInterrupted();
}

/**
* Remove or finish the process dialog.
*/
public void processDialogInterrupted()
{
jcontrol.stopDisplayOutput();
jcontrol.stopProcess();
dispose();
}

/**
* Remove or finish the process dialog.
*/
public void processDialogFinished()
{
dispose();
}

}

And then from another thread you would create, controll and destroy the
normal above shown dialog implementation:

/**
* Performs the wizards dialog process call.
*
* Invokes a process dialog as a separate thread, so that the Wizard
* can be dismissed. The dialog should appear only for ~3 seconds,
* so the JB IDE isn't blocked for other tasks.
*/
protected synchronized void dialogHandling() {
pd = new ProcessDialog(Browser.getActiveBrowser(), "Javadoc Wizard",
false, this);
Browser.getActiveBrowser().repaint();
pd.repaint();
pd.show();
}

/**
* Remove or finish the process dialog.
*/
public void processDialogFinished()
{
pd.processDialogFinished();
pd = null; // clean up for GC
if (procExitStatus == 0)
MESSAGES.setIcon(null);
else
MESSAGES.setIcon(jdw.stopicon);
Browser.getActiveBrowser().repaint();
}

Don't know if this is helpful for you (?), at least I hope a little bit.

-vkyr

"Ashima Singh" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:3efc110f$ XXXX@XXXXX.COM ...
>
>I am making a plugin for Jbuilder, where I pop up a Jdialog as a status
window(non modal), and dispose it when the process is over, the problem is
that JDialog doesnot paint its components, basically it's just a JLabel, but
if I make JDialog as modal it shows, but I need to close it to go ahead, I
just need a self closing JDialog. I tried using a separate thread and then
interrupting it, to Dispose the dialog, but nothing is working. It shows the
Thread as being active but won't interrupt it. StatusDialog is a simple
status dialog box..
>
>Here is the code..
>
>statusMsg = "Trying to do something...";
>statusDialog = new StatusDialog(Browser.getActiveBrowser(), "Process
Progress", false, statusMsg);
>Thread.currentThread().yield();
>Browser.getActiveBrowser().setCursor(hourglassCursor);
>//
>// Do some processing
>//
>statusDialog.dispose();
>Any idea?? What am I doing wrong here??
Thanks a lot , you guys were great..
 

Re:Jdialog in JBuilder

On 7/3/2003 at 5:42:39 AM, XXXX@XXXXX.COM wrote:
Quote
Valentino Kyriakides wrote:

>Some time ago I also twiddelt around with this in my JavadocWiazard
[snip, snip, snip]
Quote
>>Any idea?? What am I doing wrong here??

Thanks a lot , you guys were great..
That was 243 lines of quoted text and 1 line of original text. Please
keep quoted text to a minimum, quoting only that which is necessary to
understand your reply.
info.borland.com/newsgroups/netiquette.html
--
Regards,
John McGrath [TeamB]