From 2a119a4d8d6a71867edc027d913b7abc58efaf7e Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 8 Jul 2021 16:02:51 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-53175=E3=80=9010.0.18=E3=80=91=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E4=B8=BA=E6=A0=87?= =?UTF-8?q?=E9=A2=98/=E8=83=8C=E6=99=AF/=E8=BE=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把诸如是否已展示/是否已点击/上次选择的目录等设计器交互历史相关的需持久化数据 从ServerPreferenceConfig中抽离,放到单独的文件中存储,不要和服务器配置 数据混淆 --- .../env/utils/DesignerInteractionHistory.java | 148 ++++++++++++++++++ .../beans/location/AccessDirection.java | 31 ++-- .../gui/xpane/BorderLineAndImagePane.java | 16 +- .../main/java/com/fr/start/MainDesigner.java | 4 + 4 files changed, 181 insertions(+), 18 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/env/utils/DesignerInteractionHistory.java diff --git a/designer-base/src/main/java/com/fr/env/utils/DesignerInteractionHistory.java b/designer-base/src/main/java/com/fr/env/utils/DesignerInteractionHistory.java new file mode 100644 index 000000000..45cebca48 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/utils/DesignerInteractionHistory.java @@ -0,0 +1,148 @@ +package com.fr.env.utils; + +import com.fr.common.annotations.Compatible; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.EncodeConstants; +import com.fr.stable.ProductConstants; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLReadable; +import com.fr.stable.xml.XMLTools; +import com.fr.stable.xml.XMLWriter; +import com.fr.stable.xml.XMLableReader; +import com.fr.third.javax.xml.stream.XMLStreamException; + +import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; + +/** + * @author Starryi + * @version 10.0.18 + * Created by Starryi on 2021/7/7 + * 设计器访问和获取关键历史交互信息的持久化工具,该关键历史交互信息, + * 如用户是否点击过某按钮,是否查看过某弹窗信息,上次选择过的文件所在目录等 + */ +@Compatible +public class DesignerInteractionHistory implements XMLReadable, XMLWriter { + + private static final String FILE_NAME = "designer.ix.history.info"; + private static final String ROOT_TAG = "History"; + + private static DesignerInteractionHistory history; + public static DesignerInteractionHistory getInstance() { + if (history == null) { + history = new DesignerInteractionHistory(); + + readXMLFile(history, history.getHistoryFile()); + } + + return history; + } + + private File getHistoryFile() { + return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); + } + + private static void readXMLFile(XMLReadable xmlReadable, File xmlFile) { + if (xmlFile == null || !xmlFile.exists()) { + return; + } + String charset = EncodeConstants.ENCODING_UTF_8; + try { + String decodeContent = getFileContent(xmlFile); + InputStream xmlInputStream = new ByteArrayInputStream(decodeContent.getBytes(charset)); + InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset); + + XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader); + + if (xmlReader != null) { + xmlReader.readXMLObject(xmlReadable); + } + xmlInputStream.close(); + } catch (IOException | XMLStreamException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + + } + + private static String getFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException { + InputStream encodeInputStream = new FileInputStream(xmlFile); + return IOUtils.inputStream2String(encodeInputStream); + } + + private static void writeContentToFile(String fileContent, File file) { + try (FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8); + BufferedWriter bw = new BufferedWriter(osw)) { + bw.write(fileContent); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + public void saveXMLFile() { + File xmlFile = this.getHistoryFile(); + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + XMLTools.writeOutputStreamXML(this, out); + out.flush(); + out.close(); + String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); + writeContentToFile(fileContent, xmlFile); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + + private static final String HAS_SHOWN_SHIFT_DRAG_RESIZING_TOOLTIP = "hasShownShiftDragResizingTooltip"; + private static final String LAST_SELECTED_BORDER_IMAGE_DIR = "lastSelectedBorderImageDir"; + + // 是否已展示过按下Shift键可锁定比例拖拽尺寸的Tooltip + private boolean hasShownShiftDragResizingTooltip = false; + // 用户上次通过文件选择器选择的边框图片所在目录 + private String lastSelectedBorderImageDir = StringUtils.EMPTY; + + public boolean isHasShownShiftDragResizingTooltip() { + return hasShownShiftDragResizingTooltip; + } + + public void setHasShownShiftDragResizingTooltip(boolean shown) { + this.hasShownShiftDragResizingTooltip = shown; + } + + public String getLastSelectedBorderImageDir() { + return lastSelectedBorderImageDir; + } + + public void setLastSelectedBorderImageDir(String dirPath) { + this.lastSelectedBorderImageDir = dirPath; + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(ROOT_TAG) + .attr(HAS_SHOWN_SHIFT_DRAG_RESIZING_TOOLTIP, isHasShownShiftDragResizingTooltip()) + .attr(LAST_SELECTED_BORDER_IMAGE_DIR, getLastSelectedBorderImageDir()) + .end(); + } + + @Override + public void readXML(XMLableReader reader) { + setHasShownShiftDragResizingTooltip(reader.getAttrAsBoolean(HAS_SHOWN_SHIFT_DRAG_RESIZING_TOOLTIP, false)); + setLastSelectedBorderImageDir(reader.getAttrAsString(LAST_SELECTED_BORDER_IMAGE_DIR, StringUtils.EMPTY)); + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java b/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java index adb0c6017..eae04d998 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java @@ -3,17 +3,19 @@ */ package com.fr.design.designer.beans.location; -import com.fr.config.ServerPreferenceConfig; -import com.fr.config.utils.ConfigReadUtils; import com.fr.design.beans.location.Absorptionline; import com.fr.design.beans.location.MoveUtils; -import com.fr.design.designer.creator.*; +import com.fr.design.designer.creator.XCreatorUtils; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWAbsoluteLayout; +import com.fr.design.designer.creator.XWBorderLayout; +import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelection; import com.fr.design.utils.ComponentUtils; +import com.fr.env.utils.DesignerInteractionHistory; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; -import com.fr.form.ui.container.WParameterLayout; import java.awt.*; @@ -196,15 +198,24 @@ public abstract class AccessDirection implements Direction { // 设置当前形状 formEditor.setCursor(Cursor.getPredefinedCursor(type)); - FormSelection selection = formEditor.getSelectionModel().getSelection(); + // 显示/改变Tooltip + showTooltip(formEditor); + } + } + + private void showTooltip(FormDesigner formEditor) { + // 显示拖拽改变组件尺寸相关的提示信息 + int cursorType = formEditor.getCursor().getType(); + if (Cursor.SW_RESIZE_CURSOR <= cursorType && cursorType <= Cursor.E_RESIZE_CURSOR) { + FormSelection selection = formEditor.getSelectionModel().getSelection(); boolean canLockAspectRatioOnlyByShift = !selection.isCreatorAspectRatioLockedInAbsLayout(formEditor) && selection.isCreatorInAbsLayout(formEditor); - ServerPreferenceConfig config = ServerPreferenceConfig.getInstance(); - if (canLockAspectRatioOnlyByShift && !config.isHasShownLockedAspectRatioResizingToolTip()) { + DesignerInteractionHistory history = DesignerInteractionHistory.getInstance(); + if (canLockAspectRatioOnlyByShift && !history.isHasShownShiftDragResizingTooltip()) { formEditor.setToolTipText(getTooltip()); - config.setHasShownLockedAspectRatioResizingToolTip(true); + history.setHasShownShiftDragResizingTooltip(true); } - } - } + } + } public String getTooltip() { return null; diff --git a/designer-form/src/main/java/com/fr/design/gui/xpane/BorderLineAndImagePane.java b/designer-form/src/main/java/com/fr/design/gui/xpane/BorderLineAndImagePane.java index ca8b5abeb..9444ec1f8 100644 --- a/designer-form/src/main/java/com/fr/design/gui/xpane/BorderLineAndImagePane.java +++ b/designer-form/src/main/java/com/fr/design/gui/xpane/BorderLineAndImagePane.java @@ -5,7 +5,6 @@ import com.fr.base.Style; import com.fr.base.Utils; import com.fr.base.background.ImageBackground; import com.fr.base.background.ImageFileBackground; -import com.fr.config.ServerPreferenceConfig; import com.fr.design.border.UIRoundedBorder; import com.fr.design.constants.UIConstants; import com.fr.design.designer.IntervalConstants; @@ -27,6 +26,7 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.backgroundpane.ImagePreviewPane; import com.fr.design.style.background.image.ImageFileChooser; +import com.fr.env.utils.DesignerInteractionHistory; import com.fr.form.ui.LayoutBorderStyle; import com.fr.general.Background; import com.fr.general.IOUtils; @@ -179,14 +179,14 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { } private void initImageFileChooserDirectory() { - ServerPreferenceConfig config = ServerPreferenceConfig.getInstance(); - String lastUsedBorderImagesDirPath = config.getLastUsedBorderImagesDir(); - File lastUsedBorderImagesDir = StringUtils.isNotEmpty(lastUsedBorderImagesDirPath) ? new File(lastUsedBorderImagesDirPath) : null; + DesignerInteractionHistory history = DesignerInteractionHistory.getInstance(); + String lastUsedBorderImageDirPath = history.getLastSelectedBorderImageDir(); + File lastUsedBorderImageDir = StringUtils.isNotEmpty(lastUsedBorderImageDirPath) ? new File(lastUsedBorderImageDirPath) : null; File inbuiltBorderImagesDir = new File(StableUtils.pathJoin(ProjectLibrary.getInstance().getLibHome(), ProjectConstants.ASSETS_NAME, "border_images")); - if (lastUsedBorderImagesDir!= null && lastUsedBorderImagesDir.exists()) { - imageFileChooser.setCurrentDirectory(lastUsedBorderImagesDir); + if (lastUsedBorderImageDir!= null && lastUsedBorderImageDir.exists()) { + imageFileChooser.setCurrentDirectory(lastUsedBorderImageDir); } else if (inbuiltBorderImagesDir.exists()) { imageFileChooser.setCurrentDirectory(inbuiltBorderImagesDir); } @@ -232,9 +232,9 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver { int returnVal = imageFileChooser.showOpenDialog(DesignerContext.getDesignerFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { - ServerPreferenceConfig config = ServerPreferenceConfig.getInstance(); + DesignerInteractionHistory history = DesignerInteractionHistory.getInstance(); File selectedDirectory = imageFileChooser.getSelectedFile().getParentFile(); - config.setLastUsedBorderImagesDir(selectedDirectory.getPath()); + history.setLastSelectedBorderImageDir(selectedDirectory.getPath()); } ImgChooseWrapper.getInstance(imagePreviewPane, imageFileChooser, DEFAULT_IMAGE_LAYOUT_STYLE, new ChangeListener() { diff --git a/designer-realize/src/main/java/com/fr/start/MainDesigner.java b/designer-realize/src/main/java/com/fr/start/MainDesigner.java index 5c8c57987..dd49f1b1a 100644 --- a/designer-realize/src/main/java/com/fr/start/MainDesigner.java +++ b/designer-realize/src/main/java/com/fr/start/MainDesigner.java @@ -42,6 +42,7 @@ import com.fr.design.monitor.DesignerLifecycleMonitorContext; import com.fr.design.share.SharableManager; import com.fr.design.utils.concurrent.ThreadFactoryBuilder; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.env.utils.DesignerInteractionHistory; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; @@ -512,6 +513,9 @@ public class MainDesigner extends BaseDesigner { InformationCollector collector = InformationCollector.getInstance(); collector.collectStopTime(); collector.saveXMLFile(); + + DesignerInteractionHistory historyCollector = DesignerInteractionHistory.getInstance(); + historyCollector.saveXMLFile(); } }