Monday Nov 18, 2013

MonologFX Update: Timed JavaFX Dialogs

When I wrote the original MonologFX dialogs for JavaFX, I was just trying to clean up a few things I'd done in my earlier project, DialogFX, that I felt could have been done better. Based upon some excellent feedback and suggestions, I rolled out the update...just as the OpenJFX team was releasing their own dialog code that is destined to be in JavaFX/OpenJFX. :-) As I mentioned in this previous post, rather than just hoard the code, I released it anyway in the hopes others might continue to find it useful - and updated the dialogs in the JFXtras Labs library as well - but didn't really expect there to be much continued interest.

I'm happy to say I was wrong. One of my goals was to make a very simple set of dialogs that worked well in most cases and that just "got out of the developer's way"...tools you didn't have to think about extensively to use in your JavaFX application, just "drop & go". They were never meant to be all things to all people, rather a solid option for most use cases. But...

I've gotten some excellent follow-on requests, and I've explored several of them. While I may never have the time to implement them all - and some wander FAR from the original goals - some just fit. One of those ideas was for timed dialogs.

What is a Timed Dialog, and When Would I Use It?

A few developers pointed out that there are occasions when an app is running unattended and dialogs can either a) stop everything or b) pile up by the droves on the user's desktop. And JFXtras implementer Scott mentioned how nice it would be to have an informational dialog that worked similar to a mail notification, popping up and then disappearing after some pre-determined amount of time. The user should also be able to clear the dialog immediately, of course.

Enter the timed dialog. Drawing inspiration from the aforementioned mail notifications and a sample game by colleague Angela Caicedo, I expanded upon Angela's game-switching example to create a (hopefully pleasing) dialog fade in/out effect. Using the number of seconds specified by the developer (you!) via the method setDisplayTime(int displayTime), MonologFX apportions a reasonable percentage of that time to fade in, display, and fade out operations...making user input entirely optional.

What Does it Look Like?

It's much easier to demo than it is to explain, so I created a quick video of a normal dialog, then a timed one, in action. Click here to watch it on YouTube.

Limitations, Caveats, "Keep Off the Grass" Signs

A timed dialog is really best suited for informational dialogs - those where there is no user input required, like the aforementioned mail notifications. If a response is required from a user and a dialog disappears of its own volition, which option should be chosen? The "cancel" option would seem best in some cases, and the "default" in others.

Creating the fade in/out effect required a non-blocking implementation, which meant that it would always return a value immediately...and in the current design, that is "cancel". Which again points to using them as informational dialogs, but not for obtaining user feedback.

So for the foreseeable future, timed dialogs are really focused upon and should be confined to use as informational dialogs. If you need the application user to make a conscious choice prior to proceeding, keep that dialog prominently displayed until you get a response!

Where Can I Get Them?

I've already pushed the code to my Github repository for MonologFX and the JFXtras-Labs 2.2 and JFXtras-Labs 8.0 repos. And if you just want to download a .jar file and kick the tires, I've put a copy in the MonologFX repo's dist folder. Just download the .zip file, unzip it, and run java -jar MonologFX.jar for a quick demo.

Odds & Ends

I also made a few architectural changes to MonologFX this weekend during our first-ever "Thanks For Sharing Informal, International HackFest", and more will be integrated over time. Please stay tuned for more information. :-)

Happy Coding!
Mark

Saturday Nov 10, 2012

Polishing the MonologFX API

Earlier this week, I released "into the wild" a new JavaFX 2.x dialog library, MonologFX, that incorporated some elements of DialogFX and new features I'd been working on over time. While I did try to get the API to a point of reasonable completion (nothing is ever truly "finished", of course!), there was one bit of functionality that I'd included without providing any real "polish": that of the button icons.

Good friend and fellow JFXtras teammate José Pereda Llamas suggested I fix that oversight and provide an update (thanks much, José!), thus this post. If you'd like to take a peek at the new streamlined syntax, I've updated the earlier post; please click here if you'd like to review it. If you want to give MonologFX a try, just point your browser to GitHub to download the updated code and/or .jar.

All the best,
Mark

Wednesday Nov 07, 2012

MonologFX: FLOSS JavaFX Dialogs for the Taking

(UPDATED Nov 10 with simpler button icon API) 

Some time back, I was searching for basic dialog functionality within JavaFX and came up empty. After finding a decent open-source offering on GitHub that almost fit the bill, I began using it...and immediately began thinking of ways to "do it differently."  :-)  Having a weekend to kill, I ended up creating DialogFX and releasing it on GitHub (hecklerm/DialogFX) for anyone who might find it useful. Shortly thereafter, it was incorporated into JFXtras (jfxtras.org) as well.

