1212import java .util .Random ;
1313
1414public class RandomizerExtension extends ControllerExtension {
15+ Random rand = new Random ();
16+ Faker faker = new Faker ();
17+
18+ private SettableBooleanValue useDate ;
19+
20+ private ControllerHost host ;
21+ private DocumentState documentState ;
22+ private PopupBrowser popupBrowser ;
23+ private CursorTrack cursorTrack ;
24+ private BrowserResultsItemBank resultsItemBank ;
25+
26+ private SettableStringValue filenameOutput ;
27+ private SettableStringValue nameOutput ;
28+
1529 protected RandomizerExtension (
1630 final RandomizerExtensionDefinition definition , final ControllerHost host ) {
1731 super (definition , host );
1832 }
1933
20- private void printer (ControllerHost host , String s ) {
34+ private void printer (String s ) {
2135 host .println (s );
2236 java .lang .System .out .println (s );
2337 }
2438
25- Random rand = new Random ();
26- Faker faker = new Faker ();
2739
2840 @ Override
2941 public void init () {
30- final ControllerHost host = getHost ();
42+ host = getHost ();
3143
32- final DocumentState documentState = host .getDocumentState ();
33- final PopupBrowser popupBrowser = host .createPopupBrowser ();
44+ documentState = host .getDocumentState ();
45+ popupBrowser = host .createPopupBrowser ();
3446 popupBrowser .exists ().markInterested ();
3547 popupBrowser .resultsColumn ().entryCount ().markInterested ();
36- final CursorTrack cursorTrack = host .createCursorTrack (0 , 0 );
48+ cursorTrack = host .createCursorTrack (0 , 0 );
3749
38- BrowserResultsItemBank resultsItemBank = popupBrowser .resultsColumn ().createItemBank (100000 );
50+ resultsItemBank = popupBrowser .resultsColumn ().createItemBank (100000 );
3951
40- SettableBooleanValue useDate =
52+ useDate =
4153 host .getPreferences ().getBooleanSetting ("Prepend date for filename" , "Random name" , true );
4254
4355 documentState
4456 .getSignalSetting ("Select" , "Randomize browser selection" , "Select random item" )
45- .addSignalObserver (
46- selectRandomItem (host , popupBrowser , cursorTrack , resultsItemBank , rand ));
57+ .addSignalObserver (selectRandomItem ());
4758 documentState
4859 .getSignalSetting ("Add" , "Randomize browser selection" , "Add current item" )
4960 .addSignalObserver (popupBrowser ::commit );
5061
51- SettableStringValue filenameOutput =
52- documentState .getStringSetting ("Filename" , "Random name" , 50 , "" );
53- SettableStringValue nameOutput = documentState .getStringSetting ("Name" , "Random name" , 50 , "" );
54- documentState
55- .getSignalSetting (" " , "Random name" , "Generate" )
56- .addSignalObserver (randomName (useDate , filenameOutput , nameOutput ));
62+ filenameOutput = documentState .getStringSetting ("Filename" , "Random name" , 50 , "" );
63+ nameOutput = documentState .getStringSetting ("Name" , "Random name" , 50 , "" );
64+ documentState .getSignalSetting (" " , "Random name" , "Generate" ).addSignalObserver (randomName ());
5765 }
5866
59- private NoArgsCallback selectRandomItem (
60- ControllerHost host ,
61- PopupBrowser popupBrowser ,
62- CursorTrack cursorTrack ,
63- BrowserResultsItemBank resultsItemBank ,
64- Random rand ) {
67+ private NoArgsCallback selectRandomItem () {
6568 return () -> {
6669 if (!popupBrowser .exists ().getAsBoolean ()) {
6770 cursorTrack .endOfDeviceChainInsertionPoint ().browse ();
@@ -76,10 +79,7 @@ private NoArgsCallback selectRandomItem(
7679 };
7780 }
7881
79- private NoArgsCallback randomName (
80- SettableBooleanValue useDate ,
81- SettableStringValue filenameOutput ,
82- SettableStringValue nameOutput ) {
82+ private NoArgsCallback randomName () {
8383 return () -> {
8484 String [] moods = {faker .mood ().emotion (), faker .mood ().tone (), faker .mood ().feeling ()};
8585 String mood = moods [rand .nextInt (moods .length )];
0 commit comments