From 1e8a3098cb050e509e20a885b623c8e667c1c75d Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Mon, 2 Aug 2021 19:11:09 +0800 Subject: [PATCH 1/7] =?UTF-8?q?REPORT-55072=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=86=85=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9=E5=99=A8=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E5=8E=9F=E7=94=9F=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/DesignerEnvManager.java | 12 + .../design/actions/file/PreferencePane.java | 25 +- .../gui/ifilechooser/AbstractFileChooser.java | 103 ----- .../gui/ifilechooser/FileChooserProvider.java | 12 + .../gui/ifilechooser/FileSelectionMode.java | 5 + .../ifilechooser/JavaFxNativeFileChooser.java | 176 +++++++++ .../gui/ifilechooser/UINativeFileChooser.java | 154 -------- .../background/image/ImageFileChooser.java | 289 +++----------- .../java/com/fr/design/upm/UpmBridge.java | 27 +- .../main/java/com/fr/env/RemoteEnvPane.java | 20 +- .../series/PlotSeries/MapCustomPane.java | 352 +++++++++--------- .../share/action/InstallComponentAction.java | 33 +- 12 files changed, 492 insertions(+), 716 deletions(-) delete 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/FileChooserProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileSelectionMode.java create mode 100644 designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java delete 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/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 97b4d0f6c..7242b2295 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -192,6 +192,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private static List mapWorkerList = new ArrayList(); private boolean imageCompress = false;//图片压缩 + private boolean showImageCompressMoveTip = true; // 开启内嵌web页面的调试窗口 private boolean openDebug = false; @@ -1637,6 +1638,15 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.imageCompress = imageCompress; } + public boolean isShowImageCompressMoveTip() { + return showImageCompressMoveTip; + } + + public void setShowImageCompressMoveTip(boolean showImageCompressMoveTip) { + this.showImageCompressMoveTip = showImageCompressMoveTip; + } + + public boolean isOpenDebug() { return openDebug; } @@ -1792,6 +1802,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.setCachingTemplateLimit(reader.getAttrAsInt("cachingTemplateLimit", CACHINGTEMPLATE_LIMIT)); this.setJoinProductImprove(reader.getAttrAsBoolean("joinProductImprove", true)); this.setImageCompress(reader.getAttrAsBoolean("imageCompress", true)); + this.setShowImageCompressMoveTip(reader.getAttrAsBoolean("showImageCompressMoveTip", true)); this.setAutoBackUp(reader.getAttrAsBoolean("autoBackUp", true)); this.setTemplateTreePaneExpanded(reader.getAttrAsBoolean("templateTreePaneExpanded", false)); // peter:读取webinfLocation @@ -2072,6 +2083,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if (!this.isImageCompress()) { writer.attr("imageCompress", this.isImageCompress()); } + writer.attr("showImageCompressMoveTip", this.isShowImageCompressMoveTip()); if (!this.isAutoBackUp()) { writer.attr("autoBackUp", this.isAutoBackUp()); } 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 133bbb03f..eecff994b 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 @@ -15,6 +15,9 @@ import com.fr.design.gui.ibutton.UIColorButton; 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.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; @@ -47,6 +50,8 @@ import com.fr.transaction.Worker; import com.fr.workspace.WorkContext; import com.fr.workspace.server.vcs.VcsOperator; import com.fr.workspace.server.vcs.git.config.GcConfig; +import com.sun.javafx.tk.FileChooserType; +import javafx.stage.FileChooser; import javax.swing.BorderFactory; import javax.swing.BoxLayout; @@ -165,6 +170,7 @@ public class PreferencePane extends BasicPane { private UICheckBox joinProductImproveCheckBox; private UICheckBox autoPushUpdateCheckBox; private UICheckBox embedServerLazyStartupCheckBox; + private UICheckBox imageCompressPanelCheckBox; private UICheckBox vcsEnableCheckBox; private UICheckBox saveCommitCheckBox; @@ -256,6 +262,10 @@ public class PreferencePane extends BasicPane { embedServerPanel.add(embedServerLazyStartupCheckBox); advancePane.add(embedServerPanel); + JPanel imageCompressPanel = FRGUIPaneFactory.createVerticalTitledBorderPane(i18nText("Fine-Design_Template_Preview_Performance=")); + imageCompressPanelCheckBox = new UICheckBox(i18nText("Fine-Design_Image_Compress")); + imageCompressPanel.add(imageCompressPanelCheckBox); + advancePane.add(imageCompressPanel); } private void createVcsSettingPane(JPanel generalPane) { @@ -489,11 +499,13 @@ public class PreferencePane extends BasicPane { chooseDirBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - int saveValue = fileChooser.showOpenDialog(DesignerContext.getDesignerFrame()); + FileChooserProvider fileChooserProvider = + new JavaFxNativeFileChooser.Builder(). + fileSelectionMode(FileSelectionMode.DIR). + build(); + int saveValue = fileChooserProvider.showDialog(null); if (saveValue == JFileChooser.APPROVE_OPTION) { - File selectedFile = fileChooser.getSelectedFile(); + File selectedFile = fileChooserProvider.getSelectedFile(); logExportDirectoryField.setText(selectedFile.getAbsolutePath()); } } @@ -665,7 +677,7 @@ public class PreferencePane extends BasicPane { defaultStringToFormulaBox.setSelected(false); } VcsConfigManager vcsConfigManager = designerEnvManager.getVcsConfigManager(); - if (WorkContext.getCurrent().isCluster()){ + if (WorkContext.getCurrent().isCluster()) { vcsEnableCheckBox.setEnabled(false); gcEnableCheckBox.setEnabled(false); } @@ -717,6 +729,8 @@ public class PreferencePane extends BasicPane { } this.embedServerLazyStartupCheckBox.setSelected(designerEnvManager.isEmbedServerLazyStartup()); + + this.imageCompressPanelCheckBox.setSelected(designerEnvManager.isImageCompress()); } private int chooseCase(int sign) { @@ -775,6 +789,7 @@ public class PreferencePane extends BasicPane { designerEnvManager.setCachingTemplateLimit((int) this.cachingTemplateSpinner.getValue()); designerEnvManager.setJoinProductImprove(this.joinProductImproveCheckBox.isSelected()); designerEnvManager.setEmbedServerLazyStartup(this.embedServerLazyStartupCheckBox.isSelected()); + designerEnvManager.setImageCompress(this.imageCompressPanelCheckBox.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/gui/ifilechooser/AbstractFileChooser.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/AbstractFileChooser.java deleted file mode 100644 index ee61fd81f..000000000 --- a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/AbstractFileChooser.java +++ /dev/null @@ -1,103 +0,0 @@ -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 - */ -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 FileFilter filter); - - /** - * 设置文件选择器模式 - * - * JFileChooser.FILES_ONLY - * JFileChooser.DIRECTORIES_ONLY - * JFileChooser.FILES_AND_DIRECTORIES - */ - public abstract void setFileSelectionMode(int 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/FileChooserProvider.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserProvider.java new file mode 100644 index 000000000..aa95fe27b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileChooserProvider.java @@ -0,0 +1,12 @@ +package com.fr.design.gui.ifilechooser; + +import java.awt.*; +import java.io.File; + +public interface FileChooserProvider { + File[] getSelectedFiles(); + + File getSelectedFile(); + + int showDialog(Component parent); +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileSelectionMode.java b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileSelectionMode.java new file mode 100644 index 000000000..bee326f6a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/FileSelectionMode.java @@ -0,0 +1,5 @@ +package com.fr.design.gui.ifilechooser; + +public enum FileSelectionMode { + FILE, MULTIPLE_FILE, DIR +} 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 new file mode 100644 index 000000000..682d80fc6 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ifilechooser/JavaFxNativeFileChooser.java @@ -0,0 +1,176 @@ +package com.fr.design.gui.ifilechooser; + + +import com.fr.design.i18n.Toolkit; +import com.fr.design.upm.UpmUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; +import com.sun.javafx.application.PlatformImpl; +import javafx.stage.DirectoryChooser; +import javafx.stage.FileChooser; +import javafx.stage.Window; + +import javax.swing.*; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.*; +import java.io.File; +import java.util.List; +import java.util.concurrent.CountDownLatch; + +public class JavaFxNativeFileChooser implements FileChooserProvider { + private File[] selectedFiles = new File[0]; + private FileSelectionMode fileSelectionMode = FileSelectionMode.FILE; + private String title = Toolkit.i18nText("Fine-Design_Basic_Open"); + private FileChooser.ExtensionFilter[] filters; + private File currentDirectory; + + @Override + public File[] getSelectedFiles() { + return selectedFiles; + } + + @Override + public File getSelectedFile() { + if (selectedFiles.length > 0) { + return selectedFiles[0]; + } + return null; + } + + @Override + public int showDialog(Component parent) { + final CountDownLatch latch = new CountDownLatch(1); + PlatformImpl.startup(new Runnable() { + @Override + public void run() { + try { + if (fileSelectionMode == FileSelectionMode.FILE || fileSelectionMode == FileSelectionMode.MULTIPLE_FILE) { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle(title); + fileChooser.getExtensionFilters().addAll(filters); + fileChooser.setInitialDirectory(currentDirectory); + if (fileSelectionMode == FileSelectionMode.FILE) { + File file = fileChooser.showOpenDialog(null); + if (file != null) { + selectedFiles = new File[]{file}; + } + } else if (fileSelectionMode == FileSelectionMode.MULTIPLE_FILE) { + List fileList = fileChooser.showOpenMultipleDialog(null); + if (fileList != null) { + selectedFiles = new File[fileList.size()]; + fileList.toArray(selectedFiles); + } + } + } else if (fileSelectionMode == FileSelectionMode.DIR) { + DirectoryChooser directoryChooser = new DirectoryChooser(); + directoryChooser.setTitle(title); + directoryChooser.setInitialDirectory(currentDirectory); + File folder = directoryChooser.showDialog(null); + if (folder != null) { + selectedFiles = new File[]{folder}; + } + System.out.println(folder); + } + + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + } finally { + latch.countDown(); + } + } + }); + + try { + latch.await(); + } catch (InterruptedException ignore) { + } + return selectedFiles.length > 0 ? JFileChooser.APPROVE_OPTION : JFileChooser.CANCEL_OPTION; + } + + public void setSelectionMode(FileSelectionMode fileSelectionMode) { + this.fileSelectionMode = fileSelectionMode; + } + + public void setCurrentDirectory(File currentDirectory) { + this.currentDirectory = currentDirectory; + } + + + public static class Builder { + private FileSelectionMode fileSelectionMode = FileSelectionMode.FILE; + private String title = Toolkit.i18nText("Fine-Design_Basic_Open"); + private FileChooser.ExtensionFilter[] filters = new FileChooser.ExtensionFilter[0]; + private File currentDirectory; + + public Builder fileSelectionMode(FileSelectionMode fileSelectionMode) { + this.fileSelectionMode = fileSelectionMode; + return this; + } + + public Builder title(String title) { + this.title = title; + return this; + } + + public Builder filters(FileChooser.ExtensionFilter[] filters) { + this.filters = filters; + return this; + } + + public Builder filter(String des, String... extensions) { + if (extensions != null) { + this.filters = new FileChooser.ExtensionFilter[]{new FileChooser.ExtensionFilter(des, extensions)}; + } + return this; + } + + + public Builder currentDirectory(File currentDirectory) { + if (currentDirectory != null) { + if (!currentDirectory.isDirectory()) { + currentDirectory = currentDirectory.getParentFile(); + } + if (currentDirectory != null && currentDirectory.isDirectory()) { + this.currentDirectory = currentDirectory; + } + } + return this; + } + + public Builder currentDirectory(String path) { + if (path != null) { + return currentDirectory(new File(path)); + } + return this; + } + + public JavaFxNativeFileChooser build() { + return new JavaFxNativeFileChooser(this); + } + } + + private JavaFxNativeFileChooser(Builder builder) { + this.fileSelectionMode = builder.fileSelectionMode; + this.title = builder.title; + this.filters = builder.filters; + this.currentDirectory = builder.currentDirectory; + } + + public static void main(String[] args) { + + FileChooserProvider fileChooserProvider = + new Builder(). + fileSelectionMode(FileSelectionMode.DIR). + title("hhh"). + filters(new FileChooser.ExtensionFilter[]{ + new FileChooser.ExtensionFilter("TXT", "*.txt"), + new FileChooser.ExtensionFilter("PNG", "*.png")}). + currentDirectory(new File("D://")). + build(); + fileChooserProvider.showDialog(null); + System.out.println(fileChooserProvider.getSelectedFiles().length); + System.out.println(fileChooserProvider.getSelectedFile()); + } + + +} \ No newline at end of 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 deleted file mode 100644 index c1418f834..000000000 --- a/designer-base/src/main/java/com/fr/design/gui/ifilechooser/UINativeFileChooser.java +++ /dev/null @@ -1,154 +0,0 @@ -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 - */ -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(int 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; - } - } - -} diff --git a/designer-base/src/main/java/com/fr/design/style/background/image/ImageFileChooser.java b/designer-base/src/main/java/com/fr/design/style/background/image/ImageFileChooser.java index 1e5e96ab1..57f0d59d6 100644 --- a/designer-base/src/main/java/com/fr/design/style/background/image/ImageFileChooser.java +++ b/designer-base/src/main/java/com/fr/design/style/background/image/ImageFileChooser.java @@ -3,266 +3,77 @@ */ package com.fr.design.style.background.image; -import com.fr.base.BaseUtils; import com.fr.design.DesignerEnvManager; -import com.fr.design.style.ChooseFileView; - - -import javax.swing.filechooser.FileFilter; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import com.fr.design.gui.ifilechooser.FileSelectionMode; +import com.fr.design.gui.ifilechooser.JavaFxNativeFileChooser; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.share.collect.ComponentCollector; +import com.fr.design.mainframe.toast.DesignerToastMsgUtil; +import javafx.stage.FileChooser; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.io.File; -import java.util.Enumeration; -import java.util.Hashtable; /** * This class used to choose image files. */ -public class ImageFileChooser extends ExpandFileChooser { +public class ImageFileChooser { + + JavaFxNativeFileChooser javaFxNativeFileChooser; public ImageFileChooser() { - 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); + javaFxNativeFileChooser = + 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")}). + build(); + } - // 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); + public int showOpenDialog(Component parent, String approveButtonText) { + return showOpenDialog(parent); } - public int showDialog(Component parent, String approveButtonText) { - return super.showDialog(parent, approveButtonText); + public int showOpenDialog(Component parent) { + showImageCompressMoveTip(); + return javaFxNativeFileChooser.showDialog(parent); } - @Override - public ActionListener checkAction() { - return new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - DesignerEnvManager.getEnvManager().setImageCompress(isCheckSelected()); - DesignerEnvManager.getEnvManager().saveXMLFile(); - } - }; - + public void setCurrentDirectory(File file) { + javaFxNativeFileChooser.setCurrentDirectory(file); } - /** - * 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 - */ - 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 javax.swing.filechooser.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 javax.swing.filechooser.FileFilter#getDescription - */ - 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; + public void setMultiSelectionEnabled(boolean multiple) { + if (multiple) { + javaFxNativeFileChooser.setSelectionMode(FileSelectionMode.MULTIPLE_FILE); + } else { + javaFxNativeFileChooser.setSelectionMode(FileSelectionMode.FILE); } + } - /** - * 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; - } + public File getSelectedFile() { + return javaFxNativeFileChooser.getSelectedFile(); + } - /** - * 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; - } + public boolean isCheckSelected() { + return DesignerEnvManager.getEnvManager().isImageCompress(); + } - /** - * 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; + private void showImageCompressMoveTip() { + if (DesignerEnvManager.getEnvManager().isShowImageCompressMoveTip()) { + DesignerToastMsgUtil.toastWarning(Toolkit.i18nText("Fine-Design_Image_Compress_Move_Tip")); + DesignerEnvManager.getEnvManager().setShowImageCompressMoveTip(false); } } } diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java b/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java index fb40d5434..fee07ac46 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java @@ -14,6 +14,9 @@ import com.fr.design.extra.exe.GetPluginPrefixExecutor; import com.fr.design.extra.exe.PluginLoginExecutor; import com.fr.design.extra.exe.ReadUpdateOnlineExecutor; import com.fr.design.extra.exe.SearchOnlineExecutor; +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.i18n.Toolkit; import com.fr.design.locale.impl.BbsRegisterMark; import com.fr.design.locale.impl.BbsResetMark; @@ -36,6 +39,7 @@ import com.teamdev.jxbrowser.chromium.Browser; import com.teamdev.jxbrowser.chromium.JSArray; import com.teamdev.jxbrowser.chromium.JSFunction; import com.teamdev.jxbrowser.chromium.JSObject; +import javafx.stage.FileChooser; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; @@ -95,7 +99,7 @@ public class UpmBridge { @JSBridge public void startDownload(final JSFunction callback) { callback.invoke(window, "start", Toolkit.i18nText("Fine-Design_Basic_Update_Plugin_Manager_Download_Start")); - new SwingWorker(){ + new SwingWorker() { @Override protected Void doInBackground() throws Exception { UpmResourceLoader.INSTANCE.download(); @@ -308,16 +312,13 @@ public class UpmBridge { RunnableFuture future = new FutureTask<>(new Callable() { @Override public String call() { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - - if (StringUtils.isNotEmpty(filter)) { - fileChooser.setFileFilter(new FileNameExtensionFilter(des, UpmUtils.findMatchedExtension(filter))); - } - - int result = fileChooser.showOpenDialog(UpmFinder.getDialog()); + FileChooserProvider fileChooserProvider = new JavaFxNativeFileChooser.Builder(). + fileSelectionMode(FileSelectionMode.FILE). + filter(des, filter). + build(); + int result = fileChooserProvider.showDialog(UpmFinder.getDialog()); if (result == JFileChooser.APPROVE_OPTION) { - return fileChooser.getSelectedFile().getAbsolutePath(); + return fileChooserProvider.getSelectedFile().getAbsolutePath(); } return null; } @@ -345,11 +346,11 @@ public class UpmBridge { public String call() { JFileChooser fileChooser = new JFileChooser(); List filterList = new ArrayList<>(); - if (args instanceof String) { + if (args instanceof String) { filterList.add(GeneralUtils.objectToString(args)); } else if (args instanceof JSArray) { - JSArray array = (JSArray)args; - for (int i = 0, len = array.length(); i < len; i ++) { + JSArray array = (JSArray) args; + for (int i = 0, len = array.length(); i < len; i++) { filterList.add(array.get(i).getStringValue()); } } diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index 363593778..fe56bd433 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -11,6 +11,9 @@ import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icontainer.UIScrollPane; +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.UILabel; import com.fr.design.gui.ipasswordfield.UIPassWordField; import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength; @@ -30,6 +33,7 @@ import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.exception.WorkspaceAuthException; import com.fr.workspace.engine.exception.WorkspaceCheckException; + import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JDialog; @@ -569,11 +573,11 @@ public class RemoteEnvPane extends BasicBeanPane { fileChooserButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - int saveValue = fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this)); + FileChooserProvider fileChooserProvider = new JavaFxNativeFileChooser.Builder(). + fileSelectionMode(FileSelectionMode.FILE).build(); + int saveValue = fileChooserProvider.showDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this)); if (saveValue == JFileChooser.APPROVE_OPTION) { - File selectedFile = fileChooser.getSelectedFile(); + File selectedFile = fileChooserProvider.getSelectedFile(); certPathInput.setText(selectedFile.getAbsolutePath()); } } @@ -610,10 +614,10 @@ public class RemoteEnvPane extends BasicBeanPane { dialog.dispose(); FineLoggerFactory.getLogger().error(result.getText().replaceAll(TestConnectionResult.WRAP, StringUtils.EMPTY) + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord")); FineJOptionPane.showMessageDialog(RemoteEnvPane.this, - new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), connection.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH), - Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"), - ERROR_MESSAGE, - UIManager.getIcon("OptionPane.errorIcon")); + new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), connection.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH), + Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon")); } message.setText(result.getText()); uiLabel.setIcon(result.getIcon()); diff --git a/designer-chart/src/main/java/com/fr/design/chart/series/PlotSeries/MapCustomPane.java b/designer-chart/src/main/java/com/fr/design/chart/series/PlotSeries/MapCustomPane.java index 8cd0743da..133e2fef7 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/series/PlotSeries/MapCustomPane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/series/PlotSeries/MapCustomPane.java @@ -9,6 +9,8 @@ import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.wrapper.TableDataWrapper; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.FilterComboBox; +import com.fr.design.gui.ifilechooser.FileChooserProvider; +import com.fr.design.gui.ifilechooser.JavaFxNativeFileChooser; import com.fr.design.gui.ilable.BoldFontTextLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.DesignerContext; @@ -40,56 +42,56 @@ import java.awt.event.ItemListener; * @author kunsnat E-mail:kunsnat@gmail.com * @version 创建时间:2012-10-15 下午03:38:15 */ -public class MapCustomPane extends BasicBeanPane implements AbstrctMapAttrEditPane{ // 储存地图对应的字段. 名称, 类型. shape (点 用圆形代替) +public class MapCustomPane extends BasicBeanPane implements AbstrctMapAttrEditPane { // 储存地图对应的字段. 名称, 类型. shape (点 用圆形代替) - private FilterComboBox areaString;// 区域字段 - private DatabaseTableDataPane tableDataNameBox;// 数据集名称 + 后面跟随预览按钮 - private MapImageEditPane imageShowPane; // 图片展示编辑的界面 - private String lastSelectPath; - private boolean isNeedDataSource = true; + private FilterComboBox areaString;// 区域字段 + private DatabaseTableDataPane tableDataNameBox;// 数据集名称 + 后面跟随预览按钮 + private MapImageEditPane imageShowPane; // 图片展示编辑的界面 + private String lastSelectPath; + private boolean isNeedDataSource = true; - public MapCustomPane() { - initComp(); - } + public MapCustomPane() { + initComp(); + } - public MapCustomPane(boolean isNeedDataSource){ - this.isNeedDataSource = isNeedDataSource; - initComp(); - } + public MapCustomPane(boolean isNeedDataSource) { + this.isNeedDataSource = isNeedDataSource; + initComp(); + } - private void initComp() { - this.setLayout(new BorderLayout(0, 0)); + private void initComp() { + this.setLayout(new BorderLayout(0, 0)); - JPanel pane = new JPanel(); - this.add(pane, BorderLayout.NORTH); + JPanel pane = new JPanel(); + this.add(pane, BorderLayout.NORTH); - pane.setLayout(new BorderLayout()); + pane.setLayout(new BorderLayout()); - pane.add(northPaneCreate(), BorderLayout.NORTH); + pane.add(northPaneCreate(), BorderLayout.NORTH); - imageShowPane = new MapImageEditPane(); + imageShowPane = new MapImageEditPane(); - pane.add(imageShowPane, BorderLayout.CENTER); - } + pane.add(imageShowPane, BorderLayout.CENTER); + } - private JPanel northPaneCreate() { - JPanel northPane = new JPanel(); + private JPanel northPaneCreate() { + JPanel northPane = new JPanel(); - northPane.setLayout(new FlowLayout(FlowLayout.LEFT)); + northPane.setLayout(new FlowLayout(FlowLayout.LEFT)); - UIButton loadMap = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Import_Map")); - loadMap.setPreferredSize(new Dimension(160, 20)); - northPane.add(loadMap); + UIButton loadMap = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Import_Map")); + loadMap.setPreferredSize(new Dimension(160, 20)); + northPane.add(loadMap); - loadMap.addActionListener(selectPictureActionListener); + loadMap.addActionListener(selectPictureActionListener); - if(isNeedDataSource){ - UILabel label =new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Table_Data") + ":", SwingConstants.RIGHT) ; + if (isNeedDataSource) { + UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Table_Data") + ":", SwingConstants.RIGHT); tableDataNameBox = new DatabaseTableDataPane(label) { - protected void userEvent() { -refreshAreaNameBox(); -} + protected void userEvent() { + refreshAreaNameBox(); + } }; tableDataNameBox.setPreferredSize(new Dimension(200, 20)); northPane.add(tableDataNameBox); @@ -100,158 +102,156 @@ refreshAreaNameBox(); areaString.setPreferredSize(new Dimension(120, 20)); areaString.addItemListener(areaChange); northPane.add(areaString); - } - - - return northPane; - } - - private ActionListener selectPictureActionListener = new ActionListener() { - - public void actionPerformed(ActionEvent evt) { - JFileChooser svgFileChooser = new JFileChooser(); - svgFileChooser.addChoosableFileFilter(new SVGFileFilter()); - if (StringUtils.isNotBlank(lastSelectPath)) { - svgFileChooser.setSelectedFile(new File(lastSelectPath)); - } - int returnVal = svgFileChooser.showOpenDialog(DesignerContext.getDesignerFrame()); - if (returnVal != JFileChooser.CANCEL_OPTION) { - File selectedFile = svgFileChooser.getSelectedFile(); - try { - lastSelectPath = selectedFile.getCanonicalPath(); - } catch (Exception ex) { - FineLoggerFactory.getLogger().error(ex.getMessage(), ex); - } - if (selectedFile != null && selectedFile.isFile()) { + } + + + return northPane; + } + + private ActionListener selectPictureActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + FileChooserProvider fileChooserProvider = new JavaFxNativeFileChooser.Builder(). + filter(".svg, .svgz", "*.svg", "*.svgz"). + currentDirectory(lastSelectPath).build(); + int returnVal = fileChooserProvider.showDialog(DesignerContext.getDesignerFrame()); + if (returnVal != JFileChooser.CANCEL_OPTION) { + File selectedFile = fileChooserProvider.getSelectedFile(); + try { + lastSelectPath = selectedFile.getCanonicalPath(); + } catch (Exception ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } + if (selectedFile != null && selectedFile.isFile()) { imageShowPane.setSvgMap(selectedFile.getPath()); imageShowPane.repaint(); - } - } - } - }; - - private ItemListener areaChange = new ItemListener() { - public void itemStateChanged(ItemEvent e) { - Object select = areaString.getSelectedItem(); - if (select != null) { - String colName = Utils.objectToString(areaString.getSelectedItem()); - - TableDataWrapper tableDataWrappe = tableDataNameBox.getTableDataWrapper(); - - imageShowPane.refreshFromDataList(getColValuesInData(tableDataWrappe, colName)); - } - } - }; - - public static List getColValuesInData(TableDataWrapper tableDataWrappe, String colName) { - List colValues = new ArrayList<>(); - - EmbeddedTableData embeddedTableData = null; - try { - embeddedTableData = DesignTableDataManager.previewTableDataNotNeedInputParameters(tableDataWrappe.getTableData(), TableData.RESULT_ALL, false); - } catch (Exception ee) { + } + } + } + }; + + private ItemListener areaChange = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + Object select = areaString.getSelectedItem(); + if (select != null) { + String colName = Utils.objectToString(areaString.getSelectedItem()); + + TableDataWrapper tableDataWrappe = tableDataNameBox.getTableDataWrapper(); + + imageShowPane.refreshFromDataList(getColValuesInData(tableDataWrappe, colName)); + } + } + }; + + public static List getColValuesInData(TableDataWrapper tableDataWrappe, String colName) { + List colValues = new ArrayList<>(); + + EmbeddedTableData embeddedTableData = null; + try { + embeddedTableData = DesignTableDataManager.previewTableDataNotNeedInputParameters(tableDataWrappe.getTableData(), TableData.RESULT_ALL, false); + } catch (Exception ee) { FineLoggerFactory.getLogger().error(ee.getMessage(), ee); - } - - if(embeddedTableData == null){ - return colValues; - } - - int columnIndex = getColumnIndex(embeddedTableData, colName); - - if(columnIndex == DataModel.COLUMN_NAME_NOT_FOUND){ - return colValues; - } - - for (int rowIndex = 0, rowCount = embeddedTableData.getRowCount(); rowIndex < rowCount; rowIndex++) { - String colValueName = GeneralUtils.objectToString(embeddedTableData.getValueAt(rowIndex, columnIndex)); - if (!colValues.contains(colValueName)) { - colValues.add(colValueName); - } - } - - return colValues; - } - - private static int getColumnIndex(EmbeddedTableData tableData, String colName) { - for (int columnIndex = 0, columnCount = tableData.getColumnCount(); columnIndex < columnCount; columnIndex++) { - if (ComparatorUtils.tableDataColumnNameEquals(tableData.getColumnName(columnIndex), colName)) { - return columnIndex; - } - } - return DataModel.COLUMN_NAME_NOT_FOUND; - } - - /** - * 选中方式: 区域或者点 - */ - public void setImageSelectType(int selectType) { - if (imageShowPane != null) { - imageShowPane.setEditType(selectType); - } - } - - private void refreshAreaNameBox() {// 刷新区域名称列表 - if(!isNeedDataSource){ - return; - } - TableDataWrapper tableDataWrappe = tableDataNameBox.getTableDataWrapper(); - if (tableDataWrappe == null) { - return; - } - List columnNameList = tableDataWrappe.calculateColumnNameList(); - - Object oldSelected = areaString.getSelectedItem(); - areaString.removeAllItems(); - - for(String item : columnNameList) { - areaString.addItem(item); - } - areaString.getModel().setSelectedItem(oldSelected); - } + } + + if (embeddedTableData == null) { + return colValues; + } + + int columnIndex = getColumnIndex(embeddedTableData, colName); + + if (columnIndex == DataModel.COLUMN_NAME_NOT_FOUND) { + return colValues; + } + + for (int rowIndex = 0, rowCount = embeddedTableData.getRowCount(); rowIndex < rowCount; rowIndex++) { + String colValueName = GeneralUtils.objectToString(embeddedTableData.getValueAt(rowIndex, columnIndex)); + if (!colValues.contains(colValueName)) { + colValues.add(colValueName); + } + } + + return colValues; + } + + private static int getColumnIndex(EmbeddedTableData tableData, String colName) { + for (int columnIndex = 0, columnCount = tableData.getColumnCount(); columnIndex < columnCount; columnIndex++) { + if (ComparatorUtils.tableDataColumnNameEquals(tableData.getColumnName(columnIndex), colName)) { + return columnIndex; + } + } + return DataModel.COLUMN_NAME_NOT_FOUND; + } + + /** + * 选中方式: 区域或者点 + */ + public void setImageSelectType(int selectType) { + if (imageShowPane != null) { + imageShowPane.setEditType(selectType); + } + } + + private void refreshAreaNameBox() {// 刷新区域名称列表 + if (!isNeedDataSource) { + return; + } + TableDataWrapper tableDataWrappe = tableDataNameBox.getTableDataWrapper(); + if (tableDataWrappe == null) { + return; + } + List columnNameList = tableDataWrappe.calculateColumnNameList(); + + Object oldSelected = areaString.getSelectedItem(); + areaString.removeAllItems(); + + for (String item : columnNameList) { + areaString.addItem(item); + } + areaString.getModel().setSelectedItem(oldSelected); + } /** * 当前正在编辑的条目的类别(国家,省市)名和地图名 * @param typeName 类别名 * @param mapName 地图名 */ - public void setTypeNameAndMapName(String typeName, String mapName){ + public void setTypeNameAndMapName(String typeName, String mapName) { imageShowPane.setTypeNameAndMapName(typeName, mapName); } - /** - * 根据地图名称 加载信息 - */ - public void populateBean(String list) { - imageShowPane.populateBean(list); - } - - /** - * 根据地图名称 保存信息 - */ - public String updateBean() { - // 地图类型等 加入Helper - return imageShowPane.updateBean(); - } - - @Override - protected String title4PopupWindow() { - return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Custom_Map"); - } - - /** - * 更新界面 - * @param attr 地图属性 - */ - public void populateMapAttr(MapSvgAttr attr) { - imageShowPane.populateMapSvgAttr(attr); - } - - /** - * 更新MapSvgAttr - * @return 返回属性 - */ - public MapSvgAttr updateCurrentAttr() { - return imageShowPane.updateWithOutSave(); - } + /** + * 根据地图名称 加载信息 + */ + public void populateBean(String list) { + imageShowPane.populateBean(list); + } + + /** + * 根据地图名称 保存信息 + */ + public String updateBean() { + // 地图类型等 加入Helper + return imageShowPane.updateBean(); + } + + @Override + protected String title4PopupWindow() { + return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Custom_Map"); + } + + /** + * 更新界面 + * @param attr 地图属性 + */ + public void populateMapAttr(MapSvgAttr attr) { + imageShowPane.populateMapSvgAttr(attr); + } + + /** + * 更新MapSvgAttr + * @return 返回属性 + */ + public MapSvgAttr updateCurrentAttr() { + return imageShowPane.updateWithOutSave(); + } } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/action/InstallComponentAction.java b/designer-form/src/main/java/com/fr/design/mainframe/share/action/InstallComponentAction.java index d3173e36b..fd03dc72a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/action/InstallComponentAction.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/action/InstallComponentAction.java @@ -4,7 +4,9 @@ import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.gui.ifilechooser.UINativeFileChooser; +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.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; @@ -17,6 +19,8 @@ import com.fr.design.os.impl.SupportOSImpl; import com.fr.form.share.record.ShareWidgetInfoManager; import com.fr.form.share.utils.ReuxUtils; import com.fr.log.FineLoggerFactory; +import com.sun.javafx.tk.FileChooserType; +import javafx.stage.FileChooser; import javax.swing.Action; import javax.swing.JFileChooser; @@ -42,23 +46,16 @@ public class InstallComponentAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { - - if (SupportOSImpl.NATIVE_CHOOSER.support()) { - UINativeFileChooser nativeFileChooser = new UINativeFileChooser(); - nativeFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - nativeFileChooser.setMultiSelectionEnabled(true); - nativeFileChooser.setFileFilter(new FileNameExtensionFilter("reu reus", "reu", "reus")); - nativeFileChooser.setDialogTitle(Toolkit.i18nText("Fine-Design_Basic_Select")); - int returnValue = nativeFileChooser.showOpenDialog(new UILabel()); - installComponent(returnValue, nativeFileChooser.getSelectedFiles()); - } else { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - fileChooser.setMultiSelectionEnabled(true); - fileChooser.setFileFilter(new FileNameExtensionFilter("reu reus", "reu", "reus")); - int returnValue = fileChooser.showDialog(new UILabel(), Toolkit.i18nText("Fine-Design_Basic_Select")); - installComponent(returnValue, fileChooser.getSelectedFiles()); - } + FileChooserProvider fileChooserProvider = + new JavaFxNativeFileChooser.Builder(). + fileSelectionMode(FileSelectionMode.MULTIPLE_FILE). + title(Toolkit.i18nText("Fine-Design_Basic_Select")). + filters(new FileChooser.ExtensionFilter[]{ + new FileChooser.ExtensionFilter("reu", "*.reu"), + new FileChooser.ExtensionFilter("reus", "*.reus")}). + build(); + int returnValue = fileChooserProvider.showDialog(null); + installComponent(returnValue, fileChooserProvider.getSelectedFiles()); } private void installComponent(int returnValue, File[] selectedFiles) { From 623edcaf9176af13c1abdd01f68a1d8fd991cba5 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Mon, 2 Aug 2021 19:21:17 +0800 Subject: [PATCH 2/7] =?UTF-8?q?REPORT-55072=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=86=85=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9=E5=99=A8=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E5=8E=9F=E7=94=9F=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/actions/file/PreferencePane.java | 2 +- .../java/com/fr/design/web/CustomIconPane.java | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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 eecff994b..a41f96295 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 @@ -262,7 +262,7 @@ public class PreferencePane extends BasicPane { embedServerPanel.add(embedServerLazyStartupCheckBox); advancePane.add(embedServerPanel); - JPanel imageCompressPanel = FRGUIPaneFactory.createVerticalTitledBorderPane(i18nText("Fine-Design_Template_Preview_Performance=")); + JPanel imageCompressPanel = FRGUIPaneFactory.createVerticalTitledBorderPane(i18nText("Fine-Design_Template_Preview_Performance")); imageCompressPanelCheckBox = new UICheckBox(i18nText("Fine-Design_Image_Compress")); imageCompressPanel.add(imageCompressPanelCheckBox); advancePane.add(imageCompressPanel); diff --git a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java index ef66fc039..9e03dcc9d 100644 --- a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java +++ b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java @@ -10,6 +10,8 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.ifilechooser.FileChooserProvider; +import com.fr.design.gui.ifilechooser.JavaFxNativeFileChooser; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.iscrollbar.UIScrollBar; import com.fr.design.gui.itextarea.DescriptionTextArea; @@ -28,6 +30,7 @@ import com.fr.stable.ListMap; import com.fr.stable.StringUtils; import com.fr.transaction.Configurations; import com.fr.transaction.WorkerFacade; +import javafx.stage.FileChooser; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -108,7 +111,7 @@ public class CustomIconPane extends BasicPane { } - protected String createDescriptionText(){ + protected String createDescriptionText() { return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Icon_Message1"); } @@ -447,13 +450,12 @@ public class CustomIconPane extends BasicPane { } private void onBrowseButtonClicked() { - JFileChooser jf = new JFileChooser(); // carl:不知道是否只要png格式,反正导出时全部都转成png了 - FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("Icon Image File", "jpg", "jpeg", "png", "gif"); - jf.setFileFilter(fileFilter); - - if (JFileChooser.APPROVE_OPTION == jf.showOpenDialog(DesignerContext.getDesignerFrame())) { - String path = jf.getSelectedFile().getAbsolutePath(); + FileChooserProvider fileChooserProvider = new JavaFxNativeFileChooser.Builder(). + filter("Icon Image File", "*.jpg", "*.jpeg", "*.png", "*.gif"). + build(); + if (JFileChooser.APPROVE_OPTION == fileChooserProvider.showDialog(DesignerContext.getDesignerFrame())) { + String path = fileChooserProvider.getSelectedFile().getAbsolutePath(); // 图片存储有最大值48*48限制,没有超过最大值时,按原图大小存储,超过最大值后,压缩至最大值存储 Image image = BaseUtils.readImage(path); iconImage = ImageUtils.scale((BufferedImage) image, Math.min(image.getWidth(null), IconManager.MAXSTORAGE_ICONWIDTH), Math.min(image.getHeight(null), IconManager.MAXSTORAGE_ICONHEIGHT), true, Image.SCALE_SMOOTH); From 468b6600e872e10b1604618a9edbf2469d9afcf4 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Mon, 2 Aug 2021 19:22:59 +0800 Subject: [PATCH 3/7] =?UTF-8?q?REPORT-55072=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=86=85=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9=E5=99=A8=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E5=8E=9F=E7=94=9F=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ifilechooser/JavaFxNativeFileChooser.java | 18 ------------------ 1 file changed, 18 deletions(-) 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 682d80fc6..b5fce35db 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 @@ -155,22 +155,4 @@ public class JavaFxNativeFileChooser implements FileChooserProvider { this.filters = builder.filters; this.currentDirectory = builder.currentDirectory; } - - public static void main(String[] args) { - - FileChooserProvider fileChooserProvider = - new Builder(). - fileSelectionMode(FileSelectionMode.DIR). - title("hhh"). - filters(new FileChooser.ExtensionFilter[]{ - new FileChooser.ExtensionFilter("TXT", "*.txt"), - new FileChooser.ExtensionFilter("PNG", "*.png")}). - currentDirectory(new File("D://")). - build(); - fileChooserProvider.showDialog(null); - System.out.println(fileChooserProvider.getSelectedFiles().length); - System.out.println(fileChooserProvider.getSelectedFile()); - } - - } \ No newline at end of file From d5b22898743c69c38e568a57525934393959e040 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Tue, 3 Aug 2021 18:02:01 +0800 Subject: [PATCH 4/7] =?UTF-8?q?REPORT-55060=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=94=AF=E6=8C=81=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/clipboard/ClipboardHelper.java | 24 ++ .../data/datapane/preview/CopyableJTable.java | 203 +++++++++++++++++ .../datapane/preview/PreviewTablePane.java | 3 +- .../cell/clipboard/CellElementsClip.java | 206 +++++++++--------- 4 files changed, 331 insertions(+), 105 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardHelper.java create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java diff --git a/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardHelper.java b/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardHelper.java new file mode 100644 index 000000000..870af0be5 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/base/clipboard/ClipboardHelper.java @@ -0,0 +1,24 @@ +package com.fr.design.base.clipboard; + +import java.util.List; + +public class ClipboardHelper { + public static String formatExcelString(List> table) { + StringBuffer stringBuffer = new StringBuffer(); + + for (int row = 0; row < table.size(); row++) { + List rowValue = table.get(row); + for (int col = 0; col < rowValue.size(); col++) { + Object cell = rowValue.get(col); + stringBuffer.append(cell); + if (col != rowValue.size() - 1) { + stringBuffer.append("\t"); + } + } + if (row != table.size() - 1) { + stringBuffer.append("\n"); + } + } + return stringBuffer.toString(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java new file mode 100644 index 000000000..38b5a08e4 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java @@ -0,0 +1,203 @@ +package com.fr.design.data.datapane.preview; + +import com.fr.design.base.clipboard.ClipboardHelper; +import com.fr.design.gui.itable.SortableJTable; +import com.fr.design.gui.itable.TableSorter; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.os.OperatingSystem; + +import javax.swing.table.TableCellRenderer; +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +public class CopyableJTable extends SortableJTable { + + //区域选中用到的定位数据 + public int startRow = -1; + public int startCol = -1; + public int endRow = -1; + public int endCol = -1; + //单元格不连续多选用到的定位数据 + java.util.List pointList = new ArrayList<>(); + //shift键是否被按下 + public boolean isShiftDown = false; + //control\command键是否被按下 + public boolean isControlDown = false; + //是否可以复制 + public boolean isCopy = true; + int ctrlKeyCode = 17; + int cKeyCode = 67; + int shiftKeyCode = 16; + int commandKeyCode = 157; + //选中单元格的背景色 + Color selectBackGround = new Color(54, 133, 242, 63); + + + public CopyableJTable(TableSorter tableModel) { + super(tableModel); + initListener(); + } + + private void initListener() { + CopyableJTable self = this; + this.addMouseMotionListener(new java.awt.event.MouseAdapter() { + @Override + public void mouseDragged(MouseEvent evt) { + int row = self.rowAtPoint(evt.getPoint()); + int col = self.columnAtPoint(evt.getPoint()); + if (self.updateEndPoint(row, col)) { + self.repaint(); + } + } + }); + this.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + int row = self.rowAtPoint(e.getPoint()); + int col = self.columnAtPoint(e.getPoint()); + if (!self.isControlDown) { + self.clearPoint(); + } + if (self.isShiftDown) { + self.clearPoint(); + } else { + self.updateStartPoint(row, col); + } + self.addPoint(row, col); + self.updateEndPoint(row, col); + + self.repaint(); + } + + }); + this.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (isControlKey(e)) { + isControlDown = true; + } else if (e.getKeyCode() == shiftKeyCode) { + isShiftDown = true; + } else if (e.getKeyCode() == cKeyCode) { + if (isControlDown && isCopy) { + self.copy(); + isCopy = false; + } + } + } + + @Override + public void keyReleased(KeyEvent e) { + if (isControlKey(e)) { + isControlDown = false; + isCopy = true; + } else if (e.getKeyCode() == shiftKeyCode) { + isShiftDown = false; + } + } + + private boolean isControlKey(KeyEvent e) { + if (e.getKeyCode() == ctrlKeyCode) { + return true; + } + if (e.getKeyCode() == commandKeyCode && OperatingSystem.isMacos()) { + return true; + } + return false; + } + }); + } + + + @Override + public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { + Component comp = super.prepareRenderer(renderer, row, column); + if (isChoose(row, column)) { + comp.setBackground(selectBackGround); + } else { + comp.setBackground(this.getBackground()); + } + return comp; + } + + + private boolean updateEndPoint(int row, int col) { + if (endRow != row || endCol != col) { + endRow = row; + endCol = col; + return true; + } + return false; + } + + private boolean updateStartPoint(int row, int col) { + if (startRow != row || startCol != col) { + startRow = row; + startCol = col; + return true; + } + return false; + } + + private void addPoint(int row, int col) { + pointList.add(new Point(row, col)); + } + + private void clearPoint() { + pointList = new ArrayList<>(); + } + + private void copy() { + FineLoggerFactory.getLogger().info("copy cell value"); + java.util.List> table = new ArrayList<>(); + if ((startRow != endRow || startCol != endCol) && + Math.min(startRow, endRow) > -1 && Math.min(startCol, endCol) > -1) { + for (int i = Math.min(startRow, endRow); i <= Math.max(startRow, endRow); i++) { + table.add(new ArrayList<>()); + for (int j = Math.min(startCol, endCol); j <= Math.max(startCol, endCol); j++) { + Object text = this.getValueAt(i, j); + table.get(i - Math.min(startRow, endRow)).add(text); + } + } + } else if (pointList.size() > 0) { + Collections.sort(pointList, Comparator.comparing(Point::getX).thenComparing(Point::getY)); + int startRow = pointList.get(0).x; + int currentRow = startRow; + table.add(new ArrayList<>()); + for (Point point : pointList) { + while (currentRow < point.x) { + table.add(new ArrayList<>()); + currentRow++; + } + Object text = this.getValueAt(point.x, point.y); + table.get(currentRow - startRow).add(text); + } + } + + Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable tText = new StringSelection(ClipboardHelper.formatExcelString(table)); + clip.setContents(tText, null); + } + + private boolean isChoose(int row, int col) { + if (row >= Math.min(startRow, endRow) && row <= Math.max(startRow, endRow)) { + if (col >= Math.min(startCol, endCol) && col <= Math.max(startCol, endCol)) { + return true; + } + } + for (Point point : pointList) { + if (point.x == row && point.y == col) { + return true; + } + } + return false; + } + +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java index e95a5999a..409ae7f7f 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java @@ -26,7 +26,6 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.ui.util.UIUtil; -import com.fr.design.utils.gui.GUICoreUtils; import com.fr.function.TIME; import com.fr.general.FRFont; import com.fr.log.FineLoggerFactory; @@ -162,7 +161,7 @@ public class PreviewTablePane extends BasicPane { } }); - preveiwTable = new SortableJTable(new TableSorter()); + preveiwTable = new CopyableJTable(new TableSorter()); preveiwTable.setRowSelectionAllowed(false); preveiwTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); diff --git a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java index 2767b1a8e..64bdb3365 100644 --- a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java +++ b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java @@ -3,6 +3,7 @@ */ package com.fr.design.cell.clipboard; +import com.fr.design.base.clipboard.ClipboardHelper; import com.fr.grid.selection.CellSelection; import com.fr.log.FineLoggerFactory; import com.fr.report.cell.CellElement; @@ -12,8 +13,10 @@ import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.StringUtils; import com.fr.stable.unit.FU; +import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; +import java.util.List; /** * The clip of CellElement. @@ -21,16 +24,16 @@ import java.util.Iterator; public class CellElementsClip implements Cloneable, java.io.Serializable { private int columnSpan = 0; private int rowSpan = 0; - private FU[] columnWidth; - private FU[] rowHeight; + private FU[] columnWidth; + private FU[] rowHeight; private TemplateCellElement[] clips; - public CellElementsClip(int columnSpan, int rowSpan, FU[] columnWidth , FU[] rowHeight, TemplateCellElement[] clips) { - this.columnSpan = columnSpan; - this.rowSpan = rowSpan; - this.columnWidth = columnWidth ; - this.rowHeight = rowHeight; - this.clips = clips; + public CellElementsClip(int columnSpan, int rowSpan, FU[] columnWidth, FU[] rowHeight, TemplateCellElement[] clips) { + this.columnSpan = columnSpan; + this.rowSpan = rowSpan; + this.columnWidth = columnWidth; + this.rowHeight = rowHeight; + this.clips = clips; } public CellElementsClip(int columnSpan, int rowSpan, TemplateCellElement[] clips) { @@ -39,122 +42,119 @@ public class CellElementsClip implements Cloneable, java.io.Serializable { this.clips = clips; } - public int getColumnSpan() { - return columnSpan; - } + public int getColumnSpan() { + return columnSpan; + } - public void setColumnSpan(int columnSpan) { - this.columnSpan = columnSpan; - } + public void setColumnSpan(int columnSpan) { + this.columnSpan = columnSpan; + } - public int getRowSpan() { - return rowSpan; - } + public int getRowSpan() { + return rowSpan; + } - public void setRowSpan(int rowSpan) { - this.rowSpan = rowSpan; - } + public void setRowSpan(int rowSpan) { + this.rowSpan = rowSpan; + } - public FU[] getColumnWidth() { - return columnWidth; - } + public FU[] getColumnWidth() { + return columnWidth; + } - public void setColumnWidth(FU[] columnWidth) { - this.columnWidth = columnWidth; - } + public void setColumnWidth(FU[] columnWidth) { + this.columnWidth = columnWidth; + } - public FU[] getRowHeight() { - return rowHeight; - } + public FU[] getRowHeight() { + return rowHeight; + } - public void setRowHeight(FU[] rowHeight) { - this.rowHeight = rowHeight; - } + public void setRowHeight(FU[] rowHeight) { + this.rowHeight = rowHeight; + } - public TemplateCellElement[] getClips() { - return clips; - } + public TemplateCellElement[] getClips() { + return clips; + } - public void setClips(TemplateCellElement[] clips) { - this.clips = clips; - } + public void setClips(TemplateCellElement[] clips) { + this.clips = clips; + } - public String compateExcelPaste() { - Arrays.sort(this.clips, CellElementComparator.getRowFirstComparator()); + public String compateExcelPaste() { + Arrays.sort(this.clips, CellElementComparator.getRowFirstComparator()); - // 排序 - StringBuffer sbuf = new StringBuffer(); + // 排序 - int currentRow = -1; - for (int i = 0; i < clips.length; i++) { - CellElement cellElement = clips[i]; - if (currentRow == -1) {// 初始化当前行. - currentRow = cellElement.getRow(); - } + List> table = new ArrayList<>(); + int startRow = -1; + int currentRow = -1; + for (int i = 0; i < clips.length; i++) { + CellElement cellElement = clips[i]; + if (currentRow == -1) {// 初始化当前行. + currentRow = cellElement.getRow(); + startRow = currentRow; + table.add(new ArrayList<>()); + } + + if (currentRow < cellElement.getRow()) { + for (int r = currentRow; r < cellElement.getRow(); r++) { + table.add(new ArrayList<>()); + } + currentRow = cellElement.getRow(); + } - if (currentRow < cellElement.getRow()) { - for (int r = currentRow; r < cellElement.getRow(); r++) { - sbuf.append('\n'); - } - currentRow = cellElement.getRow(); - } - // 添加分隔符号. - if (sbuf.length() > 0 && sbuf.charAt(sbuf.length() - 1) != '\n') { - sbuf.append('\t'); - } - //REPORT-5134:会复制出null - if (cellElement.getValue() == null) { - sbuf.append(StringUtils.EMPTY); - } else { - sbuf.append(cellElement.getValue()); - } - } + Object cellValue = cellElement.getValue() == null ? StringUtils.EMPTY : cellElement.getValue(); + table.get(currentRow - startRow).add(cellValue); + } - return sbuf.toString(); + return ClipboardHelper.formatExcelString(table); } + public CellSelection pasteAt(TemplateElementCase ec, int column, int row) { - Iterator cells = ec.intersect(column, row, columnSpan, rowSpan); - while (cells.hasNext()) { - TemplateCellElement cellElement = (TemplateCellElement)cells.next(); - ec.removeCellElement(cellElement); - } - for (int i = 0; i < clips.length; i++) { - TemplateCellElement cellElement; - try { - cellElement = (TemplateCellElement) clips[i].clone(); - } catch (CloneNotSupportedException e) { + Iterator cells = ec.intersect(column, row, columnSpan, rowSpan); + while (cells.hasNext()) { + TemplateCellElement cellElement = (TemplateCellElement) cells.next(); + ec.removeCellElement(cellElement); + } + for (int i = 0; i < clips.length; i++) { + TemplateCellElement cellElement; + try { + cellElement = (TemplateCellElement) clips[i].clone(); + } catch (CloneNotSupportedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); - return null; - } - - // peter:因为前面已经将这个位置的元素删除了,所以不需要override了. - ec.addCellElement((TemplateCellElement) cellElement.deriveCellElement( - column + cellElement.getColumn(), row + cellElement.getRow() - ), false); - } - //设置单元格的宽高 - if(this.columnWidth != null && this.rowHeight != null){ + return null; + } + + // peter:因为前面已经将这个位置的元素删除了,所以不需要override了. + ec.addCellElement((TemplateCellElement) cellElement.deriveCellElement( + column + cellElement.getColumn(), row + cellElement.getRow() + ), false); + } + //设置单元格的宽高 + if (this.columnWidth != null && this.rowHeight != null) { pasteWidthAndHeight(ec, column, row, columnSpan, rowSpan); } - return new CellSelection(column, row, columnSpan, rowSpan); + return new CellSelection(column, row, columnSpan, rowSpan); } - public void pasteWidthAndHeight(TemplateElementCase ec, int column, int row, int columnSpan, int rowSpan){ - for(int i = 0; i < columnSpan; i++){ - ec.setColumnWidth(column + i, columnWidth[i]); - } - for(int j = 0; j < rowSpan; j++){ - ec.setRowHeight(row + j, rowHeight[j]); - } - } + public void pasteWidthAndHeight(TemplateElementCase ec, int column, int row, int columnSpan, int rowSpan) { + for (int i = 0; i < columnSpan; i++) { + ec.setColumnWidth(column + i, columnWidth[i]); + } + for (int j = 0; j < rowSpan; j++) { + ec.setRowHeight(row + j, rowHeight[j]); + } + } public void pasteAtRegion(TemplateElementCase ec, - int startColumn, int startRow, - int column, int row, - int columnSpan, int rowSpan) { + int startColumn, int startRow, + int column, int row, + int columnSpan, int rowSpan) { for (int i = 0; i < clips.length; i++) { TemplateCellElement cellElement = clips[i]; @@ -173,14 +173,14 @@ public class CellElementsClip implements Cloneable, java.io.Serializable { * Clone. */ @Override - public Object clone() throws CloneNotSupportedException { + public Object clone() throws CloneNotSupportedException { CellElementsClip cloned = (CellElementsClip) super.clone(); if (this.clips != null) { - cloned.clips = new TemplateCellElement[this.clips.length]; - for (int i = 0; i < this.clips.length; i++) { - cloned.clips[i] = (TemplateCellElement)this.clips[i].clone(); - } + cloned.clips = new TemplateCellElement[this.clips.length]; + for (int i = 0; i < this.clips.length; i++) { + cloned.clips[i] = (TemplateCellElement) this.clips[i].clone(); + } } return cloned; From bd6817a9763ea8d3ddb261fcf89cff1953368b58 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Tue, 3 Aug 2021 18:54:45 +0800 Subject: [PATCH 5/7] =?UTF-8?q?REPORT-55060=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=94=AF=E6=8C=81=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/cell/clipboard/CellElementsClip.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java index 64bdb3365..c391429db 100644 --- a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java +++ b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java @@ -98,14 +98,11 @@ public class CellElementsClip implements Cloneable, java.io.Serializable { table.add(new ArrayList<>()); } - if (currentRow < cellElement.getRow()) { - for (int r = currentRow; r < cellElement.getRow(); r++) { - table.add(new ArrayList<>()); - } - currentRow = cellElement.getRow(); + while (currentRow()); + currentRow++; } - Object cellValue = cellElement.getValue() == null ? StringUtils.EMPTY : cellElement.getValue(); table.get(currentRow - startRow).add(cellValue); } From ebf44c29a8bf51664783a0aeab79bb890931d68e Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Tue, 3 Aug 2021 18:55:12 +0800 Subject: [PATCH 6/7] =?UTF-8?q?REPORT-55060=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=94=AF=E6=8C=81=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/cell/clipboard/CellElementsClip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java index c391429db..8bc66e172 100644 --- a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java +++ b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java @@ -98,7 +98,7 @@ public class CellElementsClip implements Cloneable, java.io.Serializable { table.add(new ArrayList<>()); } - while (currentRow()); currentRow++; } From 705d28949b76889f968ba65d27e90c0c117f3479 Mon Sep 17 00:00:00 2001 From: kuangshuai Date: Tue, 3 Aug 2021 21:43:31 +0800 Subject: [PATCH 7/7] =?UTF-8?q?REPORT-56080=20=E5=9B=BE=E8=A1=A8=E5=8F=8C?= =?UTF-8?q?=E5=87=BB=E6=97=A0=E6=B3=95=E8=BF=9B=E5=85=A5=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/designer/beans/models/SelectionModel.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index bf1c84990..df645e2df 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -85,13 +85,14 @@ public class SelectionModel { if (e.getButton() == MouseEvent.BUTTON3 || (!InputEventBaseOnOS.isControlDown(e) && !e.isShiftDown())) { // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 XCreator selectXCreator = selection.getSelectedCreator(); - if (selectXCreator != null && comp != null) { + boolean clickOnce = e.getClickCount() == 1; + boolean hasCom = selectXCreator != null && comp != null; + if (clickOnce && hasCom) { if (StringUtils.equals(selectXCreator.toData().getWidgetName(), comp.toData().getWidgetName())) { return; } } selection.reset(); - } else { //按下Ctrl或者shift键时鼠标可以进行多选,两次点击同一控件就取消选中 XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout();