Board index » jbuilder » Hooking/Listening to MessageCategory/MessageView closing events?

Hooking/Listening to MessageCategory/MessageView closing events?


2005-06-06 04:16:33 AM
jbuilder7
I wonder what might be here the right or postulated way to listen to a
MessageCategory closing event. I've tried out ComponentListener etc. without
much success and when reviewing the BrowserListeners I don't see anything
which might be MessageView specific.
Basically what I want to do is, reacting on a specific own created
MessageCategory's close button events in a manner as the JB Messages toolbar
state button does.
To be more concrete, I have for an OT an own similar state change button as
JB's Messages button which enables/displays a custom added JComponent inside
the MessageView, e.g. MessageView.addCustomTab(MessageCategory, JComponent).
Now I would like to be able to listen and react on the closing of the
MessageCategory, when it's [x] close button is performed, so that I can
change the state of my own toolbar change button. All in all in the same
behaving manner as the JB Messages toolbar button works.
How can I hook into the MessageCategory's closing events and what sort of
specific listener is needed?
 
 

Re:Hooking/Listening to MessageCategory/MessageView closing events?

There are multiple ways to find out that your MessageCategory has been
closed.
(a) Just override MessageCategory.categoryClosing().
(b) Have your custom component override JComponent.removeNotify().
(c) Write your toolbar button action to update its state by calling
MessageView.getTabs() and checking if yours is present.
"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
Quote
I wonder what might be here the right or postulated way to listen to a
MessageCategory closing event. I've tried out ComponentListener etc.
without
much success and when reviewing the BrowserListeners I don't see anything
which might be MessageView specific.

Basically what I want to do is, reacting on a specific own created
MessageCategory's close button events in a manner as the JB Messages
toolbar
state button does.

To be more concrete, I have for an OT an own similar state change button
as
JB's Messages button which enables/displays a custom added JComponent
inside
the MessageView, e.g. MessageView.addCustomTab(MessageCategory,
JComponent).
Now I would like to be able to listen and react on the closing of the
MessageCategory, when it's [x] close button is performed, so that I can
change the state of my own toolbar change button. All in all in the same
behaving manner as the JB Messages toolbar button works.

How can I hook into the MessageCategory's closing events and what sort of
specific listener is needed?



 

Re:Hooking/Listening to MessageCategory/MessageView closing events?

Bill, using suggested method (a) MessageCategory.categoryClosing() doesn't
show the desired effect in my case, if I close a MessageCategory by using
it's close button [x] inside the MessageView the overriden categoryClosing()
method is never executed/called. As far as my tryouts showed,
categoryClosing() only reacts somehow late on
"MessageView.removeTab(MessageCategory)" code calls, but not on closing a
message category via it's [x] close button itself.
So far the suggested method (b) JComponent.removeNotify() would react on the
category's [x] close button, but this one causes other unwanted exception
problems, where I have to see if I can address and omit these in some way.
"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
There are multiple ways to find out that your MessageCategory has been
closed.

(a) Just override MessageCategory.categoryClosing().

(b) Have your custom component override JComponent.removeNotify().

(c) Write your toolbar button action to update its state by calling
MessageView.getTabs() and checking if yours is present.


"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>I wonder what might be here the right or postulated way to listen to a
>MessageCategory closing event. I've tried out ComponentListener etc.
>without
>much success and when reviewing the BrowserListeners I don't see
anything
>which might be MessageView specific.
>
>Basically what I want to do is, reacting on a specific own created
>MessageCategory's close button events in a manner as the JB Messages
>toolbar
>state button does.
>
>To be more concrete, I have for an OT an own similar state change button
>as
>JB's Messages button which enables/displays a custom added JComponent
>inside
>the MessageView, e.g. MessageView.addCustomTab(MessageCategory,
>JComponent).
>Now I would like to be able to listen and react on the closing of the
>MessageCategory, when it's [x] close button is performed, so that I can
>change the state of my own toolbar change button. All in all in the same
>behaving manner as the JB Messages toolbar button works.
>
>How can I hook into the MessageCategory's closing events and what sort
of
>specific listener is needed?
>
>
>


 

