diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 1f39f024d..b57ad6c7a 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -23,6 +23,7 @@ import com.fr.design.mainframe.ComponentReuseNotifyUtil; import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.notification.SnapChatConfig; +import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.port.DesignerPortContext; import com.fr.design.style.color.ColorSelectConfigManager; import com.fr.design.update.push.DesignerPushUpdateConfigManager; @@ -211,6 +212,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private int layoutTemplateStyle = LAYOUT_TEMPLATE_SIMPLE_STYLE; + private boolean useOptimizedUPM4Adapter; + /** * DesignerEnvManager. */ @@ -665,6 +668,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.showTemplateMissingPlugin = showTemplateMissingPlugin; } + public boolean isUseOptimizedUPM4Adapter() { + return useOptimizedUPM4Adapter; + } + + public void setUseOptimizedUPM4Adapter(boolean useOptimizedUPM4Adapter) { + this.useOptimizedUPM4Adapter = useOptimizedUPM4Adapter; + } + /** * 知否自动备份 * @@ -1888,6 +1899,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } this.setEmbedServerLazyStartup(reader.getAttrAsBoolean("embedServerLazyStartup", false)); this.setShowTemplateMissingPlugin(reader.getAttrAsBoolean("showTemplateMissingPlugin", true)); + this.setUseOptimizedUPM4Adapter(reader.getAttrAsBoolean("useOptimizedUPM4Adapter", SupportOSImpl.MACOS_12_VERSION_ADAPTER.support())); this.setShowServerDatasetAuthTip(reader.getAttrAsBoolean("showServerDatasetAuthTip", true)); this.setLayoutTemplateStyle(reader.getAttrAsInt("layoutTemplateStyle", LAYOUT_TEMPLATE_SIMPLE_STYLE)); } @@ -2165,6 +2177,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } writer.attr("layoutTemplateStyle", this.getLayoutTemplateStyle()); writer.attr("showServerDatasetAuthTip", this.isShowServerDatasetAuthTip()); + writer.attr("useOptimizedUPM4Adapter", this.isUseOptimizedUPM4Adapter()); writer.end(); } diff --git a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java index c0797e946..5a777b895 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java @@ -16,9 +16,10 @@ import com.fr.design.gui.ibutton.UINoThemeColorButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIDictionaryComboBox; +import com.fr.design.gui.ifilechooser.FileChooserArgs; +import com.fr.design.gui.ifilechooser.FileChooserFactory; import com.fr.design.gui.ifilechooser.FileChooserProvider; import com.fr.design.gui.ifilechooser.FileSelectionMode; -import com.fr.design.gui.ifilechooser.JavaFxNativeFileChooser; import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.iprogressbar.UIProgressBarUI; @@ -513,9 +514,8 @@ public class PreferencePane extends BasicPane { @Override public void actionPerformed(ActionEvent evt) { FileChooserProvider fileChooserProvider = - new JavaFxNativeFileChooser.Builder(). - fileSelectionMode(FileSelectionMode.DIR). - build(); + FileChooserFactory.createFileChooser(FileChooserArgs.newBuilder(). + setFileSelectionMode(FileSelectionMode.DIR).build()); int saveValue = fileChooserProvider.showDialog(chooseDirBtn); if (saveValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooserProvider.getSelectedFile(); @@ -728,7 +728,8 @@ public class PreferencePane extends BasicPane { this.portEditor.setValue(new Integer(designerEnvManager.getEmbedServerPort())); if (useOptimizedUPMCheckbox != null) { - useOptimizedUPMCheckbox.setSelected(ServerPreferenceConfig.getInstance().isUseOptimizedUPM()); + useOptimizedUPMCheckbox.setSelected(ServerPreferenceConfig.getInstance().isUseOptimizedUPM() + || DesignerEnvManager.getEnvManager().isUseOptimizedUPM4Adapter()); } if (useNewVersionLoginCheckbox != null) { @@ -808,6 +809,7 @@ public class PreferencePane extends BasicPane { designerEnvManager.setJoinProductImprove(this.joinProductImproveCheckBox.isSelected()); designerEnvManager.setEmbedServerLazyStartup(this.embedServerLazyStartupCheckBox.isSelected()); designerEnvManager.setImageCompress(this.imageCompressPanelCheckBox.isSelected()); + designerEnvManager.setUseOptimizedUPM4Adapter(this.useOptimizedUPMCheckbox != null && this.useOptimizedUPMCheckbox.isSelected()); VcsConfigManager vcsConfigManager = designerEnvManager.getVcsConfigManager(); vcsConfigManager.setSaveInterval(this.saveIntervalEditor.getValue()); vcsConfigManager.setVcsEnable(this.vcsEnableCheckBox.isSelected()); diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 920ecb78c..443a55671 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -15,7 +15,6 @@ import com.fr.design.mainframe.JVirtualTemplate; import com.fr.design.ui.util.UIUtil; import com.fr.file.FILE; import com.fr.file.FileNodeFILE; -import com.fr.file.StashedFILE; import com.fr.general.ComparatorUtils; import com.fr.invoke.ClassHelper; import com.fr.log.FineLoggerFactory; @@ -25,7 +24,7 @@ import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; import com.fr.third.org.apache.commons.io.FilenameUtils; -import java.io.ByteArrayOutputStream; +import javax.swing.SwingWorker; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -33,7 +32,6 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; -import javax.swing.SwingWorker; /** * 历史模板缓存 @@ -364,7 +362,7 @@ public class HistoryTemplateListCache implements CallbackEvent { int size = historyList.size(); for (int i = 0; i < size; i++) { JTemplate, ?> template = historyList.get(i); - FILE file = templateToStashFile(template); + FILE file = template.templateToStashFile(); if (file != null) { stashFILEMap.put(i, file); } @@ -372,21 +370,6 @@ public class HistoryTemplateListCache implements CallbackEvent { FineLoggerFactory.getLogger().info("Env Change Template Stashed."); } - private FILE templateToStashFile(JTemplate, ?> template) { - FILE file = template.getEditingFILE(); - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - BaseBook target = template.getTarget(); - if (target != null) { - target.export(outputStream); - return new StashedFILE(file, outputStream.toByteArray(), template.suffix()); - } - // 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理 - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return null; - } private boolean checkStash() { try { @@ -469,7 +452,7 @@ public class HistoryTemplateListCache implements CallbackEvent { FILE file = template.getEditingFILE(); boolean needReload = context == null || needReloadTemplate(context, template); if (needReload) { - FILE stashFile = templateToStashFile(template); + FILE stashFile = template.templateToStashFile(); if (stashFile != null) { FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName()); template.refreshResource(stashFile); diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java index a4354ee9d..795ff721f 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java @@ -814,10 +814,11 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { String formulaText = formulaTextArea.getText().trim(); String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText); if (unSupportFormula != null) { - showMessageDialog(Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula, false); + showMessageDialog(Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula, false, true); return; } + boolean calException = false; String messageTips; FormulaCheckResult checkResult = FormulaChecker.check(formulaText); if (checkResult.grammarValid()) { @@ -846,6 +847,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { } catch (Exception ce) { //模拟计算如果出现错误,则抛出错误 calResult = ce.getMessage(); + calException = true; FineLoggerFactory.getLogger().error(ce.getMessage(), ce); messageTips = messageTips + Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Error") + ":" + calResult; } @@ -854,7 +856,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { messageTips = checkResult.getTips(); } if (checkResult.isValid()) { - showMessageDialog(messageTips, checkResult.isValid()); + showMessageDialog(messageTips, checkResult.isValid(), calException); } else { confirmCheckResult(checkResult, messageTips); } @@ -871,7 +873,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { private boolean confirmCheckResult(FormulaCheckResult checkResult, String messageTips) { if (checkResult.isValid()) { - showMessageDialog(checkResult.getTips(), checkResult.isValid()); + showMessageDialog(checkResult.getTips(), checkResult.isValid(), false); } else { int columns = checkResult.getFormulaCoordinates().getColumns(); String position = StringUtils.EMPTY; @@ -897,8 +899,8 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { return true; } - private void showMessageDialog(String message, boolean formulaValid) { - if (formulaValid) { + private void showMessageDialog(String message, boolean formulaValid, boolean calException) { + if (formulaValid && !calException) { FineJOptionPane.showMessageDialog( FormulaPane.this, message); diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/ExtensionFilter.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/ExtensionFilter.java new file mode 100644 index 000000000..9ec582f69 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/ExtensionFilter.java @@ -0,0 +1,25 @@ +package com.fr.design.gui.ifilechooser; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2021/12/29 + */ +public class ExtensionFilter { + + private final String des; + private final String[] extensions; + + public ExtensionFilter(String des, String... extensions) { + this.des = des; + this.extensions = extensions; + } + + public String getDes() { + return des; + } + + public String[] getExtensions() { + return extensions; + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserArgs.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserArgs.java new file mode 100644 index 000000000..b011e5b35 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserArgs.java @@ -0,0 +1,109 @@ +package com.fr.design.gui.ifilechooser; + +/** + * 文件选择器可设置的参数集合 + * + * @author hades + * @version 10.0 + * Created by hades on 2021/12/21 + */ +public class FileChooserArgs { + + private final FileSelectionMode fileSelectionMode; + private final String filterDes; + private final String[] extensions; + private final String selectedPath; + private final ExtensionFilter[] filters; + private final String tipText; + private final boolean multiSelectionEnabled; + + public static Builder newBuilder() { + return new Builder(); + } + + private FileChooserArgs(Builder builder) { + this.fileSelectionMode = builder.fileSelectionMode; + this.filterDes = builder.filterDes; + this.extensions = builder.extensions; + this.selectedPath = builder.selectedPath; + this.filters = builder.filters; + this.tipText = builder.tipText; + this.multiSelectionEnabled = builder.multiSelectionEnabled; + } + + public FileSelectionMode getFileSelectionMode() { + return fileSelectionMode; + } + + public String getFilterDes() { + return filterDes; + } + + public String[] getExtensions() { + return extensions; + } + + public String getSelectedPath() { + return selectedPath; + } + + public ExtensionFilter[] getFilters() { + return filters; + } + + public String getTipText() { + return tipText; + } + + public boolean isMultiSelectionEnabled() { + return multiSelectionEnabled; + } + + public static class Builder { + + private FileSelectionMode fileSelectionMode; + private String filterDes; + private String[] extensions; + private String selectedPath; + private ExtensionFilter[] filters = new ExtensionFilter[0]; + private String tipText; + private boolean multiSelectionEnabled; + + public Builder setFileSelectionMode(FileSelectionMode fileSelectionMode) { + this.fileSelectionMode = fileSelectionMode; + return this; + } + + public Builder setFilter(String filterDes, String... extensions) { + this.filterDes = filterDes; + this.extensions = extensions; + return this; + } + + public Builder setSelectedPath(String selectedPath) { + this.selectedPath = selectedPath; + return this; + } + + public Builder setFilters(ExtensionFilter[] filters) { + this.filters = filters; + return this; + } + + public Builder setTipText(String tipText) { + this.tipText = tipText; + return this; + } + + public Builder setMultiSelectionEnabled(boolean multiSelectionEnabled) { + this.multiSelectionEnabled = multiSelectionEnabled; + return this; + } + + public FileChooserArgs build() { + return new FileChooserArgs(this); + } + } + + +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserFactory.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserFactory.java new file mode 100644 index 000000000..36a53c8dc --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserFactory.java @@ -0,0 +1,44 @@ +package com.fr.design.gui.ifilechooser; + +import com.fr.design.i18n.Toolkit; +import com.fr.design.os.impl.SupportOSImpl; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2021/12/21 + */ +public class FileChooserFactory { + + public static FileChooserProvider createFileChooser(FileChooserArgs fileChooserArgs) { + if (SupportOSImpl.OLD_STYLE_CHOOSER.support()) { + return new SwingFileChooser.Builder(). + setFileSelectionMode(fileChooserArgs.getFileSelectionMode()). + setFileFilter(fileChooserArgs.getFilterDes(), fileChooserArgs.getExtensions()). + setSelectedFile(fileChooserArgs.getSelectedPath()). + setMultiSelectionEnabled(fileChooserArgs.isMultiSelectionEnabled()). + setTipText(fileChooserArgs.getTipText()). + setFileFilter(fileChooserArgs.getFilters()).build(); + } else { + return new JavaFxNativeFileChooser.Builder(). + fileSelectionMode(fileChooserArgs.getFileSelectionMode()). + filter(fileChooserArgs.getFilterDes(), fileChooserArgs.getExtensions()). + currentDirectory(fileChooserArgs.getSelectedPath()). + title(fileChooserArgs.getTipText()). + filters(fileChooserArgs.getFilters()).build(); + } + } + + public static FileChooserProvider createImageFileChooser() { + if (SupportOSImpl.OLD_STYLE_CHOOSER.support()) { + return new SwingImageFileChooser(); + } else { + return new JavaFxNativeFileChooser.Builder(). + fileSelectionMode(FileSelectionMode.FILE). + title(Toolkit.i18nText("Fine-Design_Basic_Open")). + filter(Toolkit.i18nText("Fine-Design_Basic_Image_Image_Files"), "*.jpg", "*.gif", "*.png", "*.bmp"). + build(); + } + } + +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserProvider.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserProvider.java index aa95fe27b..a5d7e9730 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserProvider.java +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserProvider.java @@ -9,4 +9,17 @@ public interface FileChooserProvider { File getSelectedFile(); int showDialog(Component parent); + + + default int showOpenDialog(Component parent, String approveButtonText) { + return -1; + } + + default void setMultiSelectionEnabled(boolean multiple) { + + } + + default void setCurrentDirectory(File file) { + + } } diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java index fc4b8e368..4d3688324 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java @@ -4,6 +4,8 @@ package com.fr.design.gui.ifilechooser; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.log.FineLoggerFactory; +import com.fr.stable.ArrayUtils; +import com.fr.stable.StringUtils; import com.sun.javafx.application.PlatformImpl; import javafx.application.Platform; import javafx.scene.Scene; @@ -173,10 +175,20 @@ public class JavaFxNativeFileChooser implements FileChooserProvider { this.fileSelectionMode = fileSelectionMode; } + @Override public void setCurrentDirectory(File currentDirectory) { this.currentDirectory = currentDirectory; } + @Override + public void setMultiSelectionEnabled(boolean multiple) { + this.setSelectionMode(multiple ? FileSelectionMode.MULTIPLE_FILE : FileSelectionMode.FILE); + } + + @Override + public int showOpenDialog(Component parent, String approveButtonText) { + return this.showDialog(parent); + } public static class Builder { private FileSelectionMode fileSelectionMode = FileSelectionMode.FILE; @@ -190,7 +202,9 @@ public class JavaFxNativeFileChooser implements FileChooserProvider { } public Builder title(String title) { - this.title = title; + if (StringUtils.isNotEmpty(title)) { + this.title = title; + } return this; } @@ -199,6 +213,13 @@ public class JavaFxNativeFileChooser implements FileChooserProvider { return this; } + public Builder filters(ExtensionFilter[] filters) { + for (ExtensionFilter filter : filters) { + this.filters = ArrayUtils.add(this.filters, new FileChooser.ExtensionFilter(filter.getDes(), filter.getExtensions())); + } + return this; + } + public Builder filter(String des, String... extensions) { if (extensions != null) { this.filters = new FileChooser.ExtensionFilter[]{new FileChooser.ExtensionFilter(des, extensions)}; diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/SwingFileChooser.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/SwingFileChooser.java new file mode 100644 index 000000000..942c3430c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/SwingFileChooser.java @@ -0,0 +1,130 @@ +package com.fr.design.gui.ifilechooser; + +import com.fr.common.annotations.Negative; +import com.fr.design.upm.UpmUtils; +import com.fr.stable.ArrayUtils; +import com.fr.stable.StringUtils; +import java.awt.Component; +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2021/12/21 + */ +@Negative(until = "2022-6-1") +class SwingFileChooser implements FileChooserProvider { + + private final JFileChooser fileChooser; + private final Builder builder; + + private SwingFileChooser(Builder builder) { + fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(builder.fileSelectionMode); + fileChooser.setFileFilter(builder.fileFilter); + fileChooser.setSelectedFile(builder.selectedFile); + fileChooser.setMultiSelectionEnabled(builder.multiSelectionEnabled); + this.builder = builder; + } + + @Override + public File[] getSelectedFiles() { + return fileChooser.getSelectedFiles(); + } + + @Override + public File getSelectedFile() { + return fileChooser.getSelectedFile(); + } + + @Override + public int showDialog(Component parent) { + if (StringUtils.isEmpty(builder.tipText)) { + return fileChooser.showOpenDialog(parent); + } else { + return fileChooser.showDialog(parent, builder.tipText); + } + } + + @Override + public int showOpenDialog(Component parent, String approveButtonText) { + return fileChooser.showDialog(parent, approveButtonText); + } + + @Override + public void setCurrentDirectory(File file) { + fileChooser.setCurrentDirectory(file); + } + + @Override + public void setMultiSelectionEnabled(boolean multiple) { + fileChooser.setMultiSelectionEnabled(multiple); + } + + /** + * 和一般builder不同的是 setXXX还做参数转换逻辑 + */ + public static class Builder { + + private int fileSelectionMode = JFileChooser.FILES_ONLY; + private FileFilter fileFilter; + private File selectedFile; + private boolean multiSelectionEnabled; + private String tipText; + + public Builder setFileSelectionMode(FileSelectionMode fileSelectionMode) { + if (FileSelectionMode.DIR.equals(fileSelectionMode)) { + this.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY; + } else if (FileSelectionMode.FILE.equals(fileSelectionMode)) { + this.fileSelectionMode = JFileChooser.FILES_ONLY; + } else if (FileSelectionMode.MULTIPLE_FILE.equals(fileSelectionMode)) { + this.fileSelectionMode = JFileChooser.FILES_AND_DIRECTORIES; + } + return this; + } + + public Builder setFileFilter(String des, String... extension) { + if (StringUtils.isNotEmpty(des) && ArrayUtils.isNotEmpty(extension)) { + this.fileFilter = new FileNameExtensionFilter(des, UpmUtils.findMatchedExtension(extension)); + } + return this; + } + + public Builder setFileFilter(ExtensionFilter[] extensionFilters) { + StringBuilder desBuilder = new StringBuilder(); + String[] extensions = new String[0]; + for (ExtensionFilter extensionFilter : extensionFilters) { + desBuilder.append(extensionFilter.getDes()).append(" "); + extensions = ArrayUtils.addAll(extensions, UpmUtils.findMatchedExtension(extensionFilter.getExtensions())); + } + if (ArrayUtils.isNotEmpty(extensionFilters)) { + this.fileFilter = new FileNameExtensionFilter(desBuilder.toString().trim(), extensions); + } + return this; + } + + public Builder setSelectedFile(String selectedPath) { + if (StringUtils.isNotEmpty(selectedPath)) { + this.selectedFile = new File(selectedPath); + } + return this; + } + + public Builder setMultiSelectionEnabled(boolean multiSelectionEnabled) { + this.multiSelectionEnabled = multiSelectionEnabled; + return this; + } + + public Builder setTipText(String tipText) { + this.tipText = tipText; + return this; + } + + public SwingFileChooser build() { + return new SwingFileChooser(this); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/SwingImageFileChooser.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/SwingImageFileChooser.java new file mode 100644 index 000000000..3c0c6c1af --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/SwingImageFileChooser.java @@ -0,0 +1,276 @@ +package com.fr.design.gui.ifilechooser; + +import com.fr.base.BaseUtils; +import com.fr.common.annotations.Negative; +import com.fr.design.DesignerEnvManager; +import com.fr.design.style.ChooseFileView; +import com.fr.design.style.background.image.ExpandFileChooser; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.Enumeration; +import java.util.Hashtable; +import javax.swing.filechooser.FileFilter; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2021/12/30 + */ +@Negative(until = "2022-6-1") +class SwingImageFileChooser extends ExpandFileChooser implements FileChooserProvider { + + public SwingImageFileChooser() { + super(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Image_Compress"),com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Open")); + ExampleFileFilter bothFilter = new ExampleFileFilter( + new String[]{"jpg", "gif", "png", "bmp"}, + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Image_Image_Files")); + bothFilter.setExtensionListInDescription(true); + this.addChoosableFileFilter(bothFilter); + this.setAcceptAllFileFilterUsed(false); + + // Create Custom FileView + ChooseFileView fileView = new ChooseFileView(); + fileView.putIcon("jpg", BaseUtils.readIcon("/com/fr/base/images/dialog/file/jpgFile.gif")); + fileView.putIcon("gif", BaseUtils.readIcon("/com/fr/base/images/dialog/file/gifFile.gif")); + fileView.putIcon("png", BaseUtils.readIcon("/com/fr/base/images/dialog/file/pngFile.png")); + fileView.putIcon("bmp", BaseUtils.readIcon("/com/fr/base/images/dialog/file/bmpFile.gif")); + + this.setFileView(fileView); + } + + @Override + public int showDialog(Component parent, String approveButtonText) { + return super.showDialog(parent, approveButtonText); + } + + @Override + public ActionListener checkAction() { + return new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DesignerEnvManager.getEnvManager().setImageCompress(isCheckSelected()); + DesignerEnvManager.getEnvManager().saveXMLFile(); + } + }; + + } + + @Override + public int showDialog(Component parent) { + return showOpenDialog(parent); + } + + /** + * A convenience implementation of FileFilter that filters out + * all files except for those type extensions that it knows about. + *
D:\finereport\develop\code\test\TestCase\WEB-INF\reportlets\TestCase\01903.cpt + *+ * Extensions are of the type ".foo", which is typically found on + * Windows and Unix boxes, but not on Macinthosh. Case is ignored. + *
+ * Example - create a new filter that filerts out all files + * but gif and jpg image files: + * + * JFileChooser chooser = new JFileChooser(); + * ExampleFileFilter filter = new ExampleFileFilter( + * new String{"gif", "jpg"}, "JPEG & GIF Images") + * chooser.addChoosableFileFilter(filter); + * chooser.showOpenDialog(this); + * + * @author Jeff Dinkins + * @version 1.12 12/03/01 + */ + class ExampleFileFilter extends FileFilter { + private Hashtable filters = null; + private String description = null; + private String fullDescription = null; + private boolean useExtensionsInDescription = true; + + /** + * Creates a file filter. If no filters are added, then all + * files are accepted. + * + * @see #addExtension + */ + public ExampleFileFilter() { + this.filters = new Hashtable(); + } + + /** + * Creates a file filter that accepts files with the given extension. + * Example: new ExampleFileFilter("jpg"); + * + * @see #addExtension + */ + public ExampleFileFilter(String extension) { + this(extension, null); + } + + /** + * Creates a file filter that accepts the given file type. + * Example: new ExampleFileFilter("jpg", "JPEG Image Images"); + * + * Note that the "." before the extension is not needed. If + * provided, it will be ignored. + * + * @see #addExtension + */ + public ExampleFileFilter(String extension, String description) { + this(); + if (extension != null) addExtension(extension); + if (description != null) setDescription(description); + } + + /** + * Creates a file filter from the given string array. + * Example: new ExampleFileFilter(String {"gif", "jpg"}); + * + * Note that the "." before the extension is not needed adn + * will be ignored. + * + * @see #addExtension + */ + public ExampleFileFilter(String[] filters) { + this(filters, null); + } + + /** + * Creates a file filter from the given string array and description. + * Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images"); + * + * Note that the "." before the extension is not needed and will be ignored. + * + * @see #addExtension + */ + public ExampleFileFilter(String[] filters, String description) { + this(); + for (int i = 0; i < filters.length; i++) { + // add filters one by one + addExtension(filters[i]); + } + if (description != null) setDescription(description); + } + + /** + * Return true if this file should be shown in the directory pane, + * false if it shouldn't. + * + * Files that begin with "." are ignored. + * + * @see #getExtension + */ + @Override + public boolean accept(File f) { + if (f != null) { + if (f.isDirectory()) { + return true; + } + String extension = getExtension(f); + if (extension != null && filters.get(getExtension(f)) != null) { + return true; + } + } + return false; + } + + /** + * Return the extension portion of the file's name . + * + * @see #getExtension + * @see FileFilter#accept + */ + public String getExtension(File f) { + if (f != null) { + String filename = f.getName(); + int i = filename.lastIndexOf('.'); + if (i > 0 && i < filename.length() - 1) { + return filename.substring(i + 1).toLowerCase(); + } + } + return null; + } + + /** + * Adds a filetype "dot" extension to filter against. + * + * For example: the following code will create a filter that filters + * out all files except those that end in ".jpg" and ".tif": + * + * ExampleFileFilter filter = new ExampleFileFilter(); + * filter.addExtension("jpg"); + * filter.addExtension("tif"); + * + * Note that the "." before the extension is not needed and will be ignored. + */ + public void addExtension(String extension) { + if (filters == null) { + filters = new Hashtable(5); + } + filters.put(extension.toLowerCase(), this); + fullDescription = null; + } + + + /** + * Returns the human readable description of this filter. For + * example: "JPEG and GIF Image Files (*.jpg, *.gif)" + * + * @see FileFilter#getDescription + */ + @Override + public String getDescription() { + if (fullDescription == null) { + if (description == null || isExtensionListInDescription()) { + fullDescription = description == null ? "(" : description + " ("; + // build the description from the extension list + Enumeration extensions = filters.keys(); + if (extensions != null) { + fullDescription += "." + extensions.nextElement(); + while (extensions.hasMoreElements()) { + fullDescription += ", ." + extensions.nextElement(); + } + } + fullDescription += ")"; + } else { + fullDescription = description; + } + } + return fullDescription; + } + + /** + * Sets the human readable description of this filter. For + * example: filter.setDescription("Gif and JPG Images"); + */ + public void setDescription(String description) { + this.description = description; + fullDescription = null; + } + + /** + * Determines whether the extension list (.jpg, .gif, etc) should + * show up in the human readable description. + * + * Only relevent if a description was provided in the constructor + * or using setDescription(); + */ + public void setExtensionListInDescription(boolean b) { + useExtensionsInDescription = b; + fullDescription = null; + } + + /** + * Returns whether the extension list (.jpg, .gif, etc) should + * show up in the human readable description. + * + * Only relevent if a description was provided in the constructor + * or using setDescription(); + */ + public boolean isExtensionListInDescription() { + return useExtensionsInDescription; + } + } + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 499898bbf..f1a40ccdc 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -65,6 +65,7 @@ import com.fr.event.EventDispatcher; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; import com.fr.file.MemFILE; +import com.fr.file.StashedFILE; import com.fr.form.ui.NoneWidget; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; @@ -104,6 +105,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingConstants; import javax.swing.undo.UndoManager; import java.awt.BorderLayout; +import java.io.ByteArrayOutputStream; import java.awt.Dimension; import java.awt.FontMetrics; import java.util.Set; @@ -438,6 +440,22 @@ public abstract class JTemplate