#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)
Change History (35)
comment:1 by , 11 years ago
Keywords: | mac osx added; macosx removed |
---|
comment:2 by , 11 years ago
comment:3 by , 11 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.
comment:4 by , 11 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:
- source:trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java
- 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 , 11 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:7 by , 11 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 , 11 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 , 11 years ago
Milestone: | → 14.06 |
---|
comment:10 by , 11 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:
- Enter preferences
- Make sure "Expert mode" is selected
- Go to Advanced Preferences, there enter
use.native.file.dialog
- 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 , 11 years ago
I will look at it this week and see if we can integrate it :) Many thanks !
comment:12 by , 11 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 classAbstractFileChooser
(defining the methodsgetSelectedFile
,getSelectedFiles
, and other if needed). We'd provide two implementations ofAbstractFileChooser
which are based onJFileChooser
andFileDialog
respectively. TheGenericFileChooserManager
would then return either instance based on the propertyuse.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
orJFileChooser.FILES_AND_DIRECTORIES
, we could provideGenericFileChooserManager#createDirectoryChooser
andGenericFileChooserManager#createFileAndDirectoryChooser
, respectively. So there'd no need for exposing theJFileChooser
constants. - Also the plugins
cadastre-fr
andsds
need to be adapted.
comment:13 by , 11 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.
follow-up: 17 comment:15 by , 10 years ago
Sorry - no - got a little swamped with life (read football) and work so no - not yet ;-)
comment:16 by , 10 years ago
Milestone: | 14.06 → 14.07 |
---|
OK no problem :) We'll try to finish this for next release :)
follow-up: 18 comment:17 by , 10 years ago
comment:18 by , 10 years ago
comment:21 by , 10 years ago
Milestone: | 14.08 → 14.09 |
---|
comment:22 by , 10 years ago
Keywords: | macosx added; mac osx removed |
---|
comment:24 by , 10 years ago
Cc: | added |
---|
by , 10 years ago
Attachment: | 10024_beta1.patch added |
---|
comment:25 by , 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:
comment:26 by , 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 , 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:29 by , 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.
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.