{smallsort}

Re:Hooking/Listening to MessageCategory/MessageView closing events?

It works fine for me. I see both messages using single-click close button
and also when doing a remove tab from the context menu. Probably you are
not invoking the super class on the removeNotify() which is critical.
public class Untitled1 {
static MessageCategory mc = new MessageCategory("title") {
public void categoryClosing() throws VetoException {
System.out.println("categoryclosing");
}
};
public static void initOpenTool(byte majorVersion, byte minorVersion) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MessageView mv = Browser.getActiveBrowser().getMessageView();
JPanel panel = new JPanel() {
public void removeNotify() {
super.removeNotify();
System.out.println("remove notify");
}
};
mv.addCustomTab(mc, panel);
}
});
}
}
"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
Quote
Bill, using suggested method (a) MessageCategory.categoryClosing() doesn't
show the desired effect in my case, if I close a MessageCategory by using
it's close button [x] inside the MessageView the overriden
categoryClosing()
method is never executed/called. As far as my tryouts showed,
categoryClosing() only reacts somehow late on
"MessageView.removeTab(MessageCategory)" code calls, but not on closing a
message category via it's [x] close button itself.

So far the suggested method (b) JComponent.removeNotify() would react on
the
category's [x] close button, but this one causes other unwanted exception
problems, where I have to see if I can address and omit these in some way.


"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:42a3736c$ XXXX@XXXXX.COM ...
>There are multiple ways to find out that your MessageCategory has been
>closed.
>
>(a) Just override MessageCategory.categoryClosing().
>
>(b) Have your custom component override JComponent.removeNotify().
>
>(c) Write your toolbar button action to update its state by calling
>MessageView.getTabs() and checking if yours is present.
>
>
>"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
>news: XXXX@XXXXX.COM ...
>>I wonder what might be here the right or postulated way to listen to a
>>MessageCategory closing event. I've tried out ComponentListener etc.
>>without
>>much success and when reviewing the BrowserListeners I don't see
anything
>>which might be MessageView specific.
>>
>>Basically what I want to do is, reacting on a specific own created
>>MessageCategory's close button events in a manner as the JB Messages
>>toolbar
>>state button does.
>>
>>To be more concrete, I have for an OT an own similar state change
>>button
>>as
>>JB's Messages button which enables/displays a custom added JComponent
>>inside
>>the MessageView, e.g. MessageView.addCustomTab(MessageCategory,
>>JComponent).
>>Now I would like to be able to listen and react on the closing of the
>>MessageCategory, when it's [x] close button is performed, so that I can
>>change the state of my own toolbar change button. All in all in the
>>same
>>behaving manner as the JB Messages toolbar button works.
>>
>>How can I hook into the MessageCategory's closing events and what sort
of
>>specific listener is needed?
>>
>>
>>
>
>


 

Re:Hooking/Listening to MessageCategory/MessageView closing events?

