From 8c9c959a30f845da6dcd67c027cd028c35b72530 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Sat, 21 Aug 2021 09:35:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-57776=20=E6=96=87=E4=BB=B6=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8=E6=9B=BF=E6=8D=A2-=E4=B8=BBjar=E9=87=8C?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E8=A2=AB=E5=88=A0=E9=99=A4=E5=90=8E=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=E4=BA=86=E5=85=B6=E4=BB=96=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/ifilechooser/AbstractFileChooser.java | 104 ++++++++++++ .../gui/ifilechooser/UINativeFileChooser.java | 155 ++++++++++++++++++ 2 files changed, 259 insertions(+) create mode 100644 designer-base/src/main/java/com/fr/design/gui/ifilechooser/AbstractFileChooser.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/ifilechooser/UINativeFileChooser.java diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/AbstractFileChooser.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/AbstractFileChooser.java new file mode 100644 index 0000000000..b9a70557dc --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/AbstractFileChooser.java @@ -0,0 +1,104 @@ +package com.fr.design.gui.ifilechooser; + +import javax.swing.filechooser.FileFilter; +import java.awt.*; +import java.io.File; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/3/31 + */ +@Deprecated +public abstract class AbstractFileChooser { + + /** + * 返回当前目录 + * + */ + public abstract File getCurrentDirectory(); + + /** + * 返回当前的文件选择过滤器 + * + */ + public abstract FileFilter getFileFilter(); + + /** + * 返回选择的文件 + * + */ + public abstract File getSelectedFile(); + + /** + * 多文件选择模式下 返回选择的多个文件 + * + */ + public abstract File[] getSelectedFiles(); + + /** + * 是否可以选择多个文件 + * + */ + public abstract boolean isMultiSelectionEnabled(); + + /** + * 设置当前选择的目录 + * + */ + public abstract void setCurrentDirectory(File dir); + + /** + * 设置左上角标题 + * + */ + public abstract void setDialogTitle(String title); + + /** + * 设置当前的文件过滤器 + * + */ + public abstract void setFileFilter(final T filter); + + /** + * 设置文件选择器模式 + * + * JFileChooser.FILES_ONLY + * JFileChooser.DIRECTORIES_ONLY + * JFileChooser.FILES_AND_DIRECTORIES + */ + public abstract void setFileSelectionMode(E selectionMode); + + /** + * 设置是否允许选择多个文件 + * + */ + public abstract void setMultiSelectionEnabled(boolean multiple); + + /** + * 设置选择的文件 用于showSaveDialog + * + */ + public abstract void setSelectedFile(File file); + + /** + * 弹出文件选择器 打开文件 + * + */ + public abstract int showOpenDialog(Component parent); + + /** + * 弹出文件选择器 保存文件 + * + */ + public abstract int showSaveDialog(Component parent); + + + /** + * https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4031440 + * + * 设置文件名后缀 起到文件过滤的作用 形如 "*.jpg;*.jpeg" + * + */ + public abstract void setExtensionFilter(String file); +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/UINativeFileChooser.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/UINativeFileChooser.java new file mode 100644 index 0000000000..025edcf080 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/UINativeFileChooser.java @@ -0,0 +1,155 @@ +package com.fr.design.gui.ifilechooser; + +import com.fr.design.gui.ifilechooser.AbstractFileChooser; +import com.fr.design.mainframe.DesignerContext; +import com.fr.stable.os.OperatingSystem; + +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.awt.*; +import java.io.File; +import java.io.FilenameFilter; + + +/** + * 系统原生风格的文件选择器 + * + * jdk问题: + * https://bugs.openjdk.java.net/browse/JDK-4811090 不支持文件扩展选择 + * https://stackoverflow.com/questions/40713398/filter-not-working-in-filedialog windows下 setFilenameFilter不work + * + * @author hades + * @version 10.0 + * Created by hades on 2020/3/31 + */ +@Deprecated +public class UINativeFileChooser extends AbstractFileChooser { + + private final FileDialog fileDialog; + private FileFilter fileFilter; + private int selectionMode; + + public UINativeFileChooser(File file) { + fileDialog = new FileDialog(DesignerContext.getDesignerFrame()); + if (file != null) { + fileDialog.setDirectory(file.getAbsolutePath()); + fileDialog.setFile(file.toString()); + } + } + + public UINativeFileChooser() { + this(null); + } + + @Override + public File getCurrentDirectory() { + return new File(fileDialog.getDirectory()); + } + + @Override + public FileFilter getFileFilter() { + return fileFilter; + } + + @Override + public File getSelectedFile() { + return new File(fileDialog.getDirectory() + fileDialog.getFile()); + } + + @Override + public File[] getSelectedFiles() { + return fileDialog.getFiles(); + } + + @Override + public boolean isMultiSelectionEnabled() { + return fileDialog.isMultipleMode(); + } + + @Override + public void setCurrentDirectory(File f) { + fileDialog.setDirectory(f.toString()); + } + + @Override + public void setDialogTitle(String title) { + fileDialog.setTitle(title); + } + + @Override + public void setFileFilter(final FileFilter cff) { + FilenameFilter filter = new FilenameFilter() { + @Override + public boolean accept(File Directory, String fileName) { + return cff.accept(new File(Directory.getAbsolutePath() + fileName)); + } + }; + fileDialog.setFilenameFilter(filter); + fileFilter = cff; + } + + @Override + public void setFileSelectionMode(Integer selectionMode) { + this.selectionMode = selectionMode; + } + + @Override + public void setMultiSelectionEnabled(boolean multiple) { + fileDialog.setMultipleMode(multiple); + } + + @Override + public void setSelectedFile(File file) { + fileDialog.setDirectory(file.getAbsolutePath()); + fileDialog.setFile(file.getName()); + } + + @Override + public int showOpenDialog(Component parent) { + boolean appleProperty = OperatingSystem.isMacos() && selectionMode == JFileChooser.DIRECTORIES_ONLY; + if (appleProperty) { + System.setProperty("apple.awt.fileDialogForDirectories", "true"); + } + try { + fileDialog.setLocale(JComponent.getDefaultLocale()); + fileDialog.setMode(FileDialog.LOAD); + fileDialog.setVisible(true); + return fileDialog.getFile() == null ? JFileChooser.CANCEL_OPTION : JFileChooser.APPROVE_OPTION; + } finally { + if (appleProperty) { + System.setProperty("apple.awt.fileDialogForDirectories", "false"); + } + } + } + + @Override + public int showSaveDialog(Component parent) { + fileDialog.setLocale(JComponent.getDefaultLocale()); + fileDialog.setMode(FileDialog.SAVE); + fileDialog.setVisible(true); + return fileDialog.getFile() == null ? JFileChooser.CANCEL_OPTION : JFileChooser.APPROVE_OPTION; + } + + @Override + public void setExtensionFilter(String file) { + fileDialog.setFile(file); + } + + /** + * 确认本地文件选择器是否支持选择模式 + * @param selectionMode 选择模式 + * @return 是否支持选择模式 + */ + public static boolean supportsSelectionMode(int selectionMode) { + switch (selectionMode) { + case JFileChooser.FILES_AND_DIRECTORIES: + return false; + case JFileChooser.DIRECTORIES_ONLY: + return OperatingSystem.isMacos(); + case JFileChooser.FILES_ONLY: + default: + return true; + } + } + +} From 193e07f62bf1f4d9cd95f1de3c3b16455f25ea78 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Sat, 21 Aug 2021 10:22:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-55696=20=E5=9B=BD=E9=99=85=E5=8C=96-?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E7=89=88=E6=9C=AC=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA=E5=BC=B9=E7=AA=97=E5=9C=A8=E9=9D=9E?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E4=B8=8B=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/env/CheckServiceDialog.java | 7 ++++--- .../resources/com/fr/design/i18n/dimension_en.properties | 4 +++- .../com/fr/design/i18n/dimension_ja_JP.properties | 4 +++- .../com/fr/design/i18n/dimension_ko_KR.properties | 4 +++- .../resources/com/fr/design/i18n/dimension_zh.properties | 4 +++- .../com/fr/design/i18n/dimension_zh_TW.properties | 4 +++- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java index a921a03229..032f16a769 100644 --- a/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java +++ b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java @@ -5,6 +5,7 @@ import com.fr.design.RestartHelper; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.DesignSizeI18nManager; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; @@ -113,10 +114,10 @@ public class CheckServiceDialog extends JDialog implements ActionListener { font = font.applySize(15).applyStyle(1); UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Branch_Inconsistency")); label.setFont(font); - label.setPreferredSize(new Dimension(650, 30)); + label.setPreferredSize(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.version.detail.label")); UILabel label2 = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Sync_Inconsistency_Risk")); - label2.setPreferredSize(new Dimension(600, 30)); + label2.setPreferredSize(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.version.detail.label")); verticalPanel.add(label); verticalPanel.add(label2); @@ -201,7 +202,7 @@ public class CheckServiceDialog extends JDialog implements ActionListener { this.add(topPanel, BorderLayout.NORTH); this.add(centerPanel, BorderLayout.CENTER); this.add(buttonPanel, BorderLayout.SOUTH); - this.setSize(new Dimension(GeneralContext.getLocale().equals(Locale.US) ? 750 : 600, 500)); + this.setSize(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.version.detail.dialog")); this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties index bd26abb1be..dd33c6a6a4 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties @@ -4,4 +4,6 @@ com.fr.design.mainframe.check.CheckFontInfoDialog.messageWithLink=630*31 com.fr.design.mainframe.check.CheckFontInfoDialog.unfold=630*280 com.fr.design.report.ReportColumnsPane=800*600 com.fr.env.RemoteEnvPane.dialog=458*132 -com.fr.design.version.check.dialog=490*95 \ No newline at end of file +com.fr.design.version.check.dialog=490*95 +com.fr.design.version.detail.label=750*30 +com.fr.design.version.detail.dialog=900*500 \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties index 5a0cb009e3..b67a913e7a 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties @@ -3,4 +3,6 @@ com.fr.design.mainframe.check.CheckFontInfoDialog.collapse=610*185 com.fr.design.mainframe.check.CheckFontInfoDialog.messageWithLink=610*31 com.fr.design.mainframe.check.CheckFontInfoDialog.unfold=610*280 com.fr.env.RemoteEnvPane.dialog=458*132 -com.fr.design.version.check.dialog=430*95 \ No newline at end of file +com.fr.design.version.check.dialog=430*95 +com.fr.design.version.detail.label=650*30 +com.fr.design.version.detail.dialog=800*500 \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties index 17a8209db6..862580eedc 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties @@ -3,4 +3,6 @@ com.fr.design.mainframe.check.CheckFontInfoDialog.collapse=490*185 com.fr.design.mainframe.check.CheckFontInfoDialog.messageWithLink=490*35 com.fr.design.mainframe.check.CheckFontInfoDialog.unfold=490*280 com.fr.env.RemoteEnvPane.dialog=458*132 -com.fr.design.version.check.dialog=450*95 \ No newline at end of file +com.fr.design.version.check.dialog=450*95 +com.fr.design.version.detail.label=700*30 +com.fr.design.version.detail.dialog=850*500 \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties index 1c5f50ccaa..5a325b16bb 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties @@ -4,4 +4,6 @@ com.fr.design.mainframe.check.CheckFontInfoDialog.collapse=385*185 com.fr.design.mainframe.check.CheckFontInfoDialog.messageWithLink=385*31 com.fr.design.mainframe.check.CheckFontInfoDialog.unfold=385*280 com.fr.env.RemoteEnvPane.dialog=308*132 -com.fr.design.version.check.dialog=230*95 \ No newline at end of file +com.fr.design.version.check.dialog=230*95 +com.fr.design.version.detail.label=450*30 +com.fr.design.version.detail.dialog=600*500 \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties index fcbcb8c52a..1be37f9c7a 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties @@ -3,4 +3,6 @@ com.fr.design.mainframe.check.CheckFontInfoDialog.collapse=385*185 com.fr.design.mainframe.check.CheckFontInfoDialog.messageWithLink=385*31 com.fr.design.mainframe.check.CheckFontInfoDialog.unfold=385*280 com.fr.env.RemoteEnvPane.dialog=308*132 -com.fr.design.version.check.dialog=230*95 \ No newline at end of file +com.fr.design.version.check.dialog=230*95 +com.fr.design.version.detail.label=450*30 +com.fr.design.version.detail.dialog=600*500 \ No newline at end of file