Today I'm sharing a different, more flexible and capable JavaFX dialog called MonologFX that I've been developing and refining over the past few months. The summary of its progression thus far is pretty well captured in the README.md file I posted with the project on GitHub:

After creating the DialogFX library for JavaFX, I received several suggestions and requests for additional or different functionality, some of which ran counter to the interfaces and/or intent of the DialogFX "way of doing things". Great ideas, but not completely compatible with the existing functionality. Wanting to incorporate these capabilities, I started over...incorporating some parts of DialogFX into the new MonologFX, as I called it, but taking it in a different direction when it seemed sensible to do so.

In the meantime, the OpenJFX team has released dialog code that will be refined and eventually incorporated into JavaFX and OpenJFX. Rather than just scrap the MonologFX code or hoard it, I'm releasing it here on GitHub with the hope that someone may find it useful, interesting, or entertaining. You may never need it, but regardless, MonologFX is there for the taking.

Things of Note

So, what are some features of MonologFX?

  • Four kinds of dialog boxes: ACCEPT (check mark icon), ERROR (red 'x'), INFO (blue "i"), and QUESTION (blue question mark)
  • Button alignment configurable by developer: LEFT, RIGHT, or CENTER
  • Skins/stylesheets support
  • Shortcut key/mnemonics support (Alt-<key>)
  • Ability to designate default (RETURN-key) and cancel (ESCAPE-key) buttons
  • Built-in button types and labels for OK, CANCEL, ABORT, RETRY, IGNORE, YES, and NO
  • Custom button types: CUSTOM1, CUSTOM2, CUSTOM3
  • Internationalization (i18n) built in. Currently, files are provided for English/US and Spanish/Spain locales; please share others and I'll add them!
  • Icon support for your buttons, with or without text labels
  • Fully Free/Libre Open Source Software (FLOSS), with latest source code & .jar always available at GitHub

Quick Usage Overview

Having an intense distaste for rough edges and gears flying when things break (!), I've tried to provide defaults for everything and "fail-safes" to avoid messy outcomes if some property isn't specified, etc. This also feeds the goal of making MonologFX as easy to use as possible, while retaining the library's full flexibility. Or at least that's the plan.  :-)

You can hand-assemble your buttons and dialogs, but I've also included Builder classes to help move that along as well. Here are a couple examples:

        MonologFXButton mlb = MonologFXButtonBuilder.create()
                .defaultButton(true)
                .icon("/testmonologfx/dialog_apply.png")
                .type(MonologFXButton.Type.OK)
                .build();

        MonologFXButton mlb2 = MonologFXButtonBuilder.create()
                .cancelButton(true)
                .icon("/testmonologfx/dialog_cancel.png")
                .type(MonologFXButton.Type.CANCEL)
                .build();

        MonologFX mono = MonologFXBuilder.create()
                .modal(true)
                .message("Welcome to MonologFX! Please feel free to try it out and share your thoughts.")
                .titleText("Important Announcement")
                .button(mlb)
                .button(mlb2)
                .buttonAlignment(MonologFX.ButtonAlignment.CENTER)
                .build();

        MonologFXButton.Type retval = mono.showDialog();


MonologFXButton mlb = MonologFXButtonBuilder.create()
        .defaultButton(true)
        .icon("/testmonologfx/dialog_apply.png")
        .type(MonologFXButton.Type.YES)
        .build();

 

MonologFXButton mlb2 = MonologFXButtonBuilder.create()
        .cancelButton(true)
        .icon("/testmonologfx/dialog_cancel.png")
        .type(MonologFXButton.Type.NO)
        .build();

 

MonologFX mono = MonologFXBuilder.create()
        .modal(true)
        .type(MonologFX.Type.QUESTION)
        .message("Welcome to MonologFX! Does this look like it might be useful?")
        .titleText("Important Announcement")
        .button(mlb)
        .button(mlb2)
        .buttonAlignment(MonologFX.ButtonAlignment.RIGHT)
        .build();

 

MonologFXButton.Type retval = mono.showDialog();

 


Extra Credit

Thanks to everyone who offered ideas for improvement and/or extension to the functionality contained within DialogFX. The JFXtras team welcomed it into the fold, and while I doubt there will be a need to include MonologFX in JFXtras, team members Gerrit Grunwald & Jose Pereda Llamas volunteered templates and i18n expertise to make MonologFX what it is. Thanks for the push, guys!

Where to Get (Git!) It