What I did so far for tryouts was the following Bill...
------------
public class MemmonMessageCategory extends MessageCategory {
public MemmonMessageCategory(String title) {
super(title);
}
public MemmonMessageCategory(String title, Icon icon) {
super(title, icon);
}
public void categoryClosing() {
MemoryMonitorPlugin.ACTION_MemMonitor.setState(this, false);
}
}
public class MemoryMonitorMsgv
{
private Icon _msgIcon;
private Browser _browser;
private MessageView _msgv;
/** Set the message category to use */
final static MemmonMessageCategory MESSAGES =
new MemmonMessageCategory("Memory Monitor", new
ImageIcon(Images.getImage(MemoryMonitorFrame.class, "images/memmon.gif")));
public MemoryMonitorMsgv(Browser browser, MemoryMonitorOptions mo)
{
_browser = browser;
_msgv = _browser.getMessageView();
MESSAGES.setToolTip("The Memory Monitor");
_msgv.addCustomTab(MESSAGES, new MemoryMonitor(_browser,mo));
_msgv.updateUI();
}
public void hideMonitor()
{
try {
_msgv.removeTab(MESSAGES);
}
catch (VetoException ex) {
}
}
-------------------------
...I've had set up a breakpoint into the categoryClosing() methos, which was
never hit, when I invoked the message view's close button ([x]) during my
tryouts. Getting the routing/notifaction working in order to toogle my own
toolbar state toggle button is the main reason why I'am interesting in this.
So far my change toggle button never changed it's state (from pressed down
to unpressed down) when the message view is closes via it's close button
[x].
Maybe I should add that my "StateAction" also generally starts or stops
inside the OTs preferences different selected views and looks similar to
this code fragment...
static {
ACTION_MemMonitor = new StateAction("Memory Monitor", 'm', "Displays a
Memory Monitor", new ImageIcon(Images.getImage(MemoryMonitorPlugin.class,
"images/memmon.gif"))) {
public boolean getState(Object o)
{
if ("on".equals(mo.useMsgv))
monitoring = false;
return monitoring;
}
public void setState(Object o, boolean runMonitor)
{
_browser = Browser.getActiveBrowser();
if(runMonitor)
{
service.start(_browser);
monitoring = true;
} else
{
service.stop();
monitoring = false;
}
MemoryMonitorPlugin.PROPERTY_MEM_MONITOR.setBoolean(runMonitor);
}
private boolean monitoring;
{
monitoring = false;
}
};
}
...here inside the setState(...) method service.start()/stop() does always
really create and dispose the associated object views of my OT and thus
using the above showed categoryClosing() method would be a sort of unwanted
second recursive call of the StateAction setState(this, false) methos. -
What I mean is, I would usually need to have in this case for the message
view category part of my OT an additional seperate method inside StateAction
for just setting "monitoring = false" without performing a "service.stop()".
However, initially StateAction of course doesn't allow that und so I would
have to extend/subclass the abstract StateAction class in order to overcome
with this and in order to prevent the recursion problem I mentioned above.
Bill, I will give it a second try and let you know if it works this time for
me.
-Valentino
"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
It works fine for me. I see both messages using single-click close button
and also when doing a remove tab from the context menu. Probably you are
not invoking the super class on the removeNotify() which is critical.

public class Untitled1 {
static MessageCategory mc = new MessageCategory("title") {
public void categoryClosing() throws VetoException {
System.out.println("categoryclosing");
}
};

public static void initOpenTool(byte majorVersion, byte minorVersion)
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MessageView mv = Browser.getActiveBrowser().getMessageView();

JPanel panel = new JPanel() {
public void removeNotify() {
super.removeNotify();
System.out.println("remove notify");
}
};

mv.addCustomTab(mc, panel);
}
});
}
}


