Sending notification to listeners without changing value


#1

So I've subclassed a Label and added functionality so that it can be adjusted by dragging the value up and down, somewhat like a slider. It's actually an IP address inside the Label, so in my mouseDragged method I'm setting the value of the Label without sending a notification, since I don't want to establish a new connection (what my Label::Listener does) every time the value changes, but rather only when the mouse is released.

So in my mouseUp method I have to set some dummy text like this:

String tempText = getText();
setText (tempText + " ", dontSendNotification);      // dummy text to ensure I'm subsequently changing the text
setText (tempText, sendNotification);

so that that setText method will actually send a notification to the Listener, since setText compares the value being set to ensure it's different prior to sending a notification to the Listener.

Is there any way to send a notification directly to a Listener? Or maybe I'm not thinking of it right - should I be setting up an entire class to handle everything I'm doing in my Listener that I can then access from my subclassed Label?

 

 

 

And just as an aside, Jules - I'm sure you've heard this many times before, but fantastic work. I was pleasantly surprised to find out how easy it was to set up my drag-adjustable IP address label by discovering that all of the heavy lifting I thought I'd have to do was already done somewhere in the framework. Finding Font::getGlyphPositions and the IPAddress class was a pretty cool feeling... It seems like there's something here for everything! Hats off!

The only downside is that I find myself stressing a little bit too much about making my own code even a fraction as elegant and modular as the JUCE code... good practice, I guess...


#2

How about Label::callChangeListeners()? It's protected, but seeing as you're subclassing that's not a problem right?


#3

Yes, that method is provided for exactly this kind of thing.


#4

Thanks guys!

Totally missed looking into the protected functions. This is exactly what I needed.