If you'd like to check it out, point your browser to the MonologFX repository on GitHub. Full source code is there, along with the current .jar file. Please give it a try and share your thoughts! I'd love to hear from you.

All the best,
Mark

Monday Sep 03, 2012

DialogFX: A New Approach to JavaFX Dialogs

How would you like a quick and easy drop-in dialog box capability for JavaFX? That's what I was thinking when a weekend presented itself. And never being one to waste a good weekend...  :-)

After doing some "roll-your-own" basic dialog building for a JavaFX app, I recently stumbled across Anton Smirnov's work on GitHub. It was a good start, but it wasn't exactly what I was after, and ideas just kept popping up of things I'd do differently. I wanted something a bit more streamlined, a bit easier to just "drop in and use". And so DialogFX was born.

DialogFX wasn't intended to be overly fancy, overly clever - just useful and robust. Here were my goals:

  • Easy to use. A dialog "system" should be so simple to use a new developer can drop it in quickly with nearly no learning curve. A seasoned developer shouldn't even have to think, just tap in a few lines and go. Why should dialogs slow "actual development"?  :-)
  • Defaults. If you don't specify something (dialog type, buttons, etc.), a good dialog system should still work. It may not be pretty, but it shouldn't throw gears.
  • Sharable. It's all open source. Even the icons are in the commons, so they can be reused at will.

Let's take a look at some screen captures and the code used to produce them.

 

DialogFX INFO dialog

Screen captures

Windows


Mac 

Sample code

        DialogFX dialog = new DialogFX();
        dialog.setTitleText("Info Dialog Box Example");
        dialog.setMessage("This is an example of an INFO dialog box, created using DialogFX.");
        dialog.showDialog();

DialogFX ERROR dialog

Screen captures

Windows


Mac 

Sample code

        DialogFX dialog = new DialogFX(Type.ERROR);
        dialog.setTitleText("Error Dialog Box Example");
        dialog.setMessage("This is an example of an ERROR dialog box, created using DialogFX.");
        dialog.showDialog();

DialogFX ACCEPT dialog

Screen captures

Windows


Mac 

Sample code

        DialogFX dialog = new DialogFX(Type.ACCEPT);
        dialog.setTitleText("Accept Dialog Box Example");
        dialog.setMessage("This is an example of an ACCEPT dialog box, created using DialogFX.");
        dialog.showDialog();

DialogFX Question dialog (Yes/No)

Screen captures

Windows


Mac 

Sample code

        DialogFX dialog = new DialogFX(Type.QUESTION);
        dialog.setTitleText("Question Dialog Box Example");
        dialog.setMessage("This is an example of an QUESTION dialog box, created using DialogFX. Would you like to continue?");
        dialog.showDialog();

DialogFX Question dialog (custom buttons)

Screen captures

Windows


Mac 

Sample code

        List<String> buttonLabels = new ArrayList<>(2);
        buttonLabels.add("Affirmative");
        buttonLabels.add("Negative");

        DialogFX dialog = new DialogFX(Type.QUESTION);
        dialog.setTitleText("Question Dialog Box Example");
        dialog.setMessage("This is an example of an QUESTION dialog box, created using DialogFX. This also demonstrates the automatic wrapping of text in DialogFX. Would you like to continue?");
        dialog.addButtons(buttonLabels, 0, 1);
        dialog.showDialog();

A couple of things to note

You may have noticed in that last example the addButtons(buttonLabels, 0, 1) call. You can pass custom button labels in and designate the index of the default button (responding to the ENTER key) and the cancel button (for ESCAPE). Optional parameters, of course, but nice when you may want them.

Also, the showDialog() method actually returns the index of the button pressed. Rather than create EventHandlers in the dialog that really have little to do with the dialog itself, you can respond to the user's choice within the calling object. Or not. Again, it's your choice.  :-)

And finally, I've Javadoc'ed the code in the main places. Hopefully, this will make it easy to get up and running quickly and with a minimum of fuss.

How Do I Get (Git?) It?

To try out DialogFX, just point your browser here to the DialogFX GitHub repository and download away! Please take a look, try it out, and let me know what you think. All feedback welcome!

All the best,

Mark 

About

The Java Jungle addresses topics from mobile to enterprise Java, tech news to techniques, and anything even remotely related. The goal is to help us all do our work better with Java, however we use it.

Your Java Jungle guide is Mark Heckler, an Oracle Java/Middleware/Core Engineer with development experience in numerous environments. Mark's current work pursuits and passions all revolve around Java and leave little time to blog or tweet - but somehow, he finds time to do both anyway.

Mark lives with his very understanding wife, three kids, and dog in the St. Louis, MO area.



Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today