Compare commits

...

6 Commits

28 changed files with 487 additions and 89 deletions

View File

@@ -73,7 +73,8 @@ jobs:
run: ./gradlew build-natives --no-daemon run: ./gradlew build-natives --no-daemon
- name: Sign Windows DLLs - name: Sign Windows DLLs
if: matrix.os == 'windows-latest' if: false
# if: matrix.os == 'windows-latest'
uses: skymatic/code-sign-action@v3 uses: skymatic/code-sign-action@v3
with: with:
certificate: '${{ secrets.CODE_SIGN_CERT_BASE64 }}' certificate: '${{ secrets.CODE_SIGN_CERT_BASE64 }}'
@@ -82,7 +83,8 @@ jobs:
folder: 'flatlaf-core/src/main/resources/com/formdev/flatlaf/natives' folder: 'flatlaf-core/src/main/resources/com/formdev/flatlaf/natives'
- name: Sign macOS natives - name: Sign macOS natives
if: matrix.os == 'DISABLED--macos-latest' if: false
# if: matrix.os == 'DISABLED--macos-latest'
env: env:
CERT_BASE64: ${{ secrets.CODE_SIGN_CERT_BASE64 }} CERT_BASE64: ${{ secrets.CODE_SIGN_CERT_BASE64 }}
CERT_PASSWORD: ${{ secrets.CODE_SIGN_CERT_PASSWORD }} CERT_PASSWORD: ${{ secrets.CODE_SIGN_CERT_PASSWORD }}

View File