"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
news:42a4175f$ XXXX@XXXXX.COM ...
>Bill, using suggested method (a) MessageCategory.categoryClosing()
doesn't
>show the desired effect in my case, if I close a MessageCategory by
using
>it's close button [x] inside the MessageView the overriden
>categoryClosing()
>method is never executed/called. As far as my tryouts showed,
>categoryClosing() only reacts somehow late on
>"MessageView.removeTab(MessageCategory)" code calls, but not on closing
a
>message category via it's [x] close button itself.
>
>So far the suggested method (b) JComponent.removeNotify() would react on
>the
>category's [x] close button, but this one causes other unwanted
exception
>problems, where I have to see if I can address and omit these in some
way.
>
>
>"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
>news:42a3736c$ XXXX@XXXXX.COM ...
>>There are multiple ways to find out that your MessageCategory has been
>>closed.
>>
>>(a) Just override MessageCategory.categoryClosing().
>>
>>(b) Have your custom component override JComponent.removeNotify().
>>
>>(c) Write your toolbar button action to update its state by calling
>>MessageView.getTabs() and checking if yours is present.
>>
>>
>>"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
>>news: XXXX@XXXXX.COM ...
>>>I wonder what might be here the right or postulated way to listen to a
>>>MessageCategory closing event. I've tried out ComponentListener etc.
>>>without
>>>much success and when reviewing the BrowserListeners I don't see
>anything
>>>which might be MessageView specific.
>>>
>>>Basically what I want to do is, reacting on a specific own created
>>>MessageCategory's close button events in a manner as the JB Messages
>>>toolbar
>>>state button does.
>>>
>>>To be more concrete, I have for an OT an own similar state change
>>>button
>>>as
>>>JB's Messages button which enables/displays a custom added JComponent
>>>inside
>>>the MessageView, e.g. MessageView.addCustomTab(MessageCategory,
>>>JComponent).
>>>Now I would like to be able to listen and react on the closing of the
>>>MessageCategory, when it's [x] close button is performed, so that I
can
>>>change the state of my own toolbar change button. All in all in the
>>>same
>>>behaving manner as the JB Messages toolbar button works.
>>>
>>>How can I hook into the MessageCategory's closing events and what
sort
>of
>>>specific listener is needed?
>>>
>>>
>>>
>>
>>
>
>


 

Re:Hooking/Listening to MessageCategory/MessageView closing events?

Well, I did some additionally fresh tryouts and again "categoryClosing()"
will only be called when my toolbar state toogle button is
deselected/toggled, but when using inside the message view the close button
([x] icon) of my message category "categoryClosing()" it is never called.
In the meantime I found an ...let's say ugly solution... to my problem by
introducing a boolean msgv_xbutton_close help var and just using
removeNotify() in my JComponent. The following worked during first tryout
tests...
public void setState(Object o, boolean runMonitor)
{
_browser = Browser.getActiveBrowser();
if(runMonitor)
{
service.start(_browser);
monitoring = true;
} else
{
if (!msgv_xbutton_close)
service.stop();
else
msgv_xbutton_close = false;
monitoring = false;
}
MemoryMonitorPlugin.PROPERTY_MEM_MONITOR.setBoolean(runMonitor);
}
....
....
public void removeNotify()
{
super.removeNotify();
if ("on".equals(mo.useMsgv)){
MemoryMonitorPlugin.msgv_xbutton_close = true;
MemoryMonitorPlugin.ACTION_MemMonitor.setState(this, false);
}
}
...and I have now to (re)implement it in a more clean and safer manner for
my production code.
-Valentino
"Valentino Kyriakides" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
What I did so far for tryouts was the following Bill...

------------
public class MemmonMessageCategory extends MessageCategory {

public MemmonMessageCategory(String title) {
super(title);
}

public MemmonMessageCategory(String title, Icon icon) {
super(title, icon);
}

public void categoryClosing() {
MemoryMonitorPlugin.ACTION_MemMonitor.setState(this, false);
}
}

