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


Permlink Replies: 26 - Pages: 2 [ Previous | 1 2 ] - Last Post: 26 Sep 20, 08:57 Last Post By: davidekholm Threads: [ Previous | Next ]
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 24 Sep 20, 16:58   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
Thanks David. I’ll add the new try catch method to the wiki’s code snippets page, as an example of keeping skins with new features working on old versions of jAlbum.

And thanks for your patience with us (me, anyway) amateur coders.


You're welcome Rob!
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 24 Sep 20, 17:04   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
I just changed to http://jalbum.net/api/se/datadosen/component/ComponentUtilities.html#whenSelectedEnable(javax.swing.AbstractButton,javax.swing.JComponent...)

StateMonitor is still recommended for general use, but in this case the code became shorter and easier to read.


I'm afraid you've lost me, there. This is an example of what I'm seeing in the "new" Journal code:
new StateMonitor() {
	public void onChange() {
		enable(showRegions.isSelected(), showUnknown, localLink);
	}
}.add(showRegions).done();
Looks very familiar, with no use of any shorthand methods.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 24 Sep 20, 17:08   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Ah, finally found an example of the shorthand method. Nice and concise. Is there a 5-component limit, as there is with enable?
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 24 Sep 20, 17:31   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Ah, finally found an example of the shorthand method. Nice and concise. Is there a 5-component limit, as there is with enable?

No, you can use as many components as you like. True, I didn't rewrite all usages of StateMonitor, just 2 of them. The enable method of StateMonitor shouldn't be limited to 5 components either. It has one method that takes an elipsis (...), meaning any number of components.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 24 Sep 20, 17:47   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
The enable method of StateMonitor shouldn't be limited to 5 components either.

Shouldn't be, or isn't? The API is somewhat confused on the subject, and I've always observed the 5-component rule.

https://jalbum.net/api/se/datadosen/component/StateMonitor.html#enable(boolean,javax.swing.JComponent)

ETA: A quick test with one of my own skins reveals that more than 5 components can be specified in a single enable. Seems to work properly back at least as far as jAlbum 17, which is the only version I'm concerned about (all of my skins require at least that version).
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 24 Sep 20, 22:40   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
I have updated the Code Snippets to make finding this code easier in the future. It is currently the second entry, after the all important frog chorus ;) Hopefully my description and abridged code is ok.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 25 Sep 20, 10:57   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
davidekholm wrote:
The enable method of StateMonitor shouldn't be limited to 5 components either.

Shouldn't be, or isn't? The API is somewhat confused on the subject, and I've always observed the 5-component rule.

https://jalbum.net/api/se/datadosen/component/StateMonitor.html#enable(boolean,javax.swing.JComponent)

ETA: A quick test with one of my own skins reveals that more than 5 components can be specified in a single enable. Seems to work properly back at least as far as jAlbum 17, which is the only version I'm concerned about (all of my skins require at least that version).


Now I remember the catch. In plain Java you can use any number of components, but BeanShell probably doesn't understand the elipsis form. There you have to wrap the components in an array and pass the array for it to work beyond 5 components.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 25 Sep 20, 11:04   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
I have updated the Code Snippets to make finding this code easier in the future. It is currently the second entry, after the all important frog chorus ;) Hopefully my description and abridged code is ok.

Yes, well documented!
You might want to add info about the convenience methods of ComponentUtilities too.
The StateMonitor is however more generic/flexible, but it's syntax is a bit verbose for my taste, so since v14, you can use Lambda expressions instead of subclassing StateMonitor. Your StateMonitor code sample then looks like this:
StateMonitor.monitoring(themeImageHeight, themeImageWidth).onChange(src -> {
	folderImageSize.setText(themeImageWidth.getValue().toString() + "x" + themeImageHeight.getValue().toString());
	engine.setThemeImageDim(new Dimension((int)themeImageWidth.getValue(), (int)themeImageHeight.getValue()));
});
There is also a onUserChange callback in case you want to only respond to direct user actions. The "src" parameter in the example above points to the component that originated the change event.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 25 Sep 20, 12:58   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
I have updated the Code Snippets to make finding this code easier in the future.

You might want to add the needed import for setting the syntax language, since even NetBeans can't figure this one out on its own. The wildcard form is easiest:
import static org.fife.ui.rsyntaxtextarea.SyntaxConstants.*;
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 25 Sep 20, 15:16   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
RobM wrote:
I have updated the Code Snippets to make finding this code easier in the future.

You might want to add the needed import for setting the syntax language, since even NetBeans can't figure this one out on its own. The wildcard form is easiest:

import static org.fife.ui.rsyntaxtextarea.SyntaxConstants.*;
I can do that, when I add the other code David posted above. My intention is to update the example with a link to the Journal skin. Then the full Netbeans project will be available for reference, with all imports and library jar files needed.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 25 Sep 20, 21:08   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I have now updated the class example and added a new section on the use of lambda & state monitors,
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: JSmartSyntaxTextArea fallback to JSmartTextArea
Posted: 26 Sep 20, 08:57   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Great!
Legend
Forum admins
Helpful Answer
Correct Answer

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