Modify

Opened 10 years ago

Closed 10 years ago

Last modified 2 years ago

#10024 closed enhancement (fixed)

[Patch] File-choosing dialog not native

Reported by: Stereo Owned by: team
Priority: normal Milestone: 14.09
Component: Core Version:
Keywords: macosx javabug windows linux Cc: Lesath, vlada@…

Description

File-choosing dialogs in Java applications are of two main types: dialogs created with java.awt.FileDialog and those created with javax.swing.JFileChooser. Using java.awt.FileDialog on Mac OS X would make JOSM behave more like a native Mac app, and the dialog would look much like a Finder window in OS X.

See also:

Apple's native platform integration guide for Java developers, https://developer.apple.com/library/mac/documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html , section "File-Choosing Dialogs"

Netbeans bug 82821, https://netbeans.org/bugzilla/show_bug.cgi?id=82821

Attachments (5)

NativeFileDialogMac.png (111.5 KB ) - added by Lesath 10 years ago.
Mac Native FileDialog
NativeFileDialogLinuxKDE-GTK.png (89.8 KB ) - added by Lesath 10 years ago.
Linux Native FileDialog
Win8NativeFileDialog.png (45.9 KB ) - added by Lesath 10 years ago.
Win 8 Native FileDialog
NativeFileDialog.patch (77.6 KB ) - added by Lesath 10 years ago.
Patch for native filedialog
10024_beta1.patch (65.6 KB ) - added by Don-vip 10 years ago.

Download all attachments as: .zip

Change History (35)

comment:1 by Don-vip, 10 years ago

Keywords: mac osx added; macosx removed

comment:2 by Don-vip, 10 years ago

Didn't even knew that Java proposed two classes for the very same feature o_O

This is something we can do without a Mac, I think.

comment:3 by Lesath, 10 years ago

Ok - will try that one first - seems to be an easy one - with a AbstractFileChooser (to be implemented) it should work with both classes (java.awt.FileDialog/javax.swing.JFileChooser). OpenFileAction() is the class to start for this isn't it?

Or we switch completely to java.awt.FileDialog.

Last edited 10 years ago by Lesath (previous) (diff)

comment:4 by Don-vip, 10 years ago

java.awt.FileDialog will never comply to Look-and-feel chosen by user and will look like native dialog. Many users would prefer this, but I think it would be safer to also keep the JFileChooser implementation.

The two key classes are:

  1. source:trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java
  2. source:trunk/src/org/openstreetmap/josm/gui/widgets/JFileChooserManager.java

I'd see a property like use.native.file.dialog to choose between awt/swing implementation, i.e choose between JFileChooserManager (class not modified) and a new class FileDialogManager (if required) in DiskAccessAction and other classes currently using JFileChooserManager.

comment:5 by Lesath, 10 years ago

Hmm - this seems more though than on first look.

There are more classes affected than I thought - plus FileDialog does not have all functionality that JFileChooser provides. Plus there are a bunch of classes affected - DiskAccessAction, ExtensionFileFilter, OpenFileAction, SaveAction, MapPaintDialog etc.

Just wanted to let you know that I'm still working on this - but it takes longer than I expected at the first look.

I will implement a GenericFileChooser that provides the same methods as JFileChooser. The underlying implementation will differ based on use.native.file.dialog which one is taken.

So in short JOSM will work with GenericFileChooser - its interface is compatible with JFileChooser.

comment:6 by Don-vip, 10 years ago

Solution sounds nice :) Thanks for working on this :)

comment:7 by Stereo, 10 years ago

Thank you Lesath!

The Extension filter hasn't ever really worked in JOSM. It just greys out the files that are filtered and makes them impossible to select. No one has ever complained about that, so it's probably ok if it disappears.

comment:8 by Stereo, 10 years ago

The "native" file dialog would also let you sort by Kind, which is half-redundant with the extension filter anyway.

comment:9 by Don-vip, 10 years ago

Milestone: 14.06

by Lesath, 10 years ago

Attachment: NativeFileDialogMac.png added

Mac Native FileDialog

by Lesath, 10 years ago

Linux Native FileDialog

by Lesath, 10 years ago

Attachment: Win8NativeFileDialog.png added

Win 8 Native FileDialog

by Lesath, 10 years ago

Attachment: NativeFileDialog.patch added

Patch for native filedialog

comment:10 by Lesath, 10 years ago

Summary: File-choosing dialog not native Mac OS X[Patch] File-choosing dialog not native Mac OS X

Hi there,

I've got the patch finished, but I'm not really happy with it, because it simply lacks of features or extensibility. However, this patch will work and if the use.native.file.dialog is used it will show the native dialog.

Step to enable it:

  1. Enter preferences
  2. Make sure "Expert mode" is selected
  3. Go to Advanced Preferences, there enter use.native.file.dialog
  4. set the value to true

Voila - you will get the native awt FileDialog.

But as written it lacks of features - and the set locale is also ignored (see attached screenshots for example).

Nevertheless I will hope this will help you.

