|
|
|
@ -2,16 +2,22 @@ package com.fr.design.gui.ifilechooser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
import com.fr.design.upm.UpmUtils; |
|
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.sun.javafx.application.PlatformImpl; |
|
|
|
|
import javafx.application.Platform; |
|
|
|
|
import javafx.scene.Scene; |
|
|
|
|
import javafx.scene.control.Label; |
|
|
|
|
import javafx.scene.layout.Background; |
|
|
|
|
import javafx.scene.layout.BackgroundFill; |
|
|
|
|
import javafx.scene.paint.Color; |
|
|
|
|
import javafx.stage.DirectoryChooser; |
|
|
|
|
import javafx.stage.FileChooser; |
|
|
|
|
import javafx.stage.Window; |
|
|
|
|
import javafx.stage.Modality; |
|
|
|
|
import javafx.stage.Stage; |
|
|
|
|
import javafx.stage.StageStyle; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.util.List; |
|
|
|
@ -40,9 +46,17 @@ public class JavaFxNativeFileChooser implements FileChooserProvider {
|
|
|
|
|
@Override |
|
|
|
|
public int showDialog(Component parent) { |
|
|
|
|
final CountDownLatch latch = new CountDownLatch(1); |
|
|
|
|
PlatformImpl.startup(new Runnable() { |
|
|
|
|
PlatformImpl.startup(() -> { |
|
|
|
|
}); |
|
|
|
|
Platform.setImplicitExit(false); |
|
|
|
|
Platform.runLater(new Runnable() { |
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
Component fileChooserParent = parent; |
|
|
|
|
if (fileChooserParent == null) { |
|
|
|
|
fileChooserParent = DesignerContext.getDesignerFrame(); |
|
|
|
|
} |
|
|
|
|
Stage stage = showCoverStage(fileChooserParent); |
|
|
|
|
try { |
|
|
|
|
if (fileSelectionMode == FileSelectionMode.FILE || fileSelectionMode == FileSelectionMode.MULTIPLE_FILE) { |
|
|
|
|
FileChooser fileChooser = new FileChooser(); |
|
|
|
@ -50,12 +64,12 @@ public class JavaFxNativeFileChooser implements FileChooserProvider {
|
|
|
|
|
fileChooser.getExtensionFilters().addAll(filters); |
|
|
|
|
fileChooser.setInitialDirectory(currentDirectory); |
|
|
|
|
if (fileSelectionMode == FileSelectionMode.FILE) { |
|
|
|
|
File file = fileChooser.showOpenDialog(null); |
|
|
|
|
File file = fileChooser.showOpenDialog(stage); |
|
|
|
|
if (file != null) { |
|
|
|
|
selectedFiles = new File[]{file}; |
|
|
|
|
} |
|
|
|
|
} else if (fileSelectionMode == FileSelectionMode.MULTIPLE_FILE) { |
|
|
|
|
List<File> fileList = fileChooser.showOpenMultipleDialog(null); |
|
|
|
|
List<File> fileList = fileChooser.showOpenMultipleDialog(stage); |
|
|
|
|
if (fileList != null) { |
|
|
|
|
selectedFiles = new File[fileList.size()]; |
|
|
|
|
fileList.toArray(selectedFiles); |
|
|
|
@ -65,17 +79,70 @@ public class JavaFxNativeFileChooser implements FileChooserProvider {
|
|
|
|
|
DirectoryChooser directoryChooser = new DirectoryChooser(); |
|
|
|
|
directoryChooser.setTitle(title); |
|
|
|
|
directoryChooser.setInitialDirectory(currentDirectory); |
|
|
|
|
File folder = directoryChooser.showDialog(null); |
|
|
|
|
File folder = directoryChooser.showDialog(stage); |
|
|
|
|
if (folder != null) { |
|
|
|
|
selectedFiles = new File[]{folder}; |
|
|
|
|
} |
|
|
|
|
System.out.println(folder); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
} finally { |
|
|
|
|
latch.countDown(); |
|
|
|
|
closeCoverStage(stage); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void closeCoverStage(Stage stage) { |
|
|
|
|
if (stage != null) { |
|
|
|
|
stage.close(); |
|
|
|
|
closeCoverStage((Stage) stage.getOwner()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Stage showCoverStage(Component component) { |
|
|
|
|
try { |
|
|
|
|
if (component == null) |
|
|
|
|
return null; |
|
|
|
|
Stage parentStage = showCoverStage(component.getParent()); |
|
|
|
|
if (component instanceof JDialog || component instanceof JFrame) { |
|
|
|
|
return createStage(component.getX(), component.getY(), component.getWidth(), component.getHeight(), parentStage); |
|
|
|
|
} else { |
|
|
|
|
return parentStage; |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Stage createStage(double x, double y, double w, double h, Stage parentStage) { |
|
|
|
|
try { |
|
|
|
|
Stage stage = new Stage(); |
|
|
|
|
stage.setX(x); |
|
|
|
|
stage.setY(y); |
|
|
|
|
stage.setWidth(w); |
|
|
|
|
stage.setHeight(h); |
|
|
|
|
stage.setOpacity(0.2); |
|
|
|
|
stage.setResizable(false); |
|
|
|
|
stage.initStyle(StageStyle.UNDECORATED); |
|
|
|
|
|
|
|
|
|
Label label = new Label(); |
|
|
|
|
label.setBackground( |
|
|
|
|
new Background(new BackgroundFill(Color.color(0.78, 0.78, 0.80, 0.5), null, null))); |
|
|
|
|
stage.setScene(new Scene(label)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parentStage != null) { |
|
|
|
|
stage.initOwner(parentStage); |
|
|
|
|
stage.initModality(Modality.WINDOW_MODAL); |
|
|
|
|
} |
|
|
|
|
stage.show(); |
|
|
|
|
return stage; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|