@@ -1,6 +1,23 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## 3.7.1-SNAPSHOT
- System File Chooser:
- Update current filter before invoking approve callback and after closing
dialog. (issue #1065)
- Added `PatternFilter` to support glob file filter (e.g. `*.tar.gz`) on
Windows and on Linux, but not on macOS. (issue #1076)
- Fixed: System and Swing file dialogs were shown at the same time if
application has no other displayable window. (issue #1078)
- On Linux: Check whether required GSettings schemas are installed to avoid
application crash (occurred on NixOS with Plasma/KDE desktop). (issue #1069)
- ComboBox: Added UI property `ComboBox.buttonFocusedEditableBackground`. (issue
#1068)
- Popup: Fixed scrolling popup painting issue on Windows 10 when a glass pane is
visible and frame is maximized. (issue #1071)
## 3.7 ## 3.7
#### New features and improvements #### New features and improvements

View File

@@ -113,6 +113,7 @@ import com.formdev.flatlaf.util.SystemInfo;
* @uiDefault ComboBox.buttonBackground Color optional * @uiDefault ComboBox.buttonBackground Color optional
* @uiDefault ComboBox.buttonEditableBackground Color optional * @uiDefault ComboBox.buttonEditableBackground Color optional
* @uiDefault ComboBox.buttonFocusedBackground Color optional; defaults to ComboBox.focusedBackground * @uiDefault ComboBox.buttonFocusedBackground Color optional; defaults to ComboBox.focusedBackground
* @uiDefault ComboBox.buttonFocusedEditableBackground Color optional; defaults to ComboBox.buttonEditableBackground
* @uiDefault ComboBox.buttonSeparatorWidth int or float optional; defaults to Component.borderWidth * @uiDefault ComboBox.buttonSeparatorWidth int or float optional; defaults to Component.borderWidth
* @uiDefault ComboBox.buttonSeparatorColor Color optional * @uiDefault ComboBox.buttonSeparatorColor Color optional
* @uiDefault ComboBox.buttonDisabledSeparatorColor Color optional * @uiDefault ComboBox.buttonDisabledSeparatorColor Color optional
@@ -147,6 +148,7 @@ public class FlatComboBoxUI
@Styleable protected Color buttonBackground; @Styleable protected Color buttonBackground;
@Styleable protected Color buttonEditableBackground; @Styleable protected Color buttonEditableBackground;
@Styleable protected Color buttonFocusedBackground; @Styleable protected Color buttonFocusedBackground;
/** @since 3.7.1 */ @Styleable protected Color buttonFocusedEditableBackground;
/** @since 2 */ @Styleable protected float buttonSeparatorWidth; /** @since 2 */ @Styleable protected float buttonSeparatorWidth;
/** @since 2 */ @Styleable protected Color buttonSeparatorColor; /** @since 2 */ @Styleable protected Color buttonSeparatorColor;
/** @since 2 */ @Styleable protected Color buttonDisabledSeparatorColor; /** @since 2 */ @Styleable protected Color buttonDisabledSeparatorColor;
@@ -258,6 +260,7 @@ public class FlatComboBoxUI
buttonBackground = UIManager.getColor( "ComboBox.buttonBackground" ); buttonBackground = UIManager.getColor( "ComboBox.buttonBackground" );
buttonFocusedBackground = UIManager.getColor( "ComboBox.buttonFocusedBackground" ); buttonFocusedBackground = UIManager.getColor( "ComboBox.buttonFocusedBackground" );
buttonFocusedEditableBackground = UIManager.getColor( "ComboBox.buttonFocusedEditableBackground" );
buttonEditableBackground = UIManager.getColor( "ComboBox.buttonEditableBackground" ); buttonEditableBackground = UIManager.getColor( "ComboBox.buttonEditableBackground" );
buttonSeparatorWidth = FlatUIUtils.getUIFloat( "ComboBox.buttonSeparatorWidth", FlatUIUtils.getUIFloat( "Component.borderWidth", 1 ) ); buttonSeparatorWidth = FlatUIUtils.getUIFloat( "ComboBox.buttonSeparatorWidth", FlatUIUtils.getUIFloat( "Component.borderWidth", 1 ) );
buttonSeparatorColor = UIManager.getColor( "ComboBox.buttonSeparatorColor" ); buttonSeparatorColor = UIManager.getColor( "ComboBox.buttonSeparatorColor" );
@@ -293,6 +296,7 @@ public class FlatComboBoxUI
buttonBackground = null; buttonBackground = null;
buttonEditableBackground = null; buttonEditableBackground = null;
buttonFocusedBackground = null; buttonFocusedBackground = null;
buttonFocusedEditableBackground = null;
buttonSeparatorColor = null; buttonSeparatorColor = null;
buttonDisabledSeparatorColor = null; buttonDisabledSeparatorColor = null;
buttonArrowColor = null; buttonArrowColor = null;
@@ -587,7 +591,7 @@ public class FlatComboBoxUI
// paint arrow button background // paint arrow button background
if( enabled && !isCellRenderer && arrowButton.isVisible() ) { if( enabled && !isCellRenderer && arrowButton.isVisible() ) {
Color buttonColor = paintButton Color buttonColor = paintButton
? buttonEditableBackground ? (buttonFocusedEditableBackground != null && isPermanentFocusOwner( comboBox ) ? buttonFocusedEditableBackground : buttonEditableBackground)
: (buttonFocusedBackground != null || focusedBackground != null) && isPermanentFocusOwner( comboBox ) : (buttonFocusedBackground != null || focusedBackground != null) && isPermanentFocusOwner( comboBox )
? (buttonFocusedBackground != null ? buttonFocusedBackground : focusedBackground) ? (buttonFocusedBackground != null ? buttonFocusedBackground : focusedBackground)
: buttonBackground; : buttonBackground;

View File

@@ -37,7 +37,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/ */
public class FlatNativeLinuxLibrary public class FlatNativeLinuxLibrary
{ {
private static int API_VERSION_LINUX = 3003; private static int API_VERSION_LINUX = 3004;
/** /**
* Checks whether native library is loaded/available. * Checks whether native library is loaded/available.
@@ -186,8 +186,8 @@ public class FlatNativeLinuxLibrary
* Use '__' for '_' character (e.g. "Choose__and__Quit"). * Use '__' for '_' character (e.g. "Choose__and__Quit").
* @param currentName user-editable filename currently shown in the filename field in save dialog; or {@code null} * @param currentName user-editable filename currently shown in the filename field in save dialog; or {@code null}
* @param currentFolder current directory shown in the dialog; or {@code null} * @param currentFolder current directory shown in the dialog; or {@code null}
* @param optionsSet options to set; see {@code FOS_*} constants * @param optionsSet options to set; see {@code FC_*} constants
* @param optionsClear options to clear; see {@code FOS_*} constants * @param optionsClear options to clear; see {@code FC_*} constants
* @param callback approve callback; or {@code null} * @param callback approve callback; or {@code null}
* @param fileTypeIndex the file type that appears as selected (zero-based) * @param fileTypeIndex the file type that appears as selected (zero-based)
* @param fileTypes file types that the dialog can open or save. * @param fileTypes file types that the dialog can open or save.
@@ -195,19 +195,20 @@ public class FlatNativeLinuxLibrary
* First string is the display name of the filter shown in the combobox (e.g. "Text Files"). * First string is the display name of the filter shown in the combobox (e.g. "Text Files").
* Subsequent strings are the filter patterns (e.g. "*.txt" or "*"). * Subsequent strings are the filter patterns (e.g. "*.txt" or "*").
* {@code null} is required to mark end of filter. * {@code null} is required to mark end of filter.
* @param retFileTypeIndex returns selected file type (zero-based); array must be have one element
* @return file path(s) that the user selected; an empty array if canceled; * @return file path(s) that the user selected; an empty array if canceled;
* or {@code null} on failures (no dialog shown) * or {@code null} on failures (no dialog shown)
* *
* @since 3.7 * @since 3.7.1
*/ */
public native static String[] showFileChooser( Window owner, int dark, boolean open, public native static String[] showFileChooser( Window owner, int dark, boolean open,
String title, String okButtonLabel, String currentName, String currentFolder, String title, String okButtonLabel, String currentName, String currentFolder,
int optionsSet, int optionsClear, FileChooserCallback callback, int optionsSet, int optionsClear, FileChooserCallback callback,
int fileTypeIndex, String... fileTypes ); int fileTypeIndex, String[] fileTypes, int[] retFileTypeIndex );
/** @since 3.7 */ /** @since 3.7.1 */
public interface FileChooserCallback { public interface FileChooserCallback {
boolean approve( String[] files, long hwndFileDialog ); boolean approve( String[] files, int fileTypeIndex, long hwndFileDialog );
} }
/** /**

View File

@@ -45,7 +45,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/ */
public class FlatNativeMacLibrary public class FlatNativeMacLibrary
{ {
private static int API_VERSION_MACOS = 2002; private static int API_VERSION_MACOS = 2003;
/** /**
* Checks whether native library is loaded/available. * Checks whether native library is loaded/available.
@@ -115,22 +115,23 @@ public class FlatNativeMacLibrary
* @param fileTypes file types that the dialog can open or save. * @param fileTypes file types that the dialog can open or save.
* Two or more strings and {@code null} are required for each filter. * Two or more strings and {@code null} are required for each filter.
* First string is the display name of the filter shown in the combobox (e.g. "Text Files"). * First string is the display name of the filter shown in the combobox (e.g. "Text Files").
* Subsequent strings are the filter patterns (e.g. "txt" or "*"). * Subsequent strings are the file name extensions (e.g. "txt" or "*"; '.' is not supported).
* {@code null} is required to mark end of filter. * {@code null} is required to mark end of filter.
* @param retFileTypeIndex returns selected file type (zero-based); array must be have one element
* @return file path(s) that the user selected; an empty array if canceled; * @return file path(s) that the user selected; an empty array if canceled;
* or {@code null} on failures (no dialog shown) * or {@code null} on failures (no dialog shown)
* *
* @since 3.7 * @since 3.7.1
*/ */
public native static String[] showFileChooser( Window owner, int dark, boolean open, public native static String[] showFileChooser( Window owner, int dark, boolean open,
String title, String prompt, String message, String filterFieldLabel, String title, String prompt, String message, String filterFieldLabel,
String nameFieldLabel, String nameFieldStringValue, String directoryURL, String nameFieldLabel, String nameFieldStringValue, String directoryURL,
int optionsSet, int optionsClear, FileChooserCallback callback, int optionsSet, int optionsClear, FileChooserCallback callback,
int fileTypeIndex, String... fileTypes ); int fileTypeIndex, String[] fileTypes, int[] retFileTypeIndex );
/** @since 3.7 */ /** @since 3.7.1 */
public interface FileChooserCallback { public interface FileChooserCallback {
boolean approve( String[] files, long hwndFileDialog ); boolean approve( String[] files, int fileTypeIndex, long hwndFileDialog );
} }
/** /**

View File

@@ -31,7 +31,7 @@ import com.formdev.flatlaf.util.SystemInfo;
*/ */
public class FlatNativeWindowsLibrary public class FlatNativeWindowsLibrary
{ {
private static int API_VERSION_WINDOWS = 1002; private static int API_VERSION_WINDOWS = 1003;
private static long osBuildNumber = Long.MIN_VALUE; private static long osBuildNumber = Long.MIN_VALUE;
@@ -226,20 +226,21 @@ public class FlatNativeWindowsLibrary
* Pairs of strings are required for each filter. * Pairs of strings are required for each filter.
* First string is the display name of the filter shown in the combobox (e.g. "Text Files"). * First string is the display name of the filter shown in the combobox (e.g. "Text Files").
* Second string is the filter pattern (e.g. "*.txt", "*.exe;*.dll" or "*.*"). * Second string is the filter pattern (e.g. "*.txt", "*.exe;*.dll" or "*.*").
* @param retFileTypeIndex returns selected file type (zero-based); array must be have one element
* @return file path(s) that the user selected; an empty array if canceled; * @return file path(s) that the user selected; an empty array if canceled;
* or {@code null} on failures (no dialog shown) * or {@code null} on failures (no dialog shown)
* *
* @since 3.7 * @since 3.7.1
*/ */
public native static String[] showFileChooser( Window owner, boolean open, public native static String[] showFileChooser( Window owner, boolean open,
String title, String okButtonLabel, String fileNameLabel, String fileName, String title, String okButtonLabel, String fileNameLabel, String fileName,
String folder, String saveAsItem, String defaultFolder, String defaultExtension, String folder, String saveAsItem, String defaultFolder, String defaultExtension,
int optionsSet, int optionsClear, FileChooserCallback callback, int optionsSet, int optionsClear, FileChooserCallback callback,
int fileTypeIndex, String... fileTypes ); int fileTypeIndex, String[] fileTypes, int[] retFileTypeIndex );
/** @since 3.7 */ /** @since 3.7.1 */
public interface FileChooserCallback { public interface FileChooserCallback {
boolean approve( String[] files, long hwndFileDialog ); boolean approve( String[] files, int fileTypeIndex, long hwndFileDialog );
} }
/** /**

View File

@@ -108,10 +108,8 @@ public class FlatPopupFactory
} }
} }
boolean forceHeavyWeight = isOptionEnabled( owner, contents, FlatClientProperties.POPUP_FORCE_HEAVY_WEIGHT, "Popup.forceHeavyWeight" );
if( !isOptionEnabled( owner, contents, FlatClientProperties.POPUP_DROP_SHADOW_PAINTED, "Popup.dropShadowPainted" ) || SystemInfo.isProjector || SystemInfo.isWebswing ) if( !isOptionEnabled( owner, contents, FlatClientProperties.POPUP_DROP_SHADOW_PAINTED, "Popup.dropShadowPainted" ) || SystemInfo.isProjector || SystemInfo.isWebswing )
return new NonFlashingPopup( getPopupForScreenOfOwner( owner, contents, x, y, forceHeavyWeight ), owner, contents ); return new NonFlashingPopup( getPopupForScreenOfOwner( owner, contents, x, y, isForceHeavyWeight( owner, contents, x, y ) ), owner, contents );
// macOS and Linux adds drop shadow to heavy weight popups // macOS and Linux adds drop shadow to heavy weight popups
if( SystemInfo.isMacOS || SystemInfo.isLinux ) { if( SystemInfo.isMacOS || SystemInfo.isLinux ) {
@@ -131,12 +129,8 @@ public class FlatPopupFactory
return popup; return popup;
} }
// check whether popup overlaps a heavy weight component
if( !forceHeavyWeight && overlapsHeavyWeightComponent( owner, contents, x, y ) )
forceHeavyWeight = true;
// create drop shadow popup // create drop shadow popup
Popup popupForScreenOfOwner = getPopupForScreenOfOwner( owner, contents, x, y, forceHeavyWeight ); Popup popupForScreenOfOwner = getPopupForScreenOfOwner( owner, contents, x, y, isForceHeavyWeight( owner, contents, x, y ) );
GraphicsConfiguration gc = (owner != null) ? owner.getGraphicsConfiguration() : null; GraphicsConfiguration gc = (owner != null) ? owner.getGraphicsConfiguration() : null;
return (gc != null && gc.isTranslucencyCapable()) return (gc != null && gc.isTranslucencyCapable())
? new DropShadowPopup( popupForScreenOfOwner, owner, contents ) ? new DropShadowPopup( popupForScreenOfOwner, owner, contents )
@@ -226,6 +220,11 @@ public class FlatPopupFactory
} }
} }
private static boolean isForceHeavyWeight( Component owner, Component contents, int x, int y ) {
boolean forceHeavyWeight = isOptionEnabled( owner, contents, FlatClientProperties.POPUP_FORCE_HEAVY_WEIGHT, "Popup.forceHeavyWeight" );
return forceHeavyWeight || hasVisibleGlassPane( owner ) || overlapsHeavyWeightComponent( owner, contents, x, y );
}
private static boolean isOptionEnabled( Component owner, Component contents, String clientKey, String uiKey ) { private static boolean isOptionEnabled( Component owner, Component contents, String clientKey, String uiKey ) {
Object value = getOption( owner, contents, clientKey, uiKey ); Object value = getOption( owner, contents, clientKey, uiKey );
return (value instanceof Boolean) ? (Boolean) value : false; return (value instanceof Boolean) ? (Boolean) value : false;
@@ -469,6 +468,18 @@ public class FlatPopupFactory
//---- fixes -------------------------------------------------------------- //---- fixes --------------------------------------------------------------
private static boolean hasVisibleGlassPane( Component owner ) {
if( owner == null )
return false;
Window window = SwingUtilities.windowForComponent( owner );
if( !(window instanceof RootPaneContainer) )
return false;
Component glassPane = ((RootPaneContainer)window).getGlassPane();
return (glassPane != null && glassPane.isVisible());
}
private static boolean overlapsHeavyWeightComponent( Component owner, Component contents, int x, int y ) { private static boolean overlapsHeavyWeightComponent( Component owner, Component contents, int x, int y ) {
if( owner == null ) if( owner == null )
return false; return false;

View File

@@ -18,6 +18,8 @@ package com.formdev.flatlaf.util;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.KeyboardFocusManager; import java.awt.KeyboardFocusManager;
import java.awt.SecondaryLoop; import java.awt.SecondaryLoop;
import java.awt.Toolkit; import java.awt.Toolkit;
@@ -28,11 +30,13 @@ import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@@ -87,7 +91,8 @@ import com.formdev.flatlaf.ui.FlatNativeWindowsLibrary;
* <li>{@link JFileChooser#FILES_AND_DIRECTORIES} is not supported. * <li>{@link JFileChooser#FILES_AND_DIRECTORIES} is not supported.
* <li>{@link #getSelectedFiles()} returns selected file also in single selection mode. * <li>{@link #getSelectedFiles()} returns selected file also in single selection mode.
* {@link JFileChooser#getSelectedFiles()} only in multi selection mode. * {@link JFileChooser#getSelectedFiles()} only in multi selection mode.
* <li>Only file name extension filters (see {@link FileNameExtensionFilter}) are supported. * <li>Only file name extension filters (see {@link FileNameExtensionFilter}) are supported on all platforms.
* <li>Pattern filters (see {@link PatternFilter}) are only supported on Windows and Linux, but not on macOS.
* <li>If adding choosable file filters and {@link #isAcceptAllFileFilterUsed()} is {@code true}, * <li>If adding choosable file filters and {@link #isAcceptAllFileFilterUsed()} is {@code true},
* then the <b>All Files</b> filter is placed at the end of the combobox list * then the <b>All Files</b> filter is placed at the end of the combobox list
* (as usual in current operating systems) and the first choosable filter is selected by default. * (as usual in current operating systems) and the first choosable filter is selected by default.
@@ -584,6 +589,7 @@ public class SystemFileChooser
private void checkSupportedFileFilter( FileFilter filter ) throws IllegalArgumentException { private void checkSupportedFileFilter( FileFilter filter ) throws IllegalArgumentException {
if( filter == null || if( filter == null ||
filter instanceof FileNameExtensionFilter || filter instanceof FileNameExtensionFilter ||
filter instanceof PatternFilter ||
filter instanceof AcceptAllFileFilter ) filter instanceof AcceptAllFileFilter )
return; return;
@@ -607,6 +613,11 @@ public class SystemFileChooser
return filters2; return filters2;
} }
private void updateFileFilter( List<FileFilter> filters, int index ) {
if( index >= 0 && index < filters.size() )
setFileFilter( filters.get( index ) );
}
public ApproveCallback getApproveCallback() { public ApproveCallback getApproveCallback() {
return approveCallback; return approveCallback;
} }
@@ -737,6 +748,9 @@ public class SystemFileChooser
} }
private int showDialogImpl( Component parent ) { private int showDialogImpl( Component parent ) {
if( !EventQueue.isDispatchThread() )
throw new IllegalStateException( "Must be invoked from the AWT/Swing event dispatch thread" );
Window owner = (parent instanceof Window) Window owner = (parent instanceof Window)
? (Window) parent ? (Window) parent
: (parent != null) ? SwingUtilities.windowForComponent( parent ) : null; : (parent != null) ? SwingUtilities.windowForComponent( parent ) : null;
@@ -785,6 +799,16 @@ public class SystemFileChooser
{ {
@Override @Override
public File[] showDialog( Window owner, SystemFileChooser fc ) { public File[] showDialog( Window owner, SystemFileChooser fc ) {
// if there is no displayable window, then AWT's auto-shutdown feature
// quits our secondary event loop (see below) immediately
// https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/java/awt/doc-files/AWTThreadIssues.html#Autoshutdown
Window dummyWindow = null;
if( !hasDisplayableWindow( owner ) ) {
// create a (not visible) displayable window to avoid AWT auto-shutdown
dummyWindow = new Window( (Frame) null );
dummyWindow.addNotify();
}
AtomicReference<String[]> filenamesRef = new AtomicReference<>(); AtomicReference<String[]> filenamesRef = new AtomicReference<>();
// create secondary event look and invoke system file dialog on a new thread // create secondary event look and invoke system file dialog on a new thread
@@ -795,6 +819,10 @@ public class SystemFileChooser
}, "FlatLaf SystemFileChooser" ).start(); }, "FlatLaf SystemFileChooser" ).start();
secondaryLoop.enter(); secondaryLoop.enter();
// dispose dummy window to allow AWT to auto-shutdown
if( dummyWindow != null )
dummyWindow.dispose();
String[] filenames = filenamesRef.get(); String[] filenames = filenamesRef.get();
// fallback to Swing file chooser if system file dialog failed or is not available // fallback to Swing file chooser if system file dialog failed or is not available
@@ -831,6 +859,17 @@ public class SystemFileChooser
files[i] = fsv.createFileObject( filenames[i] ); files[i] = fsv.createFileObject( filenames[i] );
return files; return files;
} }
private static boolean hasDisplayableWindow( Window owner ) {
if( owner != null && owner.isDisplayable() )
return true;
for( Window window : Window.getWindows() ) {
if( window.isDisplayable() )
return true;
}
return false;
}
} }
//---- class WindowsFileChooserProvider ----------------------------------- //---- class WindowsFileChooserProvider -----------------------------------
@@ -890,6 +929,7 @@ public class SystemFileChooser
// filter // filter
int fileTypeIndex = 0; int fileTypeIndex = 0;
ArrayList<String> fileTypes = new ArrayList<>(); ArrayList<String> fileTypes = new ArrayList<>();
ArrayList<FileFilter> fileTypeFilters = new ArrayList<>();
if( !fc.isDirectorySelectionEnabled() ) { if( !fc.isDirectorySelectionEnabled() ) {
List<FileFilter> filters = fc.getFiltersForDialog(); List<FileFilter> filters = fc.getFiltersForDialog();
if( !filters.isEmpty() ) { if( !filters.isEmpty() ) {
@@ -898,9 +938,15 @@ public class SystemFileChooser
if( filter instanceof FileNameExtensionFilter ) { if( filter instanceof FileNameExtensionFilter ) {
fileTypes.add( filter.getDescription() ); fileTypes.add( filter.getDescription() );
fileTypes.add( "*." + String.join( ";*.", ((FileNameExtensionFilter)filter).getExtensions() ) ); fileTypes.add( "*." + String.join( ";*.", ((FileNameExtensionFilter)filter).getExtensions() ) );
fileTypeFilters.add( filter );
} else if( filter instanceof PatternFilter ) {
fileTypes.add( filter.getDescription() );
fileTypes.add( String.join( ";", ((PatternFilter)filter).getPatterns() ) );
fileTypeFilters.add( filter );
} else if( filter instanceof AcceptAllFileFilter ) { } else if( filter instanceof AcceptAllFileFilter ) {
fileTypes.add( filter.getDescription() ); fileTypes.add( filter.getDescription() );
fileTypes.add( "*.*" ); fileTypes.add( "*.*" );
fileTypeFilters.add( filter );
} }
} }
} }
@@ -916,19 +962,24 @@ public class SystemFileChooser
// callback // callback
FlatNativeWindowsLibrary.FileChooserCallback callback = (fc.getApproveCallback() != null) FlatNativeWindowsLibrary.FileChooserCallback callback = (fc.getApproveCallback() != null)
? (files, hwndFileDialog) -> { ? (files, fileTypeIndex2, hwndFileDialog) -> {
fc.updateFileFilter( fileTypeFilters, fileTypeIndex2 );
return invokeApproveCallback( fc, files, new WindowsApproveContext( hwndFileDialog ) ); return invokeApproveCallback( fc, files, new WindowsApproveContext( hwndFileDialog ) );
} : null; } : null;
// show system file dialog // show system file dialog
return FlatNativeWindowsLibrary.showFileChooser( owner, open, int[] retFileTypeIndex = { -1 };
String[] result = FlatNativeWindowsLibrary.showFileChooser( owner, open,
fc.getDialogTitle(), approveButtonText, fc.getDialogTitle(), approveButtonText,
fc.getPlatformProperty( WINDOWS_FILE_NAME_LABEL ), fc.getPlatformProperty( WINDOWS_FILE_NAME_LABEL ),
fileName, folder, saveAsItem, fileName, folder, saveAsItem,
fc.getPlatformProperty( WINDOWS_DEFAULT_FOLDER ), fc.getPlatformProperty( WINDOWS_DEFAULT_FOLDER ),
fc.getPlatformProperty( WINDOWS_DEFAULT_EXTENSION ), fc.getPlatformProperty( WINDOWS_DEFAULT_EXTENSION ),
optionsSet, optionsClear, callback, optionsSet, optionsClear, callback,
fileTypeIndex, fileTypes.toArray( new String[fileTypes.size()] ) ); fileTypeIndex, fileTypes.toArray( new String[fileTypes.size()] ), retFileTypeIndex );
if( result != null )
fc.updateFileFilter( fileTypeFilters, retFileTypeIndex[0] );
return result;
} }
//---- class WindowsApproveContext ---- //---- class WindowsApproveContext ----
@@ -969,6 +1020,26 @@ public class SystemFileChooser
private static class MacFileChooserProvider private static class MacFileChooserProvider
extends SystemFileChooserProvider extends SystemFileChooserProvider
{ {
@Override
public File[] showDialog( Window owner, SystemFileChooser fc ) {
// fallback to Swing file chooser if PatternFilter is used
boolean usesPatternFilter = (fc.getFileFilter() instanceof PatternFilter);
if( !usesPatternFilter ) {
for( FileFilter filter : fc.getChoosableFileFilters() ) {
if( filter instanceof PatternFilter ) {
usesPatternFilter = true;
break;
}
}
}
if( usesPatternFilter ) {
LoggingFacade.INSTANCE.logSevere( "FlatLaf: SystemFileChooser.PatternFilter is not supported on macOS. Using Swing JFileChooser.", null );
return new SwingFileChooserProvider().showDialog( owner, fc );
}
return super.showDialog( owner, fc );
}
@Override @Override
String[] showSystemDialog( Window owner, SystemFileChooser fc ) { String[] showSystemDialog( Window owner, SystemFileChooser fc ) {
int dark = FlatLaf.isLafDark() ? 1 : 0; int dark = FlatLaf.isLafDark() ? 1 : 0;
@@ -1013,6 +1084,7 @@ public class SystemFileChooser
// filter // filter
int fileTypeIndex = 0; int fileTypeIndex = 0;
ArrayList<String> fileTypes = new ArrayList<>(); ArrayList<String> fileTypes = new ArrayList<>();
ArrayList<FileFilter> fileTypeFilters = new ArrayList<>();
if( !fc.isDirectorySelectionEnabled() ) { if( !fc.isDirectorySelectionEnabled() ) {
List<FileFilter> filters = fc.getFiltersForDialog(); List<FileFilter> filters = fc.getFiltersForDialog();
if( !filters.isEmpty() ) { if( !filters.isEmpty() ) {
@@ -1023,10 +1095,12 @@ public class SystemFileChooser
for( String ext : ((FileNameExtensionFilter)filter).getExtensions() ) for( String ext : ((FileNameExtensionFilter)filter).getExtensions() )
fileTypes.add( ext ); fileTypes.add( ext );
fileTypes.add( null ); fileTypes.add( null );
fileTypeFilters.add( filter );
} else if( filter instanceof AcceptAllFileFilter ) { } else if( filter instanceof AcceptAllFileFilter ) {
fileTypes.add( filter.getDescription() ); fileTypes.add( filter.getDescription() );
fileTypes.add( "*" ); fileTypes.add( "*" );
fileTypes.add( null ); fileTypes.add( null );
fileTypeFilters.add( filter );
} }
} }
} }
@@ -1034,18 +1108,23 @@ public class SystemFileChooser
// callback // callback
FlatNativeMacLibrary.FileChooserCallback callback = (fc.getApproveCallback() != null) FlatNativeMacLibrary.FileChooserCallback callback = (fc.getApproveCallback() != null)
? (files, hwndFileDialog) -> { ? (files, fileTypeIndex2, hwndFileDialog) -> {
fc.updateFileFilter( fileTypeFilters, fileTypeIndex2 );
return invokeApproveCallback( fc, files, new MacApproveContext( hwndFileDialog ) ); return invokeApproveCallback( fc, files, new MacApproveContext( hwndFileDialog ) );
} : null; } : null;
// show system file dialog // show system file dialog
return FlatNativeMacLibrary.showFileChooser( owner, dark, open, int[] retFileTypeIndex = { -1 };
String[] result = FlatNativeMacLibrary.showFileChooser( owner, dark, open,
fc.getDialogTitle(), fc.getApproveButtonText(), fc.getDialogTitle(), fc.getApproveButtonText(),
fc.getPlatformProperty( MAC_MESSAGE ), fc.getPlatformProperty( MAC_MESSAGE ),
fc.getPlatformProperty( MAC_FILTER_FIELD_LABEL ), fc.getPlatformProperty( MAC_FILTER_FIELD_LABEL ),
fc.getPlatformProperty( MAC_NAME_FIELD_LABEL ), fc.getPlatformProperty( MAC_NAME_FIELD_LABEL ),
nameFieldStringValue, directoryURL, optionsSet, optionsClear, callback, nameFieldStringValue, directoryURL, optionsSet, optionsClear, callback,
fileTypeIndex, fileTypes.toArray( new String[fileTypes.size()] ) ); fileTypeIndex, fileTypes.toArray( new String[fileTypes.size()] ), retFileTypeIndex );
if( result != null )
fc.updateFileFilter( fileTypeFilters, retFileTypeIndex[0] );
return result;
} }
//---- class MacApproveContext ---- //---- class MacApproveContext ----
@@ -1141,6 +1220,7 @@ public class SystemFileChooser
// filter // filter
int fileTypeIndex = 0; int fileTypeIndex = 0;
ArrayList<String> fileTypes = new ArrayList<>(); ArrayList<String> fileTypes = new ArrayList<>();
ArrayList<FileFilter> fileTypeFilters = new ArrayList<>();
if( !fc.isDirectorySelectionEnabled() ) { if( !fc.isDirectorySelectionEnabled() ) {
List<FileFilter> filters = fc.getFiltersForDialog(); List<FileFilter> filters = fc.getFiltersForDialog();
if( !filters.isEmpty() ) { if( !filters.isEmpty() ) {
@@ -1149,12 +1229,19 @@ public class SystemFileChooser
if( filter instanceof FileNameExtensionFilter ) { if( filter instanceof FileNameExtensionFilter ) {
fileTypes.add( filter.getDescription() ); fileTypes.add( filter.getDescription() );
for( String ext : ((FileNameExtensionFilter)filter).getExtensions() ) for( String ext : ((FileNameExtensionFilter)filter).getExtensions() )
fileTypes.add( caseInsensitiveGlobPattern( ext ) ); fileTypes.add( "*." + caseInsensitiveGlobPattern( ext ) );
fileTypes.add( null ); fileTypes.add( null );
fileTypeFilters.add( filter );
} else if( filter instanceof PatternFilter ) {
fileTypes.add( filter.getDescription() );
for( String pattern : ((PatternFilter)filter).getPatterns() )
fileTypes.add( caseInsensitiveGlobPattern( pattern ) );
fileTypeFilters.add( filter );
} else if( filter instanceof AcceptAllFileFilter ) { } else if( filter instanceof AcceptAllFileFilter ) {
fileTypes.add( filter.getDescription() ); fileTypes.add( filter.getDescription() );
fileTypes.add( "*" ); fileTypes.add( "*" );
fileTypes.add( null ); fileTypes.add( null );
fileTypeFilters.add( filter );
} }
} }
} }
@@ -1162,20 +1249,24 @@ public class SystemFileChooser
// callback // callback
FlatNativeLinuxLibrary.FileChooserCallback callback = (fc.getApproveCallback() != null) FlatNativeLinuxLibrary.FileChooserCallback callback = (fc.getApproveCallback() != null)
? (files, hwndFileDialog) -> { ? (files, fileTypeIndex2, hwndFileDialog) -> {
fc.updateFileFilter( fileTypeFilters, fileTypeIndex2 );
return invokeApproveCallback( fc, files, new LinuxApproveContext( hwndFileDialog ) ); return invokeApproveCallback( fc, files, new LinuxApproveContext( hwndFileDialog ) );
} : null; } : null;
// show system file dialog // show system file dialog
return FlatNativeLinuxLibrary.showFileChooser( owner, dark, open, int[] retFileTypeIndex = { -1 };
String[] result = FlatNativeLinuxLibrary.showFileChooser( owner, dark, open,
fc.getDialogTitle(), approveButtonText, currentName, currentFolder, fc.getDialogTitle(), approveButtonText, currentName, currentFolder,
optionsSet, optionsClear, callback, optionsSet, optionsClear, callback,
fileTypeIndex, fileTypes.toArray( new String[fileTypes.size()] ) ); fileTypeIndex, fileTypes.toArray( new String[fileTypes.size()] ), retFileTypeIndex );
if( result != null )
fc.updateFileFilter( fileTypeFilters, retFileTypeIndex[0] );
return result;
} }
private String caseInsensitiveGlobPattern( String ext ) { private String caseInsensitiveGlobPattern( String ext ) {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append( "*." );
int len = ext.length(); int len = ext.length();
for( int i = 0; i < len; i++ ) { for( int i = 0; i < len; i++ ) {
char ch = ext.charAt( i ); char ch = ext.charAt( i );
@@ -1253,6 +1344,8 @@ public class SystemFileChooser
{ {
@Override @Override
public File[] showDialog( Window owner, SystemFileChooser fc ) { public File[] showDialog( Window owner, SystemFileChooser fc ) {
IdentityHashMap<javax.swing.filechooser.FileFilter, FileFilter> filterMap = new IdentityHashMap<>();
JFileChooser chooser = new JFileChooser() { JFileChooser chooser = new JFileChooser() {
@Override @Override
public void approveSelection() { public void approveSelection() {
@@ -1273,6 +1366,7 @@ public class SystemFileChooser
// callback // callback
ApproveCallback approveCallback = fc.getApproveCallback(); ApproveCallback approveCallback = fc.getApproveCallback();
if( approveCallback != null ) { if( approveCallback != null ) {
updateFileFilter( fc, this, filterMap );
int result = approveCallback.approve( files, new SwingApproveContext( this ) ); int result = approveCallback.approve( files, new SwingApproveContext( this ) );
if( result == CANCEL_OPTION ) if( result == CANCEL_OPTION )
return; return;
@@ -1313,6 +1407,7 @@ public class SystemFileChooser
chooser.addChoosableFileFilter( jfilter ); chooser.addChoosableFileFilter( jfilter );
if( filter == currentFilter ) if( filter == currentFilter )
chooser.setFileFilter( jfilter ); chooser.setFileFilter( jfilter );
filterMap.put( jfilter, filter );
} }
} }
} }
@@ -1340,6 +1435,7 @@ public class SystemFileChooser
// show dialog // show dialog
int result = chooser.showDialog( owner, null ); int result = chooser.showDialog( owner, null );
updateFileFilter( fc, chooser, filterMap );
// save window size // save window size
Dimension windowSize = chooser.getSize(); Dimension windowSize = chooser.getSize();
@@ -1361,12 +1457,24 @@ public class SystemFileChooser
return new javax.swing.filechooser.FileNameExtensionFilter( return new javax.swing.filechooser.FileNameExtensionFilter(
((FileNameExtensionFilter)filter).getDescription(), ((FileNameExtensionFilter)filter).getDescription(),
((FileNameExtensionFilter)filter).getExtensions() ); ((FileNameExtensionFilter)filter).getExtensions() );
} else if( filter instanceof PatternFilter ) {
return new SwingGlobFilter(
((PatternFilter)filter).getDescription(),
((PatternFilter)filter).getPatterns() );
} else if( filter instanceof AcceptAllFileFilter ) } else if( filter instanceof AcceptAllFileFilter )
return chooser.getAcceptAllFileFilter(); return chooser.getAcceptAllFileFilter();
else else
return null; return null;
} }
private void updateFileFilter( SystemFileChooser fc, JFileChooser chooser,
IdentityHashMap<javax.swing.filechooser.FileFilter, FileFilter> filterMap )
{
FileFilter fileFilter = filterMap.get( chooser.getFileFilter() );
if( fileFilter != null )
fc.setFileFilter( fileFilter );
}
private static boolean checkMustExist( JFileChooser chooser, File[] files ) { private static boolean checkMustExist( JFileChooser chooser, File[] files ) {
for( File file : files ) { for( File file : files ) {
if( !file.exists() ) { if( !file.exists() ) {
@@ -1442,6 +1550,86 @@ public class SystemFileChooser
null, buttons, buttons[Math.min( Math.max( defaultButton, 0 ), buttons.length - 1 )] ); null, buttons, buttons[Math.min( Math.max( defaultButton, 0 ), buttons.length - 1 )] );
} }
} }
//---- class SwingGlobFilter ------------------------------------------
private static class SwingGlobFilter
extends javax.swing.filechooser.FileFilter
{
private final String description;
private final String[] patterns;
private Pattern regexPattern;
SwingGlobFilter( String description, String... patterns ) {
this.description = description;
this.patterns = patterns;
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean accept( File f ) {
if( f == null )
return false;
if( f.isDirectory() )
return true;
initRegexPattern();
return regexPattern.matcher( f.getName() ).matches();
}
private void initRegexPattern() {
if( regexPattern != null )
return;
StringBuilder buf = new StringBuilder();
for( String pattern : patterns ) {
if( buf.length() > 0 )
buf.append( '|' );
glob2regexPattern( pattern, buf );
}
regexPattern = Pattern.compile( buf.toString(), Pattern.CASE_INSENSITIVE );
}
private static void glob2regexPattern( String globPattern, StringBuilder buf ) {
int globLength = globPattern.length();
// on windows, a pattern ending with "*.*" is equal to ending with "*"
if( SystemInfo.isWindows && globPattern.endsWith( "*.*" ) )
globLength -= 2;
for( int i = 0; i < globLength; i++ ) {
char ch = globPattern.charAt( i );
switch( ch ) {
// glob pattern
case '*': buf.append( ".*" ); break;
case '?': buf.append( '.' ); break;
// escape special regex characters
case '\\':
case '.':
case '+':
case '^':
case '$':
case '(':
case ')':
case '{':
case '}':
case '[':
case ']':
case '|':
buf.append( '\\' ).append( ch );
break;
default: buf.append( ch ); break;
}
}
}
}
} }
//---- class FileFilter --------------------------------------------------- //---- class FileFilter ---------------------------------------------------
@@ -1493,6 +1681,67 @@ public class SystemFileChooser
} }
} }
//---- class PatternFilter ------------------------------------------------
/**
* A case-insensitive file filter which accepts file patterns containing
* the wildcard characters {@code *?} on Windows and Linux.
* <ul>
* <li>{@code '*'} matches any sequence of characters.
* <li>{@code '?'} matches any single character.
* </ul>
* Sample filters: {@code *.tar.gz} or {@code *_copy.txt}
* <p>
* <b>Warning</b>: This filter is <b>not supported on macOS</b>.
* If used on macOS, the Swing file chooser {@link JFileChooser} is shown
* (instead of macOS file dialog) and a warning is logged.
* To avoid this, do not use this filter on macOS.
* <p>
* E.g.:
* <pre>{@code
* if( SystemInfo.isMacOS )
* chooser.addChoosableFileFilter( new FileNameExtensionFilter( "Compressed TAR", "tgz" ) );
* else
* chooser.addChoosableFileFilter( new PatternFilter( "Compressed TAR", "*.tar.gz" ) );
* } );
* }</pre>
*
* @see FileNameExtensionFilter
* @since 3.7.1
*/
public static final class PatternFilter
extends FileFilter
{
private final String description;
private final String[] patterns;
public PatternFilter( String description, String... patterns ) {
if( patterns == null || patterns.length == 0 )
throw new IllegalArgumentException( "Missing patterns" );
for( String extension : patterns ) {
if( extension == null || extension.isEmpty() )
throw new IllegalArgumentException( "Pattern is null or empty string" );
}
this.description = description;
this.patterns = patterns.clone();
}
@Override
public String getDescription() {
return description;
}
public String[] getPatterns() {
return patterns.clone();
}
@Override
public String toString() {
return super.toString() + "[description=" + description + " patterns=" + Arrays.toString( patterns ) + "]";
}
}
//---- class AcceptAllFileFilter ------------------------------------------ //---- class AcceptAllFileFilter ------------------------------------------
private static final class AcceptAllFileFilter private static final class AcceptAllFileFilter

View File

@@ -199,8 +199,9 @@ public class TestFlatStyleableInfo
"disabledForeground", Color.class, "disabledForeground", Color.class,
"buttonBackground", Color.class, "buttonBackground", Color.class,
"buttonFocusedBackground", Color.class,
"buttonEditableBackground", Color.class, "buttonEditableBackground", Color.class,
"buttonFocusedBackground", Color.class,
"buttonFocusedEditableBackground", Color.class,
"buttonSeparatorWidth", float.class, "buttonSeparatorWidth", float.class,
"buttonSeparatorColor", Color.class, "buttonSeparatorColor", Color.class,
"buttonDisabledSeparatorColor", Color.class, "buttonDisabledSeparatorColor", Color.class,

View File

@@ -388,8 +388,9 @@ public class TestFlatStyleableValue
testColor( c, ui, "disabledForeground" ); testColor( c, ui, "disabledForeground" );
testColor( c, ui, "buttonBackground" ); testColor( c, ui, "buttonBackground" );
testColor( c, ui, "buttonFocusedBackground" );
testColor( c, ui, "buttonEditableBackground" ); testColor( c, ui, "buttonEditableBackground" );
testColor( c, ui, "buttonFocusedBackground" );
testColor( c, ui, "buttonFocusedEditableBackground" );
testFloat( c, ui, "buttonSeparatorWidth" ); testFloat( c, ui, "buttonSeparatorWidth" );
testColor( c, ui, "buttonSeparatorColor" ); testColor( c, ui, "buttonSeparatorColor" );
testColor( c, ui, "buttonDisabledSeparatorColor" ); testColor( c, ui, "buttonDisabledSeparatorColor" );

View File

@@ -24,7 +24,7 @@
// increase this version if changing API or functionality of native library // increase this version if changing API or functionality of native library
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeLinuxLibrary // also update version in Java class com.formdev.flatlaf.ui.FlatNativeLinuxLibrary
#define API_VERSION_LINUX 3003 #define API_VERSION_LINUX 3004
//---- JNI methods ------------------------------------------------------------ //---- JNI methods ------------------------------------------------------------

View File

@@ -33,6 +33,9 @@ extern Window getWindowHandle( JNIEnv* env, JAWT* awt, jobject window, Display**
// declare internal methods // declare internal methods
static jobjectArray fileListToStringArray( JNIEnv* env, GSList* fileList ); static jobjectArray fileListToStringArray( JNIEnv* env, GSList* fileList );
// fields
static int settingsSchemaInstalled = -1;
//---- helper ----------------------------------------------------------------- //---- helper -----------------------------------------------------------------
#define isOptionSet( option ) ((optionsSet & com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_ ## option) != 0) #define isOptionSet( option ) ((optionsSet & com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_ ## option) != 0)
@@ -58,6 +61,7 @@ static void initFilters( GtkFileChooser* chooser, JNIEnv* env, jint fileTypeInde
gtk_file_chooser_add_filter( chooser, filter ); gtk_file_chooser_add_filter( chooser, filter );
if( fileTypeIndex == filterIndex ) if( fileTypeIndex == filterIndex )
gtk_file_chooser_set_filter( chooser, filter ); gtk_file_chooser_set_filter( chooser, filter );
g_object_set_data( G_OBJECT( filter ), "flatlaf-filter-index", GINT_TO_POINTER( filterIndex + 1 ) );
filter = NULL; filter = NULL;
filterIndex++; filterIndex++;
} }
@@ -130,32 +134,42 @@ struct ResponseData {
JNIEnv* env; JNIEnv* env;
jobject callback; jobject callback;
GSList* fileList; GSList* fileList;
int filterIndex;
ResponseData( JNIEnv* _env, jobject _callback ) { ResponseData( JNIEnv* _env, jobject _callback ) {
env = _env; env = _env;
callback = _callback; callback = _callback;
fileList = NULL; fileList = NULL;
filterIndex = -1;
} }
}; };
static void handle_response( GtkWidget* dialog, gint responseId, gpointer data ) { static void handle_response( GtkWidget* dialog, gint responseId, gpointer data ) {
GtkFileChooser* chooser = GTK_FILE_CHOOSER( dialog );
ResponseData *response = static_cast<ResponseData*>( data );
// get selected filter (even if user cancels dialog)
GtkFileFilter* filter = gtk_file_chooser_get_filter( chooser );
response->filterIndex = (filter != NULL)
? GPOINTER_TO_INT( g_object_get_data( G_OBJECT( filter ), "flatlaf-filter-index" ) ) - 1
: -1;
// get filenames if user pressed OK // get filenames if user pressed OK
if( responseId == GTK_RESPONSE_ACCEPT ) { if( responseId == GTK_RESPONSE_ACCEPT ) {
ResponseData *response = static_cast<ResponseData*>( data );
if( response->callback != NULL ) { if( response->callback != NULL ) {
GSList* fileList = gtk_file_chooser_get_filenames( GTK_FILE_CHOOSER( dialog ) ); GSList* fileList = gtk_file_chooser_get_filenames( chooser );
jobjectArray files = fileListToStringArray( response->env, fileList ); jobjectArray files = fileListToStringArray( response->env, fileList );
jint filterIndex = response->filterIndex;
GtkWindow* window = GTK_WINDOW( dialog ); GtkWindow* window = GTK_WINDOW( dialog );
// invoke callback: boolean approve( String[] files, long hwnd ); // invoke callback: boolean approve( String[] files, long hwnd );
jclass cls = response->env->GetObjectClass( response->callback ); jclass cls = response->env->GetObjectClass( response->callback );
jmethodID approveID = response->env->GetMethodID( cls, "approve", "([Ljava/lang/String;J)Z" ); jmethodID approveID = response->env->GetMethodID( cls, "approve", "([Ljava/lang/String;IJ)Z" );
if( approveID != NULL && !response->env->CallBooleanMethod( response->callback, approveID, files, window ) ) if( approveID != NULL && !response->env->CallBooleanMethod( response->callback, approveID, files, filterIndex, window ) )
return; // keep dialog open return; // keep dialog open
} }
response->fileList = gtk_file_chooser_get_filenames( GTK_FILE_CHOOSER( dialog ) ); response->fileList = gtk_file_chooser_get_filenames( chooser );
} }
// hide/destroy file dialog and quit loop // hide/destroy file dialog and quit loop
@@ -170,12 +184,29 @@ extern "C"
JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_showFileChooser JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_showFileChooser
( JNIEnv* env, jclass cls, jobject owner, jint dark, jboolean open, ( JNIEnv* env, jclass cls, jobject owner, jint dark, jboolean open,
jstring title, jstring okButtonLabel, jstring currentName, jstring currentFolder, jstring title, jstring okButtonLabel, jstring currentName, jstring currentFolder,
jint optionsSet, jint optionsClear, jobject callback, jint fileTypeIndex, jobjectArray fileTypes ) jint optionsSet, jint optionsClear, jobject callback,
jint fileTypeIndex, jobjectArray fileTypes, jintArray retFileTypeIndex )
{ {
// initialize GTK // initialize GTK
if( !gtk_init_check( NULL, NULL ) ) if( !gtk_init_check( NULL, NULL ) )
return NULL; return NULL;
// check whether required GSettings schemas are installed (e.g. on NixOS)
// this avoids output of following message on console, followed by an application crash:
// GLib-GIO-ERROR: No GSettings schemas are installed on the system
if( settingsSchemaInstalled < 0 ) {
GSettingsSchemaSource* schemaSource = g_settings_schema_source_get_default();
GSettingsSchema* schema = (schemaSource != NULL)
? g_settings_schema_source_lookup( schemaSource, "org.gtk.Settings.FileChooser", FALSE )
: NULL;
if( schema != NULL )
g_settings_schema_unref( schema );
settingsSchemaInstalled = (schema != NULL);
}
if( settingsSchemaInstalled <= 0 )
return NULL;
// convert Java strings to C strings // convert Java strings to C strings
AutoReleaseStringUTF8 ctitle( env, title ); AutoReleaseStringUTF8 ctitle( env, title );
AutoReleaseStringUTF8 cokButtonLabel( env, okButtonLabel ); AutoReleaseStringUTF8 cokButtonLabel( env, okButtonLabel );
@@ -282,7 +313,11 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrar
// start event loop (will be quit in respone handler) // start event loop (will be quit in respone handler)
gtk_main(); gtk_main();
// canceled? // return selected filter
jint selectedFilterIndex = responseData.filterIndex;
env->SetIntArrayRegion( retFileTypeIndex, 0, 1, &selectedFilterIndex );
// return empty array if canceled
if( responseData.fileList == NULL ) if( responseData.fileList == NULL )
return newJavaStringArray( env, 0 ); return newJavaStringArray( env, 0 );

View File

@@ -64,10 +64,10 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_is
/* /*
* Class: com_formdev_flatlaf_ui_FlatNativeLinuxLibrary * Class: com_formdev_flatlaf_ui_FlatNativeLinuxLibrary
* Method: showFileChooser * Method: showFileChooser
* Signature: (Ljava/awt/Window;IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILcom/formdev/flatlaf/ui/FlatNativeLinuxLibrary/FileChooserCallback;I[Ljava/lang/String;)[Ljava/lang/String; * Signature: (Ljava/awt/Window;IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILcom/formdev/flatlaf/ui/FlatNativeLinuxLibrary/FileChooserCallback;I[Ljava/lang/String;[I)[Ljava/lang/String;
*/ */
JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_showFileChooser JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLinuxLibrary_showFileChooser
(JNIEnv *, jclass, jobject, jint, jboolean, jstring, jstring, jstring, jstring, jint, jint, jobject, jint, jobjectArray); (JNIEnv *, jclass, jobject, jint, jboolean, jstring, jstring, jstring, jstring, jint, jint, jobject, jint, jobjectArray, jintArray);
/* /*
* Class: com_formdev_flatlaf_ui_FlatNativeLinuxLibrary * Class: com_formdev_flatlaf_ui_FlatNativeLinuxLibrary

View File

@@ -82,10 +82,10 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_togg
/* /*
* Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary * Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary
* Method: showFileChooser * Method: showFileChooser
* Signature: (Ljava/awt/Window;IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILcom/formdev/flatlaf/ui/FlatNativeMacLibrary/FileChooserCallback;I[Ljava/lang/String;)[Ljava/lang/String; * Signature: (Ljava/awt/Window;IZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILcom/formdev/flatlaf/ui/FlatNativeMacLibrary/FileChooserCallback;I[Ljava/lang/String;[I)[Ljava/lang/String;
*/ */
JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_showFileChooser JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_showFileChooser
(JNIEnv *, jclass, jobject, jint, jboolean, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jint, jint, jobject, jint, jobjectArray); (JNIEnv *, jclass, jobject, jint, jboolean, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jint, jint, jobject, jint, jobjectArray, jintArray);
/* /*
* Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary * Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary

View File

@@ -24,7 +24,7 @@
// increase this version if changing API or functionality of native library // increase this version if changing API or functionality of native library
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeMacLibrary // also update version in Java class com.formdev.flatlaf.ui.FlatNativeMacLibrary
#define API_VERSION_MACOS 2002 #define API_VERSION_MACOS 2003
//---- JNI methods ------------------------------------------------------------ //---- JNI methods ------------------------------------------------------------

View File

@@ -35,6 +35,7 @@ static NSArray* getDialogURLs( NSSavePanel* dialog );
@interface FileChooserDelegate : NSObject <NSOpenSavePanelDelegate, NSWindowDelegate> { @interface FileChooserDelegate : NSObject <NSOpenSavePanelDelegate, NSWindowDelegate> {
NSArray* _filters; NSArray* _filters;
int _selectedFormatIndex;
JavaVM* _jvm; JavaVM* _jvm;
jobject _callback; jobject _callback;
@@ -43,18 +44,26 @@ static NSArray* getDialogURLs( NSSavePanel* dialog );
@property (nonatomic, assign) NSSavePanel* dialog; @property (nonatomic, assign) NSSavePanel* dialog;
- (id) init;
- (void) initFilterAccessoryView: (NSMutableArray*)filters :(int)filterIndex - (void) initFilterAccessoryView: (NSMutableArray*)filters :(int)filterIndex
:(NSString*)filterFieldLabel :(bool)showSingleFilterField; :(NSString*)filterFieldLabel :(bool)showSingleFilterField;
- (void) selectFormat: (id)sender; - (void) selectFormat: (id)sender;
- (void) selectFormatAtIndex: (int)index; - (void) selectFormatAtIndex: (int)index;
- (int) selectedFormatIndex;
@end @end
@implementation FileChooserDelegate @implementation FileChooserDelegate
- (id) init {
_selectedFormatIndex = -1;
return self;
}
- (void) initFilterAccessoryView: (NSMutableArray*)filters :(int)filterIndex - (void) initFilterAccessoryView: (NSMutableArray*)filters :(int)filterIndex
:(NSString*)filterFieldLabel :(bool)showSingleFilterField :(NSString*)filterFieldLabel :(bool)showSingleFilterField
{ {
_filters = filters; _filters = filters;
_selectedFormatIndex = filterIndex;
// get filter names // get filter names
NSArray* filterNames = filters.lastObject; NSArray* filterNames = filters.lastObject;
@@ -125,6 +134,12 @@ static NSArray* getDialogURLs( NSSavePanel* dialog );
// to support older macOS versions 10.14+ and because of some problems with allowedContentTypes: // to support older macOS versions 10.14+ and because of some problems with allowedContentTypes:
// https://github.com/chromium/chromium/blob/d8e0032963b7ca4728ff4117933c0feb3e479b7a/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm#L209-232 // https://github.com/chromium/chromium/blob/d8e0032963b7ca4728ff4117933c0feb3e479b7a/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm#L209-232
_dialog.allowedFileTypes = [fileTypes containsObject:@"*"] ? nil : fileTypes; _dialog.allowedFileTypes = [fileTypes containsObject:@"*"] ? nil : fileTypes;
_selectedFormatIndex = index;
}
- (int) selectedFormatIndex {
return _selectedFormatIndex;
} }
//---- NSOpenSavePanelDelegate ---- //---- NSOpenSavePanelDelegate ----
@@ -161,12 +176,13 @@ static NSArray* getDialogURLs( NSSavePanel* dialog );
JNI_THREAD_ENTER( _jvm, true ) JNI_THREAD_ENTER( _jvm, true )
jobjectArray files = urlsToStringArray( env, urls ); jobjectArray files = urlsToStringArray( env, urls );
jint selectedFormatIndex = ((FileChooserDelegate*)((NSSavePanel*)sender).delegate).selectedFormatIndex;
jlong window = (jlong) sender; jlong window = (jlong) sender;
// invoke callback: boolean approve( String[] files, long hwnd ); // invoke callback: boolean approve( String[] files, long hwnd );
jclass cls = env->GetObjectClass( _callback ); jclass cls = env->GetObjectClass( _callback );
jmethodID approveID = env->GetMethodID( cls, "approve", "([Ljava/lang/String;J)Z" ); jmethodID approveID = env->GetMethodID( cls, "approve", "([Ljava/lang/String;IJ)Z" );
if( approveID != NULL && !env->CallBooleanMethod( _callback, approveID, files, window ) ) { if( approveID != NULL && !env->CallBooleanMethod( _callback, approveID, files, selectedFormatIndex, window ) ) {
_urlsSet = NULL; _urlsSet = NULL;
return false; // keep dialog open return false; // keep dialog open
} }
@@ -265,7 +281,8 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_
( JNIEnv* env, jclass cls, jobject owner, jint dark, jboolean open, ( JNIEnv* env, jclass cls, jobject owner, jint dark, jboolean open,
jstring title, jstring prompt, jstring message, jstring filterFieldLabel, jstring title, jstring prompt, jstring message, jstring filterFieldLabel,
jstring nameFieldLabel, jstring nameFieldStringValue, jstring directoryURL, jstring nameFieldLabel, jstring nameFieldStringValue, jstring directoryURL,
jint optionsSet, jint optionsClear, jobject callback, jint fileTypeIndex, jobjectArray fileTypes ) jint optionsSet, jint optionsClear, jobject callback,
jint fileTypeIndex, jobjectArray fileTypes, jintArray retFileTypeIndex )
{ {
JNI_COCOA_ENTER() JNI_COCOA_ENTER()
@@ -365,17 +382,26 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_
// show dialog // show dialog
NSModalResponse response = [dialog runModal]; NSModalResponse response = [dialog runModal];
// return selected filter
jint selectedFormatIndex = delegate.selectedFormatIndex;
env->SetIntArrayRegion( retFileTypeIndex, 0, 1, &selectedFormatIndex );
[delegate release]; [delegate release];
// return empty array if canceled
if( response != NSModalResponseOK ) { if( response != NSModalResponseOK ) {
*purls = @[]; *purls = @[];
return; return;
} }
// get selected file(s)
*purls = getDialogURLs( dialog ); *purls = getDialogURLs( dialog );
JNI_COCOA_CATCH() JNI_COCOA_CATCH()
}]; }];
// return null on failures
if( urls == NULL ) if( urls == NULL )
return NULL; return NULL;

View File

@@ -24,7 +24,7 @@
// increase this version if changing API or functionality of native library // increase this version if changing API or functionality of native library
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeWindowsLibrary // also update version in Java class com.formdev.flatlaf.ui.FlatNativeWindowsLibrary
#define API_VERSION_WINDOWS 1002 #define API_VERSION_WINDOWS 1003
//---- JNI methods ------------------------------------------------------------ //---- JNI methods ------------------------------------------------------------

View File

@@ -128,6 +128,11 @@ public:
} else } else
files = getFiles( env, false, dialog ); files = getFiles( env, false, dialog );
// get selected filter
UINT selectedFileTypeIndex = 0;
dialog->GetFileTypeIndex( &selectedFileTypeIndex );
jint jselectedFileTypeIndex = selectedFileTypeIndex - 1;
// get hwnd of file dialog // get hwnd of file dialog
HWND hwndFileDialog = 0; HWND hwndFileDialog = 0;
AutoReleasePtr<IOleWindow> window; AutoReleasePtr<IOleWindow> window;
@@ -136,10 +141,10 @@ public:
// invoke callback: boolean approve( String[] files, long hwnd ); // invoke callback: boolean approve( String[] files, long hwnd );
jclass cls = env->GetObjectClass( callback ); jclass cls = env->GetObjectClass( callback );
jmethodID approveID = env->GetMethodID( cls, "approve", "([Ljava/lang/String;J)Z" ); jmethodID approveID = env->GetMethodID( cls, "approve", "([Ljava/lang/String;IJ)Z" );
if( approveID == NULL ) if( approveID == NULL )
return S_OK; return S_OK;
return env->CallBooleanMethod( callback, approveID, files, hwndFileDialog ) ? S_OK : S_FALSE; return env->CallBooleanMethod( callback, approveID, files, jselectedFileTypeIndex, hwndFileDialog ) ? S_OK : S_FALSE;
} }
IFACEMETHODIMP OnFolderChange( IFileDialog* ) { return S_OK; } IFACEMETHODIMP OnFolderChange( IFileDialog* ) { return S_OK; }
@@ -147,7 +152,7 @@ public:
IFACEMETHODIMP OnHelp( IFileDialog* ) { return S_OK; } IFACEMETHODIMP OnHelp( IFileDialog* ) { return S_OK; }
IFACEMETHODIMP OnSelectionChange( IFileDialog* ) { return S_OK; } IFACEMETHODIMP OnSelectionChange( IFileDialog* ) { return S_OK; }
IFACEMETHODIMP OnShareViolation( IFileDialog*, IShellItem*, FDE_SHAREVIOLATION_RESPONSE* ) { return S_OK; } IFACEMETHODIMP OnShareViolation( IFileDialog*, IShellItem*, FDE_SHAREVIOLATION_RESPONSE* ) { return S_OK; }
IFACEMETHODIMP OnTypeChange( IFileDialog*pfd ) { return S_OK; } IFACEMETHODIMP OnTypeChange( IFileDialog* ) { return S_OK; }
IFACEMETHODIMP OnOverwrite( IFileDialog*, IShellItem*, FDE_OVERWRITE_RESPONSE* ) { return S_OK; } IFACEMETHODIMP OnOverwrite( IFileDialog*, IShellItem*, FDE_OVERWRITE_RESPONSE* ) { return S_OK; }
//---- IUnknown methods ---- //---- IUnknown methods ----
@@ -213,7 +218,8 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
( JNIEnv* env, jclass cls, jobject owner, jboolean open, ( JNIEnv* env, jclass cls, jobject owner, jboolean open,
jstring title, jstring okButtonLabel, jstring fileNameLabel, jstring fileName, jstring title, jstring okButtonLabel, jstring fileNameLabel, jstring fileName,
jstring folder, jstring saveAsItem, jstring defaultFolder, jstring defaultExtension, jstring folder, jstring saveAsItem, jstring defaultFolder, jstring defaultExtension,
jint optionsSet, jint optionsClear, jobject callback, jint fileTypeIndex, jobjectArray fileTypes ) jint optionsSet, jint optionsClear, jobject callback,
jint fileTypeIndex, jobjectArray fileTypes, jintArray retFileTypeIndex )
{ {
// initialize COM library // initialize COM library
CoInitializer coInitializer; CoInitializer coInitializer;
@@ -285,6 +291,14 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
HWND hwndOwner = (owner != NULL) ? getWindowHandle( env, owner ) : NULL; HWND hwndOwner = (owner != NULL) ? getWindowHandle( env, owner ) : NULL;
HRESULT hr = dialog->Show( hwndOwner ); HRESULT hr = dialog->Show( hwndOwner );
dialog->Unadvise( dwCookie ); dialog->Unadvise( dwCookie );
// return selected filter
UINT selectedFileTypeIndex = 0;
CHECK_HRESULT( dialog->GetFileTypeIndex( &selectedFileTypeIndex ) );
jint jselectedFileTypeIndex = selectedFileTypeIndex - 1;
env->SetIntArrayRegion( retFileTypeIndex, 0, 1, &jselectedFileTypeIndex );
// return empty array if canceled
if( hr == HRESULT_FROM_WIN32(ERROR_CANCELLED) ) if( hr == HRESULT_FROM_WIN32(ERROR_CANCELLED) )
return newJavaStringArray( env, 0 ); return newJavaStringArray( env, 0 );
CHECK_HRESULT( hr ); CHECK_HRESULT( hr );

View File

@@ -116,10 +116,10 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_
/* /*
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary * Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary
* Method: showFileChooser * Method: showFileChooser
* Signature: (Ljava/awt/Window;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILcom/formdev/flatlaf/ui/FlatNativeWindowsLibrary/FileChooserCallback;I[Ljava/lang/String;)[Ljava/lang/String; * Signature: (Ljava/awt/Window;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILcom/formdev/flatlaf/ui/FlatNativeWindowsLibrary/FileChooserCallback;I[Ljava/lang/String;[I)[Ljava/lang/String;
*/ */
JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_showFileChooser JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibrary_showFileChooser
(JNIEnv *, jclass, jobject, jboolean, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jint, jint, jobject, jint, jobjectArray); (JNIEnv *, jclass, jobject, jboolean, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jstring, jint, jint, jobject, jint, jobjectArray, jintArray);
/* /*
* Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary * Class: com_formdev_flatlaf_ui_FlatNativeWindowsLibrary

View File

@@ -184,6 +184,7 @@ buttonDisabledArrowColor java.awt.Color
buttonDisabledSeparatorColor java.awt.Color buttonDisabledSeparatorColor java.awt.Color
buttonEditableBackground java.awt.Color buttonEditableBackground java.awt.Color
buttonFocusedBackground java.awt.Color buttonFocusedBackground java.awt.Color
buttonFocusedEditableBackground java.awt.Color
buttonHoverArrowColor java.awt.Color buttonHoverArrowColor java.awt.Color
buttonPressedArrowColor java.awt.Color buttonPressedArrowColor java.awt.Color
buttonSeparatorColor java.awt.Color buttonSeparatorColor java.awt.Color

View File

@@ -235,6 +235,7 @@ ComboBox.buttonDisabledArrowColor #ababab HSL 0 0 67 javax.swing.plaf.C
ComboBox.buttonDisabledSeparatorColor #000088 HSL 240 100 27 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonDisabledSeparatorColor #000088 HSL 240 100 27 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonEditableBackground #cccccc HSL 0 0 80 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonEditableBackground #cccccc HSL 0 0 80 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonFocusedBackground #ffff00 HSL 60 100 50 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonFocusedBackground #ffff00 HSL 60 100 50 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonFocusedEditableBackground #ffff44 HSL 60 100 63 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonHighlight #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHighlight #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonHoverArrowColor #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHoverArrowColor #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI]
ComboBox.buttonPressedArrowColor #0000ff HSL 240 100 50 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonPressedArrowColor #0000ff HSL 240 100 50 javax.swing.plaf.ColorUIResource [UI]

View File

@@ -110,8 +110,8 @@ public class FlatSystemFileChooserLinuxTest
} }
int fileTypeIndex = fileTypeIndexSlider.getValue(); int fileTypeIndex = fileTypeIndexSlider.getValue();
FlatNativeLinuxLibrary.FileChooserCallback callback = (files, hwndFileDialog) -> { FlatNativeLinuxLibrary.FileChooserCallback callback = (files, fileTypeIndex2, hwndFileDialog) -> {
System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) ); System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) + " " + fileTypeIndex2 );
if( showMessageDialogOnOKCheckBox.isSelected() ) { if( showMessageDialogOnOKCheckBox.isSelected() ) {
System.out.println( FlatNativeLinuxLibrary.showMessageDialog( hwndFileDialog, System.out.println( FlatNativeLinuxLibrary.showMessageDialog( hwndFileDialog,
JOptionPane.INFORMATION_MESSAGE, JOptionPane.INFORMATION_MESSAGE,
@@ -124,24 +124,28 @@ public class FlatSystemFileChooserLinuxTest
int dark = FlatLaf.isLafDark() ? 1 : 0; int dark = FlatLaf.isLafDark() ? 1 : 0;
if( direct ) { if( direct ) {
int[] retFileTypeIndex = { -1 };
String[] files = FlatNativeLinuxLibrary.showFileChooser( owner, dark, open, String[] files = FlatNativeLinuxLibrary.showFileChooser( owner, dark, open,
title, okButtonLabel, currentName, currentFolder, title, okButtonLabel, currentName, currentFolder,
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes ); optionsSet.get(), optionsClear.get(), callback,
fileTypeIndex, fileTypes, retFileTypeIndex );
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" ); outputResult( files, retFileTypeIndex[0] );
} else { } else {
SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop(); SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
String[] fileTypes2 = fileTypes; String[] fileTypes2 = fileTypes;
new Thread( () -> { new Thread( () -> {
int[] retFileTypeIndex = { -1 };
String[] files = FlatNativeLinuxLibrary.showFileChooser( owner, dark, open, String[] files = FlatNativeLinuxLibrary.showFileChooser( owner, dark, open,
title, okButtonLabel, currentName, currentFolder, title, okButtonLabel, currentName, currentFolder,
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes2 ); optionsSet.get(), optionsClear.get(), callback,
fileTypeIndex, fileTypes2, retFileTypeIndex );
System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() ); System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() );
EventQueue.invokeLater( () -> { EventQueue.invokeLater( () -> {
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" ); outputResult( files, retFileTypeIndex[0] );
} ); } );
} ).start(); } ).start();
@@ -150,6 +154,11 @@ public class FlatSystemFileChooserLinuxTest
} }
} }
private void outputResult( String[] files, int retFileTypeIndex ) {
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" );
filesField.append( "\n\nretFileTypeIndex " + retFileTypeIndex );
}
private static String n( String s ) { private static String n( String s ) {
return s != null && !s.isEmpty() ? s : null; return s != null && !s.isEmpty() ? s : null;
} }

View File

@@ -145,8 +145,8 @@ public class FlatSystemFileChooserMacTest
} }
int fileTypeIndex = fileTypeIndexSlider.getValue(); int fileTypeIndex = fileTypeIndexSlider.getValue();
FlatNativeMacLibrary.FileChooserCallback callback = (files, hwndFileDialog) -> { FlatNativeMacLibrary.FileChooserCallback callback = (files, fileTypeIndex2, hwndFileDialog) -> {
System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) ); System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) + " " + fileTypeIndex2 );
if( showMessageDialogOnOKCheckBox.isSelected() ) { if( showMessageDialogOnOKCheckBox.isSelected() ) {
int result = FlatNativeMacLibrary.showMessageDialog( hwndFileDialog, int result = FlatNativeMacLibrary.showMessageDialog( hwndFileDialog,
JOptionPane.INFORMATION_MESSAGE, JOptionPane.INFORMATION_MESSAGE,
@@ -160,26 +160,30 @@ public class FlatSystemFileChooserMacTest
int dark = FlatLaf.isLafDark() ? 1 : 0; int dark = FlatLaf.isLafDark() ? 1 : 0;
if( direct ) { if( direct ) {
int[] retFileTypeIndex = { -1 };
String[] files = FlatNativeMacLibrary.showFileChooser( owner, dark, open, String[] files = FlatNativeMacLibrary.showFileChooser( owner, dark, open,
title, prompt, message, filterFieldLabel, title, prompt, message, filterFieldLabel,
nameFieldLabel, nameFieldStringValue, directoryURL, nameFieldLabel, nameFieldStringValue, directoryURL,
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes ); optionsSet.get(), optionsClear.get(), callback,
fileTypeIndex, fileTypes, retFileTypeIndex );
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" ); outputResult( files, retFileTypeIndex[0] );
} else { } else {
SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop(); SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
String[] fileTypes2 = fileTypes; String[] fileTypes2 = fileTypes;
new Thread( () -> { new Thread( () -> {
int[] retFileTypeIndex = { -1 };
String[] files = FlatNativeMacLibrary.showFileChooser( owner, dark, open, String[] files = FlatNativeMacLibrary.showFileChooser( owner, dark, open,
title, prompt, message, filterFieldLabel, title, prompt, message, filterFieldLabel,
nameFieldLabel, nameFieldStringValue, directoryURL, nameFieldLabel, nameFieldStringValue, directoryURL,
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes2 ); optionsSet.get(), optionsClear.get(), callback,
fileTypeIndex, fileTypes2, retFileTypeIndex );
System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() ); System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() );
SwingUtilities.invokeLater( () -> { SwingUtilities.invokeLater( () -> {
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" ); outputResult( files, retFileTypeIndex[0] );
} ); } );
} ).start(); } ).start();
@@ -188,6 +192,11 @@ public class FlatSystemFileChooserMacTest
} }
} }
private void outputResult( String[] files, int retFileTypeIndex ) {
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" );
filesField.append( "\n\nretFileTypeIndex " + retFileTypeIndex );
}
private static String n( String s ) { private static String n( String s ) {
return s != null && !s.isEmpty() ? s : null; return s != null && !s.isEmpty() ? s : null;
} }

View File

@@ -234,7 +234,9 @@ public class FlatSystemFileChooserTest
for( int i = 0; i < fileTypes.length; i += 2 ) { for( int i = 0; i < fileTypes.length; i += 2 ) {
fc.addChoosableFileFilter( "*".equals( fileTypes[i+1] ) fc.addChoosableFileFilter( "*".equals( fileTypes[i+1] )
? fc.getAcceptAllFileFilter() ? fc.getAcceptAllFileFilter()
: new SystemFileChooser.FileNameExtensionFilter( fileTypes[i], fileTypes[i+1].split( ";" ) ) ); : ((fileTypes[i+1].indexOf( '*' ) >= 0 || fileTypes[i+1].indexOf( '?' ) >= 0)
? new SystemFileChooser.PatternFilter( fileTypes[i], fileTypes[i+1].split( ";" ) )
: new SystemFileChooser.FileNameExtensionFilter( fileTypes[i], fileTypes[i+1].split( ";" ) )) );
} }
SystemFileChooser.FileFilter[] filters = fc.getChoosableFileFilters(); SystemFileChooser.FileFilter[] filters = fc.getChoosableFileFilters();
if( filters.length > 0 ) if( filters.length > 0 )
@@ -310,7 +312,8 @@ public class FlatSystemFileChooserTest
"result", result, "result", result,
"currentDirectory", fc.getCurrentDirectory(), "currentDirectory", fc.getCurrentDirectory(),
"selectedFile", fc.getSelectedFile(), "selectedFile", fc.getSelectedFile(),
"selectedFiles", fc.getSelectedFiles() ); "selectedFiles", fc.getSelectedFiles(),
"fileFilter", fc.getFileFilter() );
} }
private void outputSwingFileChooser( String type, JFileChooser fc, int result ) { private void outputSwingFileChooser( String type, JFileChooser fc, int result ) {
@@ -319,7 +322,8 @@ public class FlatSystemFileChooserTest
"result", result, "result", result,
"currentDirectory", fc.getCurrentDirectory(), "currentDirectory", fc.getCurrentDirectory(),
"selectedFile", fc.getSelectedFile(), "selectedFile", fc.getSelectedFile(),
"selectedFiles", fc.getSelectedFiles() ); "selectedFiles", fc.getSelectedFiles(),
"fileFilter", fc.getFileFilter() );
} }
private void outputAWTFileChooser( FileDialog fc ) { private void outputAWTFileChooser( FileDialog fc ) {

View File

@@ -131,8 +131,8 @@ public class FlatSystemFileChooserWindowsTest
fileTypes = fileTypesStr.trim().split( "[,]+" ); fileTypes = fileTypesStr.trim().split( "[,]+" );
int fileTypeIndex = fileTypeIndexSlider.getValue(); int fileTypeIndex = fileTypeIndexSlider.getValue();
FlatNativeWindowsLibrary.FileChooserCallback callback = (files, hwndFileDialog) -> { FlatNativeWindowsLibrary.FileChooserCallback callback = (files, fileTypeIndex2, hwndFileDialog) -> {
System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) ); System.out.println( " -- callback " + hwndFileDialog + " " + Arrays.toString( files ) + " " + fileTypeIndex2 );
if( showMessageDialogOnOKCheckBox.isSelected() ) { if( showMessageDialogOnOKCheckBox.isSelected() ) {
System.out.println( FlatNativeWindowsLibrary.showMessageDialog( hwndFileDialog, System.out.println( FlatNativeWindowsLibrary.showMessageDialog( hwndFileDialog,
JOptionPane.INFORMATION_MESSAGE, JOptionPane.INFORMATION_MESSAGE,
@@ -142,26 +142,30 @@ public class FlatSystemFileChooserWindowsTest
}; };
if( direct ) { if( direct ) {
int[] retFileTypeIndex = { -1 };
String[] files = FlatNativeWindowsLibrary.showFileChooser( owner, open, String[] files = FlatNativeWindowsLibrary.showFileChooser( owner, open,
title, okButtonLabel, fileNameLabel, fileName, title, okButtonLabel, fileNameLabel, fileName,
folder, saveAsItem, defaultFolder, defaultExtension, folder, saveAsItem, defaultFolder, defaultExtension,
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes ); optionsSet.get(), optionsClear.get(), callback,
fileTypeIndex, fileTypes, retFileTypeIndex );
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" ); outputResult( files, retFileTypeIndex[0] );
} else { } else {
SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop(); SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
String[] fileTypes2 = fileTypes; String[] fileTypes2 = fileTypes;
new Thread( () -> { new Thread( () -> {
int[] retFileTypeIndex = { -1 };
String[] files = FlatNativeWindowsLibrary.showFileChooser( owner, open, String[] files = FlatNativeWindowsLibrary.showFileChooser( owner, open,
title, okButtonLabel, fileNameLabel, fileName, title, okButtonLabel, fileNameLabel, fileName,
folder, saveAsItem, defaultFolder, defaultExtension, folder, saveAsItem, defaultFolder, defaultExtension,
optionsSet.get(), optionsClear.get(), callback, fileTypeIndex, fileTypes2 ); optionsSet.get(), optionsClear.get(), callback,
fileTypeIndex, fileTypes2, retFileTypeIndex );
System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() ); System.out.println( " secondaryLoop.exit() returned " + secondaryLoop.exit() );
EventQueue.invokeLater( () -> { EventQueue.invokeLater( () -> {
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" ); outputResult( files, retFileTypeIndex[0] );
} ); } );
} ).start(); } ).start();
@@ -170,6 +174,11 @@ public class FlatSystemFileChooserWindowsTest
} }
} }
private void outputResult( String[] files, int retFileTypeIndex ) {
filesField.setText( (files != null) ? Arrays.toString( files ).replace( ',', '\n' ) : "null" );
filesField.append( "\n\nretFileTypeIndex " + retFileTypeIndex );
}
private static String n( String s ) { private static String n( String s ) {
return s != null && !s.isEmpty() ? s : null; return s != null && !s.isEmpty() ? s : null;
} }

View File

@@ -182,6 +182,7 @@ ComboBox.buttonEditableBackground = #ccc
ComboBox.focusedBackground = #ff8 ComboBox.focusedBackground = #ff8
ComboBox.buttonFocusedBackground = #ff0 ComboBox.buttonFocusedBackground = #ff0
ComboBox.buttonFocusedEditableBackground = #ff4
ComboBox.popupBackground = #ffc ComboBox.popupBackground = #ffc

View File

@@ -226,6 +226,7 @@ ComboBox.buttonDisabledArrowColor
ComboBox.buttonDisabledSeparatorColor ComboBox.buttonDisabledSeparatorColor
ComboBox.buttonEditableBackground ComboBox.buttonEditableBackground
ComboBox.buttonFocusedBackground ComboBox.buttonFocusedBackground
ComboBox.buttonFocusedEditableBackground
ComboBox.buttonHighlight ComboBox.buttonHighlight
ComboBox.buttonHoverArrowColor ComboBox.buttonHoverArrowColor
ComboBox.buttonPressedArrowColor ComboBox.buttonPressedArrowColor

View File

@@ -15,7 +15,7 @@
# #
flatlaf.releaseVersion = 3.7 flatlaf.releaseVersion = 3.7
flatlaf.developmentVersion = 3.8-SNAPSHOT flatlaf.developmentVersion = 3.7.1-SNAPSHOT
org.gradle.configuration-cache = true org.gradle.configuration-cache = true
# org.gradle.warning.mode = all # org.gradle.warning.mode = all