public class MemoryMonitorMsgv
{

private Icon _msgIcon;
private Browser _browser;
private MessageView _msgv;
/** Set the message category to use */
final static MemmonMessageCategory MESSAGES =
new MemmonMessageCategory("Memory Monitor", new
ImageIcon(Images.getImage(MemoryMonitorFrame.class,
"images/memmon.gif")));

public MemoryMonitorMsgv(Browser browser, MemoryMonitorOptions mo)
{
_browser = browser;
_msgv = _browser.getMessageView();
MESSAGES.setToolTip("The Memory Monitor");
_msgv.addCustomTab(MESSAGES, new MemoryMonitor(_browser,mo));
_msgv.updateUI();

}

public void hideMonitor()
{
try {
_msgv.removeTab(MESSAGES);
}
catch (VetoException ex) {
}
}
-------------------------

...I've had set up a breakpoint into the categoryClosing() methos, which
was
never hit, when I invoked the message view's close button ([x]) during my
tryouts. Getting the routing/notifaction working in order to toogle my own
toolbar state toggle button is the main reason why I'am interesting in
this.
So far my change toggle button never changed it's state (from pressed down
to unpressed down) when the message view is closes via it's close button
[x].
...
...
"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:42a4ed0d$ XXXX@XXXXX.COM ...
>It works fine for me. I see both messages using single-click close
button
>and also when doing a remove tab from the context menu. Probably you
are
>not invoking the super class on the removeNotify() which is critical.
>
>public class Untitled1 {
>static MessageCategory mc = new MessageCategory("title") {
>public void categoryClosing() throws VetoException {
>System.out.println("categoryclosing");
>}
>};
>
>public static void initOpenTool(byte majorVersion, byte
minorVersion)
{
>SwingUtilities.invokeLater(new Runnable() {
>public void run() {
>MessageView mv = Browser.getActiveBrowser().getMessageView();
>
>JPanel panel = new JPanel() {
>public void removeNotify() {
>super.removeNotify();
>System.out.println("remove notify");
>}
>};
>
>mv.addCustomTab(mc, panel);
>}
>});
>}
>}
>...
>...
 

Re:Hooking/Listening to MessageCategory/MessageView closing events?

I think you have some kind of problem in your implementation. Things that
look like they might be wrong are:
(a) Your StateAction does not check the current state -- for instance if the
caller says enable it, you enable it (without checking if it is already
enabled).
(b) Your MemoryMonitorMsgv class will re-use MESSAGES without ensuring it is
not already in use. Since it is a static, you cannot do that.
"Valentino Kyriakides" < XXXX@XXXXX.COM >wrote in message
Quote
Well, I did some additionally fresh tryouts and again "categoryClosing()"
will only be called when my toolbar state toogle button is
deselected/toggled, but when using inside the message view the close
button
([x] icon) of my message category "categoryClosing()" it is never called.

In the meantime I found an ...let's say ugly solution... to my problem by
introducing a boolean msgv_xbutton_close help var and just using
removeNotify() in my JComponent. The following worked during first tryout
tests...

public void setState(Object o, boolean runMonitor)
{
_browser = Browser.getActiveBrowser();
if(runMonitor)
{
service.start(_browser);
monitoring = true;
} else
{
if (!msgv_xbutton_close)
service.stop();
else
msgv_xbutton_close = false;
monitoring = false;
}

MemoryMonitorPlugin.PROPERTY_MEM_MONITOR.setBoolean(runMonitor);
}

....
....

public void removeNotify()
{
super.removeNotify();
if ("on".equals(mo.useMsgv)){
MemoryMonitorPlugin.msgv_xbutton_close = true;
MemoryMonitorPlugin.ACTION_MemMonitor.setState(this, false);
}
}

...and I have now to (re)implement it in a more clean and safer manner for
my production code.

-Valentino


