This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 20 - Pages: 2 [ 1 2 | Next ] - Last Post: 25 Mar 18, 06:00 Last Post By: JeffTucker
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Property change listener not firing
Posted: 22 Mar 18, 17:20
 
  Click to reply to this thread Reply
This works:
engine.addPropertyChangeListener("thumbSize", (evt) -> {
	System.out.println("Thumb size changed: " + engine.getThumbDim());
	(do something);
});
This does not work:
engine.addPropertyChangeListener("imageSize", (evt) -> {
	System.out.println("Image size changed: " + engine.getImageDim());
	(do something);
});
Changing the image bounds doesn't fire the listener.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: Property change listener not firing
Posted: 22 Mar 18, 17:26   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Sorry about that asymmetric behavior. The property fired is actually called "imageDim" and it passes two Dimension objects, one for the old Dimension (a parsed imageSize string) and one for the new Dimension (a parsed imageSize string). You can get the old and new values using evt.getOldValue() and evt.getNewValue() in the listener.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 17:30   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Oy.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 17:34   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
And to spare me more thrashing around, what does getNewValue() return - Dim, String? It's not documented anywhere, not even in the API.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 17:40   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Seems to return a Dimension. But damn, I'm lost in the weeds again. This isn't working:
engine.addPropertyChangeListener("imageDim", (evt) -> {
	System.out.println("Image size changed: " + evt.getNewValue());
	engine.setThemeImageDim((Dimension) evt.getNewValue());
 });
The event fires, the new image bounds are there, but the theme image dimensions aren't getting reset. They're stubbornly remaining at their defaults.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 18:06   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Never mind. I eventually got there.

Every time I come back to the theme image stuff, I get lost for a while. It's never clear to me when setThemeImageDim() is what's controlling things, and when changing the String value of folderImageSize is the key. Or both. Or neither.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 18:18   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
For anyone following along from the cheap seats, this is the final version, unless someone can show me how to tighten it up:
engine.addPropertyChangeListener("imageDim", (evt) -> {
     Dimension newdims = (Dimension) evt.getNewValue();
     folderImageSize.setText(Integer.toString(newdims.width) + "x" + Integer.toString(newdims.height));
     engine.setThemeImageDim(newdims);
});
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 18:29   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Never mind. I eventually got there.

Every time I come back to the theme image stuff, I get lost for a while. It's never clear to me when setThemeImageDim() is what's controlling things, and when changing the String value of folderImageSize is the key. Or both. Or neither.

Remember this?
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 18:45   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Seems like a lifetime ago. As I re-read that, it implies that the skin no longer needs to do setThemeImageDim(), under any circumstances. A quick test tells me that it's not necessary.

But if that's the case, some wiki rewriting is in order. https://jalbum.net/help/en/Sample_scripts#Theme_images
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 18:55   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Seems like a lifetime ago. As I re-read that, it implies that the skin no longer needs to do setThemeImageDim(), under any circumstances. A quick test tells me that it's not necessary.

But if that's the case, some wiki rewriting is in order. https://jalbum.net/help/en/Sample_scripts#Theme_images

You mean to just delete
In order to correctly update the displayed crop area, 
following user changes in the skin’s GUI, you need to set 
your skin component first and then the themeImageDim,
for example:
new StateMonitor() {
	public void onChange() {	
		String[] parts = folderImageSize.getText().split("x");
		if(parts.length > 1) {
			int widthValue = Integer.parseInt(parts[0]);
			int heightValue = Integer.parseInt(parts[1]);
			engine.setThemeImageDim(new Dimension(widthValue, heightValue));
   		}
	}
}.add(folderImageSize).done();
? If so I’ll do that within a few hours.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: Property change listener not firing
Posted: 22 Mar 18, 19:23   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Never mind. I eventually got there.

Every time I come back to the theme image stuff, I get lost for a while. It's never clear to me when setThemeImageDim() is what's controlling things, and when changing the String value of folderImageSize is the key. Or both. Or neither.


When you have changed the string value of the skin variable folderImageSize (or whatever its name is according to SkinProperties) and the UI is written to the engine (when Ok'ing or applying settings or making albums for instance), then jAlbum automatically reads this string and applies it to setThemeImageDim. From engine.setSkinVariables():
setThemeImageDim(parseSize(themeImageSize));
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 19:51   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
You mean to just delete....

Yup, seems that's no longer needed.

I don't think including Method 2 is useful, either. When would a skin developer want to do that instead of just letting jAlbum do the image processing automatically?
Edit: I take it back. That's a chunk of code that is very helpful. Even if you don't want to do your own theme image processing, it contains clues to doing something similar in other contexts. (I still need to puzzle through some of the "do this only if isDirty()" stuff.)

Edited by: jGromit on 24-Mar-2018 23:57
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 19:52   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
...jAlbum automatically reads this string and applies it to setThemeImageDim.

Time to delete some excess code. Generally only a single line, but simpler is always better. :)
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 20:03   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
RobM wrote:
You mean to just delete....

Yup, seems that's no longer needed.

I don't think including Method 2 is useful, either. When would a skin developer want to do that instead of just letting jAlbum do the image processing automatically?

Deleted the old code but I use method 2, from memory it was to make inheriting theme images easier to do, or something like that but definately found it easier to use that method.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Property change listener not firing
Posted: 22 Mar 18, 22:09   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
RobM wrote:
You mean to just delete....

Yup, seems that's no longer needed.

I don't think including Method 2 is useful, either. When would a skin developer want to do that instead of just letting jAlbum do the image processing automatically?

I went through what I had done and there is a way to inherit theme images using method 1, I'll leave the example code in the wiki, someone might have another reason to do there own thing.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums