Browse Source

Pull request #5377: REPORT-56532 文件选择器弹窗 && REPORT-56683 文件选择器弹窗-图片压缩功能入口迁移的初次提示问题

Merge in DESIGN/design from ~HENRY.WANG/design:feature/10.0 to feature/10.0

* commit '2502b232a93886df2b1c96387a4ae48786a54099':
  REPORT-56532 文件选择器弹窗 && REPORT-56683 文件选择器弹窗-图片压缩功能入口迁移的初次提示问题
feature/10.0
Henry.Wang 3 years ago
parent
commit
6ff19e4696
  1. 2
      designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java
  2. 87
      designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java
  3. 15
      designer-base/src/main/java/com/fr/design/style/background/image/ImageFileChooser.java

2
designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java

@ -503,7 +503,7 @@ public class PreferencePane extends BasicPane {
new JavaFxNativeFileChooser.Builder().
fileSelectionMode(FileSelectionMode.DIR).
build();
int saveValue = fileChooserProvider.showDialog(null);
int saveValue = fileChooserProvider.showDialog(chooseDirBtn);
if (saveValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooserProvider.getSelectedFile();
logExportDirectoryField.setText(selectedFile.getAbsolutePath());

87
designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java

@ -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;
}
}
});

15
designer-base/src/main/java/com/fr/design/style/background/image/ImageFileChooser.java

@ -32,11 +32,7 @@ public class ImageFileChooser {
new JavaFxNativeFileChooser.Builder().
fileSelectionMode(FileSelectionMode.FILE).
title(Toolkit.i18nText("Fine-Design_Basic_Open")).
filters(new FileChooser.ExtensionFilter[]{
new FileChooser.ExtensionFilter("jpg", "*.jpg"),
new FileChooser.ExtensionFilter("gif", "*.gif"),
new FileChooser.ExtensionFilter("png", "*.png"),
new FileChooser.ExtensionFilter("bmp", "*.bmp")}).
filter(Toolkit.i18nText("Fine-Design_Basic_Image_Image_Files"), "*.jpg", "*.gif", "*.png", "*.bmp").
build();
}
@ -72,8 +68,13 @@ public class ImageFileChooser {
private void showImageCompressMoveTip() {
if (DesignerEnvManager.getEnvManager().isShowImageCompressMoveTip()) {
DesignerToastMsgUtil.toastWarning(Toolkit.i18nText("Fine-Design_Image_Compress_Move_Tip"));
DesignerEnvManager.getEnvManager().setShowImageCompressMoveTip(false);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DesignerToastMsgUtil.toastWarning(Toolkit.i18nText("Fine-Design_Image_Compress_Move_Tip"));
DesignerEnvManager.getEnvManager().setShowImageCompressMoveTip(false);
}
});
}
}
}

Loading…
Cancel
Save