"Valentino Kyriakides" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
news:42a61823$ XXXX@XXXXX.COM ...
>What I did so far for tryouts was the following Bill...
>
>------------
>public class MemmonMessageCategory extends MessageCategory {
>
>public MemmonMessageCategory(String title) {
>super(title);
>}
>
>public MemmonMessageCategory(String title, Icon icon) {
>super(title, icon);
>}
>
>public void categoryClosing() {
>MemoryMonitorPlugin.ACTION_MemMonitor.setState(this, false);
>}
>}
>
>public class MemoryMonitorMsgv
>{
>
>private Icon _msgIcon;
>private Browser _browser;
>private MessageView _msgv;
>/** Set the message category to use */
>final static MemmonMessageCategory MESSAGES =
>new MemmonMessageCategory("Memory Monitor", new
>ImageIcon(Images.getImage(MemoryMonitorFrame.class,
"images/memmon.gif")));
>
>public MemoryMonitorMsgv(Browser browser, MemoryMonitorOptions mo)
>{
>_browser = browser;
>_msgv = _browser.getMessageView();
>MESSAGES.setToolTip("The Memory Monitor");
>_msgv.addCustomTab(MESSAGES, new MemoryMonitor(_browser,mo));
>_msgv.updateUI();
>
>}
>
>public void hideMonitor()
>{
>try {
>_msgv.removeTab(MESSAGES);
>}
>catch (VetoException ex) {
>}
>}
>-------------------------
>
>...I've had set up a breakpoint into the categoryClosing() methos, which
was
>never hit, when I invoked the message view's close button ([x]) during my
>tryouts. Getting the routing/notifaction working in order to toogle my
>own
>toolbar state toggle button is the main reason why I'am interesting in
this.
>So far my change toggle button never changed it's state (from pressed
>down
>to unpressed down) when the message view is closes via it's close button
>[x].
>...
>...
>"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
>news:42a4ed0d$ XXXX@XXXXX.COM ...
>>It works fine for me. I see both messages using single-click close
button
>>and also when doing a remove tab from the context menu. Probably you
are
>>not invoking the super class on the removeNotify() which is critical.
>>
>>public class Untitled1 {
>>static MessageCategory mc = new MessageCategory("title") {
>>public void categoryClosing() throws VetoException {
>>System.out.println("categoryclosing");
>>}
>>};
>>
>>public static void initOpenTool(byte majorVersion, byte
minorVersion)
>{
>>SwingUtilities.invokeLater(new Runnable() {
>>public void run() {
>>MessageView mv = Browser.getActiveBrowser().getMessageView();
>>
>>JPanel panel = new JPanel() {
>>public void removeNotify() {
>>super.removeNotify();
>>System.out.println("remove notify");
>>}
>>};
>>
>>mv.addCustomTab(mc, panel);
>>}
>>});
>>}
>>}
>>...
>>...


 

Re:Hooking/Listening to MessageCategory/MessageView closing events?

Yes, there is still some urgend need and demand for improvements and
refactoring in order to get better working and safer behaving code. Actually
I'am more at the stage of trying and testing general things out, related to
the ActionState mechanisms, in order to get some better understanding of it,
so that I later will hopefully avoid some common pitfalls for a final
production code version. - In the meantime I've reworked the testing code
and also added some checks, but there are still some unwanted side effects.
As it is setup momentary, I use the ActionState to handle the creation and
disposing of different views (a jframe, jdialog, messageview category etc.)
related to preset preferences options. This works usually better than I
expected, but the part for recognizing the closing of the message view,
which has to dispose the custom message category isn't actually very
foolprove done at all. For example when I close the message view, the action
state button's state is now changed, but next time I use the state toggle
button to create a new custom message category view in the message view, the
message view always doesn't show up at all, as it did in former tryout
versions. Here even the new JComponent objects are created, the message view
then don't show these up, when the state button is next time used to show up
a message view based monitor. This only happens when the message view hast
been closed by using it's close button, if I instead use the state toggle
button to close my portion of the message view, e.g. my custom message
category, things work fine.
Actually I don't know exactly why the message view afterwards behaves
somehow differently when I use the message view's close button, instead of
just using the state toggle button for closing the message category inside
the message view. However, as far as I can see there is a slightly
difference in the behaviour and I have to find out why and how to solve
this.
-Valentino
"Bill Joy" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
I think you have some kind of problem in your implementation. Things that
look like they might be wrong are:

(a) Your StateAction does not check the current state -- for instance if
the
caller says enable it, you enable it (without checking if it is already
enabled).

(b) Your MemoryMonitorMsgv class will re-use MESSAGES without ensuring it
is
not already in use. Since it is a static, you cannot do that.