comment:11 by Don-vip, 10 years ago

I will look at it this week and see if we can integrate it :) Many thanks !

comment:12 by simon04, 10 years ago

+1 for a native file dialog, the Swing based one simply looks ugly on Linux. Thank you as well for your contribution! A few remarks:

  • FileDialogManager isn't used anywhere?
  • Instead of having GenericFileChooser manage both selectors at the same time in several methods, we should have an interface or abstract class AbstractFileChooser (defining the methods getSelectedFile, getSelectedFiles, and other if needed). We'd provide two implementations of AbstractFileChooser which are based on JFileChooser and FileDialog respectively. The GenericFileChooserManager would then return either instance based on the property use.native.file.dialog. Following this approach, both implementations become clearer since they focus on one GUI component only, and more extensible since it is easy to add a third/fourth dialog type …
  • I wouldn't worry about "simply lacks of features" since (as far as I checked) all usages only access the getSelectedFile/getSelectedFiles method.
  • For the few places needing JFileChooser.DIRECTORIES_ONLY or JFileChooser.FILES_AND_DIRECTORIES, we could provide GenericFileChooserManager#createDirectoryChooser and GenericFileChooserManager#createFileAndDirectoryChooser, respectively. So there'd no need for exposing the JFileChooser constants.
  • Also the plugins cadastre-fr and sds need to be adapted.

comment:13 by Lesath, 10 years ago

Thanks for the remarks - I will have a further look into it - maybe this weekend which is a long one ;-)

The abstract class should be a better and clearer implementation - this is true.

I never thought of the plugins - thanks - I will check them too.

comment:14 by Don-vip, 10 years ago

Did you have the opportunity to continue to work on this subject? :)

comment:15 by Lesath, 10 years ago

Sorry - no - got a little swamped with life (read football) and work so no - not yet ;-)

comment:16 by Don-vip, 10 years ago

Milestone: 14.0614.07

OK no problem :) We'll try to finish this for next release :)

in reply to:  15 ; comment:17 by Don-vip, 10 years ago

Replying to Lesath:

got a little swamped with life (read football)

It's finished now :)

in reply to:  17 comment:18 by Lesath, 10 years ago

Replying to Don-vip:

Replying to Lesath:

got a little swamped with life (read football)

It's finished now :)

Thought so - I saw the merge conflicts today - onto the next ticket!

Thanks!

comment:19 by Don-vip, 10 years ago

Milestone: 14.0714.08

Move some tickets to next milestone

comment:20 by Don-vip, 10 years ago

@Lesath: are you still OK to finish this patch?

comment:21 by Don-vip, 10 years ago

Milestone: 14.0814.09

comment:22 by Don-vip, 10 years ago

Keywords: macosx added; mac osx removed

comment:23 by Don-vip, 10 years ago

Ticket #10539 has been marked as a duplicate of this ticket.

comment:24 by Don-vip, 10 years ago

Cc: vlada@… added

by Don-vip, 10 years ago

Attachment: 10024_beta1.patch added

comment:25 by Don-vip, 10 years ago

First beta of the patch, based on Lesath's work and taking into account Simon's first three remarks. I didn't see there's a serious drawback with FileDialog which doesn't support file filters at all (only a single filter, but it doesn't work on Windows, as stated in Javadoc):

Filename filters do not function in Sun's reference implementation for Microsoft Windows.

We need to fix that before considering to propose it as a viable option.

Some interesting links:

  1. https://community.oracle.com/message/5455889#5455889
  2. http://stackoverflow.com/a/1224744/2257172
  3. https://netbeans.org/bugzilla/show_bug.cgi?id=82821
  4. JDK-4811086, JDK-4811090, JDK-4811095, JDK-6192906, JDK-6699863, JDK-6927978, JDK-7125172
Last edited 10 years ago by Don-vip (previous) (diff)

comment:26 by Don-vip, 10 years ago

Keywords: javabug windows linux added
Summary: [Patch] File-choosing dialog not native Mac OS X[Patch] File-choosing dialog not native

comment:27 by Don-vip, 10 years ago

Looks impossible to add filters, I'm going to propose this as an option with a warning, but not as default. I hope this dialog will be improved in Java 9. That's not impossible as the multi selection is quite new (added in Java 7 only).

comment:28 by Don-vip, 10 years ago

Resolution: fixed
Status: newclosed

In 7578/josm:

fix #10024 - Add an option in Preferences/Look-and-Feel to use native file-choosing dialogs.
They look nicer but they do not support file filters, so we cannot use them (yet) as default.
Based on patch by Lesath and code review by simon04.
The native dialogs are not used if selection mode is not supported ("files and directories" on all platforms, "directories" on systems other than OS X)

comment:29 by Stereo, 10 years ago

The file filters never worked on Mac OS X, so the new dialogs can safely be set to default there without upsetting anyone.

comment:30 by Don-vip, 10 years ago

In 7585/josm:

see #10024, see #10455 - use native file dialogs by default